From 3be39cf23d666ae27e4a1a2a6443d282d1b199c7 Mon Sep 17 00:00:00 2001 From: Rick Date: Tue, 20 Oct 2020 21:41:16 +0200 Subject: [PATCH] Ajout de la recherche --- app.py | 9 ++++++ static/recherche.js | 17 +++++++++++ static/styles/base.css | 4 +++ templates/ajout.html | 5 ++-- templates/index.html | 4 +-- templates/recherche.html | 61 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 static/recherche.js create mode 100644 templates/recherche.html diff --git a/app.py b/app.py index f477ec9..415c263 100644 --- a/app.py +++ b/app.py @@ -44,6 +44,15 @@ def categories(subpath): def ajout(): return render_template("ajout.html") +@app.route("/recherche") +def recherche(): + with open(fichierJson, 'r') as fichier: + liens = json.load(fichier) + listeLiens = liens["liens"] + listeLiens.reverse() + response = make_response(render_template("recherche.html", listeLiens=listeLiens)) + return response + @app.route("/apropos") def apropos(): return app.send_static_file("apropos.html") diff --git a/static/recherche.js b/static/recherche.js new file mode 100644 index 0000000..5e126fe --- /dev/null +++ b/static/recherche.js @@ -0,0 +1,17 @@ +function recherche() { + let categorie = document.getElementById("categorie").value; + let listElem = document.getElementsByClassName("elem"); + if (categorie == "tout") { + for (let element of listElem) { + element.classList.remove("hide"); + } + } else { + for (let element of listElem) { + if (element.classList.contains(categorie)) { + element.classList.remove("hide"); + } else { + element.classList.add("hide"); + } + } + } +} diff --git a/static/styles/base.css b/static/styles/base.css index c87634c..fb737c7 100644 --- a/static/styles/base.css +++ b/static/styles/base.css @@ -46,3 +46,7 @@ header a:hover { text-decoration: none; color: white; } + +.hide { + display: none; +} diff --git a/templates/ajout.html b/templates/ajout.html index 01733ac..df55aaa 100644 --- a/templates/ajout.html +++ b/templates/ajout.html @@ -10,8 +10,9 @@
diff --git a/templates/index.html b/templates/index.html index a928f0b..021a47b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,7 +10,7 @@