123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: BI Dashboard
- *
- * Copyright IBM Corp. 2016, 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', '../../../app/nls/StringResources'], function (BaseClass, stringResources) {
- var VIDA_MAP_ANIM_TIMEOUT_MILLIS = 10000; // milliseconds
- var ShareActionHandler = BaseClass.extend({
- /**
- * @param {options} set of initial properties
- */
- init: function init(options) {
- this.vidaMapAnimTimeout = options && options.vidaMapAnimTimeout || VIDA_MAP_ANIM_TIMEOUT_MILLIS;
- },
- execute: function execute(context) {
- if (context.urlMap.objRef) {
- var persp = context && context.target && context.target.activeObject && context.target.activeObject.aSelectedContext && context.target.activeObject.aSelectedContext[0].tags && context.target.activeObject.aSelectedContext[0].tags.indexOf('story') !== -1 ? 'story' : 'dashboard';
- var share = {
- perspective: persp,
- objRef: context.urlMap.objRef,
- action: 'view',
- mode: context.urlMap.mode ? context.urlMap.mode : 'dashboard'
- };
- var view = context.glassContext.appController.getCurrentContentView();
- if (view.perspective === 'dashboard' && typeof view.boardController.layoutController.getCurrentSubViewId === 'function') {
- share.subView = view.boardController.layoutController.getCurrentSubViewId();
- }
- return share;
- } else {
- throw new Error('Unable to resolve share context. Missing objRef.');
- }
- },
- getShareableItems: function getShareableItems(context) {
- var els = [];
- var view = context.glassContext.appController.getCurrentContentView();
- if (view.perspective === 'dashboard') {
- var item = {};
- item.el = view.el;
- if (typeof view.boardController.layoutController.getCurrentSubViewTitle === 'function') {
- item.label = stringResources.get('screenshot_label_tab', { title: view.getTitle(),
- tabName: view.boardController.layoutController.getCurrentSubViewTitle() });
- } else {
- item.label = stringResources.get('screenshot_label', { title: view.getTitle() });
- }
- els.push(item);
- }
- return this.reRenderMaps(view).then(function () {
- return els;
- });
- },
- /*
- * Returns true if there is a selected context of a dashboard or story or if there is no context (i.e. when we are in a perspective view)
- * @param {object} context
- */
- isEnabled: function isEnabled(_ref) {
- var context = _ref.context;
- if (context) {
- var tags = context.length === 1 && context[0] && context[0].tags;
- return tags && (tags.indexOf('dashboard') !== -1 || tags.indexOf('story') !== -1);
- }
- return true;
- },
- _triggerDataPlayerEvent: function _triggerDataPlayerEvent(eventName, contentView) {
- var dashboardApi = contentView.dashboardApi;
- if (dashboardApi) {
- dashboardApi.triggerDashboardEvent(eventName);
- }
- },
- enterShareState: function enterShareState(context) {
- var _this = this;
- return Promise.resolve().then(function () {
- var contentView = context.glassContext.appController.getCurrentContentView();
- _this._triggerDataPlayerEvent('open:sharePanel', contentView);
- });
- },
- leaveShareState: function leaveShareState(context) {
- var _this2 = this;
- return Promise.resolve().then(function () {
- var contentView = context.glassContext.appController.getCurrentContentView();
- _this2._triggerDataPlayerEvent('close:sharePanel', contentView);
- });
- },
- /**
- * Re-render map widgets for screen capture. Allow sub-classes to access.
- * @protected
- * @param view the content view
- * @return {Promise}
- */
- reRenderMaps: function reRenderMaps(view) {
- var layoutController = view.boardController.layoutController;
- var currentLayout = view.boardModel.getSelectedLayout();
- var widgetsOnCurrentPage = view.dashboardApi.getCanvas().getContent(currentLayout).findContent({ type: 'widget' });
- var mapWidgetList = widgetsOnCurrentPage.filter(function (widget) {
- var vis = widget.getFeature('Visualization');
- if (vis) {
- if (vis.getType() === 'Tiledmap') {
- return true;
- }
- }
- return false;
- });
- var mapWidgetIds = mapWidgetList.map(function (widget) {
- return widget.getId();
- });
- if (mapWidgetIds.length > 0) {
- return Promise.map(mapWidgetIds, function (widgetId) {
- var mapWidget = layoutController.widgetLoader.getWidget(widgetId);
- return mapWidget.mapVizRenderForPrint();
- }).delay(this.vidaMapAnimTimeout); //Timeout is needed for the VIDA map animation.
- } else {
- return Promise.resolve();
- }
- },
- /**
- * Returns true if export to pdf for dashboard is allowed.
- *
- * @param {*} context.glassContext the Glass context
- */
- canExportToPDF: function canExportToPDF() /* options */{
- return true;
- },
- getInstrumentation: function getInstrumentation(context) {
- return context.glassContext.appController.getCurrentContentView().getDashboardApi().getFeature('segment').getInfo({ type: 'Shared Object' });
- },
- /**
- * Creates a PDF.
- *
- * @param {*} context.glassContext the Glass context
- * @param {*} pageSize an object representing the page size
- * @param {*} printFilters print filters.
- * @return {Promise}
- */
- exportToPDF: function exportToPDF(context, pageSize, printFilters) {
- var dashApi = context.glassContext.appController.getCurrentContentView().getDashboardApi();
- var printFeature = dashApi.getFeature('Print');
- var pageOptions = {
- pageSize: pageSize,
- printFilters: printFilters
- };
- var id = dashApi.getCanvas().getContent().getId();
- return printFeature.print(id, context.glassContext.appController, pageOptions);
- }
- });
- return ShareActionHandler;
- });
- //# sourceMappingURL=ShareActionHandler.js.map
|