ContentUtil.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. *+------------------------------------------------------------------------+
  5. *| Licensed Materials - Property of IBM
  6. *| IBM Cognos Products: BI Dashboard
  7. *| (C) Copyright IBM Corp. 2019
  8. *|
  9. *| US Government Users Restricted Rights - Use, duplication or disclosure
  10. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  11. *+------------------------------------------------------------------------+
  12. */
  13. /**
  14. * Event helper class
  15. **/
  16. define(['underscore', '../lib/@waca/dashboard-common/dist/utils/ContentUtil'], function (_, ContentUtilCommon) {
  17. var ContentUtil = function () {
  18. function ContentUtil() {
  19. _classCallCheck(this, ContentUtil);
  20. }
  21. /**
  22. * Gets the page context api from the Page Context Service
  23. * @param {DashboardAPI} dashboard
  24. * @returns {pageContextAPI} page content api.
  25. */
  26. ContentUtil.getPageContext = function getPageContext(dashboard) {
  27. var pageContextService = dashboard.getFeature('PageContextService');
  28. return pageContextService && pageContextService.getPageContext();
  29. };
  30. ContentUtil._resolvePageContextItems = function _resolvePageContextItems(pageContextItems, slots) {
  31. if (pageContextItems.length < 1) {
  32. return [];
  33. }
  34. var mappedDataItemList = slots.getDataItemList();
  35. var categoriesCount = 0;
  36. _.each(mappedDataItemList, function (dataItem) {
  37. if (dataItem.getType() === 'attribute') {
  38. categoriesCount++;
  39. }
  40. });
  41. var resolvedPageContextItem = [];
  42. _.some(pageContextItems, function (item) {
  43. if (!item.isDataPointType()) {
  44. _.each(item.getValues(), function (itemValue) {
  45. resolvedPageContextItem.push(itemValue.u.toString());
  46. });
  47. } else {
  48. if (item.getHierarchyCount() === categoriesCount) {
  49. // intersection selection is not valid
  50. resolvedPageContextItem = [];
  51. return true;
  52. } else {
  53. _.each(item.getDataPoints(), function (dataPoint) {
  54. var dataPointItem = [];
  55. _.each(dataPoint, function (tuple) {
  56. dataPointItem.push(tuple.u);
  57. });
  58. resolvedPageContextItem.push(dataPointItem.join(','));
  59. });
  60. }
  61. }
  62. });
  63. return resolvedPageContextItem;
  64. };
  65. ContentUtil.getContextFromSelection = function getContextFromSelection(content, dashboard) {
  66. var visApi = content.getFeature('WidgetAPI.deprecated').getVisApi();
  67. var visualization = content.getFeature('Visualization');
  68. var selectors = ContentUtil.getSelectors(content, dashboard);
  69. var pageContextItems = visApi.getPageContextAPI().getPageContextItems(selectors);
  70. var slots = visualization.getSlots();
  71. return ContentUtil._resolvePageContextItems(pageContextItems, slots);
  72. };
  73. ContentUtil.getSelectors = function getSelectors(content, dashboard) {
  74. var visualization = content.getFeature('Visualization');
  75. var eventGroups = dashboard.getFeature('EventGroups');
  76. var page = ContentUtilCommon.getPageContent(content);
  77. var selectors = {
  78. scope: page && page.getId(),
  79. eventGroupId: eventGroups.getGroupId(content.getId()),
  80. sourceId: visualization.getDataSource().getId(),
  81. origin: 'visualization',
  82. eventSourceId: content.getId()
  83. };
  84. return selectors;
  85. };
  86. ContentUtil.getColumnIdList = function getColumnIdList() {
  87. var slotList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  88. var type = arguments[1];
  89. var columnIdList = [];
  90. slotList.forEach(function (slot) {
  91. slot.getDataItemList().forEach(function (dataItem) {
  92. if (!type || dataItem.getType() === type) {
  93. columnIdList.push(dataItem.getColumnId());
  94. }
  95. });
  96. });
  97. return columnIdList;
  98. };
  99. return ContentUtil;
  100. }();
  101. return ContentUtil;
  102. });
  103. //# sourceMappingURL=ContentUtil.js.map