VisPropertyProvider.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/PropertiesProviderAPI', '../../../util/TransactionUtil'], function (_, APIFactory, PropertiesProviderAPI, TransactionUtil) {
  9. var VisPropertyProvider = function () {
  10. function VisPropertyProvider(options) {
  11. _classCallCheck(this, VisPropertyProvider);
  12. this.content = options.content;
  13. this.dashboard = options.dashboardAPI;
  14. var Properties = options.features.Properties;
  15. Properties.registerProvider(this.getAPI());
  16. this.model = this.content.getFeature('Models.internal').getWidgetModel();
  17. this.content.on('change:visualization:type', this.onVisualizationTypeChange, this);
  18. }
  19. VisPropertyProvider.prototype.getAPI = function getAPI() {
  20. if (!this._api) {
  21. this._api = APIFactory.createAPI(this, [PropertiesProviderAPI]);
  22. }
  23. return this._api;
  24. };
  25. VisPropertyProvider.prototype.destroy = function destroy() {
  26. this.content.off('change:visualization:type', this.onVisualizationTypeChange, this);
  27. this.content = null;
  28. };
  29. VisPropertyProvider.prototype.onVisualizationTypeChange = function onVisualizationTypeChange() {
  30. this._propertyList = null;
  31. this._propertyLayoutList = null;
  32. };
  33. VisPropertyProvider.prototype.getWidget = function getWidget() {
  34. return this.content;
  35. };
  36. VisPropertyProvider.prototype._getPropertyFromRawDefinition = function _getPropertyFromRawDefinition(name) {
  37. var definition = this.content.getFeature('Visualization').getDefinition();
  38. var rawProp = definition && definition.getProperty(name);
  39. if (rawProp) {
  40. return JSON.parse(JSON.stringify(rawProp));
  41. }
  42. };
  43. /**
  44. * todo: we dont need this after we use new api events.
  45. * @param {*} property
  46. * @param {*} widget
  47. */
  48. VisPropertyProvider.prototype.modifyPropertyWithSetterAndGetter = function modifyPropertyWithSetterAndGetter(property, widget) {
  49. var _this = this;
  50. // [livewidget-cleanup] todo: removed the dependenty from widget
  51. var propertySupport = widget.visModelManager.propertySupport;
  52. _.extend(property, {
  53. getPropertyValue: function getPropertyValue() {
  54. return propertySupport.getPropertyValue(property.id);
  55. },
  56. setPropertyValue: function setPropertyValue(value, transactionToken) {
  57. _this.updateProperty({
  58. id: property.id,
  59. value: value
  60. }, transactionToken);
  61. }
  62. });
  63. };
  64. /**
  65. * @returns true if the property is not a 'general' property (i.e. is a
  66. * visualization property that can be overriden by a user)
  67. */
  68. VisPropertyProvider.prototype.isAnOverridableVisProperty = function isAnOverridableVisProperty(property) {
  69. var commonProps = {
  70. 'fillColor': true,
  71. 'borderColor': true,
  72. 'transparency': true,
  73. 'showTitle': true,
  74. 'saveTitle': true,
  75. 'queryRefresh': true,
  76. 'datagrid.viewOption': true, // managed by the content props
  77. 'value.graphic.content': true, // managed by the content props
  78. 'value.graphic.currentScaleOption': true, // managed by the content props
  79. 'value.graphic.fillColor': true, // managed by the content props
  80. 'value.graphic.borderColor': true // managed by the content props
  81. };
  82. return !commonProps[property];
  83. };
  84. VisPropertyProvider.prototype.updateProperty = function updateProperty(property, transactionToken) {
  85. if (this.isAnOverridableVisProperty(property.id)) {
  86. var boardModel = this.dashboard.getFeature('internal').getBoardModel();
  87. var options = TransactionUtil.transactionTokenToOptions(transactionToken);
  88. var extendedOptions = _.extend({}, options, boardModel.getLanguageModelOptions(true));
  89. if (!extendedOptions.payloadData) {
  90. extendedOptions.payloadData = {};
  91. }
  92. extendedOptions.payloadData.skipUndoRedo = true;
  93. var widgetModel = this.content.getFeature('Models.internal').getWidgetModel();
  94. // Update the properties on the vismodel
  95. widgetModel.properties.set(property, _.extend({
  96. merge: true,
  97. remove: false
  98. }, extendedOptions));
  99. }
  100. };
  101. VisPropertyProvider.prototype._getWidget = function _getWidget() {
  102. return this.content.getFeature('livewidget.internal').getWidget();
  103. };
  104. VisPropertyProvider.prototype.getPropertyList = function getPropertyList() {
  105. var _this2 = this;
  106. if (!this._propertyList) {
  107. var propertyListFromDefinition = this._getPropertyFromRawDefinition('propertyList');
  108. if (propertyListFromDefinition && propertyListFromDefinition.length > 0) {
  109. propertyListFromDefinition.forEach(function (property) {
  110. if (_this2.isAnOverridableVisProperty(property.id)) {
  111. _this2.modifyPropertyWithSetterAndGetter(property, _this2._getWidget());
  112. if (property.editor && property.editor.uiControl && property.editor.uiControl.multilingual) {
  113. var translationService = _this2.dashboard.getFeature('TranslationService');
  114. if (translationService) {
  115. var _ref = _this2.model.getMultilingualAttribute(property.id) || {},
  116. multilingualProperty = _ref.multilingualProperty;
  117. translationService.processMultilingualProperty(property, multilingualProperty);
  118. }
  119. }
  120. }
  121. });
  122. } else {
  123. propertyListFromDefinition = [];
  124. }
  125. this._propertyList = propertyListFromDefinition;
  126. }
  127. // TODO: The following if section need to be removed once the feature flag is not used
  128. // when remove the feature flag,
  129. // 1. remove the property with id "condColorPalette" from BAcrosstab.json and BAGrid.json potentially
  130. // 2. remove the following if section
  131. if (this._isNewConditionalFormatFeature() && (this._isCrosstab() || this._isTable())) {
  132. this._propertyList = this._propertyList.filter(function (element) {
  133. return !(element.editor && element.editor.sectionId === 'visualization.colorPalette');
  134. });
  135. }
  136. return this._propertyList;
  137. };
  138. VisPropertyProvider.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
  139. if (!this._propertyLayoutList) {
  140. var rawPropertyLayoutList = this._getPropertyFromRawDefinition('propertyLayoutList');
  141. this._propertyLayoutList = rawPropertyLayoutList ? rawPropertyLayoutList : [];
  142. }
  143. // TODO: The following if section need to be removed once the feature flag is not used
  144. // when remove the feature flag,
  145. // 1. remove the property layout definition of colorPalette at line 713 - 718 in BACrosstab.json and potentially BAGrid.json
  146. // 2. remove the following if section
  147. if (this._isNewConditionalFormatFeature() && (this._isCrosstab() || this._isTable())) {
  148. this._propertyLayoutList = this._propertyLayoutList.filter(function (element) {
  149. return element.id !== 'colorPalette';
  150. });
  151. }
  152. return this._propertyLayoutList;
  153. };
  154. VisPropertyProvider.prototype._isNewConditionalFormatFeature = function _isNewConditionalFormatFeature() {
  155. return !this.dashboard.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'xtabcondFormat', 'disabled');
  156. };
  157. VisPropertyProvider.prototype._isCrosstab = function _isCrosstab() {
  158. return this.content.getFeature('Visualization').getType() === 'Crosstab';
  159. };
  160. VisPropertyProvider.prototype._isTable = function _isTable() {
  161. return this.content.getFeature('Visualization').getType() === 'List';
  162. };
  163. return VisPropertyProvider;
  164. }();
  165. return VisPropertyProvider;
  166. });
  167. //# sourceMappingURL=VisPropertyProvider.js.map