CustomVizService.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. * Licensed Materials - Property of IBM
  5. * IBM Cognos Products: Dashboard (C) Copyright IBM Corp. 2019, 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define([], function () {
  9. var VIS_PREVIEW_ID = 'visualizationPreview';
  10. var SCHEMATICS_ID = 'com.ibm.vis.schematicsPreview';
  11. var VIS_IDS = [VIS_PREVIEW_ID, SCHEMATICS_ID];
  12. var CustomVizService = function () {
  13. function CustomVizService() {
  14. _classCallCheck(this, CustomVizService);
  15. }
  16. /**
  17. * The dashboard was just saved, we need to send a speocial notification for custom visualization.
  18. * @param {boolean} options.saveAs Boolean to let us know if it was a saveAs or save operations
  19. * @param {object} options.resaveDashboardSpecCallback Callback to re-save the dashboard spec. Used if the model gets updated
  20. * @param {object} options.spec
  21. * @param {object} options.context context to use to show the warning toast message
  22. * @param {object} options.stringResources stringResources to fetch the warning meassage
  23. */
  24. CustomVizService.prototype.onDashboardSave = function onDashboardSave(options) {
  25. var spec = options.spec,
  26. stringResources = options.stringResources;
  27. var showToast = options.context.glassContext.appController.showToast;
  28. if (this._findVisId(spec.layout.items)) {
  29. showToast(stringResources.get('customVizSaveWarning'), { type: 'warning' });
  30. }
  31. };
  32. CustomVizService.prototype._findVisId = function _findVisId(items) {
  33. for (var i = 0; i < items.length; i++) {
  34. var item = items[i];
  35. if (item.items) {
  36. return this._findVisId(item.items);
  37. } else {
  38. if (item.features) {
  39. var feature = item.features.Models_internal;
  40. if (feature && feature.visId && VIS_IDS.indexOf(feature.visId) !== -1) {
  41. return true;
  42. }
  43. }
  44. }
  45. }
  46. return false;
  47. };
  48. return CustomVizService;
  49. }();
  50. return CustomVizService;
  51. });
  52. //# sourceMappingURL=CustomVizService.js.map