123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (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(['../modelapis/SourcesCollectionAPI', '../modelapis/modelmanagers/EmbeddedModuleManager', '../models/DataSourcesModel', '../utils/RelinkUtils'], function (SourcesCollectionAPI, EmbeddedModuleManager, DataSourcesModel, RelinkUtils) {
- 'use strict';
- var DataSourcesService = function () {
- function DataSourcesService(options) {
- _classCallCheck(this, DataSourcesService);
- this.dashboardApi = options.features['API'];
- this.logger = options.features['Logger'];
- if (options.features['internal']) {
- this.boardModel = options.features['internal'].getBoardModel();
- }
- }
- DataSourcesService.prototype.destroy = function destroy() {
- if (this._sourcesCollectionAPI) {
- this._sourcesCollectionAPI.destroy();
- }
- };
- DataSourcesService.prototype.getAPI = function getAPI() {
- return this;
- };
- //turn off Empty Block warning
- DataSourcesService.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() {
- var _this = this;
- return [{
- name: 'pre:widget.maximize',
- action: function action(payload) {
- if (!payload || !payload.id) {
- // no payload and/or no modelId, do nothing...
- } else {
- try {
- _this._handleExpandWidget();
- } catch (e) {
- _this.logger.error(e);
- }
- }
- }
- }];
- };
- DataSourcesService.prototype._handleExpandWidget = function _handleExpandWidget() {
- var plugin = this.dashboardApi.findGlassPlugin('com.ibm.bi.dashboard.dataSources.sourcesBtn');
- if (plugin === undefined) {
- this.logger.warn('datasource panel is not available');
- } else {
- if (plugin.isVisible() && !plugin.isPressed()) {
- plugin.triggerOnPress();
- }
- }
- };
- /**
- * @description Get the wrapper API object for an embedded moser module object. And register the usage of `sourceId`
- * when the `widget` is not a preview widget
- * @param {String} sourceId The id internal to the spec
- * @param {String} referenceId The id of the widget that uses the module. It's optional
- * @return {Promise} promise that will resolve with the moser API object or null if the source can't be found
- */
- DataSourcesService.prototype.getModule = function getModule(sourceId) {
- var sourcesCollection = this.getSourcesCollection();
- var sourceAPI = sourcesCollection.getSource(sourceId);
- if (!sourceAPI) {
- return Promise.resolve();
- }
- return sourceAPI.getModule();
- };
- DataSourcesService.prototype._initializeSourcesCollection = function _initializeSourcesCollection(dataSources) {
- if (dataSources) {
- this.sourcesCollection = dataSources.get('sources');
- this._sourcesCollectionAPI = new SourcesCollectionAPI({
- sourcesCollection: this.sourcesCollection,
- dashboardApi: this.dashboardApi
- });
- } else {
- this.logger.error('No sources in the board model.', this, dataSources);
- }
- };
- /**
- * Initializes the collection of sources from a spec (typically used during upgrade).
- * If not present on the spec, it will create the sources model and save it on the spec for reuse.
- * @param {object} spec
- * @return {SourcesCollectionAPI} collection API object of sources
- */
- DataSourcesService.prototype.initializeSourcesCollection = function initializeSourcesCollection(spec) {
- if (!this._sourcesCollectionAPI) {
- if (spec && spec.dataSources instanceof DataSourcesModel === false) {
- spec.dataSources = new DataSourcesModel(spec.dataSources);
- }
- this._initializeSourcesCollection(spec && spec.dataSources);
- }
- return this._sourcesCollectionAPI || null;
- };
- /**
- * Returns the collection of sources
- * @param {Model} [dataSources] - datasoures model, otherwise we will get it from the boardModel
- * @return {SourcesCollectionAPI} collection API object of sources
- */
- DataSourcesService.prototype.getSourcesCollection = function getSourcesCollection(dataSources) {
- if (!this._sourcesCollectionAPI) {
- var sourcesModel = dataSources || this.boardModel.get('dataSources');
- this._initializeSourcesCollection(sourcesModel);
- }
- return this._sourcesCollectionAPI || null;
- };
- /**
- * Relinks an existing data source to a new source
- * @param {SourceModel} source The source you want to relink
- * @param {Object} newSourceInfo Information (assetId, name, type, searchPath, ..) of the new source
- * @return {Promise}
- */
- DataSourcesService.prototype.relink = function relink(source, newSourceInfo) {
- return RelinkUtils.relink(source, newSourceInfo, this.dashboardApi);
- };
- DataSourcesService.prototype.getDeploymentReferences = function getDeploymentReferences(isSaveAs) {
- var deploymentReferences = [];
- var sources = this.getSourcesCollection().getSources();
- // Keep a map of the assetIds we've gone through since we can have multiple sources that point to the same assetId
- var processAssetIds = {};
- sources.forEach(function (source) {
- source.getDeploymentReference(deploymentReferences, processAssetIds, isSaveAs);
- });
- return deploymentReferences;
- };
- /**
- * The dashboard was just saved, we need to update/create any needed modules under the dashboard object
- * @param {boolean} options.saveAs Boolean to let us know if it was a saveAs or save operations
- * @param {object} options.resaveDashboardSpecCallback Callback to re-save the dashboard spec. Used if the model gets updated
- * @return {Promise}
- */
- DataSourcesService.prototype.onDashboardSave = function onDashboardSave(options) {
- var promises = [];
- if (this.sourcesCollection) {
- options.dashboardAssetId = this.dashboardApi.getDashboardInfo().boardId;
- options.ajaxSvc = this.dashboardApi.getGlassCoreSvc('.Ajax');
- options.logger = this.logger;
- var sources = this.sourcesCollection.getModels();
- sources.forEach(function (source) {
- if (source.shaping) {
- promises.push(EmbeddedModuleManager.onDashboardSave(source.shaping, options));
- }
- });
- }
- return Promise.all(promises).then(function (results) {
- // If one of the onDashboardSave calls returned 'true', then the shaping model has changed. We need to re-save the dashboard spec
- if (results && results.indexOf(true) !== -1) {
- options.resaveDashboardSpecCallback();
- }
- });
- };
- /**
- * Clear shaping on all sources through the shaping model manager
- */
- DataSourcesService.prototype.clearShapingCache = function clearShapingCache() {
- if (this.sourcesCollection) {
- var sources = this.sourcesCollection.getModels();
- sources.forEach(function (source) {
- if (source.shaping && source.shaping.shapingModelManager) {
- source.shaping.shapingModelManager.clearCache();
- }
- });
- }
- };
- return DataSourcesService;
- }();
- return DataSourcesService;
- });
- //# sourceMappingURL=DataSourcesService.js.map
|