From b91b3821a4c78704f1a800b1c7bdd3559eb7fd41 Mon Sep 17 00:00:00 2001 From: Jeremy Zhang Date: Wed, 2 Aug 2017 19:28:08 +0000 Subject: [PATCH] Fully implement database cleanup button, ajax side --- webapp/titanembeds/static/js/admin_index.js | 30 +++++++++++++++++++ .../titanembeds/templates/admin_index.html.j2 | 9 ++++-- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 webapp/titanembeds/static/js/admin_index.js diff --git a/webapp/titanembeds/static/js/admin_index.js b/webapp/titanembeds/static/js/admin_index.js new file mode 100644 index 0000000..1a1f11c --- /dev/null +++ b/webapp/titanembeds/static/js/admin_index.js @@ -0,0 +1,30 @@ +/* global $ */ +/* global Materialize */ + +(function () { + function cleanup_database() { + var funct = $.ajax({ + method: "DELETE", + url: "/api/cleanup-db", + }); + return funct.promise(); + } + + $(function(){ + $("#db_cleanup_btn").click(run_cleanup_db); + }); + + function run_cleanup_db() { + $("#db_cleanup_btn").attr("disabled",true); + Materialize.toast('Please wait for the cleanup database task to finish...', 10000); + var cleanupdb = cleanup_database(); + cleanupdb.done(function () { + $("#db_cleanup_btn").attr("disabled",false); + Materialize.toast('Successfully cleaned up the database!', 10000); + }); + cleanupdb.fail(function () { + $("#db_cleanup_btn").attr("disabled",false); + Materialize.toast('Database cleanup failiure.', 10000); + }); + } +})(); \ No newline at end of file diff --git a/webapp/titanembeds/templates/admin_index.html.j2 b/webapp/titanembeds/templates/admin_index.html.j2 index 60a7ce1..2785249 100644 --- a/webapp/titanembeds/templates/admin_index.html.j2 +++ b/webapp/titanembeds/templates/admin_index.html.j2 @@ -22,10 +22,13 @@
-

Cleanup DB

-

Clean up the database

- SoonTM +

Run a Database Cleanup

+

Clears the keyval caches and purges the old messages. (Hit once, and wait a minute)

+ Run DB Cleanup Task
{% endblock %} +{% block script %} + +{% endblock %} \ No newline at end of file