StoryView.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Storytelling
  5. * (C) Copyright IBM Corp. 2015, 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['gemini/dashboard/glass/BaseBoardView', 'jquery', '../nls/StringResources', '../views/TimelinePlayerView', '../views/StoryNavControl', '../views/MouseOverArea', 'gemini/lib/@waca/dashboard-common/dist/ui/CenterLoadingSpinner', 'react-dom', '../api/impl/StoryAPIImpl', '../api/impl/TimelineAPIImpl', 'gemini/app/util/ErrorUtils', './InlineContributions', './controllers/StoryPrint'], function (BaseBoardView, $, StorytellingResources, TimelinePlayerView, StoryNavControl, MouseOverArea, CenterLoadingSpinner, ReactDom, StoryAPIImpl, TimelineAPIImpl, ErrorUtils, InlineContributions, StoryPrint) {
  9. var StoryView = BaseBoardView.extend({
  10. initialize: function initialize(options) {
  11. StoryView.inherited('initialize', this, arguments);
  12. this.dashboard = this.getDashboardApi();
  13. this.navControl = null;
  14. this.inlineContributions = options.inlineContributions || InlineContributions;
  15. // register our string resource, top priority
  16. this.stringService.register(StorytellingResources, 1);
  17. this.timelinePlayerView = null;
  18. // these params are from shareable URL
  19. this.sceneId = options.sceneId;
  20. this.sceneTime = parseInt(options.sceneTime, 10) || undefined;
  21. this.eventRouter.on('navigation:started', this._onNavigationStarted, this);
  22. this.eventRouter.on('navigation:complete', this._onNavigationComplete, this);
  23. },
  24. /**
  25. * Glass will call this method to get the type which, in turn, be used to match storytelling share action handler.
  26. * In <i>perspectives/common/story.json</i>, the shared feature types should contain this type.
  27. * @override
  28. */
  29. getType: function getType() {
  30. return 'storytelling';
  31. },
  32. getApplicationLabel: function getApplicationLabel() {
  33. return this.stringService.get('story');
  34. },
  35. /**
  36. * overridden from dashboard-core to pass desired shareable URL parameters to 'appSettings'
  37. * @override
  38. */
  39. getContent: function getContent() {
  40. var state = StoryView.inherited('getContent', this, arguments);
  41. state.sceneId = this.sceneId || null;
  42. return state;
  43. },
  44. render: function render() {
  45. var _this = this,
  46. _arguments = arguments;
  47. ReactDom.render(CenterLoadingSpinner({ variant: 'circle', size: 'normal' }), this.$el[0]);
  48. return this._addInlineContribToCollections().then(function () {
  49. return StoryView.inherited('render', _this, _arguments);
  50. }).then(function () {
  51. var dashboardState = _this.dashboard.getFeature('DashboardState');
  52. dashboardState.onUiStateChange(_this._onStateChange.bind(_this));
  53. _this.$content.on('click', '>.page', _this._onContentClick.bind(_this));
  54. _this.eventRouter.on('navigation:change', _this.onNavigationChange, _this);
  55. _this.boardController.layoutController.getTopLayoutViewWhenReady().then(function () {
  56. _this.storyPaneController.onStoryLayoutReady(_this.sceneId, _this.sceneTime);
  57. });
  58. var printFeature = _this.dashboard.getFeature('Print');
  59. var storyPrint = new StoryPrint().getAPI();
  60. printFeature.registerContent('slideshow', storyPrint);
  61. printFeature.registerContent('panAndZoom1', storyPrint);
  62. printFeature.registerContent('panAndZoom2', storyPrint);
  63. printFeature.registerContent('panAndZoom3', storyPrint);
  64. printFeature.registerContent('panAndZoom4', storyPrint);
  65. printFeature.registerContent('panAndZoom5', storyPrint);
  66. printFeature.registerContent('panAndZoom6', storyPrint);
  67. _this._appendTimelinePlayerView();
  68. });
  69. },
  70. _onStateChange: function _onStateChange(state) {
  71. if (state.fullScreen === this.oldFullScreenState) {
  72. return;
  73. }
  74. if (state.fullScreen) {
  75. this.setupFullScreenControls();
  76. } else if (!state.fullScreen) {
  77. this.teardownFullScreenControls();
  78. }
  79. this.oldFullScreenState = state.fullScreen;
  80. },
  81. _addInlineContribToCollections: function _addInlineContribToCollections() {
  82. var _this2 = this;
  83. return Promise.all(this.inlineContributions.map(function (contribution) {
  84. return _this2.options.glassContext.appController.findCollection(contribution.containerId).then(function (collection) {
  85. if (collection) {
  86. if (collection.filter(function (e) {
  87. return e.id === contribution.id;
  88. }).length) {
  89. // when we get this message we should remove it from inline contributions.
  90. console.warn('WARNING: storytelling contribution already exists in collection id =', contribution.id);
  91. } else {
  92. console.log('adding contribution ' + contribution.id + ' to collection ' + contribution.containerId);
  93. collection.push(contribution);
  94. }
  95. } else {
  96. console.error('ERROR: not adding contribution to non-existent collection. id =', contribution.containerId);
  97. }
  98. });
  99. }));
  100. },
  101. remove: function remove() {
  102. if (this.storyPaneController) {
  103. this.storyPaneController.destroy();
  104. this.storyPaneController = null;
  105. }
  106. if (this._timelineController) {
  107. this._timelineController.destroy();
  108. this._timelineController = null;
  109. }
  110. if (this.mouseOverArea) {
  111. this.mouseOverArea.remove();
  112. this.mouseOverArea = null;
  113. }
  114. if (this.navControl) {
  115. this.navControl.destroy();
  116. this.navControl = null;
  117. }
  118. if (this.eventRouter) {
  119. this.eventRouter.off('navigation:change', this.onNavigationChange, this);
  120. this.eventRouter.off('navigation:started', this._onNavigationStarted, this);
  121. this.eventRouter.off('navigation:complete', this._onNavigationComplete, this);
  122. }
  123. StoryView.inherited('remove', this, arguments);
  124. },
  125. getSplitterState: function getSplitterState() {
  126. return this.isAuthorMode() ? 'open' : 'close';
  127. },
  128. onCanvasReady: function onCanvasReady() {
  129. this._setupControllers(this.options);
  130. },
  131. deactivate: function deactivate() {
  132. if (this.storyPaneController) {
  133. this.storyPaneController.pause();
  134. }
  135. return StoryView.inherited('deactivate', this, arguments);
  136. },
  137. onNavigationChange: function onNavigationChange(evt) {
  138. this.boardModel.updateLayoutType(evt);
  139. },
  140. _onNavigationStarted: function _onNavigationStarted() {
  141. this.$content.toggleClass('animating', true);
  142. },
  143. _onNavigationComplete: function _onNavigationComplete() {
  144. this.$content.toggleClass('animating', false);
  145. },
  146. setupFullScreenControls: function setupFullScreenControls() {
  147. StoryView.inherited('setupFullScreenControls', this, arguments);
  148. this.$el.addClass('disableScroll');
  149. this.timelinePlayerView.toggleFullscreenControls(true);
  150. var el = $('<div />').addClass('storyNavControlContainer').appendTo(this.$el.parent());
  151. this.navControl = new StoryNavControl({
  152. el: el,
  153. subview: this.timelinePlayerView,
  154. startHidden: true,
  155. autohide: 4000
  156. });
  157. this._buildMouseOverArea();
  158. return this.navControl.render().then(function () {
  159. this.eventRouter.trigger('filterDock:disable');
  160. this.storyPaneController.didEnterFullScreen();
  161. this._showNavControl({ delay: 1000 });
  162. }.bind(this));
  163. },
  164. _buildMouseOverArea: function _buildMouseOverArea() {
  165. var el = $('<div />').addClass('mouseOverArea').prependTo(this.$el.parent());
  166. this.mouseOverArea = new MouseOverArea({
  167. el: el,
  168. onActivate: this._showNavControl.bind(this)
  169. });
  170. },
  171. teardownFullScreenControls: function teardownFullScreenControls() {
  172. if (!this.navControl) {
  173. return Promise.resolve();
  174. }
  175. this.storyPaneController.didExitFullScreen();
  176. this.$el.removeClass('disableScroll');
  177. this.navControl.subview = null;
  178. this.timelinePlayerView.$el.appendTo(this.$el).show();
  179. this.timelinePlayerView.toggleFullscreenControls(false);
  180. if (this.mouseOverArea) {
  181. this.mouseOverArea.remove();
  182. this.mouseOverArea = null;
  183. }
  184. if (!this.storyPaneController.isOverview()) {
  185. this.eventRouter.trigger('filterDock:enable');
  186. }
  187. return this.navControl.destroy().then(function () {
  188. this.navControl = null;
  189. StoryView.inherited('teardownFullScreenControls', this, arguments);
  190. }.bind(this));
  191. },
  192. _setupControllers: function _setupControllers(options) {
  193. var dashboardApi = this.getDashboardApi();
  194. this._timelineController = new TimelineAPIImpl({
  195. canvasController: this.boardLoader.canvasController,
  196. dashboardApi: dashboardApi,
  197. eventRouter: this.eventRouter,
  198. model: this.boardModel,
  199. authoring: options.isAuthoringMode,
  200. services: this.services
  201. });
  202. this.storyPaneController = new StoryAPIImpl({
  203. eventRouter: this.eventRouter,
  204. model: this.boardModel,
  205. authoring: options.isAuthoringMode,
  206. timelineController: this._timelineController,
  207. dashboardApi: dashboardApi
  208. });
  209. // TODO this is deprecated from dashboard API
  210. // and the parameters we need do not allow for it to be a contribution
  211. dashboardApi.registerDashboardSvc('.StoryPaneService', this.storyPaneController);
  212. this._storyApi = this.storyPaneController.getAPI();
  213. },
  214. _appendTimelinePlayerView: function _appendTimelinePlayerView() {
  215. var _this3 = this;
  216. if (!this.timelinePlayerView) {
  217. this.getDashboardApi().getDashboardSvc('.StoryPaneService').then(function (storyPaneController) {
  218. _this3.timelinePlayerView = new TimelinePlayerView({
  219. controller: storyPaneController,
  220. dashboardApi: _this3.getDashboardApi(),
  221. glassContext: _this3.options.glassContext,
  222. services: _this3.services
  223. });
  224. _this3.$el.append(_this3.timelinePlayerView.$el);
  225. _this3.timelinePlayerView.render();
  226. _this3.lifeCycleManager.registerLifeCycleHandler('post:dashboard.focus', _this3.timelinePlayerView.onSmallScreenUpdate.bind(_this3.timelinePlayerView));
  227. });
  228. }
  229. },
  230. getIconTooltip: function getIconTooltip() {
  231. // this.stringService comes from the BaseClass (BaseBoardView)
  232. return this.stringService.get('story');
  233. },
  234. getIcon: function getIcon() {
  235. return 'common-catalog';
  236. },
  237. _onContentClick: function _onContentClick(event) {
  238. if (!this.isAuthoringMode && !$(event.target).parentsUntil(event.currentTarget, '.widget').length) {
  239. this._showNavControl();
  240. this.eventRouter.trigger('playback:togglePlayPause');
  241. }
  242. },
  243. _processKeyDown: function _processKeyDown(e) {
  244. StoryView.inherited('_processKeyDown', this, arguments);
  245. var preventDefault = e.isDefaultPrevented && e.isDefaultPrevented() || false;
  246. if ((this.isPressed(37) || this.isPressed(38)) && !this.isAuthoringMode && !preventDefault) {
  247. this.eventRouter.trigger('playback:prev');
  248. } else if ((this.isPressed(39) || this.isPressed(40)) && !this.isAuthoringMode && !preventDefault) {
  249. this.eventRouter.trigger('playback:next');
  250. } else if (this.isPressed(32) && !$(e.target).is(':tabbable') && !preventDefault) {
  251. this._showNavControl();
  252. this.eventRouter.trigger('playback:togglePlayPause');
  253. }
  254. },
  255. _showNavControl: function _showNavControl(options) {
  256. if (this.navControl) {
  257. // navControl only exist in fullscreen
  258. this.navControl.show(options);
  259. }
  260. },
  261. // LEAVE BLANK
  262. // This method overrides a dashboard specific case that we in storytelling
  263. // don't want to run
  264. addFullScreenControl: function addFullScreenControl() {},
  265. getStoryAPI: function getStoryAPI() {
  266. return this._storyApi;
  267. },
  268. hasAuthoringCapability: function hasAuthoringCapability() {
  269. return ErrorUtils.hasCapability(this.glassContext, 'canAuthorDashboard');
  270. },
  271. shouldShowCloseConfirmationDialog: function shouldShowCloseConfirmationDialog() {
  272. return this.isDirty() && this.hasAuthoringCapability();
  273. }
  274. });
  275. return StoryView;
  276. });
  277. //# sourceMappingURL=StoryView.js.map