BaseFeature.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2018
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. *
  7. */
  8. define(['../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (Class) {
  9. 'use strict';
  10. /**
  11. * INTENT:
  12. * BaseFeature provides the base for exposing feature api to some host application.
  13. * Live widget has features but they may not all be exposed all the time.
  14. * Host applications can choose features to activate and when to activate
  15. *
  16. * Host application (e.g. explore, dashboard or any application using live widget api) can choose
  17. * when and which features to activate and can provide additional hooks to integrate the feature.
  18. * E.g. the result of 'showBy' in explore could be to create a compare card, but in another host application,
  19. * it could be a different action e.g. replace current widget with showBy spec
  20. *
  21. * Each feature that is exposed to host app has an api.
  22. * LiveWidget registers features to host app service (made known via perspective json) when its ready
  23. * It will also deregister features when appropriate
  24. *
  25. * Host application requests features to be activated, but LiveWidget may not have been ready at that time
  26. * Host app service coordinates this and ensures Api calls are relayed when its ready
  27. * In the future, Host app service might also expose other runtime info (if needed) to live widget,
  28. * which features could use.
  29. */
  30. var BaseFeature = Class.extend({
  31. init: function init(options) {
  32. BaseFeature.inherited('init', this, arguments);
  33. this.widgetApi = arguments[0];
  34. this.model = options && options.model;
  35. this.liveWidget = options && options.liveWidget;
  36. this._enabled = false;
  37. this._registered = false;
  38. },
  39. isRegistered: function isRegistered() {
  40. return this._registered;
  41. },
  42. register: function register(id, dashboardApi, svcName) {
  43. var _this = this;
  44. if (svcName) {
  45. this._registered = true;
  46. return dashboardApi.getDashboardSvc(svcName).then(function (svc) {
  47. svc.registerFeature(id, _this._getFeatureName(), _this._getApi());
  48. return Promise.resolve(true);
  49. });
  50. }
  51. return Promise.reject(false);
  52. },
  53. deregister: function deregister(id, dashboardApi, svcName) {
  54. var _this2 = this;
  55. if (svcName) {
  56. return dashboardApi.getDashboardSvc(svcName).then(function (svc) {
  57. svc.deregisterFeature(id, _this2._getFeatureName());
  58. return Promise.resolve(true);
  59. });
  60. }
  61. return Promise.reject(false);
  62. },
  63. _getFeatureName: function _getFeatureName() {
  64. return this._featureName || '';
  65. },
  66. //to be overriden
  67. activate: function activate(options) {
  68. this.cb = options.cb;
  69. this._enabled = true;
  70. return true;
  71. },
  72. isEnabled: function isEnabled() {
  73. return this._enabled;
  74. },
  75. //to be overriden
  76. _getApi: function _getApi() {
  77. return {};
  78. },
  79. getVisApi: function getVisApi() {
  80. return this.widgetApi.getVisApi();
  81. }
  82. });
  83. return BaseFeature;
  84. });
  85. //# sourceMappingURL=BaseFeature.js.map