123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- '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: BI Cloud (C) Copyright IBM Corp. 2018, 2020
- * 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/utils/ClassFactory', './LifeCycleManager', '../../lib/@waca/dashboard-common/dist/utils/dnd/DnDManager', '../../lib/@waca/baglass/js/baglass/services/ServiceRegistry', './DashboardStringService', '../../features/FeatureLoader', './InlineFeatures', './DeprecatedInlineFeatures'], function (ClassFactory, LifeCycleManager, DnDManager, ServiceRegistry, DashboardStringService, FeatureLoader, inlineFeatures, deprecatedInlineFeatures) {
- /**
- * Helper class used to create the core dashboard services and services registry
- */
- var ServicesHelper = function () {
- function ServicesHelper(options) {
- _classCallCheck(this, ServicesHelper);
- this.glassContext = options.glassContext;
- this.eventRouter = options.eventRouter;
- this.appSettings = options.appSettings;
- this.logger = options.logger;
- this.dashboardAPI = options.dashboardAPI;
- this.inlineFeatures = options.inlineFeatures || inlineFeatures;
- this.internalDashboardAPI = options.internalDashboardAPI;
- }
- ServicesHelper.prototype.createServices = function createServices() {
- var _this = this;
- var response = {};
- response.lifeCycleManager = new LifeCycleManager();
- response.dnDManager = new DnDManager();
- response.stringService = new DashboardStringService();
- var lifeCycleFeature = {
- registerHandler: response.lifeCycleManager.registerLifeCycleHandler.bind(response.lifeCycleManager),
- invokeHandlers: response.lifeCycleManager.invokeLifeCycleHandlers.bind(response.lifeCycleManager)
- };
- this.featureLoader = new FeatureLoader({
- lifeCycleManager: lifeCycleFeature,
- featureNamePrefix: 'Dashboard'
- });
- // Temporary -- needed by the live widget priview in order to create a content API
- // TODO - cleanup the live widget preview to be created without needing this.
- this.featureLoader.registerFeature('DashboardFeatureLoader.internal', {
- getAPI: function getAPI() {
- return _this.featureLoader;
- }
- }, null, true);
- // Some feature require the dashboard api (or the internal API)..
- // let us added so it can be requested through dependencies
- this.featureLoader.registerFeature('API', {
- getAPI: function getAPI() {
- return _this.dashboardAPI;
- }
- }, null, true);
- this.featureLoader.registerFeature('internal', {
- getAPI: function getAPI() {
- return _this.internalDashboardAPI;
- }
- }, null, true);
- // Make the logger availale as a native feature so it could be required as a dependency
- this.featureLoader.registerFeature('Logger', {
- getAPI: function getAPI() {
- return _this.logger;
- }
- }, null, true);
- this.featureLoader.registerFeature('FeatureRegistry.internal', {
- getAPI: function getAPI() {
- return _this.featureLoader.getAPI();
- }
- }, null, true);
- this.featureLoader.registerFeature('LifeCycle', {
- getAPI: function getAPI() {
- return lifeCycleFeature;
- }
- }, null, true);
- // Core dashboard services - can be called using getSvcSync
- this.services = new ServiceRegistry({
- services: {
- 'Notification': {
- showError: this.glassContext.appController.showErrorMessage.bind(this.glassContext.appController)
- },
- 'Logger': this.logger,
- '.LifeCycleManager': response.lifeCycleManager,
- '.DndManager': response.dnDManager,
- '.StringResources': response.stringService
- }
- });
- // TODO - remove this services and cleanup the code that calls it
- this.services.biGlass = {
- glassContext: this.glassContext
- };
- response.serviceRegistry = this.services;
- response.featureLoader = this.featureLoader;
- return response;
- };
- ServicesHelper.prototype._registerServiceCollection = function _registerServiceCollection(dashboardApi, collection, isFeature) {
- var promises = [];
- if (collection) {
- collection.forEach(function (serviceExtension) {
- if (!serviceExtension.name || !serviceExtension.class) {
- return;
- }
- promises.push(ClassFactory.loadModule(serviceExtension.class).then(function (ServiceExtension) {
- var _this2 = this;
- var options = serviceExtension.options || {};
- options.services = this.services;
- options.eventRouter = this.eventRouter;
- options.glassContext = this.glassContext;
- options.dashboardApi = dashboardApi;
- var extension = new ServiceExtension(options);
- var whenInitialized = void 0;
- if (isFeature && extension.initialize && typeof extension.initialize === 'function') {
- whenInitialized = extension.initialize();
- } else {
- whenInitialized = Promise.resolve();
- }
- return whenInitialized.then(function () {
- var extensionAPI = null;
- if (isFeature && extension.getAPI && typeof extension.getAPI === 'function') {
- extensionAPI = extension.getAPI();
- }
- _this2.services.register(serviceExtension.name, extensionAPI || extension);
- _this2._registerServiceHooks(extension);
- });
- }.bind(this)).catch(function (err) {
- //continue working even if an extension failed to load
- this.logger.error(err);
- // recover
- // TODO: maybe we don't need to recover.
- // Please check
- }.bind(this)));
- }.bind(this));
- }
- return Promise.all(promises);
- };
- /**
- * Create runtime services: Register services/features to be used
- * @public
- * @param {Object} options Create runtime services options
- * @param {Object} options.dashboardApi Dashboard API
- * @param {Object} options.collections Collections used to inject features
- * @param {Array} options.collections.templates Array of template collection items for injecting template feature
- * @function ServicesHelper#createRuntimeServices
- */
- ServicesHelper.prototype.createRuntimeServices = function createRuntimeServices(options) {
- var _this3 = this;
- var dashboardApi = options.dashboardApi;
- return dashboardApi.findGlassCollection('com.ibm.bi.dashboard.features').then(function (collectionItems) {
- var items = collectionItems || [];
- items = items.concat(_this3.inlineFeatures);
- items.push({
- name: 'InternalProperties',
- class: 'dashboard-core/js/features/dashboard/dashboardProperties/DashboardInternalProperties',
- options: {
- templateCollection: options.collections ? options.collections.templates : []
- },
- dependencies: ['Properties']
- });
- items.push({
- name: 'ContentTypeRegistry',
- class: 'dashboard-core/js/features/dashboard/contentTypeRegistry/api/impl/ContentTypeRegistry',
- options: options.collections ? options.collections.contentTypes : [],
- dependencies: []
- });
- items.push({
- name: 'DashboardContentProvider',
- class: 'dashboard-core/js/features/dashboard/contentProvider/api/impl/DashboardContentProvider',
- dependencies: ['ContentFactory']
- });
- return _this3.featureLoader.loadFeaturesFromArray(items, dashboardApi.getFeature('internal').getBoardModel().getContentModel().features);
- }).then(function () {
- return _this3._getServiceExtensions().then(function (servicesCollection) {
- return _this3._getFeatureExtensions().then(function (featuresCollection) {
- var promises = [];
- promises.push(_this3._registerServiceCollection(dashboardApi, servicesCollection, false));
- // TODO - removed once all features under "core-features" are moved to the correct "features" collection
- promises.push(_this3._registerServiceCollection(dashboardApi, featuresCollection, true));
- return Promise.all(promises);
- });
- });
- });
- };
- /**
- * Deprecated service collection. The new core-features collecion must e userd for new features.
- */
- ServicesHelper.prototype._getServiceExtensions = function _getServiceExtensions() {
- var promise = Promise.resolve();
- if (this.appSettings.options && this.appSettings.options.collections.serviceExtension) {
- var collectionId = this.appSettings.options.collections.serviceExtension.id;
- promise = Promise.all([this.glassContext.appController.findCollection(collectionId)]).then(function (extensions) {
- return extensions[0];
- });
- }
- return promise;
- };
- ServicesHelper.prototype._getFeatureExtensions = function _getFeatureExtensions() {
- var promise = Promise.resolve(deprecatedInlineFeatures);
- if (this.appSettings.options && this.appSettings.options.collections.featureExtension) {
- var collectionId = this.appSettings.options.collections.featureExtension.id;
- promise = Promise.all([this.glassContext.appController.findCollection(collectionId)]).then(function (extensions) {
- var collection = extensions[0] || [];
- return deprecatedInlineFeatures.concat(collection);
- });
- }
- return promise;
- };
- ServicesHelper.prototype._registerServiceHooks = function _registerServiceHooks(serviceExtension) {
- if (typeof serviceExtension.getLifeCycleHandlers === 'function') {
- var lifeCycleManager = this.services.getSvcSync('.LifeCycleManager');
- var handlers = serviceExtension.getLifeCycleHandlers();
- if (!Array.isArray(handlers)) {
- throw new Error('serviceExtension getLifeCycleHandlers method is expected to return an array');
- }
- handlers.forEach(function (handler) {
- if (!handler.name || !handler.action) {
- throw new Error('serviceExtension handlers are expected to have a name and action property');
- }
- lifeCycleManager.registerLifeCycleHandler(handler.name, handler.action, handler.priority);
- });
- }
- };
- return ServicesHelper;
- }();
- return ServicesHelper;
- });
- //# sourceMappingURL=ServicesHelper.js.map
|