A bit of cleanup before refactoring how modules are laid out.

master
Zed A. Shaw 1 month ago
parent 4b12238b03
commit b65ccc292f
  1. 14
      admin/db.go
  2. 16
      admin/handlers.go
  3. 5
      common/api.go
  4. 2
      go.sum
  5. 124
      static/style.css
  6. 2
      views/admin/table/contents.html
  7. 4
      views/admin/table/new.html

@ -8,9 +8,10 @@ import (
sq "github.com/Masterminds/squirrel"
)
func SearchTable(search string, table string, the_type reflect.Type, limit uint64, page uint64) ([]any, error) {
func SearchTable(search string, table string, limit uint64, page uint64) ([]any, error) {
var results []any
the_type := data.Models()[table]
like := fmt.Sprint("%", search, "%")
builder := sq.Select("*").
@ -28,7 +29,6 @@ func SearchTable(search string, table string, the_type reflect.Type, limit uint6
builder = builder.Where(or_clause)
sql_query, args, err := builder.ToSql()
fmt.Println("-------------- SQL QUERY:", sql_query);
if err != nil { return results, err }
@ -48,8 +48,10 @@ func SearchTable(search string, table string, the_type reflect.Type, limit uint6
return results, rows.Err()
}
func SelectTable(table string, the_type reflect.Type, limit uint64, page uint64) ([]any, error) {
func SelectTable(table string, limit uint64, page uint64) ([]any, error) {
var results []any
the_type := data.Models()[table]
sql_query, args, err := sq.Select("*").Limit(limit).Offset(limit * page).From(table).ToSql()
if err != nil { return results, err }
@ -68,7 +70,9 @@ func SelectTable(table string, the_type reflect.Type, limit uint64, page uint64)
return results, rows.Err()
}
func Get(table string, the_type reflect.Type, id int64) (reflect.Value, error) {
func Get(table string, id int64) (reflect.Value, error) {
the_type := data.Models()[table]
sql_query, args, err := sq.Select("*").From(table).Where(sq.Eq{"id": id}).ToSql()
if err != nil { return reflect.New(nil), err }

@ -29,7 +29,6 @@ func GetApiSelectAll(c *fiber.Ctx) error {
table := c.Params("table")
if table == "" { return c.Redirect("/admin/table/") }
type_is := data.Models()[table]
page := c.QueryInt("page", 0)
if page < 0 { page = 0 }
@ -38,11 +37,11 @@ func GetApiSelectAll(c *fiber.Ctx) error {
var result []any
if search == "" {
result, err = SelectTable(table, type_is, 20, uint64(page));
result, err = SelectTable(table, 20, uint64(page));
if err != nil { return IfErrNil(err, c) }
} else {
// NOTE: need a 404 here when there's no result? or empty list?
result, err = SearchTable(search, table, type_is, 20, uint64(page));
result, err = SearchTable(search, table, 20, uint64(page));
if err != nil { return IfErrNil(err, c) }
}
@ -64,9 +63,7 @@ func GetApiSelectOne(c *fiber.Ctx) error {
id, err := c.ParamsInt("id", -1)
if err != nil || id < 0 { return IfErrNil(err, c) }
type_is := data.Models()[table]
result, err := Get(table, type_is, int64(id))
result, err := Get(table, int64(id))
if err != nil { return IfErrNil(err, c) }
return c.JSON(result.Interface())
@ -160,13 +157,12 @@ func GetPageAdminIndex(c *fiber.Ctx) error {
func Setup(app *fiber.App) {
app.Get("/admin/table/", GetPageAdminIndex)
app.Get("/admin/table/:table/", GetPageSelectAll)
app.Get("/admin/new/table/:table/", GetPageInsert)
app.Get("/admin/table/new/:table/", GetPageInsert)
app.Get("/admin/table/:table/:id/", GetPageSelectOne)
app.Get("/api/admin/table", GetApiTableIndex)
app.Get("/api/admin/table/:table", GetApiSelectAll)
app.Get("/api/admin/new/table/:table", GetApiInsert)
app.Post("/api/admin/new/table/:table", PostApiInsert)
app.Get("/api/admin/table/new/:table", GetApiInsert)
app.Post("/api/admin/table/new/:table", PostApiInsert)
app.Get("/api/admin/table/:table/:id", GetApiSelectOne)
app.Post("/api/admin/table/:table/:id", PostApiUpdate)
app.Delete("/api/admin/table/:table/:id", DeleteApi)

@ -35,7 +35,10 @@ func ReceivePost[T any](c *fiber.Ctx) (*T, error) {
if err := validate.Struct(result); err != nil {
validationErrors := err.(validator.ValidationErrors)
log.Println(validationErrors)
for _, validerr := range validationErrors {
log.Println(validerr.Field(), validerr.Error())
}
return result, err
}

@ -119,7 +119,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
lcthw.dev/go/ozai v0.1.0 h1:LNuLMZV4m+ciHRjf1atcunR/63Jguvz3puEzD5vmFec=
lcthw.dev/go/ozai v0.1.0/go.mod h1:AwxRrUAb/KtUzSWgKmhv/eBg6ZjJ4tVZ9YA/DlKqtWs=
lcthw.dev/go/ssgod v0.2.1 h1:1eLbB5QofwIEJPZsvVSIKuzhQzJsLEZ+cjfXwWQ8pEI=
lcthw.dev/go/ssgod v0.2.1/go.mod h1:fCe4J/00a3T4pURfpUp6LZlkUeh5eHDpjApvy6HHiPk=
lcthw.dev/go/ssgod v0.2.2 h1:lvzhxOXDka9iejIQj7Db7ePjruBqYvqe7A5zzxsdank=
lcthw.dev/go/ssgod v0.2.2/go.mod h1:fCe4J/00a3T4pURfpUp6LZlkUeh5eHDpjApvy6HHiPk=

@ -1,4 +1,4 @@
/*! tailwindcss v4.1.11 | MIT License | https://tailwindcss.com */
/*! tailwindcss v4.1.12 | MIT License | https://tailwindcss.com */
@layer properties;
@layer theme, base, components, utilities;
@layer theme {
@ -60,6 +60,7 @@
--radius-md: 0.375rem;
--radius-lg: 0.5rem;
--radius-xl: 0.75rem;
--ease-out: cubic-bezier(0, 0, 0.2, 1);
--aspect-video: 16 / 9;
--default-transition-duration: 150ms;
--default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
@ -199,6 +200,9 @@
::-webkit-datetime-edit, ::-webkit-datetime-edit-year-field, ::-webkit-datetime-edit-month-field, ::-webkit-datetime-edit-day-field, ::-webkit-datetime-edit-hour-field, ::-webkit-datetime-edit-minute-field, ::-webkit-datetime-edit-second-field, ::-webkit-datetime-edit-millisecond-field, ::-webkit-datetime-edit-meridiem-field {
padding-block: 0;
}
::-webkit-calendar-picker-indicator {
line-height: 1;
}
:-moz-ui-invalid {
box-shadow: none;
}
@ -225,9 +229,21 @@
left: calc(var(--spacing) * 0);
width: 100%;
}
.absolute {
position: absolute;
}
.fixed {
position: fixed;
}
.relative {
position: relative;
}
.static {
position: static;
}
.sticky {
position: sticky;
}
.top-3 {
top: calc(var(--spacing) * 3);
}
@ -240,6 +256,24 @@
.left-40 {
left: calc(var(--spacing) * 40);
}
.container {
width: 100%;
@media (width >= 40rem) {
max-width: 40rem;
}
@media (width >= 48rem) {
max-width: 48rem;
}
@media (width >= 64rem) {
max-width: 64rem;
}
@media (width >= 80rem) {
max-width: 80rem;
}
@media (width >= 96rem) {
max-width: 96rem;
}
}
.block {
display: block;
}
@ -252,6 +286,9 @@
.grid {
display: grid;
}
.hidden {
display: none;
}
.inline {
display: inline;
}
@ -306,6 +343,9 @@
.transform {
transform: var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,);
}
.resize {
resize: both;
}
.grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
@ -391,6 +431,10 @@
}
}
}
.border {
border-style: var(--tw-border-style);
border-width: 1px;
}
.border-1 {
border-style: var(--tw-border-style);
border-width: 1px;
@ -555,11 +599,18 @@
--tw-shadow: 0 10px 15px -3px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 4px 6px -4px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
}
.filter {
filter: var(--tw-blur,) var(--tw-brightness,) var(--tw-contrast,) var(--tw-grayscale,) var(--tw-hue-rotate,) var(--tw-invert,) var(--tw-saturate,) var(--tw-sepia,) var(--tw-drop-shadow,);
}
.transition {
transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter, display, visibility, content-visibility, overlay, pointer-events;
transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));
transition-duration: var(--tw-duration, var(--default-transition-duration));
}
.ease-out {
--tw-ease: var(--ease-out);
transition-timing-function: var(--ease-out);
}
.\*\:text-xl {
:is(& > *) {
font-size: var(--text-xl);
@ -1110,6 +1161,63 @@ table {
inherits: false;
initial-value: 0 0 #0000;
}
@property --tw-blur {
syntax: "*";
inherits: false;
}
@property --tw-brightness {
syntax: "*";
inherits: false;
}
@property --tw-contrast {
syntax: "*";
inherits: false;
}
@property --tw-grayscale {
syntax: "*";
inherits: false;
}
@property --tw-hue-rotate {
syntax: "*";
inherits: false;
}
@property --tw-invert {
syntax: "*";
inherits: false;
}
@property --tw-opacity {
syntax: "*";
inherits: false;
}
@property --tw-saturate {
syntax: "*";
inherits: false;
}
@property --tw-sepia {
syntax: "*";
inherits: false;
}
@property --tw-drop-shadow {
syntax: "*";
inherits: false;
}
@property --tw-drop-shadow-color {
syntax: "*";
inherits: false;
}
@property --tw-drop-shadow-alpha {
syntax: "<percentage>";
inherits: false;
initial-value: 100%;
}
@property --tw-drop-shadow-size {
syntax: "*";
inherits: false;
}
@property --tw-ease {
syntax: "*";
inherits: false;
}
@property --tw-outline-style {
syntax: "*";
inherits: false;
@ -1139,6 +1247,20 @@ table {
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-offset-shadow: 0 0 #0000;
--tw-blur: initial;
--tw-brightness: initial;
--tw-contrast: initial;
--tw-grayscale: initial;
--tw-hue-rotate: initial;
--tw-invert: initial;
--tw-opacity: initial;
--tw-saturate: initial;
--tw-sepia: initial;
--tw-drop-shadow: initial;
--tw-drop-shadow-color: initial;
--tw-drop-shadow-alpha: 100%;
--tw-drop-shadow-size: initial;
--tw-ease: initial;
--tw-outline-style: solid;
}
}

@ -6,7 +6,7 @@
<block x-data="thePage">
<bar>
<button type="button"><a href="/admin/new/table/{{ .Table }}/">New</a></button>
<button type="button"><a href="/admin/table/new/{{ .Table }}/">New</a></button>
<button type="button" @click="page -= 1">Prev</button>
<button type="button" @click="page += 1">Next</button>
<input type="text" x-model.debounce="search_query" name="search" size="40" placeholder="Search" />

@ -1,9 +1,9 @@
<h1><a href="/admin/table/{{ .Table }}/">&laquo;</a>Admin {{ .Table }}</h1>
<block x-data="{item: {}}"
x-init="item = await GetJson('/api/admin/new/table/{{ .Table }}')">
x-init="item = await GetJson('/api/admin/table/new/{{ .Table }}')">
<form method="POST" action="/api/admin/new/table/{{ .Table }}">
<form method="POST" action="/api/admin/table/new/{{ .Table }}">
<card>
<top><h2>New {{ .Table }}</h2></top>

Loading…
Cancel
Save