AddSourceActionHandler.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: CA
  6. *| (C) Copyright IBM Corp. 2017 - 2020
  7. *| US Government Users Restricted Rights - Use, duplication or disclosure
  8. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *+------------------------------------------------------------------------+
  10. */
  11. define(['../../lib/@waca/core-client/js/core-client/ui/core/Class', '../nls/StringResources', 'underscore'], function (BaseClass, StringResources, _) {
  12. 'use strict';
  13. var AddSourceActionHandler = BaseClass.extend({
  14. init: function init(options) {
  15. AddSourceActionHandler.inherited('init', this, arguments);
  16. this.dashboardApi = options.dashboardApi;
  17. },
  18. /**
  19. * Add button event handler. Called when the add button is clicked or tapped.
  20. * This method will show an open dialog to select a source.
  21. */
  22. execute: function execute() {
  23. var enableReportDatasource = this.dashboardApi.getGlassCoreSvc('.FeatureChecker').checkValue('dashboard', 'reportDatasource', 'enabled');
  24. var typesToOpen = ['module', 'dataSet2', 'uploadedFile', 'package', 'data_asset'];
  25. if (enableReportDatasource) {
  26. typesToOpen.push('report');
  27. }
  28. var options = {
  29. 'typesToOpen': typesToOpen,
  30. 'multiSelect': false,
  31. 'dialogTitle': StringResources.get('addDataSourceDialogTitle'),
  32. 'primaryBtnText': StringResources.get('addDataSourceDialogButtonLabel'),
  33. 'onOpenCallback': this.addDataSource.bind(this)
  34. };
  35. this.dashboardApi.prepareGlassOptions(options);
  36. //This is present for testing purposes.
  37. if (this._openDialogInstance) {
  38. this._openDialogInstance.open(options);
  39. } else {
  40. return this.dashboardApi.getGlassSvc('.ContentDialogFactory').then(function (dialogFactory) {
  41. var openDialog = dialogFactory.createOpenDialog(options);
  42. openDialog.open();
  43. });
  44. }
  45. },
  46. /**
  47. * Add the data sources based on some selections in the open dialog
  48. *
  49. * @param selectedItems - an array of CM object items
  50. *
  51. */
  52. addDataSource: function addDataSource(selectedItems) {
  53. // There is only 1 selected data source in this function because multiSelect is set to false in onAddBtnClick
  54. var selectedItem = selectedItems[0];
  55. var dataSource = {
  56. 'assetId': selectedItem.id,
  57. 'name': selectedItem.defaultName,
  58. 'type': selectedItem.type,
  59. 'searchPath': selectedItem.searchPath,
  60. 'isOlapPackage': selectedItem.userInterfaces && _.indexOf(selectedItem.userInterfaces, 'analysisStudio') >= 0,
  61. 'modificationTime': selectedItem.modificationTime
  62. };
  63. var dataSourcesSvc = this.dashboardApi.getFeature('dataSources.deprecated');
  64. var dataSourceCollection = dataSourcesSvc.getSourcesCollection();
  65. var sourceId = dataSourceCollection.addSource(dataSource);
  66. this.dashboardApi.triggerDashboardEvent('dataSourcePanel:dataSourceAdded', {
  67. sender: sourceId
  68. });
  69. }
  70. });
  71. return AddSourceActionHandler;
  72. });
  73. //# sourceMappingURL=AddSourceActionHandler.js.map