'use strict'; /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: dashboard-core *| (C) Copyright IBM Corp. 2019, 2020 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['underscore', '../../../app/nls/StringResources', '../../../app/util/ErrorUtils', '../../../lib/@waca/core-client/js/core-client/utils/UniqueId', '../../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (_, stringResources, Utils, UniqueId, BaseClass) { var ActionHandler = BaseClass.extend({ /** * Public API to indicate if the Action should be shown */ isItemVisible: function isItemVisible(options) { return this.canExecute(options); }, /** * Public API to indicate if the Action can be executed */ canExecute: function canExecute(options) { var selection = options.target && options.target.activeObject && options.target.activeObject.aSelectedContext; var isSelectionAllowed = selection.length === 1 && this._isSelectionValid(options, true); return Utils.hasCapability(options.glassContext, 'canAuthorDashboard') && isSelectionAllowed; }, /** * Public API to perform the action */ doAction: function doAction(context) { return this._openDashboardView(context); }, /** * Handle the create from template action */ onSelectItem: function onSelectItem(context) { return this._openDashboardView(context); }, _openDashboardView: function _openDashboardView(context) { var _this = this; var selection = context.target && context.target.activeObject && context.target.activeObject.aSelectedContext; var id = selection.length && selection[0].id; return this._getTemplateSpec(context, id).then(function (spec) { // replace the template's name with the default new dashboard name spec = JSON.parse(spec); Object.assign(spec, { name: stringResources.get('defaultName') }); return _this._getTargetPerspective().then(function (perspective) { return context.glassContext.appController.openAppView(perspective, { content: { id: UniqueId.get('dashboard_'), boardSpec: spec, isAuthoringMode: true } }).then(function (view) { return view.onViewRendered(); }).then(function (view) { view.currentContentView.getDashboardApi().getFeature('DashboardState').setDirty(true); view.currentContentView.openDatasetpane(false); }); }); }); }, _getTemplateSpec: function _getTemplateSpec(context, id) { return context.glassContext.getSvc('.Content').then(function (contentSvc) { var url = contentSvc.getBaseObjectsURL() + '/' + id; var options = { dataType: 'json', type: 'GET', data: { fields: 'specification' } }; return contentSvc.get(url, options).then(function (response) { return Promise.resolve(response && response.data && response.data.length && response.data[0].specification); }); }); }, _getTargetPerspective: function _getTargetPerspective() { return Promise.resolve('dashboard'); }, _hasValidTags: function _hasValidTags(item) { var tags = item.tags || []; return tags.indexOf('dashboard_template') !== -1; }, _isSelectionValid: function _isSelectionValid(options, defaultValue) { var selection = options.target && options.target.activeObject && options.target.activeObject.aSelectedContext; if (selection) { for (var _iterator = selection, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { if (_i >= _iterator.length) break; _ref = _iterator[_i++]; } else { _i = _iterator.next(); if (_i.done) break; _ref = _i.value; } var item = _ref; if (!this._hasValidTags(item)) { return false; } var isDashboardTemplatesEnabled = !options.glassContext.getCoreSvc('.FeatureChecker').checkValue('dashboard', 'dashboardTemplates', 'disabled'); if (!isDashboardTemplatesEnabled) { return false; } if (item.type !== 'exploration') { return false; } var aPerm = ['read', 'execute']; if (_.intersection(item.permissions, aPerm).length < aPerm.length) { return false; } if (item.disabled && item.disabled.toString().toLowerCase() === 'true') { return false; } } return true; } return defaultValue || false; } }); return ActionHandler; }); //# sourceMappingURL=CreateFromTemplateActionHandler.js.map