'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * */ define(['../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (Class) { 'use strict'; /** * INTENT: * BaseFeature provides the base for exposing feature api to some host application. * Live widget has features but they may not all be exposed all the time. * Host applications can choose features to activate and when to activate * * Host application (e.g. explore, dashboard or any application using live widget api) can choose * when and which features to activate and can provide additional hooks to integrate the feature. * E.g. the result of 'showBy' in explore could be to create a compare card, but in another host application, * it could be a different action e.g. replace current widget with showBy spec * * Each feature that is exposed to host app has an api. * LiveWidget registers features to host app service (made known via perspective json) when its ready * It will also deregister features when appropriate * * Host application requests features to be activated, but LiveWidget may not have been ready at that time * Host app service coordinates this and ensures Api calls are relayed when its ready * In the future, Host app service might also expose other runtime info (if needed) to live widget, * which features could use. */ var BaseFeature = Class.extend({ init: function init(options) { BaseFeature.inherited('init', this, arguments); this.widgetApi = arguments[0]; this.model = options && options.model; this.liveWidget = options && options.liveWidget; this._enabled = false; this._registered = false; }, isRegistered: function isRegistered() { return this._registered; }, register: function register(id, dashboardApi, svcName) { var _this = this; if (svcName) { this._registered = true; return dashboardApi.getDashboardSvc(svcName).then(function (svc) { svc.registerFeature(id, _this._getFeatureName(), _this._getApi()); return Promise.resolve(true); }); } return Promise.reject(false); }, deregister: function deregister(id, dashboardApi, svcName) { var _this2 = this; if (svcName) { return dashboardApi.getDashboardSvc(svcName).then(function (svc) { svc.deregisterFeature(id, _this2._getFeatureName()); return Promise.resolve(true); }); } return Promise.reject(false); }, _getFeatureName: function _getFeatureName() { return this._featureName || ''; }, //to be overriden activate: function activate(options) { this.cb = options.cb; this._enabled = true; return true; }, isEnabled: function isEnabled() { return this._enabled; }, //to be overriden _getApi: function _getApi() { return {}; }, getVisApi: function getVisApi() { return this.widgetApi.getVisApi(); } }); return BaseFeature; }); //# sourceMappingURL=BaseFeature.js.map