SelectItemsNavigationDialog.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Dashboard
  5. * (C) Copyright IBM Corp. 2016, 2021
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', '../../../lib/@waca/core-client/js/core-client/ui/core/View', '../../../lib/@waca/dashboard-common/dist/ui/dialogs/CommonSelectItemsDialog', 'text!../templates/NavigationPathView.html', '../nls/StringResources'], function (_, View, CommonSelectItemsDialog, NavigationView, StringResources) {
  9. var SelectItemsNavigationDialog = View.extend({
  10. events: {
  11. 'primaryaction .leftArrow': '_previousDrillGroup',
  12. 'primaryaction .rightArrow': '_nextDrillGroup'
  13. },
  14. _navigationPathLabel: null,
  15. _possibleItems: null,
  16. _selectItemsDialog: null,
  17. _eventHandler: null,
  18. _currentSelectedDataItem: null,
  19. _currentSelectedItem: null, // It is the current selected item ID.
  20. _currentSelectedColumnId: null,
  21. _drillGroups: null,
  22. _drillGroupCounter: 0,
  23. _slot: null,
  24. init: function init(options) {
  25. SelectItemsNavigationDialog.inherited('init', this, arguments);
  26. var items = void 0;
  27. var index = 0;
  28. /**
  29. * _srcPossibleItems is an array. There will be more than one item here
  30. * if a column apears in more than one viz slot and user is navigating from it.
  31. * In this case, the navigation paths for all the items in the array are the same.
  32. */
  33. this._srcPossibleItems = options.state.possibleItems;
  34. if (options.state.possibleItems) {
  35. this._drillGroups = options.state.possibleItems[0].navigationPaths;
  36. var selectedNavigationPathId = options.state.possibleItems[0].dataItem.getNavigationPathId();
  37. if (selectedNavigationPathId) {
  38. index = _.indexOf(_.pluck(this._drillGroups, 'identifier'), selectedNavigationPathId);
  39. if (index === -1) {
  40. index = 0;
  41. } else {
  42. this._drillGroupCounter = index;
  43. }
  44. }
  45. this._navigationPathLabel = options.state.possibleItems[0].navigationPaths[index].label;
  46. items = options.state.possibleItems[0].navigationPaths[index].segment;
  47. this._possibleItems = this._addParameters(items);
  48. this._eventHandler = options.state.eventHandler;
  49. this._currentSelectedItem = options.state.currentSelectedItem;
  50. this._currentSelectedDataitem = options.state.possibleItems[0].dataItem;
  51. }
  52. },
  53. render: function render() {
  54. this.$el.html(NavigationView);
  55. this._renderSelectDrillColumnsDialog();
  56. return this;
  57. },
  58. _renderSelectDrillColumnsDialog: function _renderSelectDrillColumnsDialog() {
  59. this.$el.find('.caption').text(this._navigationPathLabel);
  60. var options = {
  61. possibleItems: this._possibleItems,
  62. eventHandler: this,
  63. currentSelectedItem: this._currentSelectedItem,
  64. width: this._width
  65. };
  66. this._selectableList = new CommonSelectItemsDialog(options);
  67. var selectableListHtml = this._selectableList.render();
  68. var navigationContianer = this.$el.find('.navigationPanel');
  69. navigationContianer.append(selectableListHtml.$el);
  70. navigationContianer.attr('aria-label', StringResources.get('current_nav_group', {
  71. 'navigation_group_name': this._navigationPathLabel
  72. }));
  73. this._showHideNavigationArrows();
  74. },
  75. setFocus: function setFocus() {
  76. this._selectableList.setFocus();
  77. },
  78. _nextDrillGroup: function _nextDrillGroup() {
  79. this._drillGroupCounter++;
  80. this._updateDrillGroupView();
  81. },
  82. _previousDrillGroup: function _previousDrillGroup() {
  83. this._drillGroupCounter--;
  84. this._updateDrillGroupView();
  85. },
  86. _updateDrillGroupView: function _updateDrillGroupView() {
  87. this._showHideNavigationArrows();
  88. var currentDrillGroupPath = this._drillGroups[this._drillGroupCounter];
  89. if (currentDrillGroupPath) {
  90. this._updateSelectDrillColumnsDialog(currentDrillGroupPath);
  91. if (this._currentSelectedDataitem) {
  92. this._currentSelectedDataitem.setNavigationPathId(currentDrillGroupPath.getIdForExpression());
  93. }
  94. }
  95. },
  96. _updateSelectDrillColumnsDialog: function _updateSelectDrillColumnsDialog(drillGroup) {
  97. this._navigationPathLabel = drillGroup.label;
  98. this._possibleItems = this._addParameters(drillGroup.segment);
  99. this.$el.find('.navigationPanel').empty();
  100. this._renderSelectDrillColumnsDialog();
  101. if (this._selectableList) {
  102. this.setFocus();
  103. }
  104. },
  105. _showHideNavigationArrows: function _showHideNavigationArrows() {
  106. var leftArrow = this.$el.find('.leftArrow');
  107. var rightArrow = this.$el.find('.rightArrow');
  108. leftArrow = leftArrow.attr('aria-label', StringResources.get('previous'));
  109. rightArrow = rightArrow.attr('aria-label', StringResources.get('next'));
  110. if (this._drillGroups && this._drillGroups.length <= 1) {
  111. leftArrow.css({
  112. 'cursor': 'default'
  113. });
  114. leftArrow.addClass('disabled');
  115. leftArrow.attr('tabindex', -1);
  116. rightArrow.css({
  117. 'cursor': 'default'
  118. });
  119. rightArrow.addClass('disabled');
  120. rightArrow.attr('tabindex', -1);
  121. } else {
  122. if (this._drillGroups && this._drillGroups.length - 1 === this._drillGroupCounter) {
  123. leftArrow.css({
  124. 'cursor': 'pointer'
  125. });
  126. leftArrow.removeClass('disabled');
  127. leftArrow.attr('tabindex', 0);
  128. rightArrow.css({
  129. 'cursor': 'default'
  130. });
  131. rightArrow.addClass('disabled');
  132. rightArrow.attr('tabindex', -1);
  133. } else if (this._drillGroupCounter <= 0) {
  134. rightArrow.css({
  135. 'cursor': 'pointer'
  136. });
  137. rightArrow.removeClass('disabled');
  138. rightArrow.attr('tabindex', 0);
  139. leftArrow.css({
  140. 'cursor': 'default'
  141. });
  142. leftArrow.addClass('disabled');
  143. leftArrow.attr('tabindex', -1);
  144. } else {
  145. rightArrow.css({
  146. 'cursor': 'pointer'
  147. });
  148. rightArrow.removeClass('disabled');
  149. rightArrow.attr('tabindex', 0);
  150. leftArrow.css({
  151. 'cursor': 'pointer'
  152. });
  153. leftArrow.removeClass('disabled');
  154. leftArrow.attr('tabindex', 0);
  155. }
  156. }
  157. },
  158. _addParameters: function _addParameters(possibleItems) {
  159. for (var i = 0; i < possibleItems.length; i++) {
  160. possibleItems[i].id = possibleItems[i].ref;
  161. possibleItems[i].localizedString = possibleItems[i].label;
  162. }
  163. return possibleItems;
  164. },
  165. _getNavigationPaths: function _getNavigationPaths(dataItemId) {
  166. var navigationPaths = this._eventHandler.getNavigationPaths(dataItemId) || [];
  167. var drillGroupsFromModule = this._eventHandler.getDrillGroups(dataItemId) || [];
  168. // when navigate from the custom group column to original column, the dynamically created navigation path is missing for the original column
  169. // when navigate from the original column to the custom group column, the navigation path is dynamically create again
  170. // so when the drillGroups model from module has different length than the drillGroups model from the navigateAction, means navigate path got dynamically created
  171. if (this._drillGroups && this._drillGroups.length > 0 && navigationPaths.length === drillGroupsFromModule.length) {
  172. var customDrillGroupCandidate = this._drillGroups[0];
  173. // the dynamically created drill group for custom group will always be the first one, check if the first drill group consists by current column
  174. if (_.filter(customDrillGroupCandidate.getSegment(), function (segment) {
  175. return segment.getRef() === dataItemId;
  176. }).length > 0) {
  177. // check if the first drill group can not be found from the drill groups getting from the module
  178. if (!_.filter(drillGroupsFromModule, function (drillGroup) {
  179. return drillGroup.getIdentifier() === customDrillGroupCandidate.getIdentifier();
  180. }).length) {
  181. // only custom group navigation path is dynamically created and not part of the drillGroups model from module
  182. return [customDrillGroupCandidate].concat(navigationPaths);
  183. }
  184. }
  185. }
  186. return navigationPaths;
  187. },
  188. _updateNavigationPaths: function _updateNavigationPaths(dataItemId, navigationPath) {
  189. this._drillGroups = this._getNavigationPaths(dataItemId);
  190. this._drillGroupCounter = this._drillGroups && navigationPath ? _.indexOf(_.pluck(this._drillGroups, 'identifier'), navigationPath.getIdentifier()) : 0;
  191. this._currentSelectedItem = dataItemId;
  192. this._showHideNavigationArrows();
  193. },
  194. handleSelection: function handleSelection(dataItemId) {
  195. var navigateTo = _.map(this._srcPossibleItems, function (possibleItem) {
  196. return {
  197. slot: possibleItem.slot,
  198. indexInSlot: possibleItem.indexInSlot,
  199. newColumnId: dataItemId,
  200. navigationPathId: this._drillGroups[this._drillGroupCounter].getIdentifier()
  201. };
  202. }, this);
  203. this._eventHandler.navigateTo(navigateTo);
  204. this._updateNavigationPaths(dataItemId, this._drillGroups[this._drillGroupCounter]);
  205. }
  206. });
  207. return SelectItemsNavigationDialog;
  208. });
  209. //# sourceMappingURL=SelectItemsNavigationDialog.js.map