BaseProvider.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Dashboard
  5. * (C) Copyright IBM Corp. 2016, 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/core-client/js/core-client/ui/core/Class', '../../../widgets/livewidget/nls/StringResources', '../../../lib/@waca/dashboard-common/dist/utils/ObjectHelper'], function (_, Class, resources, ObjectHelper) {
  9. var BaseProvider = Class.extend({
  10. init: function init(params) {
  11. this.dashboardApi = params.dashboardApi;
  12. // look-up map for supported viz definition id
  13. this.definitionIds = {};
  14. // setup the root path for icons from config (default: /dashboard-analytics/images)
  15. this.icon_root = this.dashboardApi && this.dashboardApi.getConfiguration('liveWidgetImagesRoot') || 'dashboard-analytics/images/';
  16. if (this.icon_root.lastIndexOf('/') !== this.icon_root.length - 1) {
  17. // ensure root ends with a slash
  18. this.icon_root += '/';
  19. }
  20. },
  21. clear: function clear() {},
  22. contains: function contains(id) {
  23. var result = void 0;
  24. if (_.size(this.definitionIds) === 0) {
  25. // need to ask the back-end since the map is not ready
  26. return this.getDefinition(id).then(function (definition) {
  27. return !!definition;
  28. });
  29. } else {
  30. result = Promise.resolve(this.definitionIds[id] ? true : false);
  31. }
  32. return result;
  33. },
  34. refreshProvider: function refreshProvider() {},
  35. setDefinitions: function setDefinitions(definitions) {
  36. var _this = this;
  37. // build the look-up map
  38. if (_.size(this.definitionIds) === 0) {
  39. _.each(definitions, function (definition) {
  40. _this.definitionIds[definition.id] = true;
  41. });
  42. }
  43. },
  44. getDefinitions: function getDefinitions() {
  45. return Promise.resolve([]);
  46. },
  47. getDefinition: function getDefinition(id) {
  48. return this.getDefinitions().then(function (definitions) {
  49. return _.find(definitions, function (def) {
  50. return def.id === id;
  51. });
  52. });
  53. },
  54. _rewriteVisUri: function _rewriteVisUri(visDef) {
  55. this.dashboardApi.getGlassSvc('.Ajax', function (ajaxSvc) {
  56. if (visDef.uri) {
  57. visDef.uri = ajaxSvc.rewriteUrl(visDef.uri);
  58. }
  59. if (visDef.icon) {
  60. visDef.icon = ajaxSvc.rewriteUrl(visDef.icon);
  61. }
  62. if (visDef.iconUri) {
  63. visDef.iconUri = ajaxSvc.rewriteUrl(visDef.iconUri);
  64. }
  65. if (visDef.specification && visDef.specification.template) {
  66. visDef.specification.template = ajaxSvc.rewriteUrl(visDef.specification.template);
  67. }
  68. });
  69. return visDef;
  70. },
  71. _getProductLocale: function _getProductLocale() {
  72. return this.dashboardApi.getGlassCoreSvc('.UserProfile').preferences.productLocale || 'en';
  73. },
  74. _getLocalizedValue: function _getLocalizedValue(id, defaultValue) {
  75. var value = resources.get(id);
  76. if (value.indexOf('__NOT_TRANSLATED__') !== -1) {
  77. // This shouldn't happen. This will be logged, but if it happens, then it is better to show the server value.
  78. value = defaultValue;
  79. }
  80. return value;
  81. },
  82. freezeDefinitions: function freezeDefinitions() {
  83. var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  84. data.forEach(function (object, idx, array) {
  85. array[idx] = ObjectHelper.deepFreezeObject(object);
  86. });
  87. },
  88. massageDefinitions: function massageDefinitions() {}
  89. });
  90. return BaseProvider;
  91. });
  92. //# sourceMappingURL=BaseProvider.js.map