123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- '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
|