123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- '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 Business Analytics (C) Copyright IBM Corp. 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- /**
- * @class KpiPropertyCallbacks
- * @hideconstructor
- * @classdesc This class provides APIs for dashboard avtivity state
- */
- define(['underscore', 'jquery', '../../../widgets/livewidget/nls/StringResources'], function (_, $, StringResources) {
- var BASE_SLOT_ID = 'actual';
- var TARGET_SLOT_ID = 'goal';
- /**
- * this class is used in VisPropertyProvider.
- */
- var KpiPropertyCallbacks = function () {
- function KpiPropertyCallbacks() {
- _classCallCheck(this, KpiPropertyCallbacks);
- }
- KpiPropertyCallbacks.prototype.getAPI = function getAPI() {
- // we have to return implementation here.
- return this;
- };
- KpiPropertyCallbacks.prototype._isSlotMapped = function _isSlotMapped(slot) {
- var dataItems = slot && slot.getDataItemList() || [];
- return dataItems.length > 0;
- };
- KpiPropertyCallbacks.prototype._getDataItem = function _getDataItem(slot) {
- var dataItemIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
- return slot.getDataItemList()[dataItemIndex];
- };
- KpiPropertyCallbacks.prototype.preRenderBaseLabelProperty = function preRenderBaseLabelProperty(_content) {
- var updatedSettings = {};
- var baseSlot = _content.getFeature('Visualization').getSlots().getSlot(BASE_SLOT_ID);
- if (this._isSlotMapped(baseSlot)) {
- var dataItem = this._getDataItem(baseSlot);
- updatedSettings.placeHolderText = _.escape(dataItem.getLabel());
- } else {
- updatedSettings.placeHolderText = '';
- }
- return updatedSettings;
- };
- KpiPropertyCallbacks.prototype.preRenderTargetLabelProperty = function preRenderTargetLabelProperty(_content) {
- var updatedSettings = {};
- var targetSlot = _content.getFeature('Visualization').getSlots().getSlot(TARGET_SLOT_ID);
- if (this._isSlotMapped(targetSlot)) {
- var dataItem = this._getDataItem(targetSlot);
- updatedSettings.placeHolderText = _.escape(dataItem.getLabel());
- } else {
- updatedSettings.placeHolderText = _.escape(StringResources.get('kpiDefaultTargetLabel'));
- }
- return updatedSettings;
- };
- KpiPropertyCallbacks.prototype._getFormatForSlot = function _getFormatForSlot(visualization, slot) {
- var dataItem = this._getDataItem(slot);
- var format = dataItem && dataItem.getFormat();
- return format || {};
- };
- KpiPropertyCallbacks.prototype.preRenderTargetValueProperty = function preRenderTargetValueProperty(_content) {
- var updatedSettings = {};
- var visualization = _content.getFeature('Visualization.internal');
- var targetSlot = visualization.getSlots().getSlot(TARGET_SLOT_ID);
- var baseSlot = visualization.getSlots().getSlot(BASE_SLOT_ID);
- if (this._isSlotMapped(targetSlot)) {
- updatedSettings.readOnly = true;
- updatedSettings.disabled = true;
- updatedSettings.placeHolderText = _.escape(StringResources.get('kpiManualTargetSlotFilled'));
- updatedSettings.value = '';
- } else if (baseSlot) {
- // If we have decimal places in the format, allow the user to enter that many decimal places in the target.
- var formatSpec = this._getFormatForSlot(visualization, baseSlot);
- var decimalPlaces = Math.max(formatSpec.maximumFractionDigits || 0, formatSpec.minimumFractionDigits || 0);
- if (decimalPlaces) {
- updatedSettings.decimalPlaces = decimalPlaces;
- }
- }
- return updatedSettings;
- };
- KpiPropertyCallbacks.prototype.preRenderValueSizeProperty = function preRenderValueSizeProperty(_content, property) {
- var update = {
- options: property.options,
- removeProperty: true //if we remove 'removeProperty' here, we should reimplement onChangeValueSizeProperty()
- };
- if (update.options[0].value === 'auto') {
- update.options[0].label = StringResources.get('kpiAutoValueSize');
- }
- return update;
- };
- KpiPropertyCallbacks.prototype.onChangeValueSizeProperty = function onChangeValueSizeProperty(_content, propertyName, propertyValue) {
- void propertyName;
- void propertyValue;
- /**
- * The property is not using now since we set "removeProperty:true".
- * [todo] if we want to re-enable the property, we should directly use widgetModel.properties...
- * There is an example in VisPropertyPropvider.
- */
- /*
- let props = {};
- if (propertyValue === 'auto') {
- props['baseValueSize'] = 'auto';
- props['targetValueSize'] = 'auto';
- } else {
- props['baseValueSize'] = _content.getPropertyValue('baseValueSize');
- props['targetValueSize'] = _content.getPropertyValue('targetValueSize');
- if (props['baseValueSize'] === 'auto') {
- props['baseValueSize'] = '32';
- props['targetValueSize'] = '16';
- }
- props[propertyName] = propertyValue;
- }
- const transactionId = _.uniqueId('kpi_font_size');
- const ownerWidget = _content.getFeature('livewidget.internal').getWidget();
- for (let property in props) {
- ownerWidget.onPropertyUpdate({
- 'category': property,
- 'item': props[property],
- 'transactionId': transactionId
- });
- }*/
- };
- KpiPropertyCallbacks.prototype.validateTargetValueProperty = function validateTargetValueProperty(_content, value) {
- var valid = $.isNumeric(value) || !value;
- return {
- isValid: valid,
- message: StringResources.get('kpiNonNumericTarget')
- };
- };
- return KpiPropertyCallbacks;
- }();
- return KpiPropertyCallbacks;
- });
- //# sourceMappingURL=KpiPropertyCallbacks.js.map
|