Skip to content

Commit

Permalink
Adding error handling for AAS conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioCasCeb committed Oct 13, 2023
1 parent db553e9 commit 6c8ae58
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
3 changes: 1 addition & 2 deletions packages/web-new/src/scripts/aas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/******************************************************************/
Expand All @@ -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")

Expand Down
21 changes: 14 additions & 7 deletions packages/web-new/src/scripts/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -117,8 +117,8 @@ visualizationOptions.forEach(option => {
break;

case "aas-tab":
AASView.classList.remove("hidden")
generateAAS(fileType, editorInstance)

enableAPIConversionWithProtocol(editorInstance)

break;

Expand Down Expand Up @@ -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)

Expand All @@ -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!")
}
}
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/web-new/src/scripts/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 0 additions & 15 deletions packages/web-new/src/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ <h1>Thing Description Playground <span>- BETA Version</span></h1>
title="Conversion to Asset Administration Shell/Asset Interface Description">
<input type="radio" name="visualization-option" id="defaults-tab"
class="visualization__option defaults-tab-btn" title="Add or remove default values">
<!-- <input type="radio" name="visualization-option" id="linting-tab"
class="visualization__option linting-tab-btn">
<input type="radio" name="visualization-option" id="canonicalize-tab"
class="visualization__option canonicalize-tab-btn"> -->
<input type="radio" name="visualization-option" id="visualize-tab"
class="visualization__option visualize-tab-btn" title="Tree or Graph TD visualizations">
</div>
Expand Down Expand Up @@ -443,9 +439,6 @@ <h1>Thing Description Playground <span>- BETA Version</span></h1>
<div class="console-view aas-view hidden" id="aas-view">
<div class="aas-container" id="aas-container"></div>
<div class="aas-inputs">
<div class="input-field">
<button id="aas-json">JSON</button>
</div>
<div class="view-download">
<button id="aas-download"><i class="fa-solid fa-download"></i>Download</button>
</div>
Expand All @@ -470,14 +463,6 @@ <h1>Thing Description Playground <span>- BETA Version</span></h1>
</div>
</div>

<!-- <div class="console-view hidden" id="linting-view">
</div>
<div class="console-view hidden" id="canonicalize-view">
</div> -->

<div class="console-view visualize-view hidden" id="visualize-view">
<div class="visualize-container" id="visualize-container">
<div id="visualized" class="visualized"></div>
Expand Down

0 comments on commit 6c8ae58

Please sign in to comment.