123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- '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. 2019, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../../lib/@waca/dashboard-common/dist/ui/interaction/Utils', '../../../../lib/@waca/core-client/js/core-client/ui/ProgressToast', '../../../../app/nls/StringResources', '../../../../dashboard/util/DashboardSpecHelper', '../../../../app/util/ErrorUtils', 'jquery', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI', 'underscore'], function (Util, ProgressToast, stringResources, DashboardSpecHelper, ErrorUtils, $, APIFactory, ContentActionsProviderAPI, _) {
- var placeholderMappings = {
- infographic: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxOS4wLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iTGF5ZXJfMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PS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PinAction = function () {
- function PinAction(_ref) {
- var features = _ref.features;
- _classCallCheck(this, PinAction);
- if (features) {
- this.dashboard = features.API;
- this.toast = {};
- features.ContentActions.registerProvider('pin', this.getAPI());
- this._icons = features.Icons;
- }
- }
- PinAction.prototype.getAPI = function getAPI() {
- if (!this._api) {
- this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
- }
- return this._api;
- };
- PinAction.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() {
- return [{
- name: 'post:dashboard.initialize',
- action: this.postDashboardInitialize.bind(this)
- }];
- };
- PinAction.prototype.postDashboardInitialize = function postDashboardInitialize() {
- this.controller = this.dashboard.getFeature('InteractionController.internal');
- this.specHelper = new DashboardSpecHelper(this.controller);
- return Promise.resolve();
- };
- PinAction.prototype._isEnabled = function _isEnabled(idList) {
- return idList.length && this._isSupportedVisualizations(idList) && this.dashboard.getMode() !== this.dashboard.MODES.EDIT_GROUP && ErrorUtils.hasCapability(this.dashboard, 'canAuthorDashboard');
- };
- PinAction.prototype._isSupportedVisualizations = function _isSupportedVisualizations(idList) {
- for (var index = 0; index < idList.length; index++) {
- if (this._isNotSupportedVisualization(idList[index])) {
- return false;
- }
- }
- return true;
- };
- PinAction.prototype._isNotSupportedVisualization = function _isNotSupportedVisualization(id) {
- var content = this.dashboard.getCanvas().getContent(id);
- if (!content) {
- return false;
- }
- var visualization = content.getFeature('Visualization');
- return content.getType() === 'widget.live' && visualization && visualization.getDefinition().getId() === 'com.ibm.vis.schematicsPreview';
- };
- PinAction.prototype.getContentActionList = function getContentActionList(idList) {
- if (this._isEnabled(idList)) {
- return [{
- name: 'pin',
- label: stringResources.get('toolbarActionPinOld'),
- icon: this._icons.getIcon('pin').id,
- type: 'Button',
- actions: {
- apply: this.pinItems.bind(this)
- }
- }];
- } else {
- return [];
- }
- };
- PinAction.prototype.pinItems = function pinItems() {
- var _this = this;
- return new Promise(function (resolve, reject) {
- var _pinItems = function _pinItems(toast_id) {
- var promises = [];
- var boardName = _this.controller.boardModel.name;
- var path = _this._createPath();
- var pinContents = _this.specHelper.getContents(true);
- pinContents.forEach(function (pinContent) {
- var pin = {
- source: 'authoredview',
- sourceName: boardName,
- sourceUri: path + '?embed=ba1', // source uri needs embed link for reopen
- sourceInstanceId: path,
- contentType: 'boardFragment',
- content: pinContent
- };
- if (_this._shouldUsePlaceholder(pinContent.widgets)) {
- pin.thumbUri = _this._getPlaceholder(pinContent.widgets);
- _this._pinItem(pin);
- } else {
- var isGroup = pinContent.layout.type === 'group';
- // TODO lifecycle_cleanup -- cleanup how we access the dom here
- var selectedNode = $('#' + pinContent.layout.id)[0];
- var widgetContent = selectedNode;
- if (!isGroup) {
- widgetContent = $(widgetContent).find('.widgetContentWrapper')[0];
- }
- var nodes = {
- widget: selectedNode,
- content: widgetContent
- };
- var nodeStyles = {};
- _this._prepareNodeStylesForThumbnail(nodes, nodeStyles);
- promises.push(_this._createThumbnail(widgetContent).then(function (dataUri) {
- pin.thumbUri = dataUri;
- _this._restoreStylesAfterThumbnail(nodes, nodeStyles);
- }, function (err) {
- _this.dashboard.getGlassCoreSvc('.Logger').error(err);
- }).then(_this._pinItem.bind(_this, pin)));
- }
- });
- return Promise.all(promises).then(function () {
- _this.toast[toast_id].setComplete(100, {
- duration: 0,
- completeMsg: stringResources.get('pinAddedToast'),
- isComplete: true
- });
- resolve();
- }).catch(function () {
- _this.toast[toast_id].fail(stringResources.get('contentPinFailOld'));
- reject();
- }).finally(function () {
- _this.toast[toast_id].remove();
- _this.toast[toast_id] = null;
- });
- };
- var toast_id = _.uniqueId('pinToast');
- var toast = new ProgressToast({
- noCancelBtn: true,
- onShown: _pinItems.bind(_this, toast_id)
- });
- toast.show(stringResources.get('pinningToast'));
- toast.indefinite(stringResources.get('pinningToast'));
- _this.toast[toast_id] = toast;
- });
- };
- PinAction.prototype._createPath = function _createPath() {
- var gateway = this.controller.gatewayUrl ? this.controller.gatewayUrl : '';
- var boardID = this.controller.boardModel.id;
- return gateway + '/board/' + boardID;
- };
- /**
- * Determines if a placeholder should be used for a given list of widget models
- * @param widgetModelsForPinning - List of widget models
- * @returns boolean value as to whether a placeholder should be used
- */
- PinAction.prototype._shouldUsePlaceholder = function _shouldUsePlaceholder(widgetModelsForPinning) {
- return widgetModelsForPinning.length === 1 && widgetModelsForPinning[0].mapping && widgetModelsForPinning[0].mapping[0] && widgetModelsForPinning[0].mapping[0].graphic;
- };
- /**
- * Gets the placeholder image to be shown for pinning, for the given widget model
- * @param widgetModelsForPinning - List of widget models
- * @returns placeholder (base 64 string) to be shown for pinning
- */
- PinAction.prototype._getPlaceholder = function _getPlaceholder(widgetModelsForPinning) {
- var placeholder;
- if (widgetModelsForPinning.length === 1 && widgetModelsForPinning[0].mapping && widgetModelsForPinning[0].mapping[0] && widgetModelsForPinning[0].mapping[0].graphic) {
- placeholder = placeholderMappings.infographic;
- }
- return placeholder;
- };
- PinAction.prototype._pinItem = function _pinItem(item) {
- return this.dashboard.getGlassSvc('.DashboardPinning').then(function (dashboardPinningService) {
- return dashboardPinningService.addPin(item);
- });
- };
- PinAction.prototype._prepareNodeStylesForThumbnail = function _prepareNodeStylesForThumbnail(nodes, styles) {
- if (nodes.widget !== nodes.content) {
- styles.widget = nodes.widget.getAttribute('style') || '';
- styles.content = nodes.content.getAttribute('style') || '';
- var tempWidgetStyles = [],
- tempContentStyles = [];
- styles.widget.split(';').forEach(function (styleRule) {
- var ruleName = styleRule.split(':')[0];
- switch (ruleName.trim()) {
- case 'width':
- case 'height':
- case 'top':
- case 'left':
- tempWidgetStyles.push(styleRule);
- break;
- default:
- tempContentStyles.push(styleRule);
- }
- });
- nodes.widget.setAttribute('style', tempWidgetStyles.join(';'));
- nodes.content.setAttribute('style', styles.content + ';' + tempContentStyles.join(';'));
- }
- $(nodes.widget).addClass('pinThumbnail');
- };
- PinAction.prototype._createThumbnail = function _createThumbnail(selectedNode) {
- return this.dashboard.getDashboardSvc('.Thumbnail').then(function (thumbnailSvc) {
- return thumbnailSvc.generateImage(selectedNode);
- });
- };
- PinAction.prototype._restoreStylesAfterThumbnail = function _restoreStylesAfterThumbnail(nodes, styles) {
- if (nodes.widget !== nodes.content) {
- nodes.widget.setAttribute('style', styles.widget);
- nodes.content.setAttribute('style', styles.content);
- }
- $(nodes.widget).removeClass('pinThumbnail');
- };
- return PinAction;
- }();
- return PinAction;
- });
- //# sourceMappingURL=PinAction.js.map
|