From 1971169e2f526fcb304f9c0bfc594848b65823e5 Mon Sep 17 00:00:00 2001 From: vinchent Date: Fri, 23 Aug 2024 13:55:21 +0200 Subject: [PATCH] use sessionStorage & add user admin pages --- cmd/web/handlers.go | 12 +++++++++ cmd/web/routes.go | 2 ++ cmd/web/templates/all-sales.page.gohtml | 6 ++--- .../templates/all-subscriptions.page.gohtml | 6 ++--- cmd/web/templates/all-users.page.gohtml | 25 +++++++++++++++++++ cmd/web/templates/base.layout.gohtml | 6 +++++ cmd/web/templates/one-user.page.gohtml | 11 ++++++++ static/js/all-sales.js | 4 +-- static/js/all-subscriptions.js | 4 +-- 9 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 cmd/web/templates/all-users.page.gohtml create mode 100644 cmd/web/templates/one-user.page.gohtml diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 9852de2..04ada9e 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -417,3 +417,15 @@ func (app *application) ShowSubscriptions(w http.ResponseWriter, r *http.Request app.errorLog.Println(err) } } + +func (app *application) AllUsers(w http.ResponseWriter, r *http.Request) { + if err := app.renderTemplate(w, r, "all-users", &templateData{}); err != nil { + app.errorLog.Println(err) + } +} + +func (app *application) OneUser(w http.ResponseWriter, r *http.Request) { + if err := app.renderTemplate(w, r, "one-user", &templateData{}); err != nil { + app.errorLog.Println(err) + } +} diff --git a/cmd/web/routes.go b/cmd/web/routes.go index c5dba9e..ec1d25c 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -19,6 +19,8 @@ func (app *application) routes() http.Handler { mux.Get("/all-subscriptions", app.AllSubscriptions) mux.Get("/sales/{id}", app.ShowSale) mux.Get("/subscriptions/{id}", app.ShowSubscriptions) + mux.Get("/all-users", app.AllUsers) + mux.Get("/all-users/{id}", app.OneUser) }) // mux.Post("/virtual-terminal-payment-succeeded", app.VirtualTerminalPaymentSucceeded) diff --git a/cmd/web/templates/all-sales.page.gohtml b/cmd/web/templates/all-sales.page.gohtml index 867af2c..2d56d74 100644 --- a/cmd/web/templates/all-sales.page.gohtml +++ b/cmd/web/templates/all-sales.page.gohtml @@ -29,9 +29,9 @@ All Sales import {showTable, currentPage} from "/static/js/all-sales.js" let curPage = currentPage; - if (localStorage.getItem("cur-page") !== null) { - curPage = localStorage.getItem("cur-page"); - localStorage.removeItem("cur-page"); + if (sessionStorage.getItem("cur-page") !== null) { + curPage = sessionStorage.getItem("cur-page"); + sessionStorage.removeItem("cur-page"); } showTable({{.API}}, pageSize, curPage); diff --git a/cmd/web/templates/all-subscriptions.page.gohtml b/cmd/web/templates/all-subscriptions.page.gohtml index 5077480..d52ae5a 100644 --- a/cmd/web/templates/all-subscriptions.page.gohtml +++ b/cmd/web/templates/all-subscriptions.page.gohtml @@ -32,9 +32,9 @@ All Subscriptions import {showTable, currentPage} from "/static/js/all-subscriptions.js" let curPage = currentPage; - if (localStorage.getItem("cur-page") !== null) { - curPage = localStorage.getItem("cur-page"); - localStorage.removeItem("cur-page"); + if (sessionStorage.getItem("cur-page") !== null) { + curPage = sessionStorage.getItem("cur-page"); + sessionStorage.removeItem("cur-page"); } showTable({{.API}}, pageSize, curPage); diff --git a/cmd/web/templates/all-users.page.gohtml b/cmd/web/templates/all-users.page.gohtml new file mode 100644 index 0000000..5d3efa6 --- /dev/null +++ b/cmd/web/templates/all-users.page.gohtml @@ -0,0 +1,25 @@ +{{ template "base". }} +{{ define "title" }} +All Users +{{ end }} +{{ define "content" }} +

All Admin users

+
+
+ Add User +
+
+ + + + + + + + + +
UserEmail
+{{ end }} +{{ define "js" }} + +{{ end }} diff --git a/cmd/web/templates/base.layout.gohtml b/cmd/web/templates/base.layout.gohtml index 220a895..561c0fa 100644 --- a/cmd/web/templates/base.layout.gohtml +++ b/cmd/web/templates/base.layout.gohtml @@ -70,6 +70,12 @@
  • +
  • + All Users +
  • +
  • + +
  • Logout
  • diff --git a/cmd/web/templates/one-user.page.gohtml b/cmd/web/templates/one-user.page.gohtml new file mode 100644 index 0000000..ac34374 --- /dev/null +++ b/cmd/web/templates/one-user.page.gohtml @@ -0,0 +1,11 @@ +{{ template "base". }} +{{ define "title" }} +Admin User +{{ end }} +{{ define "content" }} +

    Admin user

    +
    +{{ end }} +{{ define "js" }} +{{ end }} + diff --git a/static/js/all-sales.js b/static/js/all-sales.js index 01b904c..b315407 100644 --- a/static/js/all-sales.js +++ b/static/js/all-sales.js @@ -36,8 +36,8 @@ export function showTable(api, ps, cp) { newCell.innerHTML = `Order ${i.id}`; newCell.addEventListener("click", function (evt) { - // put the current_page into localStorage - localStorage.setItem("cur-page", data.current_page); + // put the current_page into sessionStorage + sessionStorage.setItem("cur-page", data.current_page); // redirect location.href = `/admin/sales/${i.id}`; diff --git a/static/js/all-subscriptions.js b/static/js/all-subscriptions.js index 5e737fe..98a9ce3 100644 --- a/static/js/all-subscriptions.js +++ b/static/js/all-subscriptions.js @@ -34,8 +34,8 @@ export function showTable(api, ps, cp) { newCell.innerHTML = `Order ${i.id}`; newCell.addEventListener("click", function (evt) { - // put the current_page into localStorage - localStorage.setItem("cur-page", data.current_page); + // put the current_page into sessionStorage + sessionStorage.setItem("cur-page", data.current_page); // redirect location.href = `/admin/subscriptions/${i.id}`;