DashboardFactory.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /**
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['./Dashboard', './DashboardCore'], function (DashboardImpl, DashboardCore) {
  9. /**
  10. * @class DashboardFactory
  11. * @classdesc Factory class creating an instance of DashboardAPI
  12. */
  13. var DashboardFactory = function () {
  14. function DashboardFactory() {
  15. _classCallCheck(this, DashboardFactory);
  16. this._bootstrapFeatures = {};
  17. this._featureDefinitions = {
  18. dashboard: [],
  19. content: []
  20. };
  21. }
  22. /**
  23. * Initializes the DashboardFactory; creates default bootstrap features if none is provided
  24. * @param {Object} initParams - map of name-instance of the bootstrap features
  25. * @param {Object} initParams.bootstrapFeatures - map of name-instance of the bootstrap features
  26. * @param {Array} initParams.dashboardFeatures - array listing all the dashboard feature definitions
  27. * @param {Array} initParams.contentFeatures - array listing all the content feature definitions
  28. * @return {Promise} - resolved if init is successful, rejected if an error occurred during the init process
  29. * @throws throws an exception if no parameter is provided
  30. */
  31. DashboardFactory.prototype.init = function init(_ref) {
  32. var bootstrapFeatures = _ref.bootstrapFeatures,
  33. dashboardFeatures = _ref.dashboardFeatures,
  34. contentFeatures = _ref.contentFeatures;
  35. if (typeof bootstrapFeatures['Logger'] === 'undefined') {
  36. this._bootstrapFeatures['Logger'] = console;
  37. } else {
  38. this._bootstrapFeatures['Logger'] = bootstrapFeatures['Logger'];
  39. }
  40. this._featureDefinitions.dashboard = dashboardFeatures ? dashboardFeatures : [];
  41. this._featureDefinitions.content = contentFeatures ? contentFeatures : [];
  42. return Promise.resolve();
  43. };
  44. /**
  45. * Returns the instance of a bootstrap feature
  46. * @param {String} name - name of the feature
  47. * @returns {Object} instance of the feature or undefined if unknown
  48. */
  49. DashboardFactory.prototype.getBootstrapFeature = function getBootstrapFeature(name) {
  50. return this._bootstrapFeatures[name];
  51. };
  52. /**
  53. * Returns the dashboard features
  54. * @returns [] Json array describing the dashboard features
  55. */
  56. DashboardFactory.prototype.getDashboardFeatures = function getDashboardFeatures() {
  57. return this._featureDefinitions.dashboard;
  58. };
  59. /**
  60. * Returns the content features
  61. * @returns [] Json array describing the content features
  62. */
  63. DashboardFactory.prototype.getContentFeatures = function getContentFeatures() {
  64. return this._featureDefinitions.content;
  65. };
  66. /**
  67. * creates an instance of DashboardAPI based on the passed spec
  68. * @param {Object} options - map of parameters
  69. * @param {Object} options.spec - dashboard spec
  70. * @returns {Promise} - resolved when the CoreDashboard instance is created
  71. */
  72. DashboardFactory.prototype.create = function create() {
  73. this._dashboardAPI = new DashboardImpl({
  74. view: {}
  75. });
  76. return Promise.resolve(new DashboardCore({ dashboardAPI: this._dashboardAPI }).getAPI());
  77. };
  78. return DashboardFactory;
  79. }();
  80. return DashboardFactory;
  81. });
  82. //# sourceMappingURL=DashboardFactory.js.map