123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- 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;
- };
-
- DataSourcesService.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() {
- var _this = this;
- return [{
- name: 'pre:widget.maximize',
- action: function action(payload) {
- if (!payload || !payload.id) {
-
- } 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();
- }
- }
- };
-
- 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);
- }
- };
-
- 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;
- };
-
- DataSourcesService.prototype.getSourcesCollection = function getSourcesCollection(dataSources) {
- if (!this._sourcesCollectionAPI) {
- var sourcesModel = dataSources || this.boardModel.get('dataSources');
- this._initializeSourcesCollection(sourcesModel);
- }
- return this._sourcesCollectionAPI || null;
- };
-
- 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();
-
- var processAssetIds = {};
- sources.forEach(function (source) {
- source.getDeploymentReference(deploymentReferences, processAssetIds, isSaveAs);
- });
- return deploymentReferences;
- };
-
- 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 (results && results.indexOf(true) !== -1) {
- options.resaveDashboardSpecCallback();
- }
- });
- };
-
- 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;
- });
|