CanvasFactory.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['./Canvas', '../features/content/InlineFeatures'], function (CanvasImpl, InlineFeatures) {
  9. var CanvasFactory = function () {
  10. function CanvasFactory(options) {
  11. _classCallCheck(this, CanvasFactory);
  12. this.dashboardAPI = options.dashboardAPI;
  13. this.glassContext = options.glassContext;
  14. this.logger = options.logger;
  15. this.featureLoader = options.featureLoader;
  16. this.inlineFeature = options.inlineFeature || InlineFeatures;
  17. this.extensions = options.extensions;
  18. this.boardModel = options.boardModel;
  19. this.eventRouter = options.eventRouter;
  20. this.widgetRegistry = options.widgetRegistry;
  21. this.featureLoader = options.featureLoader;
  22. this.stringResources = this.dashboardAPI.getDashboardCoreSvc('.StringResources');
  23. this._dashboardContent = options.dashboardContent;
  24. this.profile = this.dashboardAPI.getAppConfig('profile') || null;
  25. }
  26. CanvasFactory.prototype.createCanvas = function createCanvas() {
  27. var _this = this;
  28. var options = {
  29. // Features required by the canvas and the content API
  30. dashboardFeatures: this.featureLoader,
  31. boardModel: this.boardModel,
  32. extensions: this.extensions,
  33. // the following 2 should be cleaned up
  34. copyCallbabck: this.dashboardAPI.copy.bind(this.dashboardAPI),
  35. pasteCallback: this.dashboardAPI.paste.bind(this.dashboardAPI),
  36. profile: this.profile,
  37. dashboardContent: this._dashboardContent
  38. };
  39. return this.dashboardAPI.findGlassCollection('com.ibm.bi.dashboard.content-features').then(function (collectionItems) {
  40. options.contentFeatureCollection = _this.inlineFeature.concat(collectionItems || []);
  41. var contentTypeRegistry = _this.dashboardAPI.getFeature('ContentTypeRegistry');
  42. if (contentTypeRegistry) {
  43. options.contentFeatureCollection = contentTypeRegistry.processFeatureCollection(options.contentFeatureCollection);
  44. }
  45. var canvasImpl = new CanvasImpl(options);
  46. // Create the canvas API
  47. _this.featureLoader.registerFeature('Canvas', canvasImpl);
  48. return canvasImpl.initialize().then(function () {
  49. // now the canvas is ready, dashboard spec is available via the 'Serializer' feature, no need of the initial one
  50. _this.boardModel.deleteInitialSpec();
  51. return {
  52. canvas: canvasImpl.getAPI(),
  53. internalCanvas: {
  54. whenContentReady: function whenContentReady(contentId) {
  55. return canvasImpl.whenContentReady(contentId);
  56. },
  57. registerFeatureCollection: function registerFeatureCollection(contentId, collectionName) {
  58. return _this.dashboardAPI.findGlassCollection(collectionName).then(function (collectionItems) {
  59. return canvasImpl.registerContentFeatures(contentId, collectionItems || []);
  60. });
  61. },
  62. registerFeature: function registerFeature(contentId, featureId, featureInstance, featureSpec) {
  63. return canvasImpl.registerContentFeature(contentId, featureId, featureInstance, featureSpec);
  64. },
  65. registerDeprecatedFeature: function registerDeprecatedFeature(contentId, featureId, featureInstance) {
  66. return canvasImpl.registerContentFeature(contentId, featureId, featureInstance, {}, true);
  67. },
  68. destroy: function destroy() {
  69. canvasImpl.destroy();
  70. }
  71. }
  72. };
  73. });
  74. });
  75. };
  76. return CanvasFactory;
  77. }();
  78. return CanvasFactory;
  79. });
  80. //# sourceMappingURL=CanvasFactory.js.map