123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- 'use strict';
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
- /**
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2017, 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', 'com/ibm/vida/control/vida', './VIPRConfig', './VIPRLibraries', './VIPRUtils', './VIPRBundleHelper'], function (_, Class, vida, VIPRConfig, VIPRLibraries, VIPRUtils, VIPRBundleHelper) {
- 'use strict';
- var CUSTOM_PREVIEWS = ['visualizationPreview', 'com.ibm.vis.schematicsPreview'];
- var VIPRProxy = Class.extend({
- init: function init() {
- this._setInitialStates();
- },
- _setInitialStates: function _setInitialStates() {
- this._libs = undefined;
- //Only reset for custom libs so that they can be refreshed
- this._customLibs = undefined;
- if (!this.libraries) {
- this.libraries = {
- system: [],
- custom: []
- };
- } else {
- //Only reset for custom libs so that they can be refreshed
- this.libraries.custom = [];
- }
- },
- initialize: function initialize() {
- var _this = this;
- var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- this.dashboardApi = params.dashboardApi;
- if (params.refresh) {
- this._setInitialStates();
- }
- if (!this._libs) {
- this.ajaxSvc = params.dashboardApi.getGlassCoreSvc('.Ajax');
- return VIPRBundleHelper.getALLVIPRLibraries({ dashboardApi: params.dashboardApi }).then(function (libraries) {
- var libsToCreate = _this._getLibsBundleToCreate(libraries, params.refresh);
- return _this._setRequiredConfigurationDefaults(libsToCreate).then(function () {
- var configuredLibraries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- configuredLibraries.forEach(function (lib) {
- var bundleinfo = VIPRConfig.getConfig(lib.id);
- lib.config = {};
- // Add properties config if there is any
- if (bundleinfo) {
- if (bundleinfo.isCustomVis && bundleinfo.bundleInclude) {
- lib.config['properties'] = bundleinfo.bundleInclude;
- } else if (bundleinfo.isCustomVis && !bundleinfo.bundleInclude) {
- // never has to get to this case
- var logger = _this.dashboardApi.getGlassCoreSvc('.Logger');
- logger.error('`Failed to set lib.config.properties');
- } else if (!bundleinfo.isCustomVis && bundleinfo.config) {
- lib.config['properties'] = bundleinfo.config;
- }
- }
- // Add slots config if there is any.
- if (bundleinfo && bundleinfo.slotConfig) {
- lib.config['slots'] = bundleinfo.slotConfig;
- }
- });
- _this._createLibs(configuredLibraries, params.refresh);
- _this._setLibraries(configuredLibraries);
- });
- });
- }
- return Promise.resolve();
- },
- updateCustomLibrary: function updateCustomLibrary(id) {
- var library = this._customLibs[id];
- if (library) {
- this._updateLibrary(library);
- }
- },
- getLibraries: function getLibraries() {
- if (!this._libs) {
- var libs = _extends({}, this._systemLibs, this._customLibs);
- this._libs = _.indexBy(libs, 'id');
- }
- return this._libs;
- },
- getSystemLibIds: function getSystemLibIds() {
- return this.libraries ? this.libraries.system.map(function (library) {
- return library.id;
- }) : [];
- },
- getCustomLibIds: function getCustomLibIds() {
- return this.libraries ? this.libraries.custom.map(function (library) {
- return library.id;
- }) : [];
- },
- getBundleIds: function getBundleIds() {
- var libType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : VIPRLibraries.LIB_TYPE_ALL;
- var ids = [];
- if (libType === VIPRLibraries.LIB_TYPE_ALL || libType === VIPRLibraries.LIB_TYPE_SYSTEM) {
- ids.push.apply(ids, this.getSystemLibIds());
- }
- if (libType === VIPRLibraries.LIB_TYPE_ALL || libType === VIPRLibraries.LIB_TYPE_CUSTOM) {
- ids.push.apply(ids, this.getCustomLibIds());
- }
- return ids;
- },
- _setLibraries: function _setLibraries() {
- var _this2 = this;
- var libraries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- if (!this._customLibs) {
- this._customLibs = {};
- }
- if (!this._systemLibs) {
- this._systemLibs = {};
- }
- libraries.forEach(function (library) {
- if (library.isSchematic || library.isCustomVis || CUSTOM_PREVIEWS.indexOf(library.id) !== -1) {
- _this2._customLibs[library.id] = library;
- _this2.libraries.custom.push(library);
- } else {
- _this2._systemLibs[library.id] = library;
- _this2.libraries.system.push(library);
- }
- });
- },
- _getLibsBundleToCreate: function _getLibsBundleToCreate() {
- var libraries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- var refresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- if (!refresh) {
- return libraries;
- }
- var libsToCreate = [];
- libraries.forEach(function (library) {
- if (library.isSchematic || library.isCustomVis || CUSTOM_PREVIEWS.indexOf(library.id) !== -1) {
- libsToCreate.push(library);
- }
- });
- return libsToCreate;
- },
- _createLibs: function _createLibs() {
- var _this3 = this;
- var configuredLibraries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
- var refresh = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- if (refresh) {
- configuredLibraries.forEach(function (library) {
- _this3._updateLibrary(library);
- });
- } else {
- _.extend(this, vida.VIPR.create({ bundles: configuredLibraries }));
- }
- },
- _updateLibrary: function _updateLibrary(library) {
- var bundle = library || {};
- var isSchematic = bundle.isSchematic;
- if (bundle.id && !isSchematic) {
- this.unregister(bundle.id);
- }
- if (bundle.id && (isSchematic && !this.isRegistered(bundle.id) || !isSchematic)) {
- this.register(bundle.id, bundle.location, bundle.config, bundle.fileName, bundle);
- }
- },
- /**
- * @param {String} viprDefinitionId - Vis bundle id
- * @param {Object} requiredConfig - contains a list of required configuration tokens/properties
- * @returns {String} a definition id for a library that should be removed as the user/server doesnt have the required configuration(e.g. without mapbox tokens, the user will not be able to use maps)
- * Makes a rest call searching for specific configuration tokens on a user's server and sets the corresponding default properties
- */
- _fetchAndApplyRequiredConfigurationDefaults: function _fetchAndApplyRequiredConfigurationDefaults(_ref) {
- var _this4 = this;
- var viprDefinitionId = _ref.viprDefinitionId,
- requiredConfig = _ref.requiredConfig;
- return Promise.reduce(requiredConfig, function (values, key) {
- return _this4.dashboardApi.getGlassCoreSvc('.Config').getConfigValue(key).then(function (value) {
- values[key] = value;
- return values;
- });
- }, {}).then(function (response) {
- if (Object.values(response).indexOf('default') === -1) {
- VIPRUtils.applyRequiredConfiguration(viprDefinitionId, requiredConfig, response);
- return null;
- }
- return viprDefinitionId;
- }).catch(function () {
- return viprDefinitionId;
- });
- },
- /*
- * Check each library to see if there is a required configuration. If so, then call fetchAndApplyRequiredConfigurationDefaults
- * which will gather up any viprdefinitionids that do not have the corresponding configuration tokens--in this case, the id will
- * be removed from the libraries so that the user cannot use that type of visualization.
- */
- _setRequiredConfigurationDefaults: function _setRequiredConfigurationDefaults(libraries) {
- var _this5 = this;
- var libraryRequiredConfigs = libraries.map(function (lib) {
- return { viprDefinitionId: lib.id, requiredConfig: VIPRUtils.getRequiredConfig(lib.id) };
- }).filter(function (libraryRequiredConfig) {
- return !!libraryRequiredConfig.requiredConfig;
- });
- return Promise.map(libraryRequiredConfigs, function (config) {
- return _this5._fetchAndApplyRequiredConfigurationDefaults(config);
- }).filter(function (definition) {
- return !!definition;
- }).then(function (definitionsToBeRemoved) {
- return libraries.filter(function (lib) {
- return !_.contains(definitionsToBeRemoved, lib.id);
- });
- });
- },
- createWidget: function createWidget(nodeId, hostAPI) {
- return new vida.SmallMultipleGrid({ vipr: this, hostAPI: hostAPI }, nodeId);
- },
- unloadBundle: function unloadBundle(id) {
- this.unload(id);
- },
- loadBundle: function loadBundle(id) {
- var _this6 = this;
- return this.load(id).then(function (bundle) {
- return vida.SmallMultipleGrid.extendVizBundle(bundle);
- }).catch(function (error) {
- var logger = _this6.dashboardApi.getGlassCoreSvc('.Logger');
- if (id !== 'visualizationPreview') {
- logger.error(error);
- }
- });
- }
- });
- // create a singleton instance
- return new VIPRProxy();
- });
- //# sourceMappingURL=VIPR.js.map
|