123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: dashboard
- * (C) Copyright IBM Corp. 2018, 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', '../controls/DrillThroughController', '../managers/DrillThroughMappingManager', '../../util/JumpToActionHelper', 'underscore'], function (BaseClass, DrillThroughController, DrillThroughMappingManager, JumpToActionHelper, _) {
- var DrillThroughService = BaseClass.extend({
- /**
- * The drill through service extension which manages access to the drill through APIs and managers
- * initialized with its model (as defined in the boardModelExtension).
- */
- init: function init(options) {
- DrillThroughService.inherited('init', this, arguments);
- this.dashboardApi = options.dashboardApi;
- this._drillThroughController = new DrillThroughController(this.dashboardApi, this);
- this._mappingManager = new DrillThroughMappingManager(this.dashboardApi);
- },
- /**
- * Get public api of drill through model object
- */
- getDrillThroughModelApi: function getDrillThroughModelApi() {
- // TODO - livewidget_cleanup -- there is no need for this to be asynch
- if (!this.drillThrough) {
- var boardModel = this.dashboardApi.getFeature('internal').getBoardModel();
- this.drillThrough = boardModel.get('drillThrough');
- }
- return Promise.resolve(this.drillThrough.getAPI());
- },
- /**
- * Get public api of drill through model object synchronously
- */
- getDrillThroughModelApiSync: function getDrillThroughModelApiSync() {
- if (this.drillThrough) {
- return this.drillThrough.getAPI();
- }
- this.drillThrough = this.dashboardApi.getFeature('internal').getBoardModel().get('drillThrough');
- return this.drillThrough.getAPI();
- },
- /**
- * Get drill through definition by widget and widget groups.
- * @param {object} widgetModel - the widget model to get the drill through definitions
- */
- getDrillThroughByWidgetAndGroups: function getDrillThroughByWidgetAndGroups(widgetModel) {
- var boardModel = this.dashboardApi.getFeature('internal').getBoardModel();
- var associatedDrillDefinitions = [];
- var drillThroughDefinitions = boardModel.drillThrough.getModels();
- var eventGroup = boardModel.eventGroups.findGroup(widgetModel.get('id'));
- drillThroughDefinitions.forEach(function (drillDefinition) {
- if (drillDefinition.scope === 'visualization' && drillDefinition.ownerId === widgetModel.get('id') || drillDefinition.scope === 'connection' && eventGroup && eventGroup.widgetIds.indexOf(drillDefinition.ownerId) > -1 || drillDefinition.scope === 'dashboard') {
- // Clean mappings from current dashboard if it doesn't included in the widgetModel
- if (drillDefinition.mappings && drillDefinition.mappings.length) {
- drillDefinition.mappings = JSON.parse(JSON.stringify(drillDefinition.mappings));
- drillDefinition.mappings.forEach(function (mapping) {
- if (mapping.mapTo) {
- // Search in projected data items
- var widgetDataViews = widgetModel.data && widgetModel.data.dataViews;
- var dataItemInWidget = void 0;
- _.find(widgetDataViews, function (dataView) {
- return _.find(dataView && dataView.dataItems, function (dataItem) {
- var mappedToDataItem = dataItem && dataItem.itemId === mapping.mapTo;
- if (mappedToDataItem) {
- dataItemInWidget = dataItem;
- }
- return mappedToDataItem;
- });
- });
- if (!dataItemInWidget) {
- // pageContext are converted to local filters and copied to the new widget so look at the local filters only
- // Search in filters
- var localFilters = widgetModel.localFilters;
- dataItemInWidget = _.find(localFilters, function (localFilter) {
- return localFilter.id === mapping.mapTo || localFilter.columnId === mapping.mapTo;
- });
- if (!dataItemInWidget) {
- delete mapping.mapTo;
- }
- }
- }
- });
- }
- associatedDrillDefinitions.push(drillDefinition);
- }
- });
- return associatedDrillDefinitions;
- },
- /**
- * Add drill through definitions when add dashboard fragment
- */
- addDrillThroughOnAddFragment: function addDrillThroughOnAddFragment(boardModel, sourceIdMap, widgetIdMap) {
- var drillThroughEntries = boardModel && boardModel.drillThrough;
- if (drillThroughEntries && drillThroughEntries.length) {
- var drillThroughModelApi = this.getDrillThroughModelApiSync();
- drillThroughEntries.forEach(function (drillDefinition) {
- // Update the modelRef to the new sourceId (currently only one source is supported)
- var drillThroughDataSource = drillDefinition.modelRefs[0];
- if (sourceIdMap && sourceIdMap[drillThroughDataSource]) {
- drillDefinition.modelRefs = [sourceIdMap[drillThroughDataSource]];
- }
- // Preserve the new widget Id as the new drill through definition owner
- // when pasting to a new Dashboard.
- // For the scenarios such as pasting a widget to same tab or different tab within a Dashboard,
- // just do a simple update, i.e. no ownership will be changed.
- var options = {};
- var newWidgetId = widgetIdMap[drillDefinition.ownerId];
- if (newWidgetId) {
- options.newOwnerId = newWidgetId;
- }
- drillThroughModelApi.addUpdateDrillDefinitionEntry(drillDefinition, options);
- });
- }
- },
- getDrillThroughController: function getDrillThroughController() {
- return this._drillThroughController;
- },
- getDrillThroughMappingManager: function getDrillThroughMappingManager() {
- return this._mappingManager;
- },
- getJumpToTargets: function getJumpToTargets(options) {
- return JumpToActionHelper.getJumpToTargets(options);
- },
- getDeploymentReferences: function getDeploymentReferences() {
- var drillEntries = this.getDrillThroughModelApiSync().getDrillDefinitionEntries();
- var userProfile = this.dashboardApi.getGlassCoreSvc('.UserProfile');
- var userPreferences = userProfile && userProfile.preferences;
- var contentLocale = userPreferences && userPreferences.contentLocale || 'en-us';
- var deploymentReferences = [];
- drillEntries.forEach(function (entry) {
- var _name;
- deploymentReferences.push({
- objects: [{
- type: entry.getType(),
- searchPath: 'storeID("' + entry.getAssetId() + '")'
- }],
- name: (_name = {}, _name[contentLocale] = entry.getAssetId(), _name)
- });
- });
- return deploymentReferences;
- }
- });
- return DrillThroughService;
- });
- //# sourceMappingURL=DrillThroughService.js.map
|