From 0f6ebe1e588072a704315b67e17268a669d67e03 Mon Sep 17 00:00:00 2001 From: phga Date: Thu, 21 Oct 2021 22:19:18 +0200 Subject: [PATCH] feat: reset dbs, load new dbs, disable buttons while processing --- cmd/bs1in/bs1in.go | 14 +++++- web/static/css/bs1in.css | 96 ++++++++++++++++++++++++++++++++++++- web/static/js/main.js | 28 +++++++++++ web/templates/header.html | 1 + web/templates/main.html | 3 ++ web/templates/register.html | 11 ++++- 6 files changed, 149 insertions(+), 4 deletions(-) create mode 100644 web/static/js/main.js diff --git a/cmd/bs1in/bs1in.go b/cmd/bs1in/bs1in.go index 1f49769..f51a920 100644 --- a/cmd/bs1in/bs1in.go +++ b/cmd/bs1in/bs1in.go @@ -18,6 +18,7 @@ func main() { http.HandleFunc("/logout", validateSession(handleLogout, "")) http.HandleFunc("/", validateSession(handleIndex, "")) + http.HandleFunc("/database", validateSession(handleDatabase, "")) http.HandleFunc("/admin_panel", validateSession(handleAdminPanel, "admin")) // provide the inc directory to the useragent http.HandleFunc("/static/", validateSession(handleStatic, "")) @@ -48,13 +49,24 @@ func handleIndex(w http.ResponseWriter, r *http.Request) { func handleAdminPanel(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodGet { - t, _ := getTemplate("layouts/base.html", "admin_panel.html", "header.html") + t, _ := getTemplate("layouts/base.html", "soon.html", "header.html") currUser := r.Context().Value(currUserKey).(User) td := TmplData{currUser, nil} t.Execute(w, td) } } +func handleDatabase(w http.ResponseWriter, r *http.Request) { + if r.Method == http.MethodPatch { + currUser := r.Context().Value(currUserKey).(User) + if createMariaDbDatabasesForUser(currUser.UID) { + w.WriteHeader(http.StatusOK) + } else { + w.WriteHeader(http.StatusInternalServerError) + } + } +} + func handleRegister(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodGet { t, _ := getTemplate("layouts/base.html", "register.html") diff --git a/web/static/css/bs1in.css b/web/static/css/bs1in.css index d53976c..d84a530 100644 --- a/web/static/css/bs1in.css +++ b/web/static/css/bs1in.css @@ -114,7 +114,8 @@ form { #general-info { position: relative; - bottom: 5px; + box-sizing: border-box; + bottom: -50px; margin-left: -165px; left: 50%; line-height: 40px; @@ -125,6 +126,79 @@ form { padding: 0 10px; } +/******************* HEADER *******************/ + +header { + width: 400px; + height: 30px; + margin: auto; + border-radius: 4px; + background: var(--grey1); + line-height: 30px; +} + +nav { + width: 90%; + height: 100%; + text-align: justify; + margin: auto; +} + +nav:after { + content: ""; + width: 100%; + display: inline-block; +} + +nav * { + display: inline-block; + text-decoration: none; + color: var(--black); + font-weight: bold; + cursor: pointer; +} + +nav > * { + opacity: .7; +} + +nav > *:hover { + opacity: 1; +} + +.dropdown { + +} + +.dropdown-main { +} + +.dropdown-sub { + position: absolute; + padding: 0 8px; + z-index: 69; + display: none; + background: var(--grey1); + border-radius: 0 0 4px 4px; + filter: drop-shadow(-2px 2px 2px var(--grey2)); +} + +.dropdown-sub > a { + opacity: 0.7; +} + +.dropdown-sub > a:hover { + opacity: 1; +} + +.dropdown-sub > a { + display: block; +} + +.dropdown:hover .dropdown-sub { + display: block; +} + /******************* LOGIN *******************/ #frm-login, #frm-register { @@ -143,4 +217,24 @@ form { right: 0px; margin-top: 15px; color: var(--black); +} + +/******************* MAIN *******************/ + +#wrapper { + position: absolute; + width: 500px; + height: auto; + + margin-left: -250px; + left: 50%; + top: 100px; + + /* border: solid 2px blue; */ +} + +#wrapper > button { + position: relative; + width: 80%; + left: 10%; } \ No newline at end of file diff --git a/web/static/js/main.js b/web/static/js/main.js new file mode 100644 index 0000000..0954bc7 --- /dev/null +++ b/web/static/js/main.js @@ -0,0 +1,28 @@ +let rbtn = document.getElementById("btn-reset"); +let infoBox = document.getElementById("general-info"); + +rbtn.addEventListener("click", e => { + e.preventDefault(); + + toggleDisabled(rbtn, "on"); + setInfo(infoBox, "Processing Request...", "purple", "grey1"); + toggleHidden(infoBox, "off"); + + fetch("/database", { + method: "PATCH" + }).then(res => { + if (res.status == 200) { + setInfo(infoBox, "Success", "green", "grey1"); + setTimeout(() => { + toggleHidden(infoBox, "on"); + }, 2000); + } else { + setInfo(infoBox, "Failure", "red", "grey1"); + toggleHidden(infoBox, "off"); + setTimeout(() => { + toggleHidden(infoBox, "on"); + }, 2000); + } + toggleDisabled(rbtn, "off"); + }); +}); diff --git a/web/templates/header.html b/web/templates/header.html index 45b7818..c1742ed 100644 --- a/web/templates/header.html +++ b/web/templates/header.html @@ -2,6 +2,7 @@
diff --git a/web/templates/main.html b/web/templates/main.html index 22566a3..e7cb4eb 100644 --- a/web/templates/main.html +++ b/web/templates/main.html @@ -1,8 +1,11 @@ {{define "body"}}
+ +
{{end}} {{define "scripts"}} + {{end}} \ No newline at end of file diff --git a/web/templates/register.html b/web/templates/register.html index 19e383a..d849659 100644 --- a/web/templates/register.html +++ b/web/templates/register.html @@ -4,7 +4,7 @@ - + {{end}} @@ -12,10 +12,16 @@