admin page updates
This commit is contained in:
44
internal/view/pagination/table.templ
Normal file
44
internal/view/pagination/table.templ
Normal file
@@ -0,0 +1,44 @@
|
||||
package pagination
|
||||
|
||||
import "git.haelnorr.com/h/oslstats/internal/db"
|
||||
import "fmt"
|
||||
|
||||
// TableColumn defines a sortable column in a paginated table
|
||||
type TableColumn struct {
|
||||
Field string // database field name for sorting (e.g., "created_at")
|
||||
Label string // display label (e.g., "Timestamp")
|
||||
Sortable bool // whether this column can be sorted
|
||||
}
|
||||
|
||||
// TableHeader renders a table header with sortable columns
|
||||
// Use this inside <thead><tr>...</tr></thead>
|
||||
templ TableHeader(opts db.PageOpts, columns []TableColumn) {
|
||||
for _, col := range columns {
|
||||
if col.Sortable {
|
||||
@sortableHeaderCell(col.Field, col.Label, opts.OrderBy, string(opts.Order))
|
||||
} else {
|
||||
<th class="px-4 py-3 text-left text-sm font-semibold text-text">{ col.Label }</th>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
templ sortableHeaderCell(field string, label string, currentField string, currentOrder string) {
|
||||
{{
|
||||
isActive := currentField == field
|
||||
baseClasses := "px-4 py-3 text-left text-sm font-semibold text-text cursor-pointer select-none hover:text-blue transition-colors"
|
||||
arrow := ""
|
||||
if isActive {
|
||||
if currentOrder == "ASC" {
|
||||
arrow = " ↑"
|
||||
} else {
|
||||
arrow = " ↓"
|
||||
}
|
||||
}
|
||||
}}
|
||||
<th class={ baseClasses } @click={ fmt.Sprintf("sortByColumn('%s')", field) }>
|
||||
{ label }
|
||||
if arrow != "" {
|
||||
<span class="text-blue">{ arrow }</span>
|
||||
}
|
||||
</th>
|
||||
}
|
||||
Reference in New Issue
Block a user