This gets almost everything done, including Paging, but not search.

main
Zed A. Shaw 3 days ago
parent da183c453c
commit 51b18823ae
  1. 1
      admin/handlers.go
  2. 19
      pages/admin/table/index.html
  3. 42
      static/js/code.js
  4. 19
      views/admin/table/contents.html
  5. 27
      views/admin/table/index.html
  6. 6
      views/admin/table/new.html
  7. 15
      views/admin/table/view.html

@ -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;
} }
}
class GetJson {
constructor(url) {
this.item;
this.url = url;
}
async oneThing() { async item() {
this.item = await this.theData(); const resp = await fetch(`${this.url}`);
console.log("ITEMS", this.items); 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/">&laquo;</a> Admin {{ .Table }}</h1> <h1><a href="/admin/table/">&laquo;</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 @@
<blockstart> <script>
let Data = new PaginateTable("/api/admin/table/")
<h1>{{ .TableName }} </h1> </script>
<block> <blockstart>
<table> <h1>Admin Rows</h1>
<tr><th>ID</th></tr>
{{ range $index, $row := .Table }} <block x-data="Data">
<tr> <ul>
<td>{{ $row }}</td> <template x-for="item in contents">
</tr> <li>
{{ end }} <a x-bind:href="`/admin/table/${item}`">
</table> <span x-text="item"></span>
</a>
</li>
</template>
</ul>
</block> </block>
</blockstart> </blockstart>

@ -3,12 +3,12 @@
</script> </script>
<blockstart> <blockstart>
<h1>Admin Tables</h1> <h1><a href="/admin/table/{{ .Table }}/">&laquo;</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 }}/">&laquo;</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…
Cancel
Save