Now have a simple table list index and a table view, but the templates aren't good enough to easily use the Go reflect data. Will find one tomorrow that's better.
This commit is contained in:
parent
d481c260c5
commit
fa7f886a59
3 changed files with 55 additions and 2 deletions
|
@ -1,13 +1,37 @@
|
|||
package admin
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"zedshaw.games/webapp/data"
|
||||
"zedshaw.games/webapp/api"
|
||||
)
|
||||
|
||||
func GetPageIndex(c *fiber.Ctx) error {
|
||||
return c.Render("admin/index", fiber.Map{})
|
||||
var tables []string
|
||||
|
||||
for k := range maps.Keys(data.Models()) {
|
||||
tables = append(tables, k)
|
||||
}
|
||||
|
||||
return c.Render("admin/index", fiber.Map{"Tables": tables})
|
||||
}
|
||||
|
||||
func GetPageTableIndex(c *fiber.Ctx) error {
|
||||
table := c.Params("table")
|
||||
if table == "" { return c.Redirect("/admin/") }
|
||||
|
||||
fmt.Println("table: ", table)
|
||||
type_is := data.Models()[table]
|
||||
|
||||
result, err := SelectTable(table, type_is, 20, 0);
|
||||
if err != nil { return api.IfErrNil(err, c) }
|
||||
|
||||
return c.Render("admin/table/index", fiber.Map{"Table": result})
|
||||
}
|
||||
|
||||
func Setup(app *fiber.App) {
|
||||
app.Get("/admin/", GetPageIndex);
|
||||
app.Get("/admin/table/:table/", GetPageTableIndex);
|
||||
}
|
||||
|
|
|
@ -1 +1,13 @@
|
|||
<h1>Admin!</h1>
|
||||
<blockstart>
|
||||
|
||||
<h1>Admin Tables</h1>
|
||||
|
||||
<block>
|
||||
{{range $index, $element := .Tables}}
|
||||
<ul>
|
||||
<li><a href="/admin/table/{{ $element }}/">{{ $element }}</a></li>
|
||||
</ul>
|
||||
{{ end }}
|
||||
</block>
|
||||
|
||||
</blockstart>
|
||||
|
|
17
views/admin/table/index.html
Normal file
17
views/admin/table/index.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
<blockstart>
|
||||
|
||||
<h1>{{ .TableName }} </h1>
|
||||
|
||||
<block>
|
||||
<table>
|
||||
<tr><th>ID</th></tr>
|
||||
|
||||
{{ range $index, $row := .Table }}
|
||||
<tr>
|
||||
<td>{{ $row }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
</block>
|
||||
|
||||
</blockstart>
|
Loading…
Add table
Add a link
Reference in a new issue