rename database package -> query

This commit is contained in:
2025-03-10 14:50:57 -04:00
parent 78aac7093f
commit 5dc875107b
9 changed files with 114 additions and 73 deletions

View File

@@ -3,7 +3,7 @@ package ui
import (
. "maxwarden/basic"
"maxwarden/database"
"maxwarden/query"
. "maragu.dev/gomponents"
hx "maragu.dev/gomponents-htmx"
@@ -20,7 +20,7 @@ const FORM_PAGINATION_SUFFIX = "_paginationForm"
func BindSearch(elId string, identifier string) Node {
return Group{
FormAttr(elId + FORM_BIND_SUFFIX),
Name(database.SEARCH_URL_KEY_PREFIX + identifier),
Name(query.SEARCH_URL_KEY_PREFIX + identifier),
}
}
@@ -41,7 +41,7 @@ type AutoTableOptions struct {
// THE TABLE
// Note that "aboveTable" node is not swapped with HTMX, but "belowTable" is.
func AutoTable[E any](tableId string, url string, cols []database.ColInfo, f database.Filter, entities []E, aboveTable Node, rowComponent func(E) Node, belowTable Node, opts AutoTableOptions) Node {
func AutoTable[E any](tableId string, url string, cols []query.ColInfo, f query.Filter, entities []E, aboveTable Node, rowComponent func(E) Node, belowTable Node, opts AutoTableOptions) Node {
paginationButton := func(icon string, page int) Node {
return Button(
InlineStyle(`
@@ -58,7 +58,7 @@ func AutoTable[E any](tableId string, url string, cols []database.ColInfo, f dat
}
`),
Icon(icon, 16),
hx.Get(url+database.QueryParamsFromPagenum(page, f)),
hx.Get(url+query.QueryParamsFromPagenum(page, f)),
hx.Swap(CSSID(tableId)),
hx.Target(CSSID(tableId)),
hx.Select(CSSID(tableId)),
@@ -83,9 +83,9 @@ func AutoTable[E any](tableId string, url string, cols []database.ColInfo, f dat
hx.Swap("outerHTML"),
hx.Target(CSSID(tableId)),
hx.Select(CSSID(tableId)),
Input(Type("hidden"), Name(database.ORDER_BY_URL_KEY), Value(f.OrderBy)),
Input(Type("hidden"), Name(database.ORDER_DESC_URL_KEY), Value(ToString(f.OrderDescending))),
Input(Type("hidden"), Name(database.ITEMS_PER_PAGE_URL_KEY), Value(ToString(f.Pagination.MaxItemsPerPage))),
Input(Type("hidden"), Name(query.ORDER_BY_URL_KEY), Value(f.OrderBy)),
Input(Type("hidden"), Name(query.ORDER_DESC_URL_KEY), Value(ToString(f.OrderDescending))),
Input(Type("hidden"), Name(query.ITEMS_PER_PAGE_URL_KEY), Value(ToString(f.Pagination.MaxItemsPerPage))),
),
},
),
@@ -123,9 +123,9 @@ func AutoTable[E any](tableId string, url string, cols []database.ColInfo, f dat
// ---- TABLE HEADER ----
THead(
Tr(
Map(cols, func(col database.ColInfo) Node {
Map(cols, func(col query.ColInfo) Node {
return Th(
If(col.DisplayPosition == database.COL_POS_RIGHT,
If(col.DisplayPosition == query.COL_POS_RIGHT,
InlineStyle("$me { text-align: right; }"),
),
InlineStyle(`
@@ -147,7 +147,7 @@ func AutoTable[E any](tableId string, url string, cols []database.ColInfo, f dat
),
If(col.Sortable,
Group{
hx.Get(url + database.QueryParamsFromOrderBy(col.DbName, !f.OrderDescending && (col.DbName == f.OrderBy), f)),
hx.Get(url + query.QueryParamsFromOrderBy(col.DbName, !f.OrderDescending && (col.DbName == f.OrderBy), f)),
hx.Swap(CSSID(tableId)),
hx.Target(CSSID(tableId)),
hx.Select(CSSID(tableId)),
@@ -175,10 +175,10 @@ func AutoTable[E any](tableId string, url string, cols []database.ColInfo, f dat
font-weight: var(--font-weight-bold);
}
`),
If(col.DisplayPosition == database.COL_POS_LEFT,
If(col.DisplayPosition == query.COL_POS_LEFT,
InlineStyle("$me { flex-direction: row; }"),
),
If(col.DisplayPosition == database.COL_POS_RIGHT,
If(col.DisplayPosition == query.COL_POS_RIGHT,
InlineStyle("$me { flex-direction: row-reverse; }"),
),
Text(col.DisplayName),
@@ -267,11 +267,11 @@ func AutoTable[E any](tableId string, url string, cols []database.ColInfo, f dat
hx.Swap("outerHTML"),
MapMapWithKey(f.Search, func(s string, v string) Node {
return Input(Type("hidden"), Name(database.SEARCH_URL_KEY_PREFIX+s), Value(v))
return Input(Type("hidden"), Name(query.SEARCH_URL_KEY_PREFIX+s), Value(v))
}),
Input(Type("hidden"), Name(database.ORDER_BY_URL_KEY), Value(f.OrderBy)),
Input(Type("hidden"), Name(database.ORDER_DESC_URL_KEY), Value(ToString(f.OrderDescending))),
Input(Type("hidden"), Name(query.ORDER_BY_URL_KEY), Value(f.OrderBy)),
Input(Type("hidden"), Name(query.ORDER_DESC_URL_KEY), Value(ToString(f.OrderDescending))),
Select(
IfElse(opts.Compact,
InlineStyle("$me { padding: $2; }"),
@@ -287,7 +287,7 @@ func AutoTable[E any](tableId string, url string, cols []database.ColInfo, f dat
box-shadow: var(--shadow-sm);
}
`),
Name(database.ITEMS_PER_PAGE_URL_KEY),
Name(query.ITEMS_PER_PAGE_URL_KEY),
Option(If(f.Pagination.MaxItemsPerPage == 5, Selected()), Text("5"), Value("5")),
Option(If(f.Pagination.MaxItemsPerPage == 10, Selected()), Text("10"), Value("10")),
Option(If(f.Pagination.MaxItemsPerPage == 25, Selected()), Text("25"), Value("25")),
@@ -355,17 +355,17 @@ func AutotableSearch(c ...Node) Node {
// for simple datasets because why not. This also gives you the option to "upgrade"
// to the "full" table later on, since you are using the same api
func AutoTableLite[E any](columnNames []string, entities []E, rowComponent func(E) Node, opts AutoTableOptions) Node {
cols := []database.ColInfo{}
cols := []query.ColInfo{}
for _, v := range columnNames {
cols = append(cols, database.ColInfo{DisplayName: v})
cols = append(cols, query.ColInfo{DisplayName: v})
}
return AutoTable(
"",
"",
cols,
database.Filter{},
query.Filter{},
entities,
nil,
rowComponent,