ViprPropertyProvider.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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: Dashboard
  6. * (C) Copyright IBM Corp. 2019, 2020
  7. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/dashboard-common/dist/api/PropertiesProviderAPI', '../../../visualizations/vipr/properties/VIPRProperties', '../../../util/TransactionUtil'], function (_, APIFactory, PropertiesProviderAPI, VIPRProperties, TransactionUtil) {
  10. var ViprPropertyProvider = function () {
  11. function ViprPropertyProvider(options) {
  12. _classCallCheck(this, ViprPropertyProvider);
  13. this.content = options.content;
  14. this.dashboard = options.dashboardAPI;
  15. this.features = options.features;
  16. var Properties = options.features.Properties;
  17. Properties.registerProvider(this.getAPI());
  18. this.model = this.content.getFeature('Models.internal').getWidgetModel();
  19. this.content.on('change:visualization:type', this.onVisualizationChange, this);
  20. this.content.on('change:visualization:slots', this.onVisualizationChange, this);
  21. this.content.on('change:property', this.onVisualizationChange, this);
  22. this.VisDefinitions = this.dashboard.getFeature('VisDefinitions');
  23. this.VisDefinitions.on('refresh:definition', this.onVisualizationChange, this);
  24. this.state = this.content.getFeature('state');
  25. this.visualization = options.features.Visualization;
  26. // TODO - livewidget_cleanup - figure a a cleaner way to clean the property list cache
  27. // When the slots or type change, during rendering, we will try to access the property , so if we reset it bebfore rendering,
  28. // then we will attempt to generate the property list during rendering and using the old slots mappings and we might get the wrong properties (those props that depend on slots like legend)
  29. this.content.on('change:state:status', this.onRenderStateChange, this);
  30. this._isChanged = true;
  31. }
  32. ViprPropertyProvider.prototype.getAPI = function getAPI() {
  33. if (!this._api) {
  34. this._api = APIFactory.createAPI(this, [PropertiesProviderAPI]);
  35. }
  36. return this._api;
  37. };
  38. ViprPropertyProvider.prototype.destroy = function destroy() {
  39. this.content.off('change:state:status', this.onRenderStateChange, this);
  40. this.content.off('change:type', this.onVisualizationChange, this);
  41. this.content.off('change:property', this.onVisualizationChange, this);
  42. this.VisDefinitions.off('refresh:definition', this.onVisualizationChange, this);
  43. this.content = null;
  44. };
  45. ViprPropertyProvider.prototype.onRenderStateChange = function onRenderStateChange(event) {
  46. if (this._isChanged && event.info.value === 'rendered') {
  47. this._isChanged = false;
  48. this._propertyList = null;
  49. this._propertyLayoutList = null;
  50. }
  51. };
  52. ViprPropertyProvider.prototype.onVisualizationChange = function onVisualizationChange() {
  53. this._isChanged = true;
  54. };
  55. ViprPropertyProvider.prototype._getLivewidgetInternal = function _getLivewidgetInternal() {
  56. if (!this.livewidgetInternal) {
  57. this.livewidgetInternal = this.content.getFeature('livewidget.internal');
  58. }
  59. return this.livewidgetInternal;
  60. };
  61. ViprPropertyProvider.prototype._getView = function _getView() {
  62. var lwInternal = this._getLivewidgetInternal();
  63. return lwInternal && lwInternal.getVisView();
  64. };
  65. ViprPropertyProvider.prototype._isVIPR = function _isVIPR() {
  66. var renderer = this.visualization.getDefinition().getProperty('renderer');
  67. return renderer && renderer.indexOf('VIPRView') !== -1;
  68. };
  69. /**
  70. * @param {*} property
  71. * @param {*} widget
  72. */
  73. ViprPropertyProvider.prototype.modifyPropertyWithSetterAndGetter = function modifyPropertyWithSetterAndGetter(property) {
  74. var _this = this;
  75. // [livewidget-cleanup] todo: removed the dependenty from widget
  76. var propertySupport = this.content.getFeature('Visualization.legacy').getLegacyManagers().visPropertySupport;
  77. _.extend(property, {
  78. getPropertyValue: function getPropertyValue() {
  79. return propertySupport.getPropertyValue(property.id);
  80. },
  81. setPropertyValue: function setPropertyValue(value, transactionToken) {
  82. _this.updateProperty({
  83. id: property.id,
  84. value: value
  85. }, transactionToken);
  86. },
  87. supportsUndoRedo: true
  88. });
  89. };
  90. /**
  91. * @returns true if the property is not a 'general' property (i.e. is a
  92. * visualization property that can be overriden by a user)
  93. */
  94. ViprPropertyProvider.prototype.isAnOverridableVisProperty = function isAnOverridableVisProperty(property) {
  95. var commonProps = {
  96. 'fillColor': true,
  97. 'borderColor': true,
  98. 'transparency': true,
  99. 'showTitle': true,
  100. 'saveTitle': true,
  101. 'queryRefresh': true
  102. };
  103. return !commonProps[property];
  104. };
  105. ViprPropertyProvider.prototype.updateProperty = function updateProperty(property, transactionToken) {
  106. if (this.isAnOverridableVisProperty(property.id)) {
  107. var boardModel = this.dashboard.getFeature('internal').getBoardModel();
  108. var options = TransactionUtil.transactionTokenToOptions(transactionToken);
  109. var extendedOptions = _.extend({}, options, boardModel.getLanguageModelOptions(true));
  110. var widgetModel = this.content.getFeature('Models.internal').getWidgetModel();
  111. if (property.id.indexOf('colorPalette') > -1) {
  112. if (this.features.LiveWidgetSegment) {
  113. this.features.LiveWidgetSegment.track({
  114. category: 'colorPalette',
  115. visualization: this.content.getFeature('Visualization'),
  116. content: this.content,
  117. info: {
  118. propertyId: property.id,
  119. previousValue: this.content.getPropertyValue(property.id),
  120. newValue: property.value
  121. }
  122. });
  123. }
  124. }
  125. // Update the properties on the vismodel
  126. widgetModel.properties.set(property, _.extend({
  127. merge: true,
  128. remove: false,
  129. silent: true
  130. }, extendedOptions));
  131. }
  132. };
  133. ViprPropertyProvider.prototype.getPropertyList = function getPropertyList() {
  134. var _this2 = this;
  135. if (!this._propertyList && this._isVIPR()) {
  136. var rawPropertyList = void 0;
  137. var visView = this._getView();
  138. if (visView && this.state.getStatus() === this.state.STATUS.RENDERED) {
  139. rawPropertyList = visView.getPropertyList();
  140. } else {
  141. var slots = this.visualization.getSlots().getSlotList();
  142. var properties = this.visualization.getDefinition().getProperty('vizDefProperties');
  143. rawPropertyList = VIPRProperties.getInstance().getPropertyList(properties, slots, this.content);
  144. }
  145. if (rawPropertyList) {
  146. var propertyList = _.map(rawPropertyList, function (property) {
  147. var newProp = _.extend({}, property);
  148. _this2.modifyPropertyWithSetterAndGetter(newProp);
  149. // If the property is tagged as multilingual and we're in translation mode and we're missing the translation for the current locale
  150. if (newProp.editor && newProp.editor.uiControl && newProp.editor.uiControl.multilingual) {
  151. var translationService = _this2.dashboard.getFeature('TranslationService');
  152. if (translationService) {
  153. var _ref = _this2.model.getMultilingualAttribute(newProp.id) || {},
  154. multilingualProperty = _ref.multilingualProperty;
  155. translationService.processMultilingualProperty(newProp, multilingualProperty);
  156. }
  157. }
  158. return newProp;
  159. });
  160. this._propertyList = propertyList;
  161. }
  162. }
  163. return this._propertyList;
  164. };
  165. ViprPropertyProvider.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
  166. if (!this._propertyLayoutList && this._isVIPR()) {
  167. this._propertyLayoutList = [];
  168. var visView = this._getView();
  169. if (visView && this.state.getStatus() === this.state.STATUS.RENDERED) {
  170. this._propertyLayoutList = visView.getPropertyLayoutList();
  171. } else {
  172. var slots = this.visualization.getSlots().getSlotList();
  173. var properties = this.visualization.getDefinition().getProperty('vizDefProperties');
  174. this._propertyLayoutList = VIPRProperties.getInstance().getPropertyLayoutList(properties, slots, this.content, this.dashboard);
  175. }
  176. }
  177. return this._propertyLayoutList;
  178. };
  179. return ViprPropertyProvider;
  180. }();
  181. return ViprPropertyProvider;
  182. });
  183. //# sourceMappingURL=ViprPropertyProvider.js.map