123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- '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 Cloud (C) Copyright IBM Corp. 2018, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['../../../../lib/@waca/dashboard-common/dist/ui/interaction/Utils', '../../../../app/nls/StringResources', 'underscore', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../../lib/@waca/dashboard-common/dist/api/ContentActionsProviderAPI'], function (Util, stringResources, _, APIFactory, ContentActionsProviderAPI) {
- var OrderAction = function () {
- function OrderAction(_ref) {
- var features = _ref.features;
- _classCallCheck(this, OrderAction);
- if (features) {
- this.dashboard = features.API;
- features.ContentActions.registerProvider('order', this.getAPI());
- this._dashboardState = features.DashboardState;
- this._icons = features.Icons;
- }
- }
- OrderAction.prototype.getAPI = function getAPI() {
- if (!this._api) {
- this._api = APIFactory.createAPI(this, [ContentActionsProviderAPI]);
- }
- return this._api;
- };
- OrderAction.prototype.getLifeCycleHandlers = function getLifeCycleHandlers() {
- return [{
- name: 'post:dashboard.initialize',
- action: this.postDashboardInitialize.bind(this)
- }];
- };
- OrderAction.prototype.postDashboardInitialize = function postDashboardInitialize() {
- if (this.dashboard) {
- this.controller = this.dashboard.getFeature('InteractionController.internal');
- }
- return Promise.resolve();
- };
- OrderAction.prototype.destroy = function destroy() {
- this.dashboard = null;
- this.controller = null;
- };
- OrderAction.prototype.getNodes = function getNodes(idList) {
- return Util.getNodes(this.controller, idList);
- };
- OrderAction.prototype.getParentModel = function getParentModel(idList) {
- var nodes = this.getNodes(idList);
- if (nodes.length > 0) {
- return nodes[0]._layout.model.getParent();
- }
- };
- /**
- * Get the list of items that can be ordered and that belong to the same parent
- */
- OrderAction.prototype.getItems = function getItems(idList) {
- var parentModel = this.getParentModel(idList);
- return parentModel && parentModel.items.filter(function (item) {
- return item.type !== 'templateDropZone' && item.type !== 'templateIndicator';
- });
- };
- OrderAction.prototype._isAvailable = function _isAvailable(idList) {
- var nodes = this.getNodes(idList);
- var items = this.getItems(idList);
- return nodes.length && items.length > 1 && this.dashboard.getMode() === this.dashboard.MODES.EDIT && _.find(nodes, function (node) {
- return items.indexOf(node._layout.model) === -1;
- }) === undefined;
- };
- OrderAction.prototype._isDisabled = function _isDisabled() {
- return this._dashboardState.getUiState().focus;
- };
- OrderAction.prototype.getContentActionList = function getContentActionList(idList) {
- if (this._isAvailable(idList)) {
- return [{
- name: 'orderToFront',
- label: stringResources.get('toolbarActionOrderToFront'),
- icon: this._icons.getIcon('bring-to-front').id,
- type: 'Button',
- disabled: this._isDisabled.bind(this),
- actions: {
- apply: this.orderContent.bind(this, idList, this.getItems(idList).length - this.getNodes(idList).length)
- }
- }, {
- name: 'orderToBack',
- label: stringResources.get('toolbarActionOrderToBack'),
- icon: this._icons.getIcon('send-to-back').id,
- type: 'Button',
- disabled: this._isDisabled.bind(this),
- actions: {
- apply: this.orderContent.bind(this, idList, 0)
- }
- }];
- }
- return [];
- };
- /**
- * Set the order of the selected nodes.
- */
- OrderAction.prototype.orderContent = function orderContent(idList, order) {
- var items = this.getItems(idList);
- var nodes = this.getNodes(idList);
- var selectedModels = _.map(nodes, function (node) {
- return node._layout.model;
- });
- var parentModel = this.getParentModel(idList);
- var updateArray = [];
- var sortedSelection = [];
- var sortedLeftOver = [];
- var model = void 0,
- i = void 0,
- j = void 0,
- newOrder = void 0;
- for (i = 0, j = 0, newOrder = false; i < items.length; i++) {
- model = items[i];
- if (selectedModels.indexOf(model) === -1) {
- sortedLeftOver.push(model);
- j++;
- } else {
- sortedSelection.push(model);
- if (j !== order) {
- newOrder = true;
- }
- }
- }
- if (newOrder) {
- //Only update the model if this will result in a net change
- var modelToInsertBefore = sortedLeftOver[order];
- for (i = 0; i < selectedModels.length; i++) {
- model = selectedModels[i];
- updateArray.push({
- id: model.id,
- parentId: parentModel.id,
- insertBefore: modelToInsertBefore ? modelToInsertBefore.id : null
- });
- }
- parentModel.updateModel({ updateArray: updateArray });
- }
- };
- return OrderAction;
- }();
- return OrderAction;
- });
- //# sourceMappingURL=OrderAction.js.map
|