123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Storytelling (C) Copyright IBM Corp. 2014, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['baglass/core-client/js/core-client/ui/core/Class'], function (Class) {
- var NavigationController = Class.extend({
- /**
- * @param {Object} options A normal object of properties
- * @param {Object} options.transitionController An instance of a class whose base class is a TransitionController
- * @param {Object} options.sceneLoader An instance of the SceneLoader class
- * @param {Object} options.logger The logging class
- * @param {Object} options.sceneLayoutApi The SceneLayout API
- *
- * @see TransitionController.js
- * @see SceneLoader.js
- * @see SceneLayout.js
- */
- init: function init(options) {
- NavigationController.inherited('init', this, arguments);
- this._transitionController = options.transitionController;
- this._sceneLoader = options.sceneLoader;
- this.logger = options.logger;
- this.sceneLayoutApi = options.sceneLayoutApi; // Required
- this.inProgress = false;
- },
- /**
- * @param {Object} options
- * @param {Number} options.index (Deprecated) This value is still used by StoryPaneController but should be avoided for new uses
- * @param {String} options.modelId This is the layout model id and should be used over an index value
- * @param {Function} [options.onTargetSelected] An optional function that, when provided, will trigger a 'navigation:started' event
- * @param {Function} [options.refreshData] An optional parameter that, when provided, will trigger a refresh of all the story data widgets
- */
- jumpTo: function jumpTo(options) {
- var _this = this;
- if (this.inProgress) {
- return Promise.reject();
- }
- this.inProgress = true;
- // TODO: Update StoryPaneController to use sceneIds instead of index values
- var targetSceneByIndex = this.sceneLayoutApi.getSceneByIndex(options.index);
- var targetScene = targetSceneByIndex || this.sceneLayoutApi.getSceneById(options.modelId);
- var currentScene = this.sceneLayoutApi.getCurrentScene() || targetScene;
- var onDeck = this.sceneLayoutApi.getAdjacentScenes(targetScene).concat([targetScene]);
- var offDeck = this.sceneLayoutApi.getAdjacentScenes(currentScene).concat([currentScene]);
- return this._sceneLoader.waitForSceneToLoad(targetScene, options).then(function () {
- // start pre-loading of the next scenes.
- _this._sceneLoader.startBackgroundLoad(_this._generateShiftedSceneArray(targetScene), options);
- _this._transitionController.deckScenes(onDeck);
- _this._updateSelection(currentScene, targetScene);
- if (options && options.onTargetSelected) {
- options.onTargetSelected({
- scene: targetScene,
- play: options.play
- });
- }
- return _this._transitionController.jumpTo(currentScene, targetScene);
- }).then(function (result) {
- _this._transitionController.undeckScenes(offDeck);
- _this.inProgress = false;
- return {
- scene: targetScene,
- overview: result.overview
- };
- }).catch(function (error) {
- _this.logger.error('NavigationController.jumpTo()', error);
- _this.inProgress = false;
- return Promise.reject();
- });
- },
- nextPage: function nextPage(options) {
- var _this2 = this;
- if (this.inProgress) {
- return Promise.reject();
- }
- this.inProgress = true;
- var targetScene = this.sceneLayoutApi.getSceneByIndex(options.to) || this.sceneLayoutApi.getNextScene();
- var currentScene = this.sceneLayoutApi.getCurrentScene() || targetScene;
- var onDeck = this.sceneLayoutApi.getAdjacentScenes(targetScene).concat([targetScene]);
- var offDeck = this.sceneLayoutApi.getAdjacentScenes(currentScene).concat([currentScene]);
- return this._sceneLoader.waitForSceneToLoad(targetScene, options).then(function () {
- if (options.refreshData) {
- _this2._sceneLoader.startBackgroundLoad(_this2._generateShiftedSceneArray(targetScene), options);
- }
- _this2._transitionController.deckScenes(onDeck);
- _this2._updateSelection(currentScene, targetScene);
- if (options && options.onTargetSelected) {
- options.onTargetSelected({ scene: targetScene });
- }
- return _this2._transitionController.forward(currentScene, targetScene);
- }).then(function (result) {
- _this2._transitionController.undeckScenes(offDeck);
- _this2.inProgress = false;
- return {
- scene: targetScene,
- overview: result.overview
- };
- }).catch(function (error) {
- _this2.logger.error('NavigationController.nextPage()', error);
- _this2.inProgress = false;
- return Promise.reject();
- });
- },
- previousPage: function previousPage(options) {
- var _this3 = this;
- if (this.inProgress) {
- return Promise.reject();
- }
- this.inProgress = true;
- var targetScene = this.sceneLayoutApi.getSceneByIndex(options.to) || this.sceneLayoutApi.getPreviousScene();
- var currentScene = this.sceneLayoutApi.getCurrentScene() || targetScene;
- var onDeck = this.sceneLayoutApi.getAdjacentScenes(targetScene).concat([targetScene]);
- var offDeck = this.sceneLayoutApi.getAdjacentScenes(currentScene).concat([currentScene]);
- return this._sceneLoader.waitForSceneToLoad(targetScene, options).then(function () {
- if (options.refreshData) {
- _this3._sceneLoader.startBackgroundLoad(_this3._generateShiftedSceneArray(targetScene), options);
- }
- _this3._transitionController.deckScenes(onDeck);
- _this3._updateSelection(currentScene, targetScene);
- if (options && options.onTargetSelected) {
- options.onTargetSelected({ scene: targetScene });
- }
- return _this3._transitionController.backward(currentScene, targetScene);
- }).then(function (result) {
- _this3._transitionController.undeckScenes(offDeck);
- _this3.inProgress = false;
- return {
- scene: targetScene,
- overview: result.overview
- };
- }).catch(function (error) {
- _this3.logger.error('NavigationController.previousPage()', error);
- _this3.inProgress = false;
- return Promise.reject();
- });
- },
- /**
- * FIXME: This method should probably be within SceneLayout.js / part of the SceneLayout API
- */
- _updateSelection: function _updateSelection(from, to) {
- from.$el.removeClass('selected');
- to.$el.addClass('selected');
- },
- /**
- * Create a new ordered array of all scenes in sequential order starting from the provided scene
- * Example:
- * array = [1, 2, 3, 4, 5, 6]
- * currentIndex = 2 (value of 3)
- * newArray = [3, 4, 5, 6, 1]
- *
- * @param {Object} scene The scene to use as the starting scene of the new array
- */
- _generateShiftedSceneArray: function _generateShiftedSceneArray(scene) {
- var _inRange = function _inRange(value, array) {
- return value >= 0 && value < array.length;
- };
- var firstScene = this.sceneLayoutApi.getNextScene(scene);
- var scenes = this.sceneLayoutApi.getScenes();
- var index = this.sceneLayoutApi.getSceneIndex(firstScene);
- index = _inRange(index, scenes) ? index : 0;
- var orderedScenes = [];
- for (var i = 0; i < scenes.length; i++) {
- var _scene = scenes[(i + index) % scenes.length];
- orderedScenes.push(_scene);
- }
- if (orderedScenes[orderedScenes.length - 1].id === scene.id) {
- orderedScenes.pop();
- }
- return orderedScenes;
- },
- /**
- * Used when a story type (like Slideshow) has multiples transition types
- */
- setTransitionController: function setTransitionController(transitionController) {
- delete this._transitionController;
- this._transitionController = transitionController;
- }
- });
- return NavigationController;
- });
- //# sourceMappingURL=NavigationController.js.map
|