123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- 'use strict';
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * Licensed Materials - Property of IBM
- * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['jquery', 'underscore', '../../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../PropertiesAPI'], function ($, _, APIFactory, PropertiesAPI) {
- var Properties = function () {
- function Properties(options) {
- _classCallCheck(this, Properties);
- this._api = APIFactory.createAPI(this, [PropertiesAPI]);
- this.dashboard = options.features['Dashboard.API'];
- /**
- * this Properties implementation is been used for both as Dashboard-feature and Content-feature.
- * this.content will bu undefined if this is a dashboard feature instance.
- */
- this.content = options.content;
- this._providers = [];
- }
- Properties.prototype.getAPI = function getAPI() {
- return this._api;
- };
- Properties.prototype.registerProvider = function registerProvider(provider) {
- this._providers.push(provider);
- };
- Properties.prototype.deregisterProvider = function deregisterProvider(provider) {
- var idx = this._providers.findIndex(function (p) {
- return p === provider;
- });
- if (idx !== -1) {
- this._providers.splice(idx, 1);
- }
- };
- Properties.prototype.getProviderPropertyNameList = function getProviderPropertyNameList() {
- var providerProperties = {};
- var ind = 1;
- _.each(this._providers, function (provider) {
- var impltype = void 0;
- if (provider.getImplType) {
- impltype = provider.getImplType();
- } else {
- impltype = 'someViewClass_' + ind;
- ind += 1;
- }
- if (!providerProperties[impltype]) {
- providerProperties[impltype] = [];
- }
- if (provider.getPropertyList) {
- var _providerProperties$i;
- (_providerProperties$i = providerProperties[impltype]).push.apply(_providerProperties$i, provider.getPropertyList().map(function (prop) {
- return prop.id;
- }));
- }
- });
- return providerProperties;
- };
- Properties.prototype.getPropertyList = function getPropertyList() {
- var allProperties = {};
- try {
- for (var i = 0; i < this._providers.length; i++) {
- var provider = this._providers[i];
- if (!provider.isEnabled || provider.isEnabled()) {
- var properties = provider.getPropertyList ? provider.getPropertyList() : [];
- if (properties) {
- for (var j = 0; j < properties.length; j++) {
- var property = properties[j];
- this.modifyPropertyWithCallback(property);
- if (allProperties[property.id]) {
- this._mergeProperty(allProperties, property.id, property);
- } else {
- allProperties[property.id] = property;
- }
- }
- }
- }
- }
- } catch (e) {
- // Do nothing since all error should be logged by render sequence
- }
- this._filterUnsupportedProperties(allProperties);
- return _.values(allProperties);
- };
- Properties.prototype._filterUnsupportedProperties = function _filterUnsupportedProperties(allProps) {
- if (this.dashboard) {
- var featureChecker = this.dashboard.getGlassCoreSvc && this.dashboard.getGlassCoreSvc('.FeatureChecker');
- if (featureChecker) {
- var isSmartTitleEnabled = !(featureChecker.checkValue && featureChecker.checkValue('dashboard', 'SmartTitle', 'disabled'));
- if (isSmartTitleEnabled) {
- delete allProps.showTitle;
- } else {
- delete allProps.titleMode;
- }
- }
- }
- return allProps;
- };
- Properties.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
- var _this = this;
- var allLayouts = {};
- _.each(this._providers, function (provider) {
- if (!provider.isEnabled || provider.isEnabled()) {
- var layouts = provider.getPropertyLayoutList ? provider.getPropertyLayoutList() || [] : [];
- _.each(layouts, function (layout) {
- if (allLayouts[layout.id]) {
- _this._mergeProperty(allLayouts, layout.id, layout);
- } else {
- allLayouts[layout.id] = layout;
- }
- });
- }
- });
- return _.values(allLayouts);
- };
- Properties.prototype._mergeProperty = function _mergeProperty(properties, id, provided) {
- var current = properties[id];
- if (provided.override === false) {
- return;
- }
- var currentProfile = current.profile && [].concat(current.profile);
- properties[id] = $.extend(true, {}, current, provided);
- if (currentProfile && provided.profile) {
- var _properties$id$profil;
- (_properties$id$profil = properties[id].profile).push.apply(_properties$id$profil, currentProfile);
- properties[id].profile = _.uniq(properties[id].profile);
- }
- };
- Properties.prototype.modifyPropertyWithCallback = function modifyPropertyWithCallback(propObj) {
- for (var key in propObj) {
- if (key.indexOf('Callback') !== -1 || key === 'onChange') {
- var defCallback = propObj[key];
- if (typeof defCallback === 'function') {
- return;
- }
- if (typeof defCallback === 'string') {
- /// todo: should not have this case
- console.error('callback in definition should use new property callback method.');
- return;
- }
- try {
- var _feature$defCallback$;
- var featurePath = defCallback.feature;
- var feature = null;
- if (featurePath.indexOf('Dashboard.') === 0) {
- var featureName = featurePath.split('.')[1];
- feature = this.dashboard.getFeature(featureName);
- }
- if (!feature) {
- feature = this.content.getFeature(featurePath);
- }
- var params = [this.content];
- params.push.apply(params, defCallback.callbackParams);
- propObj[key] = (_feature$defCallback$ = feature[defCallback.callbackFunction]).bind.apply(_feature$defCallback$, [feature].concat(params));
- } catch (error) {
- console.error(error);
- }
- } else {
- if (_typeof(propObj[key]) == 'object' && propObj[key] !== null) {
- this.modifyPropertyWithCallback(propObj[key]);
- }
- }
- }
- };
- return Properties;
- }();
- return Properties;
- });
- //# sourceMappingURL=Properties.js.map
|