'use strict'; /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2018 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', '../../app/nls/StringResources', '../../lib/@waca/core-client/js/core-client/ui/core/Class'], function (_, stringResources, Class) { /** * NOTE: All functions defined in widgetRegistry (other than initialize) * begin with the _fn prefix to emphasize that they are functions not widget class keys. */ var WidgetRegistry = Class.extend({ initialize: function initialize(dashboardApi) { var collectionId = dashboardApi.getCollectionConfig('widget').id; return dashboardApi.findGlassCollection(collectionId).then(function (collection) { //TODO: Remove this when server has the filter widget contribution. // collection=collection.concat(this._fnHackInFilterWidgetForDevelopers()); return this._fnInitializeRegistryItems(collection).then(function () { //TODO: next step is to change the callers to use bluebird promises as well. return this; }.bind(this)); }.bind(this)).fail(function () { throw stringResources.get('errorLoadingWidgetList'); }.bind(this)); }, /** * @returns a promise which resolves when all initialized widget registry items have been loaded. */ _fnInitializeRegistryItems: function _fnInitializeRegistryItems(collection) { if (!collection || !collection.length) { //No registry items to process. return Promise.resolve(collection); } var promises = []; _.each(collection, function (item) { promises.push(this._fnInitializeRegistryItem(item)); }.bind(this)); return Promise.all(promises); }, /** * @returns a promise which resolves when a single widgetRegistry entry has been loaded. * In cases where a widgetRegistry entry has a custom model, the ModelClass is loaded. */ _fnInitializeRegistryItem: function _fnInitializeRegistryItem(item) { // convert to local identifier for all built-in widgets if (item.builtin && item.id.indexOf('.') >= 0) { item.id = item.id.replace(/(\w+\.)/g, ''); } else { this._fnInitCustomWidget(item); } // default values for all widgets _.defaults(item, { layoutAuthoringView: 'dashboard-core/js/dashboard/layout/authoring/views/Widget', disableTitle: false, ownTitle: true, createContentNode: true }); // store the item to the widget registry this[item.id] = item; if (!item.modelClassPath || item.ModelClass) { //There is no modelClassPath in the widget definition or the ModelClass prototype has already been loaded. return Promise.resolve(item); } return this._fnLoadWidgetModelClass(item.modelClassPath).then(function (ModelClass) { item.ModelClass = ModelClass; return item; }); }, _fnLoadWidgetModelClass: function _fnLoadWidgetModelClass(modelClassPath) { return new Promise(function (resolve, reject) { try { require([modelClassPath], resolve, reject); } catch (error) { reject(error); } }); }, _fnInitCustomWidget: function _fnInitCustomWidget(widget) { // default values for custom widgets widget = _.defaults(widget, { ownTitle: false, title: stringResources.get('customWidget'), layoutConsumeView: 'dashboard-core/js/dashboard/layout/views/Widget', svgIcon: 'dashboard-default-custom-widget', scroll: 'scroll', // [scroll | scrollNone | scrollX | scrollY], propertyLayoutList: [{ id: 'banner', value: widget.title, name: 'banner', type: 'Banner' }], propertyList: [{ id: 'fillColor', defaultValue: 'transparent', editor: { sectionId: 'general.appearance', uiControl: { type: 'ColorPicker', label: stringResources.get('propFillColor'), showHexValue: true, addButton: true, open: false, ariaLabel: stringResources.get('propFillColor'), paletteType: 'DashboardColorSet' } } }, { id: 'borderColor', defaultValue: 'transparent', editor: { sectionId: 'general.appearance', uiControl: { type: 'ColorPicker', label: stringResources.get('propBorderColor'), showHexValue: true, addButton: true, open: false, ariaLabel: stringResources.get('propBorderColor'), paletteType: 'DashboardColorSet' } } }] }); // define a default spec for custom widget widget.defaultSpec = _.defaults(widget.defaultSpec || {}, { model: { type: widget.id, name: widget.ownTitle ? null : widget.title }, layoutProperties: { style: { 'display': 'flex', 'border': '1px solid transparent', 'border-radius': '5px', 'flex-direction': 'column', 'width': '250px', 'height': '250px' } } }); } }); return WidgetRegistry; }); //# sourceMappingURL=WidgetRegistry.js.map