From 19e6dbd05226ae5105eb6ba0e5056bbef889d1d2 Mon Sep 17 00:00:00 2001 From: Fauvet Matthis Date: Fri, 21 Jun 2024 19:31:52 +0200 Subject: [PATCH] added possibility to filter datas --- model.js | 19 +++++++++++++++++++ onzer.riot | 18 ++++++++++-------- 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 model.js diff --git a/model.js b/model.js new file mode 100644 index 0000000..f077c59 --- /dev/null +++ b/model.js @@ -0,0 +1,19 @@ +function execQuery(table, filter = "all", id = -1){ + let baseHttpRequest = "https://dwarves.iut-fbleau.fr/~fauvet/api/" + let computeHttpRequest; + if(filter !== undefined){ + switch(table){ + case "songs": + computeHttpRequest = baseHttpRequest+table+"?title="+filter; + default : + computeHttpRequest = baseHttpRequest+table+"?name="+filter; + } + } else if(id !== undefined) { + computeHttpRequest = baseHttpRequest+table+"/"+id; + } else { + computeHttpRequest = baseHttpRequest+table; + } + return fetch(computeHttpRequest).then(response => { + return response.json(); + }); +}; \ No newline at end of file diff --git a/onzer.riot b/onzer.riot index f19e16c..f1e2d9e 100644 --- a/onzer.riot +++ b/onzer.riot @@ -11,7 +11,7 @@
+ placeholder={ state.placeholder } onkeyup={ edit } />
@@ -25,17 +25,24 @@