diff --git a/admin/handlers.go b/admin/handlers.go index 2eca09f..33a81e8 100644 --- a/admin/handlers.go +++ b/admin/handlers.go @@ -112,6 +112,7 @@ func DeleteApi(c *fiber.Ctx) error { } func Setup(app *fiber.App) { + app.Get("/admin/table/", Page("admin/table/index")) app.Get("/api/admin/table/", GetApiTableIndex) app.Get("/api/admin/table/:table/", GetApiSelectAll) diff --git a/pages/admin/table/index.html b/pages/admin/table/index.html deleted file mode 100644 index 5dc131b..0000000 --- a/pages/admin/table/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - -

Admin Rows

- - - - - -
diff --git a/static/js/code.js b/static/js/code.js index 4649d54..9c2105f 100644 --- a/static/js/code.js +++ b/static/js/code.js @@ -1,20 +1,46 @@ -class GetJson { +class PaginateTable { constructor(url) { - this.url = url; + this.page = 0; this.items = []; - this.item = undefined; + this.url = url; + this.headers = []; } - async theData() { - const resp = await fetch(this.url); + async contents() { + if(this.page < 0) this.page = 0; + + const resp = await fetch(`${this.url}?page=${this.page}`); console.assert(resp.status == 200, "failed to get it"); + this.items = await resp.json(); + + this.headers = Object.keys(this.items[0]); + return this.items; } +} + +class GetJson { + constructor(url) { + this.item; + this.url = url; + } - async oneThing() { - this.item = await this.theData(); - console.log("ITEMS", this.items); + async item() { + const resp = await fetch(`${this.url}`); + console.assert(resp.status == 200, "failed to get it"); + + this.item = await resp.json(); return this.item; } } + +const ConfirmDelete = async (table, obj_id) => { + if(confirm("Are you sure?")) { + await fetch("/api/admin/table/" + table + "/" + obj_id + "/", + { method: "DELETE" }); + window.location = "/admin/table/" + table + "/"; + } else { + return false; + } +} diff --git a/views/admin/table/contents.html b/views/admin/table/contents.html index 9704049..766eb19 100644 --- a/views/admin/table/contents.html +++ b/views/admin/table/contents.html @@ -1,18 +1,11 @@

« Admin {{ .Table }}

- + @@ -21,7 +14,13 @@ -