use sessionStorage & add user admin pages
This commit is contained in:
parent
0e7b9d8c20
commit
1971169e2f
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
</script>
|
||||
|
@ -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);
|
||||
</script>
|
||||
|
25
cmd/web/templates/all-users.page.gohtml
Normal file
25
cmd/web/templates/all-users.page.gohtml
Normal file
@ -0,0 +1,25 @@
|
||||
{{ template "base". }}
|
||||
{{ define "title" }}
|
||||
All Users
|
||||
{{ end }}
|
||||
{{ define "content" }}
|
||||
<h2 class="mt-5">All Admin users</h2>
|
||||
<hr>
|
||||
<div class="float-end">
|
||||
<a class="btn btn-outline-secondary" href="/admin/all-users/0">Add User</a>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<table id="user-table" class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Email</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
</table>
|
||||
{{ end }}
|
||||
{{ define "js" }}
|
||||
<script>let tbody = document.getElementById("user-table").getElementByTagName("tbody")[0]</script>
|
||||
{{ end }}
|
@ -70,6 +70,12 @@
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="/admin/all-users">All Users</a>
|
||||
</li>
|
||||
<li>
|
||||
<hr class="dropdown-divider">
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item" href="/logout">Logout</a>
|
||||
</li>
|
||||
|
11
cmd/web/templates/one-user.page.gohtml
Normal file
11
cmd/web/templates/one-user.page.gohtml
Normal file
@ -0,0 +1,11 @@
|
||||
{{ template "base". }}
|
||||
{{ define "title" }}
|
||||
Admin User
|
||||
{{ end }}
|
||||
{{ define "content" }}
|
||||
<h2 class="mt-5">Admin user</h2>
|
||||
<hr>
|
||||
{{ end }}
|
||||
{{ define "js" }}
|
||||
{{ end }}
|
||||
|
@ -36,8 +36,8 @@ export function showTable(api, ps, cp) {
|
||||
|
||||
newCell.innerHTML = `<a href="#!">Order ${i.id}</a>`;
|
||||
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}`;
|
||||
|
@ -34,8 +34,8 @@ export function showTable(api, ps, cp) {
|
||||
|
||||
newCell.innerHTML = `<a href="#!">Order ${i.id}</a>`;
|
||||
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}`;
|
||||
|
Loading…
Reference in New Issue
Block a user