123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- '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. 2019, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', '../../../lib/@waca/dashboard-common/dist/api/PropertiesProviderAPI', '../../../lib/@waca/dashboard-common/dist/core/APIFactory'], function (_, PropertiesProviderAPI, APIFactory) {
- var WidgetPropertiesProvider = function () {
- function WidgetPropertiesProvider(_ref) {
- var dashboardAPI = _ref.dashboardAPI,
- content = _ref.content,
- features = _ref.features;
- _classCallCheck(this, WidgetPropertiesProvider);
- this.content = content;
- this.dashboard = dashboardAPI;
- this._api = APIFactory.createAPI(this, [PropertiesProviderAPI]);
- features.Properties.registerProvider(this.getAPI());
- this.type = this.content.getType().split('.').splice(1).join('.');
- }
- WidgetPropertiesProvider.prototype._isHandledByTheContentProps = function _isHandledByTheContentProps(id) {
- // temporary until we upgrade the widget proeprties
- return id === 'datagrid.viewOption';
- };
- WidgetPropertiesProvider.prototype.getAPI = function getAPI() {
- return this._api;
- };
- WidgetPropertiesProvider.prototype.getContributionSpec = function getContributionSpec() {
- //TODO cache spec ?
- //if( !this._spec ) {
- // getWidgetRegistry returns a spec that is DEEP FROZEN.
- var spec = this.dashboard.getFeature('internal.deprecated').getWidgetRegistry()[this.type];
- // Since any contribute property layouts can potentially be merged with other contributed properties, we need to ensure the spec is cloned.
- this._spec = JSON.parse(JSON.stringify(spec));
- //}
- return this._spec;
- };
- WidgetPropertiesProvider.prototype.getWidgetModel = function getWidgetModel() {
- return this.content.getFeature('Models.internal').getWidgetModel();
- };
- WidgetPropertiesProvider.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
- var contributionSpec = this.getContributionSpec();
- if (!this._propertyLayoutList) {
- this._propertyLayoutList = [];
- if (contributionSpec && contributionSpec.propertyLayoutList) {
- var _propertyLayoutList;
- (_propertyLayoutList = this._propertyLayoutList).push.apply(_propertyLayoutList, contributionSpec.propertyLayoutList.slice());
- }
- }
- // Return a copy of our cached property list
- return this._propertyLayoutList.slice();
- };
- /**
- * @param {boolean} [overrideTheme] - set to true if the default colors for the widget should not be updated w.r.t. theme
- */
- WidgetPropertiesProvider.prototype.getPropertyList = function getPropertyList(overrideTheme) {
- var _this = this;
- var contributionSpec = this.getContributionSpec();
- if (!this._propertyList) {
- if (contributionSpec && contributionSpec.propertyList) {
- this._propertyList = JSON.parse(JSON.stringify(contributionSpec.propertyList));
- } else {
- this._propertyList = [];
- }
- // Default the setPropertyValue and getPropertyValue methods
- this._propertyList.forEach(function (property) {
- // If the property is tagged as multilingual and we're in translation mode and we're missing the translation for the current locale
- if (property.editor && property.editor.uiControl && property.editor.uiControl.multilingual) {
- var translationService = _this.dashboard.getFeature('TranslationService');
- if (translationService) {
- var _ref2 = _this.getWidgetModel().getMultilingualAttribute(property.id) || {},
- multilingualProperty = _ref2.multilingualProperty;
- translationService.processMultilingualProperty(property, multilingualProperty);
- }
- }
- var _customValidatorCallback = property.editor && property.editor.uiControl && property.editor.uiControl.customValidatorCallback;
- if (_customValidatorCallback && typeof _this[_customValidatorCallback] === 'function') {
- property.editor.uiControl.customValidatorCallback = _this[_customValidatorCallback].bind(_this);
- }
- if (!_this._isHandledByTheContentProps(property.id)) {
- // set the prop gettter and setter to sie the existing model location for widget props
- // until those are handled by the content props.
- if (!property.getPropertyValue) {
- property.getPropertyValue = function () {
- return _this._getPropertyValue(property.id);
- };
- }
- if (!property.setPropertyValue) {
- property.setPropertyValue = function (propertyValue) {
- _this.setPropertyValue(property.id, propertyValue);
- };
- }
- }
- });
- }
- // Return a copy of our cached property list
- var propertyList = this._propertyList.slice();
- if (!overrideTheme) {
- this._setDefaultSpecPropertyColorForCurrentTheme('border' /*themeId*/, 'borderColor' /*specId*/, propertyList);
- this._setDefaultSpecPropertyColorForCurrentTheme('backgroundColor' /*themeId*/, 'fillColor' /*specId*/, propertyList);
- }
- return propertyList;
- };
- /**
- * Get the current theme default color value for the specified property id.
- * @param themeId - ID to use when asking the theme for this color property
- * @returns defaultSpecColor - a valid color with which a properties default value can be set to, or null.
- */
- WidgetPropertiesProvider.prototype._getDefaultThemeColorForCurrentTheme = function _getDefaultThemeColorForCurrentTheme(themeId) {
- var colors = this.dashboard.getFeature('Colors');
- var defaultSpecColor = colors.getPropertyForUIElement('widget', themeId).value;
- // The value may be equal to a simple hex or variable name or it may be an object which we have to dig into a little more.
- if (_.isObject(defaultSpecColor)) {
- defaultSpecColor = defaultSpecColor.color;
- }
- // I love themes and the theme definition object <insert sarcasm smirk here>. The color may come back
- // as a nice hex value or as a variable that needs to be mapped. If its a variable it will begin with
- // a '$' and we have to map it to get the hex value.
- if (defaultSpecColor.substring(0, 1) === '$') {
- defaultSpecColor = colors.getValueForVariable('Color', defaultSpecColor.substr(1));
- }
- // Ensure we have a valid hex value or transparent
- if (defaultSpecColor.substring(0, 1) === '#' && !isNaN(parseInt(defaultSpecColor.substr(1), 16)) || defaultSpecColor === 'transparent') {
- return defaultSpecColor;
- }
- return null;
- };
- /**
- * set the current theme default value for the specified property ids.
- * @param themeId - ID to use when asking the theme for this color property
- * @param specPropId - ID to use when getting the property from the items array
- * @param items - array of properties that better hold a property with an id = specPropId
- */
- WidgetPropertiesProvider.prototype._setDefaultSpecPropertyColorForCurrentTheme = function _setDefaultSpecPropertyColorForCurrentTheme(themeId, specPropId, items) {
- // Ensure the property specified actually is in the items list
- // Also ensure we have a valid hex value
- var specColorProp = _.find(items, function (item) {
- return item.id === specPropId;
- });
- var defaultSpecColor = this._getDefaultThemeColorForCurrentTheme(themeId);
- if (!specColorProp || defaultSpecColor === null) {
- return Promise.resolve();
- }
- var colors = this.dashboard.getFeature('Colors').getDashboardColorSet();
- var colorMatched = _.find(colors, function (spec) {
- return spec.hexValue === defaultSpecColor;
- });
- if (!colorMatched) {
- colorMatched = colors[colors.length - 1];
- }
- specColorProp.editor.uiControl.defaultValue = colorMatched.id;
- };
- WidgetPropertiesProvider.prototype._getPropertyValue = function _getPropertyValue(propertyName) {
- return this.getWidgetModel().get(propertyName);
- };
- /**
- * Derived widgets may override
- * @param {string} propertyName
- * @param {*} propertyValue
- */
- WidgetPropertiesProvider.prototype.setPropertyValue = function setPropertyValue(propertyName, propertyValue) {
- var colors = this.dashboard.getFeature('Colors');
- var propertyPayload = {};
- propertyPayload[propertyName] = propertyValue;
- if (propertyName === 'fillColor' || propertyName === 'borderColor') {
- if (propertyValue) {
- propertyPayload[propertyName] = colors.getColorClassName(propertyValue);
- } else {
- propertyPayload[propertyName] = null;
- }
- colors.prepareForColorModelChange(propertyPayload, propertyName);
- }
- this.set(propertyPayload, {
- payloadData: { skipUndoRedo: true }
- });
- };
- WidgetPropertiesProvider.prototype.set = function set(attributes, options) {
- if (attributes) {
- options = options || {};
- options = _.defaults(options, {
- sender: this.id
- });
- this.getWidgetModel().set(attributes, options);
- }
- };
- return WidgetPropertiesProvider;
- }();
- return WidgetPropertiesProvider;
- });
- //# sourceMappingURL=WidgetPropertiesProvider.js.map
|