'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Dashboard * (C) Copyright IBM Corp. 2016, 2021 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ 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) { var SelectItemsNavigationDialog = View.extend({ events: { 'primaryaction .leftArrow': '_previousDrillGroup', 'primaryaction .rightArrow': '_nextDrillGroup' }, _navigationPathLabel: null, _possibleItems: null, _selectItemsDialog: null, _eventHandler: null, _currentSelectedDataItem: null, _currentSelectedItem: null, // It is the current selected item ID. _currentSelectedColumnId: null, _drillGroups: null, _drillGroupCounter: 0, _slot: null, init: function init(options) { SelectItemsNavigationDialog.inherited('init', this, arguments); var items = void 0; var index = 0; /** * _srcPossibleItems is an array. There will be more than one item here * if a column apears in more than one viz slot and user is navigating from it. * In this case, the navigation paths for all the items in the array are the same. */ this._srcPossibleItems = options.state.possibleItems; if (options.state.possibleItems) { this._drillGroups = options.state.possibleItems[0].navigationPaths; var selectedNavigationPathId = options.state.possibleItems[0].dataItem.getNavigationPathId(); if (selectedNavigationPathId) { index = _.indexOf(_.pluck(this._drillGroups, 'identifier'), selectedNavigationPathId); if (index === -1) { index = 0; } else { this._drillGroupCounter = index; } } this._navigationPathLabel = options.state.possibleItems[0].navigationPaths[index].label; items = options.state.possibleItems[0].navigationPaths[index].segment; this._possibleItems = this._addParameters(items); this._eventHandler = options.state.eventHandler; this._currentSelectedItem = options.state.currentSelectedItem; this._currentSelectedDataitem = options.state.possibleItems[0].dataItem; } }, render: function render() { this.$el.html(NavigationView); this._renderSelectDrillColumnsDialog(); return this; }, _renderSelectDrillColumnsDialog: function _renderSelectDrillColumnsDialog() { this.$el.find('.caption').text(this._navigationPathLabel); var options = { possibleItems: this._possibleItems, eventHandler: this, currentSelectedItem: this._currentSelectedItem, width: this._width }; this._selectableList = new CommonSelectItemsDialog(options); var selectableListHtml = this._selectableList.render(); var navigationContianer = this.$el.find('.navigationPanel'); navigationContianer.append(selectableListHtml.$el); navigationContianer.attr('aria-label', StringResources.get('current_nav_group', { 'navigation_group_name': this._navigationPathLabel })); this._showHideNavigationArrows(); }, setFocus: function setFocus() { this._selectableList.setFocus(); }, _nextDrillGroup: function _nextDrillGroup() { this._drillGroupCounter++; this._updateDrillGroupView(); }, _previousDrillGroup: function _previousDrillGroup() { this._drillGroupCounter--; this._updateDrillGroupView(); }, _updateDrillGroupView: function _updateDrillGroupView() { this._showHideNavigationArrows(); var currentDrillGroupPath = this._drillGroups[this._drillGroupCounter]; if (currentDrillGroupPath) { this._updateSelectDrillColumnsDialog(currentDrillGroupPath); if (this._currentSelectedDataitem) { this._currentSelectedDataitem.setNavigationPathId(currentDrillGroupPath.getIdForExpression()); } } }, _updateSelectDrillColumnsDialog: function _updateSelectDrillColumnsDialog(drillGroup) { this._navigationPathLabel = drillGroup.label; this._possibleItems = this._addParameters(drillGroup.segment); this.$el.find('.navigationPanel').empty(); this._renderSelectDrillColumnsDialog(); if (this._selectableList) { this.setFocus(); } }, _showHideNavigationArrows: function _showHideNavigationArrows() { var leftArrow = this.$el.find('.leftArrow'); var rightArrow = this.$el.find('.rightArrow'); leftArrow = leftArrow.attr('aria-label', StringResources.get('previous')); rightArrow = rightArrow.attr('aria-label', StringResources.get('next')); if (this._drillGroups && this._drillGroups.length <= 1) { leftArrow.css({ 'cursor': 'default' }); leftArrow.addClass('disabled'); leftArrow.attr('tabindex', -1); rightArrow.css({ 'cursor': 'default' }); rightArrow.addClass('disabled'); rightArrow.attr('tabindex', -1); } else { if (this._drillGroups && this._drillGroups.length - 1 === this._drillGroupCounter) { leftArrow.css({ 'cursor': 'pointer' }); leftArrow.removeClass('disabled'); leftArrow.attr('tabindex', 0); rightArrow.css({ 'cursor': 'default' }); rightArrow.addClass('disabled'); rightArrow.attr('tabindex', -1); } else if (this._drillGroupCounter <= 0) { rightArrow.css({ 'cursor': 'pointer' }); rightArrow.removeClass('disabled'); rightArrow.attr('tabindex', 0); leftArrow.css({ 'cursor': 'default' }); leftArrow.addClass('disabled'); leftArrow.attr('tabindex', -1); } else { rightArrow.css({ 'cursor': 'pointer' }); rightArrow.removeClass('disabled'); rightArrow.attr('tabindex', 0); leftArrow.css({ 'cursor': 'pointer' }); leftArrow.removeClass('disabled'); leftArrow.attr('tabindex', 0); } } }, _addParameters: function _addParameters(possibleItems) { for (var i = 0; i < possibleItems.length; i++) { possibleItems[i].id = possibleItems[i].ref; possibleItems[i].localizedString = possibleItems[i].label; } return possibleItems; }, _getNavigationPaths: function _getNavigationPaths(dataItemId) { var navigationPaths = this._eventHandler.getNavigationPaths(dataItemId) || []; var drillGroupsFromModule = this._eventHandler.getDrillGroups(dataItemId) || []; // when navigate from the custom group column to original column, the dynamically created navigation path is missing for the original column // when navigate from the original column to the custom group column, the navigation path is dynamically create again // so when the drillGroups model from module has different length than the drillGroups model from the navigateAction, means navigate path got dynamically created if (this._drillGroups && this._drillGroups.length > 0 && navigationPaths.length === drillGroupsFromModule.length) { var customDrillGroupCandidate = this._drillGroups[0]; // the dynamically created drill group for custom group will always be the first one, check if the first drill group consists by current column if (_.filter(customDrillGroupCandidate.getSegment(), function (segment) { return segment.getRef() === dataItemId; }).length > 0) { // check if the first drill group can not be found from the drill groups getting from the module if (!_.filter(drillGroupsFromModule, function (drillGroup) { return drillGroup.getIdentifier() === customDrillGroupCandidate.getIdentifier(); }).length) { // only custom group navigation path is dynamically created and not part of the drillGroups model from module return [customDrillGroupCandidate].concat(navigationPaths); } } } return navigationPaths; }, _updateNavigationPaths: function _updateNavigationPaths(dataItemId, navigationPath) { this._drillGroups = this._getNavigationPaths(dataItemId); this._drillGroupCounter = this._drillGroups && navigationPath ? _.indexOf(_.pluck(this._drillGroups, 'identifier'), navigationPath.getIdentifier()) : 0; this._currentSelectedItem = dataItemId; this._showHideNavigationArrows(); }, handleSelection: function handleSelection(dataItemId) { var navigateTo = _.map(this._srcPossibleItems, function (possibleItem) { return { slot: possibleItem.slot, indexInSlot: possibleItem.indexInSlot, newColumnId: dataItemId, navigationPathId: this._drillGroups[this._drillGroupCounter].getIdentifier() }; }, this); this._eventHandler.navigateTo(navigateTo); this._updateNavigationPaths(dataItemId, this._drillGroups[this._drillGroupCounter]); } }); return SelectItemsNavigationDialog; }); //# sourceMappingURL=SelectItemsNavigationDialog.js.map