'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Dashboard * (C) Copyright IBM Corp. 2016, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ 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) { var BaseProvider = Class.extend({ init: function init(params) { this.dashboardApi = params.dashboardApi; // look-up map for supported viz definition id this.definitionIds = {}; // setup the root path for icons from config (default: /dashboard-analytics/images) this.icon_root = this.dashboardApi && this.dashboardApi.getConfiguration('liveWidgetImagesRoot') || 'dashboard-analytics/images/'; if (this.icon_root.lastIndexOf('/') !== this.icon_root.length - 1) { // ensure root ends with a slash this.icon_root += '/'; } }, clear: function clear() {}, contains: function contains(id) { var result = void 0; if (_.size(this.definitionIds) === 0) { // need to ask the back-end since the map is not ready return this.getDefinition(id).then(function (definition) { return !!definition; }); } else { result = Promise.resolve(this.definitionIds[id] ? true : false); } return result; }, refreshProvider: function refreshProvider() {}, setDefinitions: function setDefinitions(definitions) { var _this = this; // build the look-up map if (_.size(this.definitionIds) === 0) { _.each(definitions, function (definition) { _this.definitionIds[definition.id] = true; }); } }, getDefinitions: function getDefinitions() { return Promise.resolve([]); }, getDefinition: function getDefinition(id) { return this.getDefinitions().then(function (definitions) { return _.find(definitions, function (def) { return def.id === id; }); }); }, _rewriteVisUri: function _rewriteVisUri(visDef) { this.dashboardApi.getGlassSvc('.Ajax', function (ajaxSvc) { if (visDef.uri) { visDef.uri = ajaxSvc.rewriteUrl(visDef.uri); } if (visDef.icon) { visDef.icon = ajaxSvc.rewriteUrl(visDef.icon); } if (visDef.iconUri) { visDef.iconUri = ajaxSvc.rewriteUrl(visDef.iconUri); } if (visDef.specification && visDef.specification.template) { visDef.specification.template = ajaxSvc.rewriteUrl(visDef.specification.template); } }); return visDef; }, _getProductLocale: function _getProductLocale() { return this.dashboardApi.getGlassCoreSvc('.UserProfile').preferences.productLocale || 'en'; }, _getLocalizedValue: function _getLocalizedValue(id, defaultValue) { var value = resources.get(id); if (value.indexOf('__NOT_TRANSLATED__') !== -1) { // This shouldn't happen. This will be logged, but if it happens, then it is better to show the server value. value = defaultValue; } return value; }, freezeDefinitions: function freezeDefinitions() { var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; data.forEach(function (object, idx, array) { array[idx] = ObjectHelper.deepFreezeObject(object); }); }, massageDefinitions: function massageDefinitions() {} }); return BaseProvider; }); //# sourceMappingURL=BaseProvider.js.map