123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2017
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['q', 'underscore', 'bi/commons/ui/View', 'bi/admin/nls/StringResource', 'bi/commons/ui/properties/PropertyUIControl', 'react-dom', 'react', 'ba-react-admin/ba-react-admin.min'], function (Q, _, View, StringResource, PropertyUIControl, ReactDOM, React, AdminReact) {
- 'use strict'; //NOSONAR
- var FeaturesBody = View.extend({
- g_MappedIcons: {
- 'com.ibm.bi.glass.appbar': 'common-appbar',
- 'com.ibm.bi.glass.navbar': 'common-navbar',
- 'com.ibm.bi.glass.common.cognosLogo': 'common-cognoslogo',
- 'com.ibm.bi.sample.cognosLogoHomePage': 'common-cognoslogo',
- 'com.ibm.bi.glass.contextmenus': 'common-contextmenus',
- 'com.ibm.bi.glass.collections': 'common-collections'
- },
- init: function init(options) {
- FeaturesBody.inherited('init', this, arguments);
- _.extend(this, options);
- },
- reset: function reset() {
- if (this._propertyUIControl) {
- _.each(this._propertyUIControl.getProperties(), function (treeView) {
- treeView.selectAll();
- }.bind(this));
- }
- },
- filter: function filter(value) {
- AdminReact.FeaturesTreeStore.setFilterString(value);
- },
- render: function render() {
- var deferred = Q.defer();
- var getPerspectivesPromise = this.getPerspectives();
- var getExcludedFeaturesPromise = this.getExcludeList();
- Q.all([getPerspectivesPromise, getExcludedFeaturesPromise]).then(function (results) {
- var lensiblePerspectives = results[0
- /*LENSIBLE_PERSPECTIVES_RESULT_INDEX*/
- ];
- var excludedFeatures = results[1
- /*EXCLUDED_FEATURES_RESULT_INDEX*/
- ];
- var spec = this._buildCollapsibleViewDataSpecification(excludedFeatures.ids, lensiblePerspectives);
- this.featureTree = React.createElement(AdminReact.FeaturesTree, {
- StringResource: StringResource,
- data: spec,
- glassContext: this.glassContext,
- excludedFeatures: excludedFeatures,
- onChange: this.onChange
- });
- var reactEl = ReactDOM.render(this.featureTree, this.$el[0]);
- deferred.resolve(this.$el);
- }.bind(this), function (err) {
- this.glassContext.appController.showToast(StringResource.get('failedToRetrievePerspectivesList'), {
- type: 'error'
- });
- }.bind(this));
- return deferred.promise;
- },
- remove: function remove() {
- if (this._propertyUIControler) {
- this._propertyUIControl.remove();
- }
- },
- _buildCollapsibleViewDataSpecification: function _buildCollapsibleViewDataSpecification(excludedIdList, lensiblePerspectives) {
- var items = []; // build a data specification for the CollapsibleSection
- _.each(_.sortBy(lensiblePerspectives, function (perspective) {
- return perspective.name;
- }), function (perspective) {
- var item = this._createTreeItem(perspective, false, excludedIdList); // use the label specified in the definition if it exists
- if (perspective.definition && perspective.definition.label) {
- item.label = perspective.definition.label;
- }
- item.onChange = this._onChange.bind(this);
- item.items = this._extractPerspectiveFeatures(perspective, excludedIdList);
- items.push(item);
- }.bind(this), this);
- return items;
- },
- _extractPerspectiveFeatures: function _extractPerspectiveFeatures(perspectiveSpecification, excludedIdList) {
- var items = [];
- if (perspectiveSpecification.definition.toolBars) {
- _.each(perspectiveSpecification.definition.toolBars, function (toolbar) {
- var item = this._createTreeItem(toolbar, false, excludedIdList);
- _.each(toolbar.toolItemGroups, function (toolItemGroup) {
- this._addPerspectiveFeature(item, toolItemGroup.toolItems, excludedIdList);
- }.bind(this));
- item.hasChildren = item.items.length > 0;
- items.push(item);
- }.bind(this));
- }
- if (perspectiveSpecification.definition.contextMenus) {
- var contextMenusTreeItem = this._createTreeItem({
- 'label': 'Context Menus',
- 'id': 'com.ibm.bi.glass.contextmenus'
- }, false, excludedIdList);
- _.each(perspectiveSpecification.definition.contextMenus, function (contextMenuDefinition) {
- var contextMenuTreeItem = this._createTreeItem(contextMenuDefinition, true, excludedIdList);
- contextMenusTreeItem.items.push(contextMenuTreeItem);
- this._addPerspectiveFeature(contextMenuTreeItem, contextMenuDefinition.items, excludedIdList);
- }.bind(this));
- items.push(contextMenusTreeItem);
- }
- if (perspectiveSpecification.definition.collectionContainers) {
- var collectionsTreeItem = this._createTreeItem({
- 'label': 'Collections',
- 'id': 'com.ibm.bi.glass.collections'
- }, false, excludedIdList);
- _.each(perspectiveSpecification.definition.collectionContainers, function (collectionDefinition) {
- var collectionTreeItem = this._createTreeItem(collectionDefinition, true, excludedIdList);
- collectionsTreeItem.items.push(collectionTreeItem);
- this._addPerspectiveFeature(collectionTreeItem, collectionDefinition.items, excludedIdList);
- }.bind(this));
- items.push(collectionsTreeItem);
- }
- return items;
- },
- _addPerspectiveFeature: function _addPerspectiveFeature(parent, itemsToAdd, excludedIdList) {
- _.each(itemsToAdd, function (itemToAdd) {
- var item = this._createTreeItem(itemToAdd, true, excludedIdList);
- parent.items.push(item);
- this._addPerspectiveFeature(item, itemToAdd.items, excludedIdList);
- }.bind(this));
- },
- _createTreeItem: function _createTreeItem(item, checkBox, excludedIdList) {
- var itemId = this._getIdFromItem(item);
- return {
- 'glassContext': this.glassContext,
- 'slideout': this.slideout,
- 'name': itemId,
- 'label': this._getLabelFromItem(item),
- 'ariaLabel': item['aria-label'] ? item['aria-label'] : null,
- 'checkBox': checkBox,
- 'root': item.definition ? true : false,
- 'checked': checkBox ? _.indexOf(excludedIdList, itemId) === -1 ? true : false : null,
- 'indent': 1,
- 'icon': this._getIconFromItem(item),
- 'readOnly': this._isReadOnly(item),
- 'items': []
- };
- },
- _getIconFromItem: function _getIconFromItem(item) {
- var iconType;
- var iconValue;
- var mappedValue = this.g_MappedIcons[this._getIdFromItem(item)];
- if (mappedValue) {
- iconType = 'sprite';
- iconValue = mappedValue;
- } else if (item.icon) {
- if (item.icon.indexOf('.svg') === -1) {
- iconType = 'sprite';
- } else {
- iconType = 'path';
- }
- iconValue = item.icon;
- } else if (item.fonticon) {
- iconType = 'font';
- iconValue = item.fonticon;
- } else {
- iconValue = this.g_MappedIcons[this._getIdFromItem(item)];
- iconType = iconValue ? 'sprite' : 'blank';
- }
- return {
- 'type': iconType,
- 'value': iconValue
- };
- },
- _isReadOnly: function _isReadOnly(item) {
- return item.id === "com.ibm.bi.admin.admin" && this.objectInfo.id === "xOjpTeXN0ZW0gQWRtaW5pc3RyYXRvcnM_";
- },
- _getIdFromItem: function _getIdFromItem(item) {
- return item.id ? item.id : item.name ? item.name : item.label;
- },
- _getLabelFromItem: function _getLabelFromItem(item) {
- if (item.label) {
- return item.label;
- } else if (item['aria-label']) {
- return item['aria-label'];
- } else if (item.title) {
- return item.title;
- } else if (item.name) {
- return item.name;
- } else {
- return this._getIdFromItem(item);
- }
- },
- _onChange: function _onChange(name, checked) {
- _.each(this._propertyUIControl.getProperties(), function (property) {
- property.synchCommon(name, checked);
- });
- if (this.onChange) {
- this.onChange(name, checked);
- }
- }
- });
- return FeaturesBody;
- });
|