SchematicVis.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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: BI Cloud (C) Copyright IBM Corp. 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', './SchematicEditorUI', '../VIPRConfig'], function (_, SchematicEditorUI) {
  9. return function () {
  10. function SchematicVis() {
  11. _classCallCheck(this, SchematicVis);
  12. this.schematicPromises = {};
  13. }
  14. SchematicVis.prototype.destroy = function destroy() {
  15. this.schematicPromises = {};
  16. this.ajaxSvc = null;
  17. this.schematicEditorUI = null;
  18. };
  19. SchematicVis.prototype.getSchematicContent = function getSchematicContent() {
  20. var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  21. var dashboardApi = arguments[1];
  22. if (payload.method === 'edit') {
  23. return this._openSchematicEditor(payload, dashboardApi);
  24. } else if (payload.method === 'publish') {
  25. // TODO:
  26. } else if (payload.method === 'get') {
  27. return this._getSchematicContent(payload, dashboardApi);
  28. }
  29. };
  30. SchematicVis.prototype._openSchematicEditor = function _openSchematicEditor() {
  31. var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  32. var dashboardApi = arguments[1];
  33. var logger = dashboardApi.getGlassCoreSvc('.Logger');
  34. logger.debug('openSchematicEditorUI');
  35. return SchematicEditorUI.openSchematicEditor(payload.metadata, dashboardApi);
  36. };
  37. // get schematic content for a runtime schematic - either returns a meta.json file
  38. // or the svg which is to be displayed
  39. SchematicVis.prototype._getSchematicContent = function _getSchematicContent() {
  40. var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  41. var dashboardApi = arguments[1];
  42. var logger = dashboardApi.getGlassCoreSvc('.Logger');
  43. logger.debug('getSchematicContent');
  44. var key = payload.type && payload.type === 'meta' ? payload.type : payload.name;
  45. if (!this.schematicPromises[key]) {
  46. var param = this._getUrlParm(payload);
  47. var ajaxSvc = this._getAjaxSvc(dashboardApi);
  48. this.schematicPromises[key] = ajaxSvc.ajax(param).then(function (response) {
  49. return response.jqXHR.responseText;
  50. });
  51. }
  52. return this.schematicPromises[key];
  53. };
  54. SchematicVis.prototype._getUrlParm = function _getUrlParm() {
  55. var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  56. var endPoint = SchematicVis.getVisualizationEndPoint() + payload.library + (payload.type && payload.type === 'meta' ? '/content/meta.json' : '/content/' + SchematicVis.cleanseFilename(payload.name));
  57. return {
  58. url: endPoint,
  59. type: payload.method,
  60. headers: {
  61. 'Content-Type': 'application/xml; charset=utf-8',
  62. 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*; charset=utf-8'
  63. }
  64. };
  65. };
  66. SchematicVis.prototype._getAjaxSvc = function _getAjaxSvc(dashboardApi) {
  67. if (!this.ajaxSvc) {
  68. this.ajaxSvc = dashboardApi.getGlassCoreSvc('.Ajax');
  69. }
  70. return this.ajaxSvc;
  71. };
  72. SchematicVis.cleanseFilename = function cleanseFilename(name) {
  73. var nameParts = name.split('\\');
  74. name = nameParts.join('/');
  75. return name;
  76. };
  77. SchematicVis.getVisualizationEndPoint = function getVisualizationEndPoint() {
  78. return 'v1/visualizations/';
  79. };
  80. return SchematicVis;
  81. }();
  82. });
  83. //# sourceMappingURL=SchematicVis.js.map