LiveVisualizationActionHandler.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Dashboard
  6. *| (C) Copyright IBM Corp. 2017, 2019
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['../lib/@waca/dashboard-common/dist/glass/controllers/WidgetBaseActionHandler', '../widgets/livewidget/nls/StringResources', '../DynamicFileLoader'], function (BaseClass, stringResources, DynamicFileLoader) {
  13. 'use strict';
  14. /**
  15. * Glass Action controller which loads visualizations
  16. * based on the LiveWidget using the LiveWidgetUIHelper
  17. */
  18. var ActionHandler = BaseClass.extend({
  19. getOptions: function getOptions(context) {
  20. var view = this._getDashboardView(context);
  21. var dashboardApi = view.getDashboardApi();
  22. var options = {
  23. className: 'visualizationSlideout',
  24. dashboardApi: dashboardApi,
  25. services: view.services, // TODO: remove once core is using the dashboardApi
  26. title: stringResources.get('visualizationSlideoutTitle'),
  27. module: 'dashboard-analytics/visualizationPanel/VisualizationPanelView',
  28. getEntries: this.getEntries.bind(this, context)
  29. };
  30. return Promise.resolve(options);
  31. },
  32. getEntries: function getEntries(context) {
  33. return this.createWidgetAddUIHelper(context).then(function (helper) {
  34. return helper.getEntries();
  35. }).then(this.getSpecs.bind(this, context));
  36. },
  37. getSpecs: function getSpecs(context, entries) {
  38. return this.createWidgetAddUIHelper(context).then(function (helper) {
  39. var spec = {};
  40. var options = {
  41. onItemClick: function onItemClick(widget, event) {
  42. return helper.addWidgetBySelection(widget, event, {
  43. selectOptions: {
  44. flyout: false
  45. }
  46. });
  47. },
  48. onItemStartDrag: helper.addWidgetByDrag.bind(helper)
  49. };
  50. spec.options = options;
  51. spec.items = entries;
  52. return spec;
  53. });
  54. },
  55. // Private
  56. _getDashboardView: function _getDashboardView(context) {
  57. return context.glassContext.appController.currentAppView.currentContentView;
  58. },
  59. _getUiHelperClass: function _getUiHelperClass() {
  60. return DynamicFileLoader.load(['dashboard-analytics/widgets/livewidget/LiveWidgetUIHelper']).then(function (modules) {
  61. return modules[0];
  62. }.bind(this));
  63. },
  64. createWidgetAddUIHelper: function createWidgetAddUIHelper(context) {
  65. var view = this._getDashboardView(context);
  66. return this._getUiHelperClass().then(function (HelperClass) {
  67. var helper = new HelperClass({
  68. dashboardApi: view.getDashboardApi(),
  69. services: view.services // TODO : remove once the common add ui helper is not using the services.
  70. });
  71. helper.panelAttributes = {
  72. dashboardApi: view.dashboardApi,
  73. cdnUrl: view.getCDNUrl(),
  74. ajaxSvc: view.ajaxSvc
  75. };
  76. return helper;
  77. });
  78. }
  79. });
  80. return ActionHandler;
  81. });
  82. //# sourceMappingURL=LiveVisualizationActionHandler.js.map