DashboardTemplatesImpl.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 Business Analytics (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', '../DashboardTemplatesAPI', '../../../../../lib/@waca/dashboard-common/dist/core/APIFactory'], function (_, DashboardTemplatesAPI, APIFactory) {
  9. var DashboardTemplatesImpl = function () {
  10. function DashboardTemplatesImpl(options) {
  11. _classCallCheck(this, DashboardTemplatesImpl);
  12. this._logger = options.logger;
  13. this._feature = options.feature;
  14. this._getContentSvc = options.getContentSvc;
  15. this._featureChecker = options.featureChecker;
  16. }
  17. DashboardTemplatesImpl.prototype.destroy = function destroy() {
  18. this._feature.destroy();
  19. this._feature = null;
  20. };
  21. DashboardTemplatesImpl.prototype.getAPI = function getAPI() {
  22. var isEnabled = !this._featureChecker.checkValue('dashboard', 'dashboardTemplates', 'disabled');
  23. return isEnabled ? APIFactory.createAPI(this, [DashboardTemplatesAPI]) : APIFactory.createAPI(new DashboardTemplatesAPI(), [DashboardTemplatesAPI]);
  24. };
  25. DashboardTemplatesImpl.prototype.listTemplates = function listTemplates() {
  26. var _this = this;
  27. return this._getContentSvc.then(function (contentSvc) {
  28. var url = 'v1/search/cm?filter=type%7Cexploration&filter=tags%7Cdashboard_template';
  29. var options = {
  30. type: 'GET',
  31. data: {
  32. 'fields': 'defaultName,data,id,ancestors,modificationTime'
  33. }
  34. };
  35. return contentSvc.get(url, options).then(function (response) {
  36. var results = response && response.results;
  37. if (!results) {
  38. return [];
  39. }
  40. results.sort(function (a, b) {
  41. return Date.parse(b.modificationTime) - Date.parse(a.modificationTime);
  42. });
  43. return results;
  44. }).catch(function (error) {
  45. _this._logger.error(error, _this);
  46. return [];
  47. });
  48. });
  49. };
  50. DashboardTemplatesImpl.prototype.getTemplate = function getTemplate(id, includeSpec) {
  51. return this._getContentSvc.then(function (contentSvc) {
  52. var url = contentSvc.getBaseObjectsURL() + '/' + id;
  53. var options = {
  54. dataType: 'json',
  55. type: 'GET'
  56. };
  57. if (includeSpec) {
  58. options.data = {
  59. fields: 'specification'
  60. };
  61. }
  62. return contentSvc.get(url, options).then(function (response) {
  63. var result = response && response.data && response.data.length && response.data[0];
  64. if (result.specification) {
  65. try {
  66. result.specification = JSON.parse(result.specification);
  67. } catch (e) {
  68. return Promise.reject(e);
  69. }
  70. }
  71. return result;
  72. });
  73. });
  74. };
  75. DashboardTemplatesImpl.prototype.getThumbnail = function getThumbnail(id) {
  76. return this._getContentSvc.then(function (contentSvc) {
  77. var url = contentSvc.getBaseObjectsURL() + '/' + id + '/items?types=graphic';
  78. var options = {
  79. type: 'GET',
  80. data: {
  81. 'fields': 'data'
  82. }
  83. };
  84. return contentSvc.get(url, options).then(function (response) {
  85. var result = response && response.data && response.data.length && response.data[0].data;
  86. return result;
  87. });
  88. });
  89. };
  90. return DashboardTemplatesImpl;
  91. }();
  92. return DashboardTemplatesImpl;
  93. });
  94. //# sourceMappingURL=DashboardTemplatesImpl.js.map