KpiPropertyCallbacks.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2019
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. /**
  9. * @class KpiPropertyCallbacks
  10. * @hideconstructor
  11. * @classdesc This class provides APIs for dashboard avtivity state
  12. */
  13. define(['underscore', 'jquery', '../../../widgets/livewidget/nls/StringResources'], function (_, $, StringResources) {
  14. var BASE_SLOT_ID = 'actual';
  15. var TARGET_SLOT_ID = 'goal';
  16. /**
  17. * this class is used in VisPropertyProvider.
  18. */
  19. var KpiPropertyCallbacks = function () {
  20. function KpiPropertyCallbacks() {
  21. _classCallCheck(this, KpiPropertyCallbacks);
  22. }
  23. KpiPropertyCallbacks.prototype.getAPI = function getAPI() {
  24. // we have to return implementation here.
  25. return this;
  26. };
  27. KpiPropertyCallbacks.prototype._isSlotMapped = function _isSlotMapped(slot) {
  28. var dataItems = slot && slot.getDataItemList() || [];
  29. return dataItems.length > 0;
  30. };
  31. KpiPropertyCallbacks.prototype._getDataItem = function _getDataItem(slot) {
  32. var dataItemIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  33. return slot.getDataItemList()[dataItemIndex];
  34. };
  35. KpiPropertyCallbacks.prototype.preRenderBaseLabelProperty = function preRenderBaseLabelProperty(_content) {
  36. var updatedSettings = {};
  37. var baseSlot = _content.getFeature('Visualization').getSlots().getSlot(BASE_SLOT_ID);
  38. if (this._isSlotMapped(baseSlot)) {
  39. var dataItem = this._getDataItem(baseSlot);
  40. updatedSettings.placeHolderText = _.escape(dataItem.getLabel());
  41. } else {
  42. updatedSettings.placeHolderText = '';
  43. }
  44. return updatedSettings;
  45. };
  46. KpiPropertyCallbacks.prototype.preRenderTargetLabelProperty = function preRenderTargetLabelProperty(_content) {
  47. var updatedSettings = {};
  48. var targetSlot = _content.getFeature('Visualization').getSlots().getSlot(TARGET_SLOT_ID);
  49. if (this._isSlotMapped(targetSlot)) {
  50. var dataItem = this._getDataItem(targetSlot);
  51. updatedSettings.placeHolderText = _.escape(dataItem.getLabel());
  52. } else {
  53. updatedSettings.placeHolderText = _.escape(StringResources.get('kpiDefaultTargetLabel'));
  54. }
  55. return updatedSettings;
  56. };
  57. KpiPropertyCallbacks.prototype._getFormatForSlot = function _getFormatForSlot(visualization, slot) {
  58. var dataItem = this._getDataItem(slot);
  59. var format = dataItem && dataItem.getFormat();
  60. return format || {};
  61. };
  62. KpiPropertyCallbacks.prototype.preRenderTargetValueProperty = function preRenderTargetValueProperty(_content) {
  63. var updatedSettings = {};
  64. var visualization = _content.getFeature('Visualization.internal');
  65. var targetSlot = visualization.getSlots().getSlot(TARGET_SLOT_ID);
  66. var baseSlot = visualization.getSlots().getSlot(BASE_SLOT_ID);
  67. if (this._isSlotMapped(targetSlot)) {
  68. updatedSettings.readOnly = true;
  69. updatedSettings.disabled = true;
  70. updatedSettings.placeHolderText = _.escape(StringResources.get('kpiManualTargetSlotFilled'));
  71. updatedSettings.value = '';
  72. } else if (baseSlot) {
  73. // If we have decimal places in the format, allow the user to enter that many decimal places in the target.
  74. var formatSpec = this._getFormatForSlot(visualization, baseSlot);
  75. var decimalPlaces = Math.max(formatSpec.maximumFractionDigits || 0, formatSpec.minimumFractionDigits || 0);
  76. if (decimalPlaces) {
  77. updatedSettings.decimalPlaces = decimalPlaces;
  78. }
  79. }
  80. return updatedSettings;
  81. };
  82. KpiPropertyCallbacks.prototype.preRenderValueSizeProperty = function preRenderValueSizeProperty(_content, property) {
  83. var update = {
  84. options: property.options,
  85. removeProperty: true //if we remove 'removeProperty' here, we should reimplement onChangeValueSizeProperty()
  86. };
  87. if (update.options[0].value === 'auto') {
  88. update.options[0].label = StringResources.get('kpiAutoValueSize');
  89. }
  90. return update;
  91. };
  92. KpiPropertyCallbacks.prototype.onChangeValueSizeProperty = function onChangeValueSizeProperty(_content, propertyName, propertyValue) {
  93. void propertyName;
  94. void propertyValue;
  95. /**
  96. * The property is not using now since we set "removeProperty:true".
  97. * [todo] if we want to re-enable the property, we should directly use widgetModel.properties...
  98. * There is an example in VisPropertyPropvider.
  99. */
  100. /*
  101. let props = {};
  102. if (propertyValue === 'auto') {
  103. props['baseValueSize'] = 'auto';
  104. props['targetValueSize'] = 'auto';
  105. } else {
  106. props['baseValueSize'] = _content.getPropertyValue('baseValueSize');
  107. props['targetValueSize'] = _content.getPropertyValue('targetValueSize');
  108. if (props['baseValueSize'] === 'auto') {
  109. props['baseValueSize'] = '32';
  110. props['targetValueSize'] = '16';
  111. }
  112. props[propertyName] = propertyValue;
  113. }
  114. const transactionId = _.uniqueId('kpi_font_size');
  115. const ownerWidget = _content.getFeature('livewidget.internal').getWidget();
  116. for (let property in props) {
  117. ownerWidget.onPropertyUpdate({
  118. 'category': property,
  119. 'item': props[property],
  120. 'transactionId': transactionId
  121. });
  122. }*/
  123. };
  124. KpiPropertyCallbacks.prototype.validateTargetValueProperty = function validateTargetValueProperty(_content, value) {
  125. var valid = $.isNumeric(value) || !value;
  126. return {
  127. isValid: valid,
  128. message: StringResources.get('kpiNonNumericTarget')
  129. };
  130. };
  131. return KpiPropertyCallbacks;
  132. }();
  133. return KpiPropertyCallbacks;
  134. });
  135. //# sourceMappingURL=KpiPropertyCallbacks.js.map