This gets almost everything done, including Paging, but not search.
This commit is contained in:
parent
da183c453c
commit
51b18823ae
7 changed files with 64 additions and 65 deletions
|
@ -112,6 +112,7 @@ func DeleteApi(c *fiber.Ctx) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(app *fiber.App) {
|
func Setup(app *fiber.App) {
|
||||||
|
app.Get("/admin/table/", Page("admin/table/index"))
|
||||||
app.Get("/api/admin/table/", GetApiTableIndex)
|
app.Get("/api/admin/table/", GetApiTableIndex)
|
||||||
|
|
||||||
app.Get("/api/admin/table/:table/", GetApiSelectAll)
|
app.Get("/api/admin/table/:table/", GetApiSelectAll)
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
<script>
|
|
||||||
let Rows = new GetJson("/api/admin/table/")
|
|
||||||
console.log("Rows", Rows)
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<blockstart>
|
|
||||||
<h1>Admin Rows</h1>
|
|
||||||
|
|
||||||
<block x-data="Rows">
|
|
||||||
<ul>
|
|
||||||
<template x-for="item in theData">
|
|
||||||
<li><a x-bind:href="'/admin/table/' + item + '/'">
|
|
||||||
<span x-text="item"></span>
|
|
||||||
</a></li>
|
|
||||||
</template>
|
|
||||||
</ul>
|
|
||||||
</block>
|
|
||||||
|
|
||||||
</blockstart>
|
|
|
@ -1,20 +1,46 @@
|
||||||
class GetJson {
|
class PaginateTable {
|
||||||
constructor(url) {
|
constructor(url) {
|
||||||
this.url = url;
|
this.page = 0;
|
||||||
this.items = [];
|
this.items = [];
|
||||||
this.item = undefined;
|
this.url = url;
|
||||||
|
this.headers = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
async theData() {
|
async contents() {
|
||||||
const resp = await fetch(this.url);
|
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");
|
console.assert(resp.status == 200, "failed to get it");
|
||||||
|
|
||||||
this.items = await resp.json();
|
this.items = await resp.json();
|
||||||
|
|
||||||
|
this.headers = Object.keys(this.items[0]);
|
||||||
|
|
||||||
return this.items;
|
return this.items;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async oneThing() {
|
class GetJson {
|
||||||
this.item = await this.theData();
|
constructor(url) {
|
||||||
console.log("ITEMS", this.items);
|
this.item;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
<script>
|
<script>
|
||||||
let page = 0;
|
let thePage = new PaginateTable("/api/admin/table/{{ .Table }}/");
|
||||||
let Tables = new GetJson(`/api/admin/table/{{ .Table }}/?page=${page}`);
|
|
||||||
|
|
||||||
const newPage = (new_page_num) => {
|
|
||||||
console.log("the function");
|
|
||||||
page = new_page_num;
|
|
||||||
new GetJson(`/api/admin/table/{{ .Table }}/?page=${page}`);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<blockstart>
|
<blockstart>
|
||||||
<h1><a href="/admin/table/">«</a> Admin {{ .Table }}</h1>
|
<h1><a href="/admin/table/">«</a> Admin {{ .Table }}</h1>
|
||||||
|
|
||||||
<block x-data="Tables" x-effect="newPage(page)">
|
<block x-data="thePage">
|
||||||
<block class="horizontal">
|
<block class="horizontal">
|
||||||
<button type="button"><a href="/admin/new/table/{{ .Table }}/">New</a></button>
|
<button type="button"><a href="/admin/new/table/{{ .Table }}/">New</a></button>
|
||||||
<button type="button" @click="page -= 1">Prev</button>
|
<button type="button" @click="page -= 1">Prev</button>
|
||||||
|
@ -21,7 +14,13 @@
|
||||||
<button type="button">Search</button>
|
<button type="button">Search</button>
|
||||||
</block>
|
</block>
|
||||||
<table>
|
<table>
|
||||||
<template x-for="item in theData">
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<template x-for="header in headers">
|
||||||
|
<th x-text="header"></th>
|
||||||
|
</template>
|
||||||
|
</tr>
|
||||||
|
<template x-for="item in contents">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<a x-bind:href="'/admin/table/{{ .Table }}/' + item.id + '/'">
|
<a x-bind:href="'/admin/table/{{ .Table }}/' + item.id + '/'">
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
|
<script>
|
||||||
|
let Data = new PaginateTable("/api/admin/table/")
|
||||||
|
</script>
|
||||||
|
|
||||||
<blockstart>
|
<blockstart>
|
||||||
|
<h1>Admin Rows</h1>
|
||||||
|
|
||||||
<h1>{{ .TableName }} </h1>
|
<block x-data="Data">
|
||||||
|
<ul>
|
||||||
<block>
|
<template x-for="item in contents">
|
||||||
<table>
|
<li>
|
||||||
<tr><th>ID</th></tr>
|
<a x-bind:href="`/admin/table/${item}`">
|
||||||
|
<span x-text="item"></span>
|
||||||
{{ range $index, $row := .Table }}
|
</a>
|
||||||
<tr>
|
</li>
|
||||||
<td>{{ $row }}</td>
|
</template>
|
||||||
</tr>
|
</ul>
|
||||||
{{ end }}
|
|
||||||
</table>
|
|
||||||
</block>
|
</block>
|
||||||
|
|
||||||
</blockstart>
|
</blockstart>
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<blockstart>
|
<blockstart>
|
||||||
<h1>Admin Tables</h1>
|
<h1><a href="/admin/table/{{ .Table }}/">«</a>Admin {{ .Table }}</h1>
|
||||||
|
|
||||||
<block x-init="item = await Data.oneThing()" x-data="{item: {}}">
|
<block x-data="Data">
|
||||||
<form method="POST" action="/api/admin/new/table/{{ .Table }}/">
|
<form method="POST" action="/api/admin/new/table/{{ .Table }}/">
|
||||||
<card>
|
<card>
|
||||||
<top><h2>{{ .Table }} : New</h2></top>
|
<top><h2>New {{ .Table }}</h2></top>
|
||||||
<middle>
|
<middle>
|
||||||
<template x-for="(value, key) in item">
|
<template x-for="(value, key) in item">
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -1,22 +1,11 @@
|
||||||
<script>
|
<script>
|
||||||
let Data = new GetJson("/api/admin/table/{{ .Table }}/{{ .Id }}/");
|
let Data = new GetJson("/api/admin/table/{{ .Table }}/{{ .Id }}/");
|
||||||
|
|
||||||
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 {
|
|
||||||
console.log("NOOOOO");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<blockstart>
|
<blockstart>
|
||||||
<h1>Admin Tables</h1>
|
<h1><a href="/admin/table/{{ .Table }}/">«</a>Admin {{ .Table }}</h1>
|
||||||
|
|
||||||
<block x-init="item = await Data.oneThing()" x-data="{item: {}}">
|
<block x-data="Data">
|
||||||
<form method="POST" action="/api/admin/table/{{ .Table }}/{{ .Id }}/">
|
<form method="POST" action="/api/admin/table/{{ .Table }}/{{ .Id }}/">
|
||||||
<card>
|
<card>
|
||||||
<top><h1>{{ .Table }} : {{ .Id }}</h1></top>
|
<top><h1>{{ .Table }} : {{ .Id }}</h1></top>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue