Skip to content

Commit

Permalink
fix: add document checker function call to console
Browse files Browse the repository at this point in the history
  • Loading branch information
egekorkan committed Oct 4, 2024
1 parent c72b8af commit 2ccf0d4
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions packages/web/src/scripts/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { visualize } from './visualize'
import { validationView, validationTab } from './validation'
import { convertTDYamlToJson } from '../../../core/dist/web-bundle.min.js'
import { detectProtocolSchemes } from '@thingweb/td-utils/dist/web-bundle.min.js'
import { generateOAP, generateAAP, addDefaultsUtil, validate, generateAAS, resetValidationStatus } from './util'
import { generateOAP, generateAAP, addDefaultsUtil, validate, generateAAS, resetValidationStatus, checkDocumentType } from './util'
import { editorList, getEditorData } from './editor'
import { textIcon } from './main.js'

Expand Down Expand Up @@ -143,76 +143,78 @@ visualizationOptions.forEach(option => {
let td = JSON.parse(editorValue)
hideConsoleError()

if ((td["@type"] === "tm:ThingModel" && option.id === "open-api-tab") || (td["@type"] === "tm:ThingModel" && option.id === "async-api-tab") || (td["@type"] === "tm:ThingModel" && option.id === "defaults-tab") || (td["@type"] === "tm:ThingModel" && option.id === "aas-tab")) {
showConsoleError("This function is only allowed for Thing Descriptions!")
if (
(checkDocumentType(td) === "tm" && option.id === "open-api-tab") ||
(checkDocumentType(td) === "tm" && option.id === "async-api-tab") ||
(checkDocumentType(td) === "tm" && option.id === "defaults-tab") ||
(checkDocumentType(td) === "tm" && option.id === "aas-tab")
) {
showConsoleError("This function is only allowed for Thing Descriptions!");
} else {
switch (option.id) {
case "open-api-tab": {

if (fileType === "yaml") {
openApiJsonBtn.disabled = false
openApiYamlBtn.disabled = true
openApiJsonBtn.disabled = false;
openApiYamlBtn.disabled = true;
} else {
openApiJsonBtn.disabled = true
openApiYamlBtn.disabled = false
openApiJsonBtn.disabled = true;
openApiYamlBtn.disabled = false;
}

enableAPIConversionWithProtocol(editorInstance)
enableAPIConversionWithProtocol(editorInstance);

break;
}
case "async-api-tab": {
if (fileType === "yaml") {
asyncApiJsonBtn.disabled = false
asyncApiYamlBtn.disabled = true
asyncApiJsonBtn.disabled = false;
asyncApiYamlBtn.disabled = true;
} else {
asyncApiJsonBtn.disabled = true
asyncApiYamlBtn.disabled = false
asyncApiJsonBtn.disabled = true;
asyncApiYamlBtn.disabled = false;
}

enableAPIConversionWithProtocol(editorInstance)
enableAPIConversionWithProtocol(editorInstance);

break;
}
case "aas-tab": {

generateAAS(fileType, editorInstance)
AASView.classList.remove("hidden")
generateAAS(fileType, editorInstance);
AASView.classList.remove("hidden");

break;
}
case "defaults-tab": {
if (fileType === "yaml") {
defaultsJsonBtn.disabled = false
defaultsYamlBtn.disabled = true
defaultsJsonBtn.disabled = false;
defaultsYamlBtn.disabled = true;
} else {
defaultsJsonBtn.disabled = true
defaultsYamlBtn.disabled = false
defaultsJsonBtn.disabled = true;
defaultsYamlBtn.disabled = false;
}

addDefaultsUtil(editorInstance)
defaultsAddBtn.disabled = true
defaultsView.classList.remove("hidden")
addDefaultsUtil(editorInstance);
defaultsAddBtn.disabled = true;
defaultsView.classList.remove("hidden");

break;
}
case "visualize-tab": {
visualize(td)
visualize(td);

break;
}
case "validation-tab": {
validationView.classList.remove("hidden")
const editorData = getEditorData(editorInstance)
validate(editorData[1], editorValue)
validationView.classList.remove("hidden");
const editorData = getEditorData(editorInstance);
validate(editorData[1], editorValue);

break;
}
default: {
break;
}
}

}

}
Expand Down

0 comments on commit 2ccf0d4

Please sign in to comment.