From d8b441374e6c983f434f819041b22ee2c9940081 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 16 Dec 2023 21:27:49 +1100 Subject: [PATCH] Add ability to add new http functions (Needs refactor, bad stuff) --- app.py | 13 ++ db.py | 4 + templates/dashboard/http_functions.html | 3 +- templates/dashboard/http_functions/new.html | 148 ++++++++++++++++++++ 4 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 templates/dashboard/http_functions/new.html diff --git a/app.py b/app.py index 8512101..709b9ee 100644 --- a/app.py +++ b/app.py @@ -81,6 +81,19 @@ def dashboard_http_functions(): http_functions = create_http_functions_view_model(http_functions) return render_template("dashboard/http_functions.html", http_functions=http_functions) +@ app.route("/dashboard/http_functions/add_form", methods=["GET"]) +def get_http_function_add_form(): + script=DEFAULT_SCRIPT + name = "foo" + return render_template("dashboard/http_functions/new.html", name=name, script=script) + +@ 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) + @ 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 843b639..897a787 100644 --- a/db.py +++ b/db.py @@ -55,3 +55,7 @@ class DataBase(): http_function = self.execute( 'SELECT id, NAME, script_content, invoked_count FROM http_functions WHERE NAME=%s', [name], one=True) return http_function + + def create_new_http_function(self, name, script_content): + self.execute( + 'INSERT INTO http_functions (NAME, script_content) VALUES (%s, %s)', [name, script_content], commit=True) diff --git a/templates/dashboard/http_functions.html b/templates/dashboard/http_functions.html index d12415c..a104f90 100644 --- a/templates/dashboard/http_functions.html +++ b/templates/dashboard/http_functions.html @@ -1,7 +1,8 @@

HTTP functions

diff --git a/templates/dashboard/http_functions/new.html b/templates/dashboard/http_functions/new.html new file mode 100644 index 0000000..c94fc36 --- /dev/null +++ b/templates/dashboard/http_functions/new.html @@ -0,0 +1,148 @@ +
+

New HTTP function

+
+ + +
+
+ + + + + +
+ +
{{ script }} +
+
+ +
+ +
+ + \ No newline at end of file