diff --git a/app.py b/app.py index cef47d7..3c7f296 100644 --- a/app.py +++ b/app.py @@ -89,10 +89,16 @@ def get_http_function_add_form(): @ app.route("/dashboard/http_functions/create", methods=["POST"]) def create_http_function(): - name = request.json.get('name') - script_content = request.json.get('script_content') - db.create_new_http_function(name, script_content) - return render_template("dashboard/http_functions/new.html", name=name, script=script_content) + try: + name = request.json.get('name') + script_content = request.json.get('script_content') + db.create_new_http_function(name, script_content) + + http_functions = db.get_http_functions() + 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 render_template("dashboard/http_functions/new.html", name=name, script=script_content) @ app.route("/dashboard/http_functions/edit_form", methods=["GET"]) def get_http_function_edit_form(): @@ -109,10 +115,25 @@ def edit_http_function(): name = request.json.get('name') script_content = request.json.get('script_content') db.edit_http_function(name, script_content) - return redirect(url_for('dashboard_http_functions')) + + http_functions = db.get_http_functions() + 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 render_template("dashboard/http_functions/edit.html", name=name, script=script_content) +@ app.route("/dashboard/http_functions/delete", methods=["DELETE"]) +def delete_http_function(): + try: + name = request.args.get('name') + db.delete_http_function(name) + + http_functions = db.get_http_functions() + 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 + @ app.route("/dashboard/timer_functions", methods=["GET"]) def dashboard_timer_functions(): return render_template("dashboard/timer_functions.html") diff --git a/db.py b/db.py index 04107de..77335ea 100644 --- a/db.py +++ b/db.py @@ -63,3 +63,7 @@ class DataBase(): def edit_http_function(self, name, script_content): self.execute( 'UPDATE http_functions SET script_content=%s WHERE NAME=%s', [script_content, name], commit=True) + + def delete_http_function(self, name): + self.execute( + 'DELETE FROM http_functions WHERE NAME=%s', [name], commit=True) diff --git a/templates/client.html b/templates/client.html index 4eb03f6..8a0b583 100644 --- a/templates/client.html +++ b/templates/client.html @@ -2,6 +2,15 @@ {% block content %} +