From 8ad1b6bb855eebca59e166b3951308e42fe3af88 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Mon, 18 Dec 2023 18:39:55 +1100 Subject: [PATCH] Add js function to show alerts when updating http functions --- app.py | 8 +++--- templates/base.html | 28 ++++++++++++++++++++ templates/dashboard/http_functions/edit.html | 7 +++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index e7b97c8..0df8984 100644 --- a/app.py +++ b/app.py @@ -102,7 +102,7 @@ def create_http_function(): return render_template("dashboard/http_functions.html", http_functions=http_functions) except Exception as e: print(e) - return render_template("dashboard/http_functions/new.html", name=name, script=script_content) + return { "status": "error", "message": str(e) } @ app.route("/dashboard/http_functions/edit_form", methods=["GET"]) def get_http_function_edit_form(): @@ -122,10 +122,10 @@ def edit_http_function(): environment_info = json.dumps(eval(request.json.get('environment_info'))) db.edit_http_function(name, script_content, environment_info) - return render_template("dashboard/http_functions/edit.html", name=name, script=script_content, environment_info=environment_info) + return { "status": "success", "message": f'{name} updated' } except Exception as e: print(e) - return render_template("dashboard/http_functions/edit.html", name=name, script=script_content) + return { "status": "error", "message": str(e) } @ app.route("/dashboard/http_functions/delete", methods=["DELETE"]) def delete_http_function(): @@ -137,7 +137,7 @@ def delete_http_function(): http_functions = create_http_functions_view_model(http_functions) return render_template("dashboard/http_functions.html", http_functions=http_functions) except Exception as e: - return jsonify({'error': str(e)}), 500 + return jsonify({"status": 'error', "message": str(e)}), 500 @ app.route("/dashboard/timer_functions", methods=["GET"]) def dashboard_timer_functions(): diff --git a/templates/base.html b/templates/base.html index d159fab..b083dce 100644 --- a/templates/base.html +++ b/templates/base.html @@ -28,5 +28,33 @@ {% block content %} {% endblock %} + +
+ + \ No newline at end of file diff --git a/templates/dashboard/http_functions/edit.html b/templates/dashboard/http_functions/edit.html index 0ccdca4..5c2c963 100644 --- a/templates/dashboard/http_functions/edit.html +++ b/templates/dashboard/http_functions/edit.html @@ -190,10 +190,9 @@ }, body: JSON.stringify({ name, script_content, environment_info }), }) - .then(response => response.text()) - .then(text => { - document.querySelector('#container').innerHTML = text - htmx.process(htmx.find('#container')) + .then(response => response.json()) + .then(json => { + showAlert(json.message, json.status) }) }) \ No newline at end of file