DashboardPropertiesProvider.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 (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/api/PropertiesProviderAPI', '../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../../../lib/@waca/core-client/js/core-client/utils/ClassFactory', '../../../app/nls/StringResources'], function (_, PropertiesProviderAPI, APIFactory, ClassFactory, StringResources) {
  9. var DashboardPropertiesProvider = function () {
  10. function DashboardPropertiesProvider(options) {
  11. _classCallCheck(this, DashboardPropertiesProvider);
  12. this._api = APIFactory.createAPI(this, [PropertiesProviderAPI]);
  13. this._properties = options.features.Properties;
  14. this._internal = options.features.internal;
  15. // TODO - we should not depend on the dashboard API in here
  16. this.dashboard = options.features.API;
  17. }
  18. DashboardPropertiesProvider.prototype.getAPI = function getAPI() {
  19. return this._api;
  20. };
  21. DashboardPropertiesProvider.prototype.initialize = function initialize() {
  22. // register self as a properties provider contributing align properties
  23. this._properties.registerProvider(this._api);
  24. return this._fetchThemes();
  25. };
  26. DashboardPropertiesProvider.prototype.destroy = function destroy() {
  27. if (this._properties) {
  28. this._properties.deregisterProvider(this._api);
  29. }
  30. };
  31. DashboardPropertiesProvider.prototype.getPropertyLayoutList = function getPropertyLayoutList() {
  32. return [{
  33. 'value': StringResources.get('dashboardProperties'),
  34. 'id': 'banner',
  35. 'type': 'Banner',
  36. 'editable': false
  37. }, {
  38. id: 'general',
  39. type: 'Group',
  40. label: StringResources.get('tabName_general')
  41. }, {
  42. id: 'colorsAndTheme',
  43. type: 'Section',
  44. label: StringResources.get('sectionName_colorsAndThemes'),
  45. position: 3
  46. }];
  47. };
  48. DashboardPropertiesProvider.prototype.getPropertyList = function getPropertyList() {
  49. var _this = this;
  50. var internalApi = this._internal;
  51. var boardModel = internalApi.getBoardModel();
  52. var propertiesModel = boardModel.properties;
  53. return [{
  54. id: 'theme',
  55. setPropertyValue: function setPropertyValue(value) {
  56. boardModel.set({ 'theme': value });
  57. },
  58. getPropertyValue: function getPropertyValue() {
  59. return boardModel.get('theme');
  60. },
  61. editor: {
  62. sectionId: 'general.colorsAndTheme',
  63. position: 1,
  64. uiControl: {
  65. type: 'DropDown',
  66. label: StringResources.get('propTheme'),
  67. getOptions: function getOptions() {
  68. return _this._themeListing;
  69. }
  70. }
  71. }
  72. }, {
  73. id: 'dashboardColorSet',
  74. setPropertyValue: function setPropertyValue(value) {
  75. propertiesModel.set({ 'dashboardColorSet': value });
  76. },
  77. getPropertyValue: function getPropertyValue() {
  78. return propertiesModel.get('dashboardColorSet') || 'userPaletteColor';
  79. },
  80. editor: {
  81. sectionId: 'general.colorsAndTheme',
  82. position: 1,
  83. uiControl: {
  84. type: 'NewPalette',
  85. paletteType: 'ColorPalette',
  86. sectionLabel: StringResources.get('propDashboardColorPalette'),
  87. newPaletteLabel: StringResources.get('propNewDashboardPaletteLabel'),
  88. linkLabel: StringResources.get('propDashboardChangePaletteLink'),
  89. ariaLabel: StringResources.get('propDashboardColorPalette'),
  90. includeUserColorPalette: true,
  91. onChange: function onChange(propertyName, propertyValue) {
  92. _this.setPropertyValue(propertyName, propertyValue);
  93. _this.dashboard.triggerDashboardEvent('properties:refreshPane', {
  94. sender: propertiesModel.id
  95. });
  96. }
  97. }
  98. }
  99. }, {
  100. id: 'fredIsRed',
  101. setPropertyValue: function setPropertyValue(value) {
  102. propertiesModel.set({ 'fredIsRed': value });
  103. },
  104. getPropertyValue: function getPropertyValue() {
  105. return propertiesModel.get('fredIsRed');
  106. },
  107. validatePropertyValue: function validatePropertyValue(value) {
  108. return {
  109. isValid: typeof value === 'boolean',
  110. message: 'fredIsRed property must be of type boolean.'
  111. };
  112. },
  113. editor: {
  114. sectionId: 'general.advanced',
  115. position: 1,
  116. uiControl: {
  117. type: 'ToggleButton',
  118. label: StringResources.get('propFredIsRed')
  119. }
  120. }
  121. }, {
  122. id: 'dataCache',
  123. setPropertyValue: function setPropertyValue(value) {
  124. var modelledValue = value === 'automatic' ? undefined : value;
  125. propertiesModel.set({
  126. 'localCache': modelledValue
  127. });
  128. },
  129. getPropertyValue: function getPropertyValue() {
  130. return propertiesModel.get('localCache') || 'automatic';
  131. },
  132. editor: {
  133. sectionId: 'general.advanced',
  134. position: 2,
  135. uiControl: {
  136. type: 'DropDown',
  137. label: StringResources.get('dataCache'),
  138. options: [{
  139. label: StringResources.get('dataCache_auto'),
  140. value: 'automatic'
  141. }, {
  142. label: StringResources.get('dataCache_on'),
  143. value: 'yes'
  144. }, {
  145. label: StringResources.get('dataCache_off'),
  146. value: 'no'
  147. }]
  148. }
  149. }
  150. }];
  151. };
  152. DashboardPropertiesProvider.prototype._fetchThemes = function _fetchThemes() {
  153. var _this2 = this;
  154. if (!this._themeListing) {
  155. this._themeListing = [];
  156. return ClassFactory.loadModule('text!dashboard-core/js/lib/@waca/dashboard-common/dist/themes/themeListing.json').then(function (themeListing) {
  157. var themesInfo = JSON.parse(themeListing);
  158. _.each(themesInfo.themes, function (theme) {
  159. _this2._themeListing.push({
  160. label: StringResources.get(theme.name + 'Label'),
  161. value: theme.name
  162. });
  163. });
  164. return _this2._themeListing;
  165. }, function () {
  166. _this2._themeListing = [];
  167. return _this2._themeListing;
  168. });
  169. } else {
  170. return Promise.resolve(this._themeListing);
  171. }
  172. };
  173. return DashboardPropertiesProvider;
  174. }();
  175. return DashboardPropertiesProvider;
  176. });
  177. //# sourceMappingURL=DashboardPropertiesProvider.js.map