TimelineHighlightFlyoutController.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: Storytelling (C) Copyright IBM Corp. 2018, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', 'dashboard-analytics/visualizations/renderer/filter/FilterLabelHelper', './TimelineHighlightAction'], function (_, FilterLabelHelper, TimelineHighlightAction) {
  9. var TimelineHighlightFlyoutController = function () {
  10. function TimelineHighlightFlyoutController(options) {
  11. _classCallCheck(this, TimelineHighlightFlyoutController);
  12. this.highlightAct = options.highlightAct;
  13. this.launchView = options.launchView;
  14. this.launchPoint = options.launchPoint;
  15. this.backButtonCallback = options.show;
  16. this.dashboardApi = options.dashboardApi;
  17. this.pageContextAPI = options.pageContextAPI;
  18. this.services = options.services;
  19. this.logger = this.dashboardApi.getGlassCoreSvc('.Logger');
  20. this.stringResources = this.dashboardApi.getDashboardCoreSvc('.StringResources');
  21. this.content = options.content;
  22. this.visualization = options.visualization;
  23. this.filterLabelHelper = new FilterLabelHelper({
  24. dataSource: this.visualization.getDataSource(),
  25. 'timelineFilter': 'timelineFilter',
  26. 'filterLineEnabled': this._isFilterLineEnabled,
  27. 'filterLineDeleteEnabled': this._isFilterLineDeleteEnabled,
  28. dashboardApi: this.dashboardApi
  29. });
  30. }
  31. TimelineHighlightFlyoutController.prototype.onEditTimelineFilter = function onEditTimelineFilter(event, dataId) {
  32. this.editTimelineFilter(dataId, event.currentTarget);
  33. };
  34. TimelineHighlightFlyoutController.prototype.onRemoveTimelineFilter = function onRemoveTimelineFilter(event, dataId) {
  35. event.stopPropagation();
  36. var matchingSlotDataItem = _.find(this.visualization.getSlots().getMappingInfoList(), function (mapping) {
  37. return mapping.dataItem.getColumnId() === dataId;
  38. });
  39. var slot = matchingSlotDataItem.slot;
  40. var index = matchingSlotDataItem.indexInSlot;
  41. var timelineHighlightAction = new TimelineHighlightAction(this.visualization, slot, index, this.pageContextAPI, this.services, this.logger, this.highlightAct);
  42. timelineHighlightAction.removeFilter(dataId);
  43. };
  44. TimelineHighlightFlyoutController.prototype.getItemActions = function getItemActions() {
  45. return this._generateFilterListItems(this.highlightAct.get('payload'));
  46. };
  47. TimelineHighlightFlyoutController.prototype._generateFilterListItems = function _generateFilterListItems(timelineFilters) {
  48. var _this = this;
  49. var listItems = this.filterLabelHelper.generateFilterListItems(timelineFilters);
  50. listItems.forEach(function (item) {
  51. item.editLabel = _this.stringResources.get('editTimelineHighlight');
  52. item.deleteLabel = _this.stringResources.get('deleteTimelineHighlight');
  53. item.editAction = _this.onEditTimelineFilter.bind(_this);
  54. item.deleteAction = _this.onRemoveTimelineFilter.bind(_this);
  55. });
  56. return listItems;
  57. };
  58. TimelineHighlightFlyoutController.prototype.editTimelineFilter = function editTimelineFilter(columnId, node) {
  59. if (!node) {
  60. return Promise.resolve();
  61. }
  62. var filterEntry = [_.findWhere(this.highlightAct.get('payload'), {
  63. columnId: columnId
  64. })];
  65. var matchingSlotDataItem = _.find(this.visualization.getSlots().getMappingInfoList(), function (mapping) {
  66. return mapping.dataItem.getColumnId() === columnId;
  67. });
  68. var slot = matchingSlotDataItem.slot;
  69. var dataItem = matchingSlotDataItem.dataItem;
  70. var index = matchingSlotDataItem.indexInSlot;
  71. var timelineHighlightAction = new TimelineHighlightAction(this.visualization, slot, index, this.pageContextAPI, this.services, this.logger, this.highlightAct);
  72. var dialogModule = timelineHighlightAction.getEditorModuleName();
  73. var viewOptions = {
  74. columnId: columnId,
  75. filterSpec: filterEntry,
  76. highlightAct: this.highlightAct,
  77. columnTitle: dataItem.getLabel(),
  78. title: this.stringResources.get('timelineHighlightTitle'),
  79. slot: slot,
  80. dashboardApi: this.dashboardApi,
  81. pageContextAPI: this.pageContextAPI,
  82. services: this.services,
  83. itemContext: timelineHighlightAction.itemContext
  84. };
  85. var interactivityController = this.content.getFeature('InteractivityController.deprecated');
  86. return interactivityController.getActionHelper().renderFilterDialog(dialogModule, viewOptions, this.launchPoint, this.launchView, this.backButtonCallback);
  87. };
  88. TimelineHighlightFlyoutController.prototype._isFilterLineDeleteEnabled = function _isFilterLineDeleteEnabled(filter) {
  89. return Boolean(filter.values.length);
  90. };
  91. TimelineHighlightFlyoutController.prototype._isFilterLineEnabled = function _isFilterLineEnabled() {
  92. return true;
  93. };
  94. return TimelineHighlightFlyoutController;
  95. }();
  96. return TimelineHighlightFlyoutController;
  97. });
  98. //# sourceMappingURL=TimelineHighlightFlyoutController.js.map