123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- 'use strict';
- /**
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (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(['underscore', 'dashboard-analytics/widgets/livewidget/nls/StringResources'], function (_, StringResources) {
- 'use strict';
- //[241060] This sliderLoc is used in core so we re-use to avoid
- var UiSliderLoc = '../../core-client/ui/UiSlider';
- /*
- * The purpose of this object is to provide a singleton that can create
- * property descriptions of different types that is consumeable by the
- * properties panel.
- */
- var PropertiesCreator = function () {
- /**
- * Instance stores a reference to the Singleton
- * @type {object}
- */
- var instance = null;
- function init() {
- return {
- /**
- * @returns Create the checkbox property JSON in a format consumeable by the
- * properties panel
- */
- createCheckboxProperty: function createCheckboxProperty(options) {
- var defaultValue = !!(options.defaultValue ? options.defaultValue : options.value);
- return {
- id: options.name,
- type: 'ToggleButton',
- propertyType: 'CheckBox',
- label: options.caption,
- ariaLabel: options.caption,
- public: this._isPropertyPublic(options),
- name: options.name,
- displayPos: this._isPropertyValidNumber(options.displayPos) ? options.displayPos : 10,
- checked: defaultValue,
- defaultValue: defaultValue,
- active: options.active ? options.active : false
- };
- },
- /**
- * @returns Create the text input property JSON in a format consumeable by the
- * properties panel
- */
- createTextInputProperty: function createTextInputProperty(options) {
- return {
- id: options.name,
- type: 'InputLabel',
- propertyType: 'InputLabel',
- label: options.caption,
- 'ariaLabel': options.caption,
- public: true,
- name: options.name,
- handleReturnKey: true,
- displayPos: 10,
- defaultValue: options.defaultValue ? options.defaultValue : '',
- active: options.active ? options.active : false,
- multilingual: options.multilingual ? options.multilingual : false
- };
- },
- /**
- * @returns Create the font size property object
- */
- createFontSizeProperty: function createFontSizeProperty(options) {
- var possibleValues = [{
- 'value': 'auto',
- 'label': StringResources.get('fontSizeAuto')
- }, {
- 'value': '12',
- 'label': '12'
- }, {
- 'value': '14',
- 'label': '14'
- }, {
- 'value': '16',
- 'label': '16'
- }, {
- 'value': '24',
- 'label': '24'
- }];
- return {
- type: 'DropDown',
- id: options.name,
- name: options.name,
- label: options.caption,
- propertyType: 'font',
- defaultValue: options.defaultValue ? options.defaultValue : 'auto',
- public: false,
- active: options.active ? options.active : false,
- options: possibleValues
- };
- },
- /**
- * Create an number in a form that is consumable by the properties panel
- * @param options - It must be a number type
- * @returns number property description consumable by the properties panel
- */
- createNumberProperty: function createNumberProperty(options) {
- var propertyDesc = {
- 'type': 'InputLabel',
- 'inputType': 'text',
- 'id': options.name,
- 'label': options.caption,
- 'defaultValue': options.defaultValue ? options.defaultValue : null,
- 'ariaLabel': options.caption,
- 'displayMultiplier': options.displayMultiplier,
- 'value': options.value ? options.value : null,
- 'active': options.active ? options.active : false,
- 'public': this._isPropertyPublic(options),
- 'parseFloat': true
- };
- if (options.supportsValidationChecks && options.validationInfo) {
- instance._addValidationChecksForNumberProp(options, propertyDesc);
- }
- return propertyDesc;
- },
- /**
- * Add generic validation information for the number property if the
- * property is configured to support it. Note, it is assumed that we
- * should be handling return key for this prop as well. This method
- * may change over time if new requirements are put forward.
- * @param {Object} options - property configuration
- * @param {Object} prop - property description being built.
- */
- _addValidationChecksForNumberProp: function _addValidationChecksForNumberProp(options, prop) {
- prop.handleReturnKey = true;
- prop.showInlineError = true;
- if (options.validationInfo && options.validationInfo.placeHolderTextId) {
- prop.placeHolderText = StringResources.get(options.validationInfo.placeHolderTextId);
- }
- prop.customValidatorCallback = function (value) {
- return {
- isValid: Number.isInteger(value) || value === '' && options.allowNull,
- message: StringResources.get(options.validationInfo.messageId)
- };
- };
- },
- /**
- * Ok, so some enums are defaulted to a string value, some to the actual
- * object. Even the object might be different. Being tired of finding
- * issues this method is used to check all cases.
- * @params {Object} options - property description.
- * @returns {String} the default value to use.
- */
- _getDefaultValueForEnum: function _getDefaultValueForEnum(options) {
- var defaultValue = void 0;
- if (options.hasOwnProperty('def') && options['def'].hasOwnProperty('defaultValue') && options['def']['defaultValue']) {
- defaultValue = options['def']['defaultValue'].name;
- } else if (options.hasOwnProperty('defaultValue')) {
- if (options['defaultValue'] && options['defaultValue'].name) {
- defaultValue = options['defaultValue'].name;
- } else {
- defaultValue = options['defaultValue'];
- }
- } else {
- defaultValue = options.value;
- }
- return defaultValue;
- },
- /**
- * @param options - It must be an enum type
- * @returns enum property description consumable by the properties panel
- */
- createEnumProperty: function createEnumProperty(options) {
- var values = [];
- /*
- possibleValues is an array of values with a structure of
- { caption: 'x', name: 'y'} but we need {label: 'x', value: 'y'} so we
- need to do some basic conversion.
- */
- _.each(options.possibleValues, function (possibleValue) {
- /*
- * A label can either have been pre-localized or we need to take care of it now. If the possible value has
- * a resourceLabel defined then we localize it, otherwise we assume that there is a localizedLabel defined.
- */
- var valSpec = { label: possibleValue.caption, value: possibleValue.name };
- values.push(valSpec);
- });
- var defaultValue = instance._getDefaultValueForEnum(options);
- return {
- 'type': 'DropDown',
- 'id': options.name,
- 'label': options.caption,
- 'ariaLabel': options.caption,
- 'defaultValue': defaultValue,
- 'options': values,
- 'active': options.active ? options.active : false,
- 'public': this._isPropertyPublic(options)
- };
- },
- // properties are public unless they are configured to not be
- _isPropertyPublic: function _isPropertyPublic(property) {
- return property.public === undefined ? true : property.public;
- },
- _isPropertyValidNumber: function _isPropertyValidNumber(prop) {
- return typeof prop === 'number' ? true : false;
- },
- getMaintainAxisScaleProperty: function getMaintainAxisScaleProperty() {
- return {
- 'type': 'ToggleButton',
- 'id': 'maintainAxisScales',
- name: 'maintainAxisScales',
- 'label': StringResources.get('propMaintainAxisScales'),
- 'ariaLabel': StringResources.get('propMaintainAxisScales'),
- 'public': true,
- 'defautValue': false,
- 'displayPos': 0,
- active: true
- };
- },
- /**
- * Donut radius is a special case. Its type is a number but so
- * is the element color so we can't just create a generic number type property.
- * Few things to note as slider type properties are treated differently (i.e.
- * they are modified in the PropertiesUtil class):
- * 1) We have to set the id... of course
- * 2) The module is an exact pattern match in PropertiesUtil so.... don't
- * plan on changing it lol.
- * 3) PropertiesUtil will read the current value straight from the visApi
- * @param options - actual donut radius property description
- * @returns a properties utils readable property.
- */
- getDonutRadius: function getDonutRadius(options) {
- return {
- 'name': 'donutRadius',
- 'id': 'donutRadius',
- 'label': StringResources.get('propDonutRadius'),
- 'ariaLabel': StringResources.get('propDonutRadius'),
- 'type': null,
- 'module': UiSliderLoc,
- 'sliderType': 'percentage',
- 'connect': [true, false],
- 'defaultValue': options.value || options.defaultValue ? options.value || options.defaultValue : 0.50,
- 'range': {
- 'min': 0,
- 'max': 100
- },
- 'step': 1,
- 'format': {
- 'decimals': 1,
- 'postfix': '%'
- },
- 'displayPos': 19,
- 'noInputView': true,
- active: options.active ? options.active : false
- };
- },
- /**
- * @param options - transparency property description of interest
- * @returns transparency property description
- */
- getTransparencyPropertyForLayer: function getTransparencyPropertyForLayer(options) {
- if (options) {
- return {
- 'name': options.name,
- 'id': options.name,
- 'label': options.caption,
- 'ariaLabel': options.caption,
- 'type': null,
- 'module': UiSliderLoc,
- 'sliderType': 'percentage',
- 'connect': [true, false],
- 'defaultValue': options.value || options.defaultValue ? options.value || options.defaultValue : 0.20,
- 'range': {
- 'min': 0,
- 'max': 100
- },
- 'step': 1,
- 'format': {
- 'decimals': 1,
- 'postfix': '%'
- },
- 'displayPos': 19,
- 'noInputView': true,
- active: options.active ? options.active : false
- };
- }
- return null;
- }
- };
- }
- return {
- // Get the Singleton instance if one exists
- // or create one if it doesn't
- getInstance: function getInstance() {
- if (!instance) {
- instance = init();
- }
- return instance;
- }
- };
- }();
- return PropertiesCreator;
- });
- //# sourceMappingURL=PropertiesCreator.js.map
|