123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- '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 Dashboard
- *| (C) Copyright IBM Corp. 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- /**
- * Event helper class
- **/
- define(['underscore', '../lib/@waca/dashboard-common/dist/utils/ContentUtil'], function (_, ContentUtilCommon) {
- var ContentUtil = function () {
- function ContentUtil() {
- _classCallCheck(this, ContentUtil);
- }
- /**
- * Gets the page context api from the Page Context Service
- * @param {DashboardAPI} dashboard
- * @returns {pageContextAPI} page content api.
- */
- ContentUtil.getPageContext = function getPageContext(dashboard) {
- var pageContextService = dashboard.getFeature('PageContextService');
- return pageContextService && pageContextService.getPageContext();
- };
- ContentUtil._resolvePageContextItems = function _resolvePageContextItems(pageContextItems, slots) {
- if (pageContextItems.length < 1) {
- return [];
- }
- var mappedDataItemList = slots.getDataItemList();
- var categoriesCount = 0;
- _.each(mappedDataItemList, function (dataItem) {
- if (dataItem.getType() === 'attribute') {
- categoriesCount++;
- }
- });
- var resolvedPageContextItem = [];
- _.some(pageContextItems, function (item) {
- if (!item.isDataPointType()) {
- _.each(item.getValues(), function (itemValue) {
- resolvedPageContextItem.push(itemValue.u.toString());
- });
- } else {
- if (item.getHierarchyCount() === categoriesCount) {
- // intersection selection is not valid
- resolvedPageContextItem = [];
- return true;
- } else {
- _.each(item.getDataPoints(), function (dataPoint) {
- var dataPointItem = [];
- _.each(dataPoint, function (tuple) {
- dataPointItem.push(tuple.u);
- });
- resolvedPageContextItem.push(dataPointItem.join(','));
- });
- }
- }
- });
- return resolvedPageContextItem;
- };
- ContentUtil.getContextFromSelection = function getContextFromSelection(content, dashboard) {
- var visApi = content.getFeature('WidgetAPI.deprecated').getVisApi();
- var visualization = content.getFeature('Visualization');
- var selectors = ContentUtil.getSelectors(content, dashboard);
- var pageContextItems = visApi.getPageContextAPI().getPageContextItems(selectors);
- var slots = visualization.getSlots();
- return ContentUtil._resolvePageContextItems(pageContextItems, slots);
- };
- ContentUtil.getSelectors = function getSelectors(content, dashboard) {
- var visualization = content.getFeature('Visualization');
- var eventGroups = dashboard.getFeature('EventGroups');
- var page = ContentUtilCommon.getPageContent(content);
- var selectors = {
- scope: page && page.getId(),
- eventGroupId: eventGroups.getGroupId(content.getId()),
- sourceId: visualization.getDataSource().getId(),
- origin: 'visualization',
- eventSourceId: content.getId()
- };
- return selectors;
- };
- ContentUtil.getColumnIdList = function getColumnIdList() {
- var slotList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- var type = arguments[1];
- var columnIdList = [];
- slotList.forEach(function (slot) {
- slot.getDataItemList().forEach(function (dataItem) {
- if (!type || dataItem.getType() === type) {
- columnIdList.push(dataItem.getColumnId());
- }
- });
- });
- return columnIdList;
- };
- return ContentUtil;
- }();
- return ContentUtil;
- });
- //# sourceMappingURL=ContentUtil.js.map
|