123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- /**
- * Licensed Materials - Property of IBM
- * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', '../DashboardTemplatesAPI', '../../../../../lib/@waca/dashboard-common/dist/core/APIFactory'], function (_, DashboardTemplatesAPI, APIFactory) {
- var DashboardTemplatesImpl = function () {
- function DashboardTemplatesImpl(options) {
- _classCallCheck(this, DashboardTemplatesImpl);
- this._logger = options.logger;
- this._feature = options.feature;
- this._getContentSvc = options.getContentSvc;
- this._featureChecker = options.featureChecker;
- }
- DashboardTemplatesImpl.prototype.destroy = function destroy() {
- this._feature.destroy();
- this._feature = null;
- };
- DashboardTemplatesImpl.prototype.getAPI = function getAPI() {
- var isEnabled = !this._featureChecker.checkValue('dashboard', 'dashboardTemplates', 'disabled');
- return isEnabled ? APIFactory.createAPI(this, [DashboardTemplatesAPI]) : APIFactory.createAPI(new DashboardTemplatesAPI(), [DashboardTemplatesAPI]);
- };
- DashboardTemplatesImpl.prototype.listTemplates = function listTemplates() {
- var _this = this;
- return this._getContentSvc.then(function (contentSvc) {
- var url = 'v1/search/cm?filter=type%7Cexploration&filter=tags%7Cdashboard_template';
- var options = {
- type: 'GET',
- data: {
- 'fields': 'defaultName,data,id,ancestors,modificationTime'
- }
- };
- return contentSvc.get(url, options).then(function (response) {
- var results = response && response.results;
- if (!results) {
- return [];
- }
- results.sort(function (a, b) {
- return Date.parse(b.modificationTime) - Date.parse(a.modificationTime);
- });
- return results;
- }).catch(function (error) {
- _this._logger.error(error, _this);
- return [];
- });
- });
- };
- DashboardTemplatesImpl.prototype.getTemplate = function getTemplate(id, includeSpec) {
- return this._getContentSvc.then(function (contentSvc) {
- var url = contentSvc.getBaseObjectsURL() + '/' + id;
- var options = {
- dataType: 'json',
- type: 'GET'
- };
- if (includeSpec) {
- options.data = {
- fields: 'specification'
- };
- }
- return contentSvc.get(url, options).then(function (response) {
- var result = response && response.data && response.data.length && response.data[0];
- if (result.specification) {
- try {
- result.specification = JSON.parse(result.specification);
- } catch (e) {
- return Promise.reject(e);
- }
- }
- return result;
- });
- });
- };
- DashboardTemplatesImpl.prototype.getThumbnail = function getThumbnail(id) {
- return this._getContentSvc.then(function (contentSvc) {
- var url = contentSvc.getBaseObjectsURL() + '/' + id + '/items?types=graphic';
- var options = {
- type: 'GET',
- data: {
- 'fields': 'data'
- }
- };
- return contentSvc.get(url, options).then(function (response) {
- var result = response && response.data && response.data.length && response.data[0].data;
- return result;
- });
- });
- };
- return DashboardTemplatesImpl;
- }();
- return DashboardTemplatesImpl;
- });
- //# sourceMappingURL=DashboardTemplatesImpl.js.map
|