From d9707a25df0e9358c3e2de2d06062c0b54618521 Mon Sep 17 00:00:00 2001 From: J-Klinke Date: Mon, 1 Jul 2024 10:21:43 +0200 Subject: [PATCH 1/2] implemented fetching categories from backend --- src/main/resources/static/main.js | 16 ++++++++++++++++ src/main/resources/templates/index.html | 3 +-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js index aa82a16..3100f54 100644 --- a/src/main/resources/static/main.js +++ b/src/main/resources/static/main.js @@ -166,7 +166,23 @@ function updateSections() { } } +// fetches the further categories used in the filter function +function fetchCategories() { + const fetchURL = new URL( + "api/v1/categories" , baseURL); + fetch(fetchURL) + .then(resp => resp.json()) + .then((data) => { + console.log(data); // TODO remove + for (let i = 0; i < data.length; i++) { + console.log(data[i]); // TODO remove + document.getElementById("other-categories").appendChild(new Option(data[i])); + } + }); +} + window.onload = function () { + fetchCategories(); updateSections(); if (searchBar.value !== "") { search(searchBar.value); diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index c894c6a..e5f46f2 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -52,8 +52,7 @@ - - + From 1dfd2f765a751f774a01610e4488b1ade0406763 Mon Sep 17 00:00:00 2001 From: J-Klinke Date: Mon, 1 Jul 2024 10:42:25 +0200 Subject: [PATCH 2/2] formatted the categories --- src/main/resources/static/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js index 3100f54..1400175 100644 --- a/src/main/resources/static/main.js +++ b/src/main/resources/static/main.js @@ -173,10 +173,10 @@ function fetchCategories() { fetch(fetchURL) .then(resp => resp.json()) .then((data) => { - console.log(data); // TODO remove for (let i = 0; i < data.length; i++) { - console.log(data[i]); // TODO remove - document.getElementById("other-categories").appendChild(new Option(data[i])); + let category = data[i].toLowerCase(); + category = category.charAt(0).toUpperCase() + category.slice(1); + document.getElementById("other-categories").appendChild(new Option(category)); } }); }