From 1d4998356de0937b1663ce0512151b1b52251db9 Mon Sep 17 00:00:00 2001 From: TheophileDiot Date: Tue, 29 Nov 2022 14:40:15 +0100 Subject: [PATCH] Fix darkmode + Add new variables to pass to the front --- src/ui/main.py | 30 ++++++++++++++++++++++++------ src/ui/static/js/global.js | 5 +++-- src/ui/templates/jobs.html | 2 +- src/ui/templates/plugins.html | 5 ++--- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/ui/main.py b/src/ui/main.py index 4d36a5ebe..434b6c4d9 100755 --- a/src/ui/main.py +++ b/src/ui/main.py @@ -1015,8 +1015,23 @@ def plugins(): ), ) + app.config["CONFIG"].reload_plugins() + plugins = app.config["CONFIG"].get_plugins() + plugins_internal = 0 + plugins_external = 0 + + for plugin in plugins: + if plugin["external"] is True: + plugins_external += 1 + else: + plugins_internal += 1 + return render_template( "plugins.html", + plugins=plugins, + plugins_internal=plugins_internal, + plugins_external=plugins_external, + plugins_errors=db.get_plugins_errors(), dark_mode=app.config["DARK_MODE"], ) @@ -1389,6 +1404,7 @@ def jobs(): return render_template( "jobs.html", jobs=db.get_jobs(), + jobs_errors=db.get_plugins_errors(), dark_mode=app.config["DARK_MODE"], ) @@ -1460,13 +1476,15 @@ def login(): @app.route("/darkmode", methods=["POST"]) @login_required def darkmode(): - if "darkmode" in request.form: - if request.form["darkmode"] == "true": - app.config["DARK_MODE"] = True - else: - app.config["DARK_MODE"] = False + if not request.is_json: + return jsonify({"status": "ko", "message": "invalid request"}), 400 - return jsonify({"status": "ok"}) + if "darkmode" in request.json: + app.config["DARK_MODE"] = request.json["darkmode"] == "true" + else: + return jsonify({"status": "ko", "message": "darkmode is required"}), 422 + + return jsonify({"status": "ok"}), 200 @app.route("/check_reloading") diff --git a/src/ui/static/js/global.js b/src/ui/static/js/global.js index 03e878428..f4519b76c 100644 --- a/src/ui/static/js/global.js +++ b/src/ui/static/js/global.js @@ -69,10 +69,11 @@ class darkMode { headers: { Accept: "application/json", "Content-Type": "application/json", + "X-CSRF-Token": this.csrf.value, }, - body: JSON.stringify({ darkmode: isDark, csrf_token: this.csrf.value }), + body: JSON.stringify({ darkmode: isDark }), }; - const send = await fetch(`${location.href}/darkmode}`, data); + const send = await fetch(`${location.href.split("/").slice(0, -1).join("/")}/darkmode`, data); } } diff --git a/src/ui/templates/jobs.html b/src/ui/templates/jobs.html index a446e0b09..4ed2c364f 100644 --- a/src/ui/templates/jobs.html +++ b/src/ui/templates/jobs.html @@ -14,7 +14,7 @@ url_for(request.endpoint)[1:].split("/")[-1].strip() %}

- {{jobs_total}} + {{jobs|length}}

diff --git a/src/ui/templates/plugins.html b/src/ui/templates/plugins.html index c67b4bd33..1c958ec85 100644 --- a/src/ui/templates/plugins.html +++ b/src/ui/templates/plugins.html @@ -1,6 +1,5 @@ {% extends "base.html" %} {% block content %}{% set current_endpoint = -url_for(request.endpoint)[1:].split("/")[-1].strip().replace('_', '-') %} {% set -plugins = config["CONFIG"].get_plugins() %} +url_for(request.endpoint)[1:].split("/")[-1].strip().replace('_', '-') %}
- {{plugins_total}} + {{plugins|length}}