'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', './SchematicEditorUI', '../VIPRConfig'], function (_, SchematicEditorUI) { return function () { function SchematicVis() { _classCallCheck(this, SchematicVis); this.schematicPromises = {}; } SchematicVis.prototype.destroy = function destroy() { this.schematicPromises = {}; this.ajaxSvc = null; this.schematicEditorUI = null; }; SchematicVis.prototype.getSchematicContent = function getSchematicContent() { var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var dashboardApi = arguments[1]; if (payload.method === 'edit') { return this._openSchematicEditor(payload, dashboardApi); } else if (payload.method === 'publish') { // TODO: } else if (payload.method === 'get') { return this._getSchematicContent(payload, dashboardApi); } }; SchematicVis.prototype._openSchematicEditor = function _openSchematicEditor() { var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var dashboardApi = arguments[1]; var logger = dashboardApi.getGlassCoreSvc('.Logger'); logger.debug('openSchematicEditorUI'); return SchematicEditorUI.openSchematicEditor(payload.metadata, dashboardApi); }; // get schematic content for a runtime schematic - either returns a meta.json file // or the svg which is to be displayed SchematicVis.prototype._getSchematicContent = function _getSchematicContent() { var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var dashboardApi = arguments[1]; var logger = dashboardApi.getGlassCoreSvc('.Logger'); logger.debug('getSchematicContent'); var key = payload.type && payload.type === 'meta' ? payload.type : payload.name; if (!this.schematicPromises[key]) { var param = this._getUrlParm(payload); var ajaxSvc = this._getAjaxSvc(dashboardApi); this.schematicPromises[key] = ajaxSvc.ajax(param).then(function (response) { return response.jqXHR.responseText; }); } return this.schematicPromises[key]; }; SchematicVis.prototype._getUrlParm = function _getUrlParm() { var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var endPoint = SchematicVis.getVisualizationEndPoint() + payload.library + (payload.type && payload.type === 'meta' ? '/content/meta.json' : '/content/' + SchematicVis.cleanseFilename(payload.name)); return { url: endPoint, type: payload.method, headers: { 'Content-Type': 'application/xml; charset=utf-8', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*; charset=utf-8' } }; }; SchematicVis.prototype._getAjaxSvc = function _getAjaxSvc(dashboardApi) { if (!this.ajaxSvc) { this.ajaxSvc = dashboardApi.getGlassCoreSvc('.Ajax'); } return this.ajaxSvc; }; SchematicVis.cleanseFilename = function cleanseFilename(name) { var nameParts = name.split('\\'); name = nameParts.join('/'); return name; }; SchematicVis.getVisualizationEndPoint = function getVisualizationEndPoint() { return 'v1/visualizations/'; }; return SchematicVis; }(); }); //# sourceMappingURL=SchematicVis.js.map