From 49461a0c9759355adb49a47c47d0a8426bb24cb3 Mon Sep 17 00:00:00 2001 From: Saba Date: Sat, 27 Nov 2021 11:14:49 -0500 Subject: [PATCH] Working example for reading and display the config.yml --- views/scripts/config.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/views/scripts/config.js b/views/scripts/config.js index 337aa72d..240ee0f0 100644 --- a/views/scripts/config.js +++ b/views/scripts/config.js @@ -1,13 +1,26 @@ var showConfig = document.getElementById("show-config"); -var configForm = document.getElementById("config-form"); + showConfig.addEventListener("click", () => { + var configForm = document.getElementById("config-form"); fetch("/config") .then(response => response.json()) .then(data => { configForm.style.display = "block"; - for (let key in data) { - console.log('key: ', key); - console.log(data[key]); - } + processChildren(configForm, data); }); -}); \ No newline at end of file +}); + +function processChildren(element, data) { + for (let key in data) { + var child = document.createElement("div"); + child.id = key; + child.appendChild(document.createTextNode(key + ": ")); + if (data[key] === Object(data[key])) { + console.log(key, data[key]); + processChildren(child, data[key]); + } else { + child.textContent+=data[key]; + } + element.appendChild(child); + } +} \ No newline at end of file