123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- 'use strict';
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
- /**
- * Licensed Materials - Property of IBM
- * IBM Business Analytics (C) Copyright IBM Corp. 2018, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- /**
- * @class VisDefinitionsAPI
- * @hideconstructor
- *
- * @classdesc
- * Represents the API to access the visualization definitions that are registered in the dashboard application
- */
- define(['../../../../../lib/@waca/dashboard-common/dist/core/APIFactory', '../VisDefinitionsAPI', '../InternalVisDefinitionsAPI', '../VisDefinitionsAPISpec', '../../../../../api/VisDefinitionAPI', '../../../../../api/impl/VisDefinition', '../../../../../visualizations/definitions/VisDefinitionManager', '../../../../../widgets/livewidget/util/VisUtil'], function (APIFactory, VisDefinitionsAPI, InternalVisDefinitionsAPI, VisDefinitionsAPISpec, VisDefinitionAPI, VisDefinitionImpl, VisDefinitionManager, VisUtil) {
- var VisDefinitions = function (_VisDefinitionsAPISpe) {
- _inherits(VisDefinitions, _VisDefinitionsAPISpe);
- function VisDefinitions(options) {
- _classCallCheck(this, VisDefinitions);
- var _this = _possibleConstructorReturn(this, _VisDefinitionsAPISpe.call(this));
- _this.dashboard = options.features.API;
- // TODO : VisDefinitionManager should go away and the implementation should belong to this feature implementation
- _this.visDefinitionManager = new VisDefinitionManager({
- dashboardApi: _this.dashboard
- });
- _this.internalAPI = APIFactory.createAPI(_this, [VisDefinitionsAPI, InternalVisDefinitionsAPI]);
- _this.api = APIFactory.createAPI(_this, [VisDefinitionsAPI]);
- _this._definitionAPIMap = null;
- _this._definitionsJSON = null;
- _this._modifiers = [];
- return _this;
- }
- VisDefinitions.prototype.getAPI = function getAPI(type) {
- if (type === 'internal') {
- return this.internalAPI;
- } else {
- return this.api;
- }
- };
- VisDefinitions.prototype.destroy = function destroy() {
- if (this._definitionAPIMap) {
- for (var id in this._definitionAPIMap.implById) {
- this._definitionAPIMap.implById[id].destroy();
- }
- }
- this._definitionsJSON = null;
- this._definitionAPIMap = null;
- this.dashboard = null;
- this.visDefinitionManager = null;
- this.internalAPI = null;
- this.api = null;
- this._modifiers = null;
- };
- VisDefinitions.prototype.initialize = function initialize() {
- var _this2 = this;
- if (this._definitionAPIMap) {
- return Promise.resolve(this._definitionAPIMap);
- } else {
- return this.visDefinitionManager.getAll(this.dashboard).then(function (definitions) {
- _this2._definitionsJSON = definitions;
- return _this2._createDefinitionAPIMap(definitions);
- });
- }
- };
- VisDefinitions.prototype._createDefinitionAPIMap = function _createDefinitionAPIMap() {
- var _this3 = this;
- var definitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- var conditionalFormattingFeature = !this.dashboard.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'xtabcondFormat', 'disabled');
- this._definitionAPIMap = definitions.jsonDefinitions.reduce(function (map, definition) {
- definition = _this3.modifyDefinition(definition);
- var id = definition.id;
- if (conditionalFormattingFeature && (id === 'crosstab' || id === 'JQGrid')) {
- definition = JSON.parse(JSON.stringify(definition));
- definition.dataSlots.forEach(function (slot) {
- if (slot.id === 'heat') {
- slot.hidden = true;
- }
- });
- }
- var impl = new VisDefinitionImpl(definition, _this3.visDefinitionManager);
- var definitionAPI = APIFactory.createAPI(impl, [VisDefinitionAPI]);
- _this3._addToDefinitionMap(map, impl, definitionAPI);
- return map;
- }, { implById: {}, byId: {}, byType: {}, list: [] });
- return this._definitionAPIMap;
- };
- VisDefinitions.prototype._addToDefinitionMap = function _addToDefinitionMap(definitionAPIMap, definitionImpl, definitionApi) {
- var id = definitionApi.getId();
- definitionAPIMap.implById[id] = definitionImpl;
- definitionAPIMap.byId[id] = definitionApi;
- definitionAPIMap.byType[definitionApi.getType() || id] = definitionApi;
- definitionAPIMap.list.push(definitionApi);
- // ensure the events are propagated to the parent
- APIFactory.setParentChildRelation(this, definitionImpl);
- };
- VisDefinitions.prototype.getList = function getList() {
- var list = this._definitionAPIMap && this._definitionAPIMap.list || [];
- /**
- * livewidget-cleanup [todo] need to revisit here:
- * should we always filter out the definition with error state or just for empty definition ?
- * currently, we only set error for empty definition..
- */
- return list.filter(function (definition) {
- return !definition.getState().getError();
- });
- };
- VisDefinitions.prototype.loadById = function loadById(id) {
- return this.visDefinitionManager.get(id);
- };
- VisDefinitions.prototype.getById = function getById(id) {
- var visDefinition = this._definitionAPIMap && this._definitionAPIMap.byId[id];
- if (!visDefinition) {
- var visDefinitionImpl = new VisDefinitionImpl({ id: id, type: id }, this.visDefinitionManager);
- visDefinition = visDefinitionImpl.getAPI();
- this._addToDefinitionMap(this._definitionAPIMap, visDefinitionImpl, visDefinition);
- visDefinitionImpl.setError(VisUtil.createVisDefinitionLoadingError(id));
- }
- return visDefinition;
- };
- VisDefinitions.prototype.getByType = function getByType(type) {
- return this._definitionAPIMap && this._definitionAPIMap.byType[type];
- };
- VisDefinitions.prototype.refresh = function refresh() {
- var _this4 = this;
- return this.visDefinitionManager.refreshProviders(this.dashboard).then(function (visDefinitions) {
- _this4._definitionsJSON = visDefinitions;
- _this4._createDefinitionAPIMap(visDefinitions);
- });
- };
- // Internal API
- VisDefinitions.prototype.getAll = function getAll() {
- return this.visDefinitionManager.getAll(this.dashboard);
- };
- // Internal API
- VisDefinitions.prototype.getRawDefinition = function getRawDefinition(id) {
- var definitionImpl = this._definitionAPIMap.implById[id];
- var error = definitionImpl && definitionImpl.getState().getError();
- if (!error && !definitionImpl) {
- error = VisUtil.createVisDefinitionLoadingError(id);
- }
- if (error) {
- throw error;
- }
- return this._definitionAPIMap.implById[id].visSpec;
- };
- VisDefinitions.prototype.modifyDefinition = function modifyDefinition(definition) {
- if (this._modifiers.length > 0) {
- // The definition object may be frozen
- definition = JSON.parse(JSON.stringify(definition));
- this._modifiers.forEach(function (modifier) {
- try {
- modifier.modifyDefinition(definition);
- } catch (e) {
- // a bad extension.. ignore it.
- }
- });
- }
- return definition;
- };
- VisDefinitions.prototype.registerModifier = function registerModifier(modifier) {
- if (this._modifiers.indexOf(modifier) === -1 && typeof modifier.modifyDefinition === 'function') {
- this._modifiers.push(modifier);
- if (this._definitionsJSON) {
- this._createDefinitionAPIMap(this._definitionsJSON);
- }
- }
- };
- VisDefinitions.prototype.deregisterModifier = function deregisterModifier(modifier) {
- var idx = this._modifiers.indexOf(modifier);
- if (idx !== -1) {
- this._modifiers.splice(idx, 1);
- if (this._definitionsJSON) {
- this._createDefinitionAPIMap(this._definitionsJSON);
- }
- }
- };
- return VisDefinitions;
- }(VisDefinitionsAPISpec);
- return VisDefinitions;
- });
- //# sourceMappingURL=VisDefinitions.js.map
|