123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2017, 2020
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['underscore', '../../../lib/@waca/dashboard-common/dist/glass/controllers/WidgetBaseActionHandler', '../../../app/nls/StringResources', '../../../lib/@waca/core-client/js/core-client/utils/ClassFactory', '../../widgets/staticwidget/ShapeWidget'], function (_, BaseClass, stringResources, ClassFactory, ShapeWidget) {
- var ActionHandler = BaseClass.extend({
- getDashboardView: function getDashboardView(context) {
- return context.glassContext.appController.getCurrentContentView();
- },
- getUiHelperClass: function getUiHelperClass() {
- return ClassFactory.loadModule('dashboard-core/js/lib/@waca/dashboard-common/dist/ui/WidgetAddUIHelper');
- },
- createWidgetAddUIHelper: function createWidgetAddUIHelper(context) {
- var view = this.getDashboardView(context);
- this.uiHelperClassOptions = {
- dashboardApi: view.getDashboardApi(),
- services: view.services
- };
- return this.getUiHelperClass().then(function (UIHelperClass) {
- var widgetAddUIHelper = new UIHelperClass(this.uiHelperClassOptions);
- widgetAddUIHelper.panelAttributes = {
- canvasController: view.boardLoader.canvasController,
- cdnUrl: view.getCDNUrl(),
- ajaxSvc: view.ajaxSvc,
- glassContext: context.glassContext
- };
- return widgetAddUIHelper;
- }.bind(this));
- },
- getOptions: function getOptions(context) {
- var view = this.getDashboardView(context);
- var options = {
- className: 'widgetsPanelSlideout',
- title: stringResources.get('widgetsPanelTitle'),
- module: 'dashboard-core/js/dashboard/views/WidgetsPanelView',
- getEntries: this.getEntries.bind(this, context),
- services: view.services,
- dashboardApi: view.getDashboardApi()
- };
- return Promise.resolve(options);
- },
- getEntries: function getEntries(context) {
- var glassContext = context.glassContext;
- return Promise.all([this._getShapeWidgets(glassContext), this._getImageLibrary(glassContext), this._getWidgets(glassContext)]).then(function (results) {
- var shapeWidgets = results[0];
- var images = results[1];
- var widgets = results[2];
- var entries = {
- widgets: widgets,
- images: {},
- shapeWidgets: shapeWidgets
- };
- if (images && images.list && images.list.length > 0) {
- entries.images = images;
- }
- return entries;
- }).then(this.getSpecs.bind(this, context));
- },
- getSpecs: function getSpecs(context, entries) {
- var defaultColors = this._getWidgetColorsHelper(entries.widgets);
- // Notebook config check required here until Story 264685 complete
- var notebookConfigPromise = context.glassContext.getCoreSvc('.Config').getConfigValue('BIProxy.jupyter', false);
- return Promise.all([this.createWidgetAddUIHelper(context), this._getShapeSpecHelper(entries.shapeWidgets, defaultColors), this._getImageLibrarySpecHelper(entries.images), notebookConfigPromise]).then(function (results) {
- var helper = results[0],
- shapes = results[1],
- images = results[2],
- notebook = results[3];
- var icons = helper.dashboardApi.getFeature('Icons');
- var spec = {
- items: [{
- value: stringResources.get('widgetsPanelTitle'),
- name: 'widgetsPanel',
- type: 'Banner',
- editable: false
- }, {
- type: 'Separator'
- }]
- };
- var options = {
- onItemClick: helper.addWidgetBySelection.bind(helper),
- onItemStartDrag: helper.addWidgetByDrag.bind(helper)
- };
- // Basic widgets
- var basicWidgetItems = {
- name: stringResources.get('widgetsPanelTitle'),
- module: 'dashboard-core/js/dashboard/contentpane/PropertyUIControlView',
- items: [{
- type: 'SectionLabel',
- name: 'basicWidgets',
- label: stringResources.get('widgetsPanelSectionBasic')
- }, {
- type: 'IconCollection',
- id: _.uniqueId('basic_'),
- options: options,
- items: [{
- label: stringResources.get('textWidgetLabel'),
- name: stringResources.get('textWidgetLabel'),
- icon: icons.getIcon('text-creation').id,
- content: {
- widget: 'dashboard-core/js/dashboard/widgets/staticwidget/TextWidget',
- title: stringResources.get('textWidgetLabel')
- }
- }, {
- label: stringResources.get('imageWidgetLabel'),
- name: stringResources.get('imageWidgetLabel'),
- icon: icons.getIcon('image').id,
- content: {
- widget: 'dashboard-core/js/dashboard/widgets/staticwidget/ImageWidget',
- name: stringResources.get('imageWidgetLabel'),
- title: stringResources.get('imageWidgetLabel')
- }
- }, {
- label: stringResources.get('mediaWidgetLabel'),
- name: stringResources.get('mediaWidgetLabel'),
- icon: icons.getIcon('video-file').id,
- content: {
- widget: 'dashboard-core/js/dashboard/widgets/staticwidget/MediaWidget',
- name: stringResources.get('mediaWidgetLabel'),
- title: stringResources.get('mediaWidgetLabel')
- }
- }, {
- label: stringResources.get('webpageWidgetLabel'),
- name: stringResources.get('webpageWidgetLabel'),
- icon: icons.getIcon('webpage').id,
- content: {
- widget: 'dashboard-core/js/dashboard/widgets/staticwidget/WebpageWidget',
- name: stringResources.get('webpageWidgetLabel'),
- title: stringResources.get('webpageWidgetLabel')
- }
- }]
- }, {
- type: 'Separator'
- }]
- };
- this._addWidgets(entries.widgets.list, 'basicWidgets', basicWidgetItems.items[1].items);
- // Notebook
- if (notebook) {
- var advancedWidgetItems = {
- name: stringResources.get('widgetsPanelTitle'),
- module: 'dashboard-core/js/dashboard/contentpane/PropertyUIControlView',
- items: [{
- type: 'SectionLabel',
- name: 'advancedWidgets',
- label: stringResources.get('widgetsPanelSectionAdvanced')
- }, {
- type: 'IconCollection',
- id: _.uniqueId('advanced_'),
- options: options,
- items: [{
- label: stringResources.get('notebookWidgetLabel'),
- name: stringResources.get('notebookWidgetLabel'),
- icon: icons.getIcon('data-notebook').id,
- content: {
- widget: 'notebook/DashboardWidget',
- title: stringResources.get('notebookWidgetLabel')
- }
- }]
- }, {
- type: 'Separator'
- }]
- };
- basicWidgetItems.items.push(advancedWidgetItems);
- }
- // Shapes
- var shapesSpec = {
- name: stringResources.get('widgetsPanelTitle'),
- module: 'dashboard-core/js/dashboard/contentpane/PropertyUIControlView',
- items: [{
- type: 'SectionLabel',
- name: 'shapeWidgets',
- label: stringResources.get('widgetsPanelSectionShapes')
- }, {
- type: 'IconCollection',
- id: _.uniqueId('shapes_'),
- options: options,
- items: shapes
- }]
- };
- basicWidgetItems.items.push(shapesSpec);
- // Images
- if (images && images.length > 0) {
- var imageWidgetSpec = {
- name: stringResources.get('widgetsPanelImageLibraryTab'),
- module: 'dashboard-core/js/dashboard/contentpane/PropertyUIControlView',
- items: [{
- type: 'IconCollection',
- id: _.uniqueId('images_'),
- options: options,
- items: images
- }]
- };
- spec.items.push({
- type: 'TabControl',
- name: 'tabControl',
- items: [basicWidgetItems, imageWidgetSpec]
- });
- } else {
- spec.items.push(basicWidgetItems);
- }
- return spec;
- }.bind(this));
- },
- // Private
- /**
- * Adds widgets from the collection to the given section widget list if they have been attributed the given section name
- */
- _addWidgets: function _addWidgets(widgetsList, sectionName, sectionWidgets) {
- var widgetsToAdd = (widgetsList || []).filter(function (widget) {
- return widget.sections && widget.sections.indexOf(sectionName) !== -1;
- });
- widgetsToAdd.forEach(function (widget) {
- sectionWidgets.push({
- label: widget.label,
- name: widget.label,
- icon: widget.icon,
- content: {
- widget: widget.widget,
- name: widget.label,
- title: widget.label
- }
- });
- });
- },
- _getShapeSpecHelper: function _getShapeSpecHelper(shapes, colors) {
- var shapePromises = [];
- var shapeColors = colors && colors.shape;
- _.each(shapes.list, function (shape) {
- shape.options.fillColor = shapeColors.fillColor;
- shape.options.borderColor = shapeColors.borderColor;
- shape.options.fillColorIndex = shapeColors.fillColorIndex;
- shape.options.borderColorIndex = shapeColors.borderColorInder;
- var promise = ShapeWidget.getDefaultSpec(shape.name, shape.options).then(function (spec) {
- return {
- label: stringResources.get(shape.name),
- name: stringResources.get(shape.name),
- svg: spec.model.content,
- content: shape
- };
- });
- shapePromises.push(promise);
- });
- return Promise.all(shapePromises);
- },
- _getImageLibrarySpecHelper: function _getImageLibrarySpecHelper(images) {
- var imageSpecs = [];
- if (images.list) {
- _.each(images.list, function (image) {
- imageSpecs.push({
- label: image.name,
- name: image.name,
- image: image.options,
- content: image
- });
- });
- }
- return Promise.resolve(imageSpecs);
- },
- _getWidgetColorsHelper: function _getWidgetColorsHelper(widgets) {
- var widgetColors = {};
- if (widgets.list) {
- var getProperty = function getProperty(properties, color) {
- return _.find(properties, function (property) {
- return property.id === color;
- });
- };
- _.each(widgets.list, function (widget) {
- widgetColors[widget.id] = {};
- if (widget.propertyList) {
- var fillColor = getProperty(widget.propertyList, 'fillColor');
- var borderColor = getProperty(widget.propertyList, 'borderColor');
- widgetColors[widget.id].fillColor = fillColor && fillColor.defaultValue;
- widgetColors[widget.id].borderColor = borderColor && borderColor.defaultValue;
- }
- });
- }
- return widgetColors;
- },
- _getShapeWidgets: function _getShapeWidgets(context) {
- return this._getEntries(context, 'com.ibm.bi.dashboard.shapes', 'dashboard-core/js/dashboard/widgets/staticwidget/ShapeWidget');
- },
- _getImageLibrary: function _getImageLibrary(context) {
- return this._getEntries(context, 'com.ibm.bi.common.media', 'dashboard-core/js/dashboard/widgets/staticwidget/ImageWidget');
- },
- _getWidgets: function _getWidgets(context) {
- return this._getEntries(context, 'com.ibm.bi.dashboard.widgets', 'dashboard-core/js/dashboard/widgets/staticwidget/StaticWidget');
- },
- _getEntries: function _getEntries(context, perspectiveId, widgetModule) {
- return this.createWidgetAddUIHelper({ glassContext: context }).then(function (widgetAddUIHelper) {
- return widgetAddUIHelper.fetchWidgetListFromPerspective(perspectiveId, context);
- }).then(function (entries) {
- if (entries) {
- _.each(entries.list, function (entry) {
- if (!entry.widget) {
- entry.widget = widgetModule;
- }
- });
- }
- return entries;
- });
- }
- });
- return ActionHandler;
- });
- //# sourceMappingURL=WidgetsPanelHandler.js.map
|