123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- '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: BI Cloud (C) Copyright IBM Corp. 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore'], function (_) {
- var SaveActionUtil = function () {
- function SaveActionUtil() {
- _classCallCheck(this, SaveActionUtil);
- }
- /**
- * Saves the dashboard spec to the specified location
- *
- * @param {object} options
- * @param {object} options.ajaxService ajax service
- * @param {string} options.name dashboard name
- * @param {string} options.url url location to save the dashboard spec
- * @param {object} options.dashboard the dashboard api object to be saved
- * @param {object} options.overwrite whether or not to overwrite a dashboard with same name and given location
- */
- SaveActionUtil.saveAs = function saveAs(options) {
- var ajaxService = options.ajaxService,
- name = options.name,
- dashboard = options.dashboard,
- overwrite = options.overwrite;
- var url = options.url;
- var boardModel = dashboard.getFeature('internal').getBoardModel();
- var spec = dashboard.getFeature('Serializer').toJSON();
- SaveActionUtil.cleanUnusedCustomColors(dashboard, spec, boardModel);
- if (name) {
- spec.name = name;
- }
- var cmSpec = SaveActionUtil.getCMSpec(spec, boardModel, true);
- url = url + (overwrite ? '?updateAction=replace&ignoreInvalidObjectReference=true' : '?ignoreInvalidObjectReference=true');
- return new Promise(function (resolve, reject) {
- ajaxService.post(url, {
- contentType: 'application/json',
- processData: false,
- dataType: 'text',
- data: JSON.stringify(cmSpec)
- }).done(function (data, status, request) {
- var url = request.getResponseHeader('location');
- var assetId = url.substring(url.lastIndexOf('/') + 1);
- boardModel.set({ id: assetId, name: name }, { silent: true });
- resolve({
- 'status': 'success',
- 'name': name,
- 'saveRequest': request,
- 'assetId': assetId,
- 'url': url,
- 'savedSpec': cmSpec.specification
- });
- }).fail(function (ajaxRequestDeferred, request) {
- reject({
- 'status': 'fail',
- 'saveRequest': request,
- 'cmSpec': cmSpec
- });
- });
- });
- };
- SaveActionUtil.getCMSpec = function getCMSpec(spec, boardModel, isSaveAs) {
- var contentReferences = boardModel.getContentReferences().map(function (refInfo) {
- return refInfo.value;
- });
- var cmSpec = {
- defaultName: spec.name,
- type: SaveActionUtil.getAssetType(boardModel.dashboardApi),
- specification: JSON.stringify(spec),
- deploymentReferences: SaveActionUtil._getAllDeploymentReferences(boardModel.dashboardApi, isSaveAs),
- references: contentReferences
- };
- // Asset tags are used to distinguish the sub types of a dashboard (ie. explore).
- var assetTags = SaveActionUtil._getAssetTags(boardModel.dashboardApi);
- if (assetTags) {
- cmSpec.tags = assetTags;
- }
- //this is a HACK for WA TODO fix me ... AHHHH HACK! Hacks like this keep me up at night.
- //now that you're finished panicking after reading that this is a hack, the reason for it is
- //CAL stores properties/metadata and content seperatly, CM doesn't. it was easier to add the hack on
- //the dashboard side than the content service side. Sooo.. one day when we have a dashboard server, this should be
- //aggregated on there.
- if (cmSpec.type === 'page_asset' || cmSpec.type === 'card_group') {
- delete cmSpec.specification;
- cmSpec.content = spec;
- }
- return cmSpec;
- };
- SaveActionUtil.getAssetType = function getAssetType(dashboard) {
- return dashboard.getConfiguration('assetType') || 'exploration';
- };
- SaveActionUtil._getAllDeploymentReferences = function _getAllDeploymentReferences(dashboard, isSaveAs) {
- //TODO For cleanup, 'Datasource' and DrillThroughService
- //features can register themselves as providers to the DeploymentReferences feature
- //TODO rm when ContentStoreReference is avaiable for system tests
- var contentStoreReferences = dashboard.getFeature('ContentStoreReferences');
- var contentStoreReferencesContrib = contentStoreReferences ? contentStoreReferences.getContentStoreReferences() : [];
- return [].concat(dashboard.getFeature('dataSources.deprecated').getDeploymentReferences(isSaveAs), dashboard.getFeature('DrillThroughService').getDeploymentReferences(), contentStoreReferencesContrib);
- };
- SaveActionUtil._getAssetTags = function _getAssetTags(dashboard) {
- return dashboard.getConfiguration('assetTags');
- };
- /*
- * Clean unused custom colors and override the saved spec.
- */
- SaveActionUtil.cleanUnusedCustomColors = function cleanUnusedCustomColors(dashboard, spec, boardModel) {
- var customColor = dashboard.getFeature('CustomColor');
- var customPalette = boardModel.properties.customColors.getCustomPaletteDefinition();
- if (customPalette && customPalette.ids.length) {
- var _colorsUsed;
- var colorsUsed = boardModel.getUsedCustomColors(customPalette);
- (_colorsUsed = colorsUsed).push.apply(_colorsUsed, customColor.getUsedCustomColors());
- colorsUsed = _.uniq(colorsUsed);
- if (spec && spec.properties && spec.properties.customColors) {
- spec.properties.customColors.colors = colorsUsed;
- }
- }
- };
- return SaveActionUtil;
- }();
- return SaveActionUtil;
- });
- //# sourceMappingURL=SaveActionUtil.js.map
|