diff --git a/web/assets/js/accordions/result.js b/web/assets/js/components/accordions/result.js similarity index 100% rename from web/assets/js/accordions/result.js rename to web/assets/js/components/accordions/result.js diff --git a/web/assets/js/modals/playground-mode.js b/web/assets/js/components/modals/playground-mode.js similarity index 93% rename from web/assets/js/modals/playground-mode.js rename to web/assets/js/components/modals/playground-mode.js index 54237cb..ec6434a 100644 --- a/web/assets/js/modals/playground-mode.js +++ b/web/assets/js/components/modals/playground-mode.js @@ -1,8 +1,9 @@ import { renderExamplesInSelectInstance, renderTabs, -} from "../utils/render-functions.js"; -import { AceEditor } from "../editor.js"; +} from "../../utils/render-functions.js"; +import { AceEditor } from "../../editor.js"; +import { ModesService } from "../../services/modes.js"; const celEditor = new AceEditor("cel-input"); const dataEditor = new AceEditor("data-input"); @@ -51,7 +52,7 @@ function handleModeClick(event, mode, element) { function renderModeOptions() { const el = document.querySelector(".playground-modes__options"); - getModes() + ModesService.getModes() .then((modes) => { modes.forEach((mode, i) => { const divOption = createParentElement(mode); @@ -102,12 +103,6 @@ function createInputElement(mode) { return input; } -async function getModes() { - const response = await fetch("../../assets/modes.json"); - const modes = await response.json(); - return modes; -} - function closeModal() { playgroundModesModalEl.style.display = "none"; } diff --git a/web/assets/js/tooltips/index.js b/web/assets/js/components/tooltips/index.js similarity index 100% rename from web/assets/js/tooltips/index.js rename to web/assets/js/components/tooltips/index.js diff --git a/web/assets/js/services/examples.js b/web/assets/js/services/examples.js new file mode 100644 index 0000000..e47d6b6 --- /dev/null +++ b/web/assets/js/services/examples.js @@ -0,0 +1,11 @@ +async function getExampleContentById(mode, exampleID) { + const response = await fetch( + `../../assets/examples/${mode.id}/${exampleID}.json` + ); + const data = await response.json(); + return data; +} + +export const ExampleService = { + getExampleContentById, +}; diff --git a/web/assets/js/services/modes.js b/web/assets/js/services/modes.js new file mode 100644 index 0000000..5a36257 --- /dev/null +++ b/web/assets/js/services/modes.js @@ -0,0 +1,9 @@ +async function getModes() { + const response = await fetch("../../assets/modes.json"); + const modes = await response.json(); + return modes; +} + +export const ModesService = { + getModes, +}; diff --git a/web/assets/js/utils/render-functions.js b/web/assets/js/utils/render-functions.js index b78fa08..cad1da4 100644 --- a/web/assets/js/utils/render-functions.js +++ b/web/assets/js/utils/render-functions.js @@ -1,4 +1,5 @@ import { AceEditor } from "../editor.js"; +import { ExampleService } from "../services/examples.js"; const celEditor = new AceEditor("cel-input"); const dataEditor = new AceEditor("data-input"); @@ -119,12 +120,12 @@ export function renderTabs(mode) { } function fetchTabData(mode, exampleID, tabButton) { - fetch(`../../assets/examples/${mode.id}/${exampleID}.json`) - .then((response) => response.json()) - .then(({ code, inputs }) => { + ExampleService.getExampleContentById(mode, exampleID).then( + ({ code, inputs }) => { celEditor.setValue(code, -1); if (tabButton) { dataEditor.setValue(inputs[tabButton.id], -1); } - }); + } + ); } diff --git a/web/index.html b/web/index.html index 8dc57dd..3183d6d 100644 --- a/web/index.html +++ b/web/index.html @@ -407,11 +407,18 @@

Playground modes

+ - - - + + +