From 6c8ae5806c778669b150d8bc471a10f6cde96f33 Mon Sep 17 00:00:00 2001 From: Sergio Eduardo Castro Ceballos <72516762+SergioCasCeb@users.noreply.github.com> Date: Sat, 14 Oct 2023 00:26:13 +0200 Subject: [PATCH 1/4] Adding error handling for AAS conversion --- packages/web-new/src/scripts/aas.js | 3 +-- packages/web-new/src/scripts/console.js | 21 ++++++++++++++------- packages/web-new/src/scripts/util.js | 6 ++---- packages/web-new/src/template.html | 15 --------------- 4 files changed, 17 insertions(+), 28 deletions(-) diff --git a/packages/web-new/src/scripts/aas.js b/packages/web-new/src/scripts/aas.js index 7184761f9..abcc1d2b1 100644 --- a/packages/web-new/src/scripts/aas.js +++ b/packages/web-new/src/scripts/aas.js @@ -22,7 +22,7 @@ import { editor } from 'monaco-editor' import { setFontSize, editorForm, fontSizeSlider } from './settings-menu' -import { generateTD, offerFileDownload } from './util' +import { offerFileDownload } from './util' import { getEditorData } from './editor' /******************************************************************/ @@ -31,7 +31,6 @@ import { getEditorData } from './editor' //AAS Elements export const AASTab = document.querySelector(".aas-tab-btn") -export const AASJsonBtn = document.querySelector("#aas-json") export const AASView = document.querySelector("#aas-view") const AASDownload = document.querySelector("#aas-download") diff --git a/packages/web-new/src/scripts/console.js b/packages/web-new/src/scripts/console.js index 55857730f..83b128e83 100644 --- a/packages/web-new/src/scripts/console.js +++ b/packages/web-new/src/scripts/console.js @@ -21,7 +21,7 @@ import { openApiTab, openApiJsonBtn, openApiYamlBtn, openApiView } from './open-api' import { asyncApiTab, asyncApiJsonBtn, asyncApiYamlBtn, asyncApiView } from './async-api' -import { AASJsonBtn, AASView } from './aas' +import { AASView, AASTab } from './aas' import { defaultsView, defaultsJsonBtn, defaultsYamlBtn, defaultsAddBtn } from './defaults' import { visualize } from './visualize' import { validationView } from './validation' @@ -117,8 +117,8 @@ visualizationOptions.forEach(option => { break; case "aas-tab": - AASView.classList.remove("hidden") - generateAAS(fileType, editorInstance) + + enableAPIConversionWithProtocol(editorInstance) break; @@ -172,10 +172,8 @@ visualizationOptions.forEach(option => { * @param {object} editor - currently active monaco editor */ function enableAPIConversionWithProtocol(editorInstance) { - let td = editorInstance.getValue() - if (editorInstance["_domElement"].dataset.modeId === "yaml") { - td = convertTDYamlToJson(td) - } + + let td = editorInstance["_domElement"].dataset.modeId === "yaml" ? convertTDYamlToJson(editorInstance.getValue()) : editorInstance.getValue() const protocolSchemes = detectProtocolSchemes(td) @@ -198,6 +196,15 @@ function enableAPIConversionWithProtocol(editorInstance) { showConsoleError("Please insert a TD which uses MQTT!") } } + + if (AASTab.checked === true) { + if (["mqtt", "mqtts", "http", "https", "coap", "modbus"].some(p => protocolSchemes.includes(p))) { + generateAAS(editorInstance["_domElement"].dataset.modeId, editorInstance) + AASView.classList.remove("hidden") + } else { + showConsoleError("Please insert a TD which uses HTTP, MQTT, CoAP or Modbus!") + } + } } } diff --git a/packages/web-new/src/scripts/util.js b/packages/web-new/src/scripts/util.js index 0a584a3b2..2db6cd790 100644 --- a/packages/web-new/src/scripts/util.js +++ b/packages/web-new/src/scripts/util.js @@ -174,11 +174,9 @@ export function generateAAS(fileType, editorInstance){ const AASInstance = assetInterfaceDescriptionUtil.transformTD2SM(tdToConvert) try { - const content = fileType === "json" - ? JSON.stringify(JSON.parse(AASInstance), undefined, 4) - : convertTDJsonToYaml(AASInstance) + const content = JSON.stringify(JSON.parse(AASInstance), undefined, 4) - editor.setModelLanguage(window.AASEditor.getModel(), fileType) + editor.setModelLanguage(window.AASEditor.getModel(), 'json') window.AASEditor.getModel().setValue(content) } catch (err) { console.error(err); diff --git a/packages/web-new/src/template.html b/packages/web-new/src/template.html index 7c1491cff..af8a15c42 100644 --- a/packages/web-new/src/template.html +++ b/packages/web-new/src/template.html @@ -241,10 +241,6 @@

Thing Description Playground - BETA Version

title="Conversion to Asset Administration Shell/Asset Interface Description"> - @@ -443,9 +439,6 @@

Thing Description Playground - BETA Version

- -