Properties.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. 'use strict';
  2. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. /**
  5. * Licensed Materials - Property of IBM
  6. * IBM Business Analytics (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(['jquery', 'underscore', '../../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../PropertiesAPI'], function ($, _, APIFactory, PropertiesAPI) {
  10. var Properties = function () {
  11. function Properties(options) {
  12. _classCallCheck(this, Properties);
  13. this._api = APIFactory.createAPI(this, [PropertiesAPI]);
  14. this.dashboard = options.features['Dashboard.API'];
  15. /**
  16. * this Properties implementation is been used for both as Dashboard-feature and Content-feature.
  17. * this.content will bu undefined if this is a dashboard feature instance.
  18. */
  19. this.content = options.content;
  20. this._providers = [];
  21. }
  22. Properties.prototype.getAPI = function getAPI() {
  23. return this._api;
  24. };
  25. Properties.prototype.registerProvider = function registerProvider(provider) {
  26. this._providers.push(provider);
  27. };
  28. Properties.prototype.deregisterProvider = function deregisterProvider(provider) {
  29. var idx = this._providers.findIndex(function (p) {
  30. return p === provider;
  31. });
  32. if (idx !== -1) {
  33. this._providers.splice(idx, 1);
  34. }
  35. };
  36. Properties.prototype.getProviderPropertyNameList = function getProviderPropertyNameList() {
  37. var providerProperties = {};
  38. var ind = 1;
  39. _.each(this._providers, function (provider) {
  40. var impltype = void 0;
  41. if (provider.getImplType) {
  42. impltype = provider.getImplType();
  43. } else {
  44. impltype = 'someViewClass_' + ind;
  45. ind += 1;
  46. }
  47. if (!providerProperties[impltype]) {
  48. providerProperties[impltype] = [];
  49. }
  50. if (provider.getPropertyList) {
  51. var _providerProperties$i;
  52. (_providerProperties$i = providerProperties[impltype]).push.apply(_providerProperties$i, provider.getPropertyList().map(function (prop) {
  53. return prop.id;
  54. }));
  55. }
  56. });
  57. return providerProperties;
  58. };
  59. Properties.prototype.getPropertyList = function getPropertyList() {
  60. var allProperties = {};
  61. try {
  62. for (var i = 0; i < this._providers.length; i++) {
  63. var provider = this._providers[i];
  64. if (!provider.isEnabled || provider.isEnabled()) {
  65. var properties = provider.getPropertyList ? provider.getPropertyList() : [];
  66. if (properties) {
  67. for (var j = 0; j < properties.length; j++) {
  68. var property = properties[j];
  69. this.modifyPropertyWithCallback(property);
  70. if (allProperties[property.id]) {
  71. this._mergeProperty(allProperties, property.id, property);
  72. } else {
  73. allProperties[property.id] = property;
  74. }
  75. }
  76. }
  77. }
  78. }
  79. } catch (e) {
  80. // Do nothing since all error should be logged by render sequence
  81. }
  82. this._filterUnsupportedProperties(allProperties);
  83. return _.values(allProperties);
  84. };
  85. Properties.prototype._filterUnsupportedProperties = function _filterUnsupportedProperties(allProps) {
  86. if (this.dashboard) {
  87. var featureChecker = this.dashboard.getGlassCoreSvc && this.dashboard.getGlassCoreSvc('.FeatureChecker');
  88. if (featureChecker) {
  89. var isSmartTitleEnabled = !(featureChecker.checkValue && featureChecker.checkValue('dashboard', 'SmartTitle', 'disabled'));
  90. if (isSmartTitleEnabled) {
  91. delete allProps.showTitle;
  92. } else {
  93. delete allProps.titleMode;
  94. }
  95. }
  96. }
  97. return allProps;
  98. };
  99. Properties.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
  100. var _this = this;
  101. var allLayouts = {};
  102. _.each(this._providers, function (provider) {
  103. if (!provider.isEnabled || provider.isEnabled()) {
  104. var layouts = provider.getPropertyLayoutList ? provider.getPropertyLayoutList() || [] : [];
  105. _.each(layouts, function (layout) {
  106. if (allLayouts[layout.id]) {
  107. _this._mergeProperty(allLayouts, layout.id, layout);
  108. } else {
  109. allLayouts[layout.id] = layout;
  110. }
  111. });
  112. }
  113. });
  114. return _.values(allLayouts);
  115. };
  116. Properties.prototype._mergeProperty = function _mergeProperty(properties, id, provided) {
  117. var current = properties[id];
  118. if (provided.override === false) {
  119. return;
  120. }
  121. var currentProfile = current.profile && [].concat(current.profile);
  122. properties[id] = $.extend(true, {}, current, provided);
  123. if (currentProfile && provided.profile) {
  124. var _properties$id$profil;
  125. (_properties$id$profil = properties[id].profile).push.apply(_properties$id$profil, currentProfile);
  126. properties[id].profile = _.uniq(properties[id].profile);
  127. }
  128. };
  129. Properties.prototype.modifyPropertyWithCallback = function modifyPropertyWithCallback(propObj) {
  130. for (var key in propObj) {
  131. if (key.indexOf('Callback') !== -1 || key === 'onChange') {
  132. var defCallback = propObj[key];
  133. if (typeof defCallback === 'function') {
  134. return;
  135. }
  136. if (typeof defCallback === 'string') {
  137. /// todo: should not have this case
  138. console.error('callback in definition should use new property callback method.');
  139. return;
  140. }
  141. try {
  142. var _feature$defCallback$;
  143. var featurePath = defCallback.feature;
  144. var feature = null;
  145. if (featurePath.indexOf('Dashboard.') === 0) {
  146. var featureName = featurePath.split('.')[1];
  147. feature = this.dashboard.getFeature(featureName);
  148. }
  149. if (!feature) {
  150. feature = this.content.getFeature(featurePath);
  151. }
  152. var params = [this.content];
  153. params.push.apply(params, defCallback.callbackParams);
  154. propObj[key] = (_feature$defCallback$ = feature[defCallback.callbackFunction]).bind.apply(_feature$defCallback$, [feature].concat(params));
  155. } catch (error) {
  156. console.error(error);
  157. }
  158. } else {
  159. if (_typeof(propObj[key]) == 'object' && propObj[key] !== null) {
  160. this.modifyPropertyWithCallback(propObj[key]);
  161. }
  162. }
  163. }
  164. };
  165. return Properties;
  166. }();
  167. return Properties;
  168. });
  169. //# sourceMappingURL=Properties.js.map