From b5fe6335c73ed0e8424c119e6463f08fa4a66eef Mon Sep 17 00:00:00 2001 From: bunkerity Date: Thu, 24 Dec 2020 14:55:11 +0100 Subject: [PATCH] UI - instances backend started --- ui/entrypoint.py | 44 ++++++++++++++++++------------- ui/static/js/custom.js | 30 ++++++++++++++++++--- ui/templates/error.html | 11 +++++--- ui/templates/instances.html | 26 ++++++++++++------ ui/templates/services-delete.html | 2 +- ui/templates/services-edit.html | 2 +- ui/templates/services-new.html | 2 +- ui/templates/services.html | 2 +- ui/wrappers.py | 38 +++++++++++++++++++++++++- 9 files changed, 119 insertions(+), 38 deletions(-) diff --git a/ui/entrypoint.py b/ui/entrypoint.py index f520e6e..4c20f64 100644 --- a/ui/entrypoint.py +++ b/ui/entrypoint.py @@ -26,12 +26,31 @@ def home(): return render_template("error.html", title="Error", error=services) return render_template("home.html", title="Home", instances_number=len(instances), services_number=len(services)) -@app.route('/instances') +@app.route('/instances', methods=["GET", "POST"]) def instances(): + + # Manage instances + operation = "" + if request.method == "POST" : + + # Check operation + if not "operation" in request.form or not request.form["operation"] in ["reload", "start", "stop", "restart", "delete"] : + return render_template("error.html", title="Error", error="Missing operation parameter on /instances.") + + # Check that all fields are present + if not "INSTANCE_ID" in request.form : + return render_template("error.html", title="Error", error="Missing INSTANCE_ID parameter.") + + # Do the operation + check, operation = wrappers.operation_instance(request.form) + if not check : + return render_template("error.html", title="Error", error=operation) + + # Display instances check, instances = wrappers.get_instances() if not check : return render_template("error.html", title="Error", error=instances) - return render_template("instances.html", title="Instances", instances=instances) + return render_template("instances.html", title="Instances", instances=instances, operation=operation) @app.route('/services', methods=["GET", "POST"]) def services(): @@ -65,23 +84,10 @@ def services(): if not re.search("^([a-z\-0-9]+\.?)+$", request.form["SERVER_NAME"]) : return render_template("error.html", title="Error", error="Parameter SERVER_NAME doesn't match regex.") - # Create new service - if request.form["operation"] == "new" : - check, operation = wrappers.new_service(env) - if not check : - render_template("error.html", title="Error", error=service) - - # Edit existing service - elif request.form["operation"] == "edit" : - check, operation = wrappers.edit_service(request.form["OLD_SERVER_NAME"], env) - if not check : - render_template("error.html", title="Error", error=service) - - # Delete existing service - elif request.form["operation"] == "delete" : - check, operation = wrappers.delete_service(request.form["SERVER_NAME"]) - if not check : - render_template("error.html", title="Error", error=service) + # Do the operation + check, operation = wrappers.operation_service(request.form, env) + if not check : + render_template("error.html", title="Error", error=operation) # Display services check, services = wrappers.get_services() diff --git a/ui/static/js/custom.js b/ui/static/js/custom.js index 23a2fc8..ce7abbe 100644 --- a/ui/static/js/custom.js +++ b/ui/static/js/custom.js @@ -43,14 +43,38 @@ function getData(id) { return data; } -function postNew() { +function newService() { post("new", "services", getData('form-new')); } -function postEdit(id) { +function editService(id) { post("edit", "services", getData('form-edit-' + id)); } -function postDelete(id) { +function deleteService(id) { post("delete", "services", getData('form-delete-' + id)); } + +function reloadInstance(id) { + post("reload", "instances", getData('form-instance-' + id)); +} + +function startInstance(id) { + post("start", "instances", getData('form-instance-' + id)); + return false; +} + +function stopInstance(id) { + post("stop", "instances", getData('form-instance-' + id)); + return false; +} + +function restartInstance(id) { + post("restart", "instances", getData('form-instance-' + id)); + return false; +} + +function deleteInstance(id) { + post("delete", "instances", getData('form-instance-' + id)); + return false; +} diff --git a/ui/templates/error.html b/ui/templates/error.html index bb63c8a..c69d8ab 100644 --- a/ui/templates/error.html +++ b/ui/templates/error.html @@ -2,8 +2,13 @@ {% block content %} -Something went wrong. - -Some information : {{ error }} +
+
+
+ Something went wrong...
+ {{ error }} +
+
+
{% endblock %} diff --git a/ui/templates/instances.html b/ui/templates/instances.html index 800dfd8..fb1211a 100644 --- a/ui/templates/instances.html +++ b/ui/templates/instances.html @@ -2,9 +2,16 @@ {% block content %} - +{% if operation != "" %} +
+
+ +
+
+{% endif %}
@@ -19,6 +26,9 @@ {% endif %}
+
+ +
{{ instance["name"] }} @@ -27,13 +37,13 @@ manage container
- +
Status : {{ instance["status"] }}
diff --git a/ui/templates/services-delete.html b/ui/templates/services-delete.html index 319c349..dd89165 100644 --- a/ui/templates/services-delete.html +++ b/ui/templates/services-delete.html @@ -13,7 +13,7 @@
diff --git a/ui/templates/services-edit.html b/ui/templates/services-edit.html index 1ab29bc..22e7d63 100644 --- a/ui/templates/services-edit.html +++ b/ui/templates/services-edit.html @@ -34,7 +34,7 @@ diff --git a/ui/templates/services-new.html b/ui/templates/services-new.html index ea841a9..defd05c 100644 --- a/ui/templates/services-new.html +++ b/ui/templates/services-new.html @@ -33,7 +33,7 @@ diff --git a/ui/templates/services.html b/ui/templates/services.html index be2f5a1..e1f640c 100644 --- a/ui/templates/services.html +++ b/ui/templates/services.html @@ -5,7 +5,7 @@ {% if operation != "" %}
-