From a0748636d443ccf7dab436dc75c1e2abe859b24c Mon Sep 17 00:00:00 2001 From: Kostya Bats Date: Mon, 11 Mar 2024 12:22:18 +0300 Subject: [PATCH] do not format advanced json in admin panel --- .../main/kotlin/org/icpclive/admin/Routing.kt | 7 +++++- .../admin/src/components/AdvancedJson.js | 24 +++++++++---------- src/frontend/admin/src/utils.js | 10 ++++---- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/backend/src/main/kotlin/org/icpclive/admin/Routing.kt b/src/backend/src/main/kotlin/org/icpclive/admin/Routing.kt index f77faad1e..ffee6c91d 100644 --- a/src/backend/src/main/kotlin/org/icpclive/admin/Routing.kt +++ b/src/backend/src/main/kotlin/org/icpclive/admin/Routing.kt @@ -19,6 +19,7 @@ import org.icpclive.cds.tunning.toAdvancedProperties import org.icpclive.data.Controllers import org.icpclive.data.DataBus import org.icpclive.util.sendFlow +import java.io.IOException import java.nio.file.Files fun Route.configureAdminApiRouting() { @@ -98,7 +99,11 @@ fun Route.configureAdminApiRouting() { route("/advancedJson") { get { - call.respondFile(Config.cdsSettings.advancedJsonPath.toFile()) + try { + call.respondFile(Config.cdsSettings.advancedJsonPath.toFile()) + } catch (e: IOException) { + call.respondText("{}") + } } post { call.adminApiAction { diff --git a/src/frontend/admin/src/components/AdvancedJson.js b/src/frontend/admin/src/components/AdvancedJson.js index 673458fc2..4c57f3efe 100644 --- a/src/frontend/admin/src/components/AdvancedJson.js +++ b/src/frontend/admin/src/components/AdvancedJson.js @@ -8,16 +8,16 @@ import { createApiGet, createApiPost } from "../utils"; import JsonEditor from "./atoms/JsonEditor"; import Box from "@mui/material/Box"; +const SCHEMA_URL = SCHEMAS_LOCATION + "/advanced.schema.json"; +const API_URL = BASE_URL_BACKEND + "/advancedJson"; + function AdvancedJson() { const { enqueueSnackbar } = useSnackbar(); const errorHandler = errorHandlerWithSnackbar(enqueueSnackbar); - const schemaUrl = SCHEMAS_LOCATION + "/advanced.schema.json"; - const apiUrl = BASE_URL_BACKEND + "/advancedJson"; - - const schemaGet = createApiGet(schemaUrl); - const apiGet = createApiGet(apiUrl); - const apiPost = createApiPost(apiUrl); + const schemaGet = createApiGet(SCHEMA_URL); + const apiGet = createApiGet(API_URL); + const apiPost = createApiPost(API_URL); const [schema, setSchema] = useState(); const [content, setContent] = useState(); @@ -26,16 +26,16 @@ function AdvancedJson() { schemaGet("") .then(data => setSchema(data)) .catch(errorHandler("Failed to load advanced json schema")); - }, [schemaUrl]); + }, []); useEffect(() => { - apiGet("") + apiGet("", undefined, true) .then(data => setContent(data)) .catch(errorHandler("Failed to load advanced json data")); - }, [apiUrl]); + }, []); const onSubmit = () => { - apiPost("", content) + apiPost("", content, "POST", true) .catch(errorHandler("Failed to save advanced json data")); }; @@ -52,8 +52,8 @@ function AdvancedJson() { setContent(JSON.parse(value))} - defaultValue={JSON.stringify(content, null, 2)} + onChange={(value) => setContent(value)} + defaultValue={content} />