123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../lib/@waca/core-client/js/core-client/ui/core/Class', '../../../lib/@waca/dashboard-common/dist/utils/ObjectHelper', 'jquery'], function (Class, ObjectHelper, $) {
- var DashboardController = Class.extend({
- init: function init(options) {
- DashboardController.inherited('init', this, arguments);
- this.view = options.view;
- this.glassContext = options.glassContext;
- this.eventRouter = options.eventRouter;
- this.services = options.services;
- this.widgetRegistry = options.widgetRegistry;
- this.featuresOverride = options.featuresOverride || {};
- this.FrozenWidgetRegistry = null;
- var _ref = options.appSettings || {},
- _ref$options = _ref.options;
- _ref$options = _ref$options === undefined ? {} : _ref$options;
- var _ref$options$collecti = _ref$options.collections,
- collections = _ref$options$collecti === undefined ? {} : _ref$options$collecti,
- _ref$options$config = _ref$options.config,
- config = _ref$options$config === undefined ? {} : _ref$options$config;
- this.collectionsConfig = collections;
- this.config = config;
- },
- createContent: function createContent(boardModel) {
- var options = {
- featureLoader: this.featureLoader,
- dashboardFeatures: this.featureLoader,
- boardModel: boardModel,
- type: 'dashboard'
- };
- var contentFactory = this.featureLoader.getFeature('ContentFactory');
- this._dashboardContent = contentFactory.createContent(options);
- return this._dashboardContent.initialize();
- },
- getFeature: function getFeature(name) {
- var feature = void 0;
- if (this.featureLoader) {
- feature = this.featureLoader.getFeature(name);
- }
- if (!feature) {
- try {
- feature = this.getDashboardCoreSvc(name);
- } catch (e) {
- // Ignore if getDashboardCoreSvc threw a missing feature error. getFeature should never throw a fault.
- // and won't once we clean up the old service stuff
- }
- }
- return feature;
- },
- setDirty: function setDirty(dirty) {
- // Sync dirty state to undoredo controller
- if (this.view.boardController && this.view.boardController.undoRedoController) {
- this.view.boardController.undoRedoController.setDirty(dirty);
- }
- this.view.trigger('change:dirty', {
- value: dirty
- });
- this.view.eventRouter.trigger('change:dirty', {
- value: dirty
- });
- },
- setServices: function setServices(services) {
- this.services = services;
- },
- setFeatureLoader: function setFeatureLoader(featureLoader) {
- this.featureLoader = featureLoader;
- },
- /**
- * Return the current content view
- */
- getCurrentContentView: function getCurrentContentView() {
- return this.view;
- },
- /**
- * Return the canvas API. This method might retrun null if the canvas is not ready yet
- */
- getCanvas: function getCanvas() {
- // The deprecated canvas contains all the deprecated api + the proper public apis
- return this.view.getDeprecatedCanvas();
- },
- /**
- * Return a promise that will be resolved with the canvas API
- */
- getCanvasWhenReady: function getCanvasWhenReady() {
- // The deprecated canvas contains all the deprecated api + the proper public apis
- return this.view.getDeprecatedCanvasWhenReady();
- },
- isDevInstall: function isDevInstall() {
- return this.glassContext.isDevInstall();
- },
- /**
- * Add a new widget to the canvas or new content to selected widgets
- *
- * @param {object} - options containing the widget to be added
- */
- addContentToCanvas: function addContentToCanvas(options) {
- this.view.boardController.addDataItemsOrAddWidget(options);
- },
- /**
- * Return the application name
- */
- getApplicationName: function getApplicationName() {
- return this.glassContext.appController.getCurrentPerspective();
- },
- /**
- * Return the localized application name
- */
- getApplicationLabel: function getApplicationLabel() {
- return this.view.getApplicationLabel();
- },
- /**
- * Reload the dashboard using a give json specified
- * @param {object} JSONSpec An object that represents a dashboard spec
- * @param {object} extOptions extra options to use when re-initializing BaseBoardView
- * @returns {Promise} The resolved object is the new dashboardApi instance from the reinitialization of the dashboad from the given spec
- */
- reloadFromJSONSpec: function reloadFromJSONSpec(JSONspec, extOptions) {
- return this.view.reloadFromJSONSpec(JSONspec, extOptions);
- },
- /**
- * Return the CDN url
- */
- getCDNUrl: function getCDNUrl() {
- return this.view.getCDNUrl();
- },
- /**
- * Get layout
- *
- * @param {string} id - layout id
- *
- * @return {Layout} layout
- *
- * @deprecated Use getCanvas().getLayout instead
- */
- getLayout: function getLayout(id) {
- return this.view.boardController.layoutController.getView(id);
- },
- /**
- * Glassify the options a.k.a - make an options object ready to be passed to a glass dependant component
- *
- * @param {object} options to be glassified.
- *
- */
- prepareGlassOptions: function prepareGlassOptions(options) {
- options.glassContext = this.glassContext;
- },
- /**
- * Open a glass application view
- *
- * @param {string} name - application anme
- * @param {object} options - application options.
- *
- */
- openGlassApplication: function openGlassApplication(name, options) {
- return this.glassContext.appController.openAppView(name, options);
- },
- /**
- * Close a glass application view
- *
- * @param {string} name - application name
- * @param {object} id - id of the application being closed.
- * @param {object} options - application options.
- *
- */
- closeGlassApplication: function closeGlassApplication(name, id, options) {
- return this.glassContext.appController.closeAppView(name, id, options);
- },
- /**
- * Return a collection config specified through the perspective
- * @param {string} name collection name
- * @return {object} config value
- */
- getCollectionConfig: function getCollectionConfig(name) {
- return this.collectionsConfig[name];
- },
- /**
- * Return a config specified through the perspective
- * @param {string} config name
- * @return {object} config value
- */
- getAppConfig: function getAppConfig(name) {
- return this.config[name];
- },
- /**
- * Return a dashboard service
- * @param {string} name service name
- * @return {Promise} - resolved with the service object
- */
- getDashboardSvc: function getDashboardSvc(name) {
- return this.services.getSvc(name);
- },
- /**
- * Register a dashboard service
- * @param {string} name service name
- * @param {Object} service service object
- *
- */
- registerDashboardSvc: function registerDashboardSvc(name, service) {
- return this.services.register(name, service);
- },
- /**
- * Return a dashboard core service
- * @param {string} name service name
- * @return {Object} - Service object
- */
- getDashboardCoreSvc: function getDashboardCoreSvc(name) {
- return this.services.getSvcSync(name);
- },
- /**
- * Return a glass service
- * @param {string} name service name
- * @return {Promise} - resolved with the service object
- */
- getGlassSvc: function getGlassSvc(name) {
- return this.glassContext.getSvc(name);
- },
- /**
- * Return a glass core service
- * @param {string} name service name
- * @return {Object} - Service object
- */
- getGlassCoreSvc: function getGlassCoreSvc(name) {
- return this.glassContext.getCoreSvc(name);
- },
- /**
- * Show an error message
- * @param {string} message
- * @param {string} title
- */
- showErrorMessage: function showErrorMessage(message, title) {
- return this.glassContext.appController.showErrorMessage(message, title);
- },
- /**
- * Show a message in the UI
- * @param {string} message
- */
- showMessage: function showMessage(message) {
- return this.glassContext.appController.showMessage(message);
- },
- /**
- * Show a toast message in the UI
- * @param {string} message
- * @param {object} options - toast options
- */
- showToast: function showToast(message, options) {
- return this.glassContext.appController.showToast(message, options);
- },
- /**
- * Show a glass slideout
- * @param {object} options - slideout options
- */
- showSlideOut: function showSlideOut(options) {
- return this.glassContext.appController.showSlideOut(options);
- },
- /**
- * Show a glass context menu
- * @param {object} options - context menu options
- */
- showContextMenu: function showContextMenu(options) {
- return this.glassContext.appController.showContextMenu(options);
- },
- /**
- * Find a glass plugin
- * @param {string} name - plugin name
- * @return {object} glass plugin object
- */
- findGlassPlugin: function findGlassPlugin(name) {
- return this.glassContext.appController.findPlugin(name);
- },
- /**
- * Find a glass collection
- * @param {string} name - plugin name
- * @return {Promise} promise resolved with the collection
- */
- findGlassCollection: function findGlassCollection(name) {
- var _this = this;
- return this.glassContext.appController.findCollection(name).then(function () {
- var collection = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- var featureOverride = _this.featuresOverride[name] || {};
- var excludes = featureOverride.excludes || [];
- return collection.filter(function (item) {
- return !(excludes.indexOf(item.name) !== -1);
- });
- });
- },
- /**
- * Open a glass app view
- * @param {string} name
- * @param {object} options
- */
- openAppView: function openAppView(name, options) {
- return this.glassContext.appController.openAppView(name, options);
- },
- /**
- * @deprecated Use getCanvas().getSelectedWidgets() instead
- */
- getSelectedWidgets: function getSelectedWidgets() {
- return this.view.getSelectedWidgets();
- },
- /**
- * Set the permissions on the dashboard
- * @param {object} permissions
- */
- setPermissions: function setPermissions(permissions) {
- this.view.setPermissions(permissions);
- },
- /**
- * Checks for write access to the dashboard
- */
- canAuthor: function canAuthor() {
- return this.view.canAuthor();
- },
- /**
- * Destroy the dashboard - clean up
- */
- destroy: function destroy() {
- DashboardController.inherited('init', this, arguments);
- if (this.services) {
- this.services.destroy();
- }
- if (this.featureLoader) {
- this.featureLoader.destroy();
- }
- if (this._dashboardContent) {
- this._dashboardContent.destroy();
- this._dashboardContent = null;
- }
- this.view = null;
- this.glassContext = null;
- this.eventRouter = null;
- this.services = null;
- this.collectionsConfig = null;
- this.config = null;
- this.widgetRegistry = null;
- this.services = null;
- this.featureLoader = null;
- },
- /**
- * Map between API event names and internal event names
- */
- eventMap: {
- dirty: 'change:dirty'
- },
- /**
- * Register an event handler for dashboard events
- * @param {string} eventName Name of the dashboard event
- * @param {function} handler Event handler to be called when the event occurrs
- */
- on: function on(eventName, callback, context) {
- if (!eventName) {
- return;
- }
- var name = this.eventMap[eventName] || eventName;
- return this.eventRouter.on(name, callback, context);
- },
- /**
- * Unregister an event handler for dashboard events
- * @param {string} eventName Name of the dashboard event
- * @param {function} handler Event handler to be called when the event occurrs
- */
- off: function off(eventName, callback, context) {
- if (!eventName) {
- return;
- }
- var name = this.eventMap[eventName] || eventName;
- this.eventRouter.off(name, callback, context);
- },
- /**
- * Trigger a dashboard event
- * @param {string} eventName Name of the dashboard event
- * @param {object} payload Event payload
- */
- triggerDashboardEvent: function triggerDashboardEvent(eventName, payload) {
- if (!eventName) {
- return;
- }
- var name = this.eventMap[eventName] || eventName;
- this.eventRouter.trigger(name, payload);
- },
- /**
- * Relink an existing source to a new module.
- * Widgets that reference this source will reload after the relink is finished.
- * @param {String} sourceInfo.id Id of the source to relink. This id is passed to the caller in the relink:clicked event
- * @param {String=} sourceInfo.cognosAssetId Cognos Content Story ID.
- * @param {String=} sourceInfo.module The module definition
- * @param {String=} sourceInfo.type The type of the source, only needed if using cognosAssetId and the type if the source is changing.
- * @param {String=} sourceInfo.name Name of the source, only needed if you wish to change the name.
- */
- relink: function relink() /*sourceInfo*/{
- // var dataSourcesSvc = this.services.getSvcSync('dataSources');
- // dataSourcesSvc.relink(this.oDataSource, oNewDataSourceObj);
- },
- /**
- * Change the mode between authoring, consumption and eventGroups
- * @param {string} mode
- */
- setMode: function setMode(mode) {
- var promise = void 0;
- var contentView = this.view;
- if (contentView) {
- if (mode === 'eventGroups' && !contentView.isEventGroupViewMode || mode !== 'eventGroups' && contentView.isEventGroupViewMode) {
- // toggle from/to 'eventGroup'
- promise = contentView.toggleEventGroupMode(mode);
- } else if (mode === 'authoring' && !contentView.isAuthoringMode || mode === 'consumption' && contentView.isAuthoringMode) {
- promise = contentView.toggleMode();
- }
- // Ensure the properties pane is closed in eventGroup or consumption mode
- if (contentView.isEventGroupViewMode || !contentView.isAuthoringMode) {
- this.toggleProperties(false);
- }
- }
- return promise || Promise.reject(new Error('Cannot set mode without a content view'));
- },
- getMode: function getMode() {
- var contentView = this.view;
- if (contentView) {
- return contentView.isEventGroupViewMode ? 'eventGroups' : contentView.isAuthoringMode ? 'authoring' : 'consumption';
- }
- },
- /**
- * Get the dashboard instance specification
- * @return {Object} dashboard spec
- */
- getSpec: function getSpec() {
- var contentView = this.view;
- if (contentView && contentView.getContent) {
- var content = contentView.getContent();
- return content.boardSpec;
- }
- },
- /**
- * Undo the last action performed on the dashboard
- */
- undo: function undo() {
- var contentView = this.view;
- if (contentView) {
- contentView.doUndo();
- }
- },
- /**
- * Reverse the last undo performed on the dashboard
- */
- redo: function redo() {
- var contentView = this.view;
- if (contentView) {
- contentView.doRedo();
- }
- },
- /**
- * Toggle the properties pane
- * @param {boolean} [toggle] if <tt>true</tt> display the properties pane, otherwise hide the properties pane.
- * @param {Object} [context] Optional context for toggling properties pane
- */
- toggleProperties: function toggleProperties(toggle, context) {
- var contentView = this.view;
- if (contentView) {
- var controller = contentView.boardController;
- var dashboardAuthoringToolsPane = contentView.dashboardApi.getFeature('InAppSlideoutState');
- var propertiesManager = controller.getExtension('propertiesManager');
- var selectTab = function selectTab() {
- propertiesManager.getPropertyControl('tabControl').selectTabByName(context.tabName);
- };
- // in case an invalid toggle state (non-boolean) is given, simply toggle the state
- if (typeof toggle !== 'boolean') {
- toggle = !propertiesManager.isSlideoutOpen();
- }
- // Properties pane is always off on event group and consumption mode
- toggle = contentView.isEventGroupViewMode || !contentView.isAuthoringMode ? false : toggle;
- context = context || {};
- // close the pane when in non authoring (consumption and fullscreen) and event group mode
- if (contentView.isEventGroupViewMode || !contentView.isAuthoringMode) {
- dashboardAuthoringToolsPane && dashboardAuthoringToolsPane.close();
- }
- //TODO: remove the following block when the focus mode epic is ready
- if (propertiesManager.isSlideoutOpen()) {
- if (!toggle) {
- propertiesManager.hide();
- } else if (context.tabName) {
- selectTab();
- }
- } else if (toggle && !propertiesManager.isSlideoutOpen()) {
- propertiesManager.show({
- 'context': context,
- 'onSetFocus': context.tabName ? selectTab : null
- });
- }
- }
- },
- /**
- * @returns an object containing dashboard information (isDirty, dashboard id and dashboard search path)
- */
- getDashboardInfo: function getDashboardInfo() {
- return this.view.getBoardInfo();
- },
- /**
- * Select widget
- *
- * @param {string} widgetId - widget id to select
- */
- selectWidget: function selectWidget(widgetId) {
- var _view$boardController = this.view.boardController;
- _view$boardController = _view$boardController === undefined ? {} : _view$boardController;
- var layoutController = _view$boardController.layoutController;
- if (layoutController) {
- return layoutController.getInteractionController().then(function (controller) {
- var widgetEl = $('#' + widgetId).get(0);
- controller.selectionHandler.selectNode(widgetEl);
- });
- }
- return Promise.reject(new Error('Unable to select widget. Canvas not fully initialized.'));
- },
- deselectAllWidgets: function deselectAllWidgets() {
- var _view$boardController2 = this.view.boardController;
- _view$boardController2 = _view$boardController2 === undefined ? {} : _view$boardController2;
- var layoutController = _view$boardController2.layoutController;
- if (layoutController) {
- return layoutController.getInteractionController().then(function (controller) {
- controller.selectionHandler.deselectAll();
- });
- }
- return Promise.resolve();
- },
- getToolbarActions: function getToolbarActions() {
- var toolbarItems = this.view.boardController && this.view.boardController.layoutController && this.view.boardController.layoutController.interactionController && this.view.boardController.layoutController.interactionController.toolbarItems;
- return toolbarItems;
- },
- /**
- * Waits till all widgets in input list are rendered
- *
- * @param {string[]} widgetIds
- * @param {Promise} number of widgets rendered
- */
- waitTillWidgetsRendered: function waitTillWidgetsRendered(widgetIds) {
- if (!widgetIds || widgetIds.length === 0) {
- return Promise.resolve(0);
- }
- return this.getCanvasWhenReady().then(function (canvas) {
- var promises = [];
- var renderCount = 0;
- widgetIds.forEach(function (widgetId) {
- var prom = canvas.getWidgetWhenReady(widgetId);
- promises.push(prom);
- });
- return Promise.all(promises).then(function (widgetApis) {
- var renderPromises = [];
- widgetApis.forEach(function (widgetApi) {
- var prom2 = widgetApi.whenRenderComplete().then(function () {
- renderCount++;
- });
- renderPromises.push(prom2);
- });
- return Promise.all(renderPromises).then(function () {
- return renderCount;
- });
- });
- });
- },
- /**
- * get live widget registry
- *
- * @return a copy of live widget registry
- */
- getWidgetRegistry: function getWidgetRegistry() {
- if (!this.FrozenWidgetRegistry) {
- this.FrozenWidgetRegistry = ObjectHelper.deepFreezeObject(JSON.parse(JSON.stringify(this.widgetRegistry)));
- }
- return this.FrozenWidgetRegistry;
- },
- /**
- * Copy the selected widget(s) on the dashboard
- */
- copy: function copy() {
- var contentView = this.view;
- if (contentView) {
- contentView.doCopy();
- }
- },
- /**
- * Paste the selected widget(s) on the dashboard
- */
- paste: function paste() {
- var contentView = this.view;
- if (contentView) {
- return contentView.doPaste();
- }
- return Promise.reject();
- },
- getContent: function getContent() {
- return this._dashboardContent && this._dashboardContent.getAPI();
- }
- });
- return DashboardController;
- });
- //# sourceMappingURL=DashboardController.js.map
|