'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