123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- 'use strict';
- 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; };
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Dashboard
- * (C) Copyright IBM Corp. 2017, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define(['underscore', './BaseProvider', '../../../DynamicFileLoader'], function (_, BaseProvider, DynamicFileLoader) {
- var ID_prefix = 'com.ibm.bi.dashboard.';
- var ICON_REG_EXP = /{{ICON:.*}}/;
- var LocalProvider = BaseProvider.extend({
- definitionsPromise: null,
- init: function init(options) {
- LocalProvider.inherited('init', this, arguments);
- this.logger = options.dashboardApi.getGlassCoreSvc('.Logger');
- this.localDefinitions = [];
- },
- clear: function clear() {
- this.definitionsPromise = null;
- },
- /**
- * this helper function will traverse the entire definition and replace {{ICON:....}} with the right icon id.
- * e.g. for "{{ICON:restore_16.default.id}}", it is equivalent as:
- * const module = require('dashboard-analytics/lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/restore_16');
- * const iconId = module['default']['id']
- */
- _fetchIconId: function _fetchIconId(definitionObj) {
- var _this = this;
- var proms = [];
- var _loop = function _loop(key) {
- if (_typeof(definitionObj[key]) == 'object' && definitionObj[key] !== null) {
- proms.push.apply(proms, _this._fetchIconId(definitionObj[key]));
- } else if (typeof definitionObj[key] === 'string' && ICON_REG_EXP.test(definitionObj[key])) {
- var iconPath = definitionObj[key].slice(7, -2).split('.');
- var filename = iconPath[0];
- var paths = iconPath.slice(1);
- var url = 'dashboard-analytics/lib/@waca/dashboard-common/dist/lib/@ba-ui-toolkit/ba-graphics/dist/icons-js/' + filename;
- proms.push(DynamicFileLoader.load([url]).then(function (modules) {
- var m = modules[0];
- paths.forEach(function (n) {
- m = m[n];
- });
- definitionObj[key] = m;
- }));
- }
- };
- for (var key in definitionObj) {
- _loop(key);
- }
- return proms;
- },
- _preprocessDefinitions: function _preprocessDefinitions(definitionList) {
- var _this2 = this;
- var proms = [];
- definitionList.forEach(function (definition) {
- // fix any fully qualified ids to local ids
- definition.id = definition.id.replace(ID_prefix, '');
- // replace {{ICON:****}} with the correct id
- proms.push.apply(proms, _this2._fetchIconId(definition));
- });
- return Promise.all(proms).then(function () {
- return definitionList;
- });
- },
- getDefinitions: function getDefinitions() {
- var _this3 = this;
- if (!this.definitionsPromise) {
- this.definitionsPromise = new Promise(function (resolve) {
- _this3.dashboardApi.findGlassCollection(ID_prefix + 'live-visualizations').then(function (data) {
- return _this3._preprocessDefinitions(data);
- }).then(function (definitionList) {
- var _localDefinitions;
- _this3.setDefinitions(definitionList);
- _this3.massageDefinitions(definitionList);
- _this3.freezeDefinitions(definitionList);
- definitionList = definitionList || [];
- (_localDefinitions = _this3.localDefinitions).push.apply(_localDefinitions, definitionList);
- resolve(_this3.localDefinitions);
- }).catch(function (e) {
- _this3.logger.error('Error: unable to query local definitions', e);
- resolve([]);
- });
- });
- }
- return this.definitionsPromise;
- },
- massageDefinitions: function massageDefinitions() {
- var definitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- definitions.forEach(function (definition) {
- var datasets = definition.datasets;
- if (datasets) {
- datasets.forEach(function (dataset) {
- dataset.getId = function () {
- return dataset.name;
- };
- });
- }
- });
- },
- refreshProvider: function refreshProvider() {
- return Promise.resolve(this.localDefinitions);
- },
- refresh: function refresh() {
- throw new Error('refresh is not supported for local provider');
- }
- });
- return LocalProvider;
- });
- //# sourceMappingURL=LocalProvider.js.map
|