123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- '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 Cognos Products: Dashboard
- * (C) Copyright IBM Corp. 2018, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *
- */
- define(['../../../DynamicFileLoader', './InlineFeatures', 'underscore'], function (DynamicFileLoader, inlineFeatures, _) {
- 'use strict';
- /**
- * @deprecated Replaced by dashboard-core/js/features/FeatureLoader.js
- */
- var FeatureLoader = function () {
- function FeatureLoader(widgetApi, dashboardApi) {
- _classCallCheck(this, FeatureLoader);
- this.widgetApi = widgetApi;
- this.dashboardApi = dashboardApi;
- this.features = {};
- this.disabledFeatures = {};
- }
- /**
- * Load the live widget features
- * @param Array(String) featureSet - list of feature to be loaded. If no featureSet is defined, then we load everything.
- *
- */
- FeatureLoader.prototype.loadFeatures = function loadFeatures(featureSet) {
- var _this = this;
- return this.dashboardApi.findGlassCollection('com.ibm.bi.dashboard.live-features').then(function (collectionItems) {
- var promises = [];
- if (collectionItems) {
- // Adde the inline features. Inline features are a quick and easy way to test features without having to add the perspective json
- collectionItems = collectionItems.concat(inlineFeatures);
- collectionItems.forEach(function (feature) {
- var identifier = feature.name || feature.id;
- if (!featureSet || featureSet.indexOf(identifier) !== -1) {
- promises.push(DynamicFileLoader.load([feature.class]).then(function (modules) {
- _this.features[identifier] = new modules[0](_this.widgetApi, _this.dashboardApi);
- }));
- }
- });
- }
- return Promise.all(promises);
- });
- };
- FeatureLoader.prototype.setFeatureEnabled = function setFeatureEnabled(name, isEnabled) {
- if (isEnabled) {
- delete this.disabledFeatures[name];
- } else {
- this.disabledFeatures[name] = true;
- }
- };
- FeatureLoader.prototype.unloadFeatures = function unloadFeatures() {
- var _this2 = this;
- _.each(_.keys(this.features), function (featureName) {
- if (_this2.features[featureName].destroy) {
- _this2.features[featureName].destroy();
- }
- delete _this2.features[featureName];
- });
- this.features = {};
- };
- FeatureLoader.prototype.setFeature = function setFeature(name, feature) {
- this.features[name] = feature;
- };
- FeatureLoader.prototype.getFeature = function getFeature(name) {
- var api;
- if (this.features[name] && this.isFeatureEnabled(name) && this.features[name].getAPI) {
- api = this.features[name].getAPI();
- }
- return api;
- };
- FeatureLoader.prototype.isFeatureEnabled = function isFeatureEnabled(name) {
- return !this.disabledFeatures[name] && (!this.features[name].isEnabled || this.features[name].isEnabled());
- };
- /**
- * @param tagToMatch - a tag that any feature must include in its getTags() api.
- * @returns any features that match the tag passed in as an array (empty array is returned if no features match).
- */
- FeatureLoader.prototype.getMatchingFeatures = function getMatchingFeatures(tagToMatch) {
- var _this3 = this;
- var matchingFeatures = [];
- _.each(_.keys(this.features), function (featureName) {
- var feature = _this3.features[featureName];
- if (feature && _this3.isFeatureEnabled(featureName) && feature.getFeatureTags && feature.getFeatureTags().indexOf(tagToMatch) >= 0) {
- var featureAPI = _this3.getFeature(featureName);
- if (featureAPI) {
- matchingFeatures.push(featureAPI);
- }
- }
- });
- return matchingFeatures;
- };
- /**
- * Enable or disable a feature that matches the supplied tag
- * @param tagToMatch - a tag that any feature must include in its getTags() api.
- * @param isEnabled
- */
- FeatureLoader.prototype.setMatchingFeaturesEnabled = function setMatchingFeaturesEnabled(tagToMatch, isEnabled) {
- var _this4 = this;
- _.each(_.keys(this.features), function (featureName) {
- var feature = _this4.features[featureName];
- if (feature && feature.getFeatureTags && feature.getFeatureTags().indexOf(tagToMatch) >= 0) {
- _this4.setFeatureEnabled(featureName, isEnabled);
- }
- });
- };
- FeatureLoader.prototype.getExtraRenderSequenceSteps = function getExtraRenderSequenceSteps() {
- var steps = [];
- for (var name in this.features) {
- if (this.isFeatureEnabled(name) && this.features[name].getExtraRenderSequenceSteps) {
- var extraSteps = this.features[name].getExtraRenderSequenceSteps();
- if (extraSteps) {
- steps.push.apply(steps, Array.isArray(extraSteps) ? extraSteps : [extraSteps]);
- }
- }
- }
- return steps;
- };
- /**
- * Return an array of render sequence step names that are associated with the supplied tag.
- * If enabledFeaturesOnly is set to true, only return the steps associated with enabled features.
- * @param tagToMatch - a tag hat any feature must include in its getTags() api.
- * @param enabledFeaturesOnly (default false) - if set, only steps for enabled features will be returned.
- * @returns an array of step ids for the renderSequence steps that are associated with the features that match the tag.
- */
- FeatureLoader.prototype.getMatchingFeatureStepIds = function getMatchingFeatureStepIds(tagToMatch) {
- var enabledFeaturesOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- var stepIds = [];
- for (var name in this.features) {
- if (!enabledFeaturesOnly || this.isFeatureEnabled(name)) {
- var feature = this.features[name];
- if (feature && feature.getFeatureTags && feature.getExtraRenderSequenceSteps && feature.getFeatureTags().indexOf(tagToMatch) >= 0) {
- var extraSteps = this.features[name].getExtraRenderSequenceSteps();
- if (extraSteps) {
- extraSteps = Array.isArray(extraSteps) ? extraSteps : [extraSteps];
- stepIds.push.apply(stepIds, extraSteps.map(function (step) {
- return step.id;
- }));
- }
- }
- }
- }
- return stepIds;
- };
- return FeatureLoader;
- }();
- return FeatureLoader;
- });
- //# sourceMappingURL=FeatureLoader.js.map
|