Documentation
¶
Index ¶
- Constants
- func AdminHeaderUI(r *http.Request, homeURL string) hb.TagInterface
- func Breadcrumbs(r *http.Request, pageBreadcrumbs []Breadcrumb) hb.TagInterface
- func BreadcrumbsUI(breadcrumbs []Breadcrumb) hb.TagInterface
- func BrowserBadge(visitor statsstore.VisitorInterface) hb.TagInterface
- func CardUI(title string, body hb.TagInterface) hb.TagInterface
- func ClampPerPage(perPage int) int
- func CountryBadge(ui ControllerOptions, visitor statsstore.VisitorInterface) hb.TagInterface
- func DeviceBadge(visitor statsstore.VisitorInterface) hb.TagInterface
- func ExportCSV(w http.ResponseWriter, filename string, headers []string, rows [][]string) string
- func ExportDropdown(exportURL string) hb.TagInterface
- func ExportFilename(prefix string) string
- func FilterModal(config FilterModalConfig) hb.TagInterface
- func FilterModalButton(modalID string) hb.TagInterface
- func FormatLocation(ui ControllerOptions, visitor statsstore.VisitorInterface) string
- func FormatTimestamp(value string) string
- func FullPathURL(ui ControllerOptions, path string) string
- func HTTPBuildQuery(queryData urlpkg.Values) string
- func InfoLine(label string, value hb.TagInterface) hb.TagInterface
- func InfoMuted(text string) hb.TagInterface
- func InfoText(text string) hb.TagInterface
- func NavCardUI(title string, href string, icon string, description string) hb.TagInterface
- func OptionsButton() hb.TagInterface
- func PaginationSummary(page, pageSize int, totalCount int64, itemLabel string) hb.TagInterface
- func PaginationUI(currentPage int, totalPages int, urlFunc func(page int) string) hb.TagInterface
- func ParseIntWithDefault(value string, defaultValue int) int
- func PathLink(ui ControllerOptions, path string) hb.TagInterface
- func PerPageSelector(r *http.Request, currentPageSize int, ...) hb.TagInterface
- func Query(queryData map[string]string) string
- func QueryParamsWith(r *http.Request, overrides map[string]string) map[string]string
- func QuickRangeButtons(r *http.Request, urlFunc func(params map[string]string) string) hb.TagInterface
- func RangeLabel(value string) string
- func ResolvedCountryName(ui ControllerOptions, code string) string
- func ShortDate(value string) string
- func StatCardUI(title string, value string, icon string, color string) hb.TagInterface
- func StrTruncate(s string, maxLength int) string
- func TimeParse(value string) (time.Time, error)
- func URL(r *http.Request, path string, params map[string]string) string
- func UrlHome(r *http.Request, params ...map[string]string) string
- func UrlPageViewActivity(r *http.Request, params ...map[string]string) string
- func UrlSettings(r *http.Request, params ...map[string]string) string
- func UrlVisitorActivity(r *http.Request, params ...map[string]string) string
- func UrlVisitorPaths(r *http.Request, params ...map[string]string) string
- type Breadcrumb
- type ContextKey
- type ControllerOptions
- type FilterFieldDef
- type FilterModalConfig
- type FilterSelectOption
- type LayoutInterface
Constants ¶
const ( ControllerHome = "home" ControllerVisitorActivity = "visitor-activity" ControllerVisitorPaths = "visitor-paths" ControllerPageViewActivity = "page-view-activity" ControllerSettings = "settings" )
Controller name constants
const ( PathHome = "/admin/home" PathVisitorActivity = "/admin/visitor-activity" PathVisitorPaths = "/admin/visitor-paths" PathPageViewActivity = "/admin/page-view-activity" PathSettings = "/admin/settings" )
Path constants for admin routes
Variables ¶
This section is empty.
Functions ¶
func AdminHeaderUI ¶
func AdminHeaderUI(r *http.Request, homeURL string) hb.TagInterface
AdminHeaderUI creates the admin header navigation
func Breadcrumbs ¶
func Breadcrumbs(r *http.Request, pageBreadcrumbs []Breadcrumb) hb.TagInterface
Breadcrumbs creates a breadcrumb navigation component
func BreadcrumbsUI ¶
func BreadcrumbsUI(breadcrumbs []Breadcrumb) hb.TagInterface
BreadcrumbsUI generates the UI for breadcrumbs
func BrowserBadge ¶ added in v1.5.0
func BrowserBadge(visitor statsstore.VisitorInterface) hb.TagInterface
BrowserBadge renders a badge showing the visitor's browser and version.
func CardUI ¶
func CardUI(title string, body hb.TagInterface) hb.TagInterface
CardUI creates a standard card component
func ClampPerPage ¶ added in v1.5.0
ClampPerPage constrains a per-page value to the 1–100 range.
func CountryBadge ¶ added in v1.5.0
func CountryBadge(ui ControllerOptions, visitor statsstore.VisitorInterface) hb.TagInterface
CountryBadge renders a badge with a CSS flag icon and country name tooltip.
func DeviceBadge ¶ added in v1.5.0
func DeviceBadge(visitor statsstore.VisitorInterface) hb.TagInterface
DeviceBadge renders a contextual badge for the visitor's device type.
func ExportCSV ¶ added in v1.5.0
ExportCSV writes CSV content to the response writer with proper headers and a UTF-8 BOM for Excel/Google Sheets compatibility. It returns the CSV string so callers (which return a string from their Handler) can pass it through.
On error it sets a 500 status code and returns an error message string.
func ExportDropdown ¶ added in v1.5.0
func ExportDropdown(exportURL string) hb.TagInterface
ExportDropdown renders a dropdown with a link to the given export URL.
func ExportFilename ¶ added in v1.5.0
ExportFilename generates a CSV filename with the current UTC date. Example: ExportFilename("visitor-paths") → "visitor-paths-2024-01-15.csv"
func FilterModal ¶ added in v1.10.0
func FilterModal(config FilterModalConfig) hb.TagInterface
FilterModal renders a Bootstrap modal with filter form fields. On "Apply Filters", JavaScript collects non-empty field values, preserves per_page from the current URL, resets to page 1, and navigates. On "Clear Filters", all filter params are removed and the page reloads.
func FilterModalButton ¶ added in v1.10.0
func FilterModalButton(modalID string) hb.TagInterface
FilterModalButton renders a button that opens the filter modal.
func FormatLocation ¶ added in v1.5.0
func FormatLocation(ui ControllerOptions, visitor statsstore.VisitorInterface) string
FormatLocation returns a human-readable location string for a visitor.
func FormatTimestamp ¶ added in v1.5.0
FormatTimestamp parses a timestamp and returns a user-friendly formatted string.
func FullPathURL ¶ added in v1.5.0
func FullPathURL(ui ControllerOptions, path string) string
FullPathURL builds an absolute URL from a website base URL and a path.
func HTTPBuildQuery ¶
HTTPBuildQuery converts URL values to a query string
func InfoLine ¶ added in v1.5.0
func InfoLine(label string, value hb.TagInterface) hb.TagInterface
InfoLine renders a labelled value line with a muted label and bold value.
func InfoMuted ¶ added in v1.5.0
func InfoMuted(text string) hb.TagInterface
InfoMuted renders a muted, italic span — used for placeholder values.
func InfoText ¶ added in v1.5.0
func InfoText(text string) hb.TagInterface
InfoText renders a plain body-text span.
func OptionsButton ¶ added in v1.5.0
func OptionsButton() hb.TagInterface
OptionsButton renders a gear-icon button placeholder used in card headers.
func PaginationSummary ¶ added in v1.5.0
func PaginationSummary(page, pageSize int, totalCount int64, itemLabel string) hb.TagInterface
PaginationSummary renders a "Showing X-Y of Z" summary text.
func PaginationUI ¶
PaginationUI creates a pagination component
func ParseIntWithDefault ¶ added in v1.5.0
ParseIntWithDefault parses a string to int, returning the default on error or non-positive values.
func PathLink ¶ added in v1.5.0
func PathLink(ui ControllerOptions, path string) hb.TagInterface
PathLink renders an anchor tag with an external icon pointing to the full absolute URL for the given path.
func PerPageSelector ¶ added in v1.5.0
func PerPageSelector(r *http.Request, currentPageSize int, urlFunc func(params map[string]string) string) hb.TagInterface
PerPageSelector renders a button group for selecting rows per page. The urlFunc parameter receives the query-params map and should return the fully qualified URL for that per-page value.
func QueryParamsWith ¶ added in v1.5.0
QueryParamsWith takes the current request's query parameters, applies the given overrides (empty values delete the key), and returns a map suitable for passing to URL builder functions.
func QuickRangeButtons ¶ added in v1.5.0
func QuickRangeButtons(r *http.Request, urlFunc func(params map[string]string) string) hb.TagInterface
QuickRangeButtons renders a button group of common time-range filters. The urlFunc parameter receives the query-params map and should return the fully qualified URL for that range.
func RangeLabel ¶ added in v1.5.0
RangeLabel converts a range code to a human-readable label.
func ResolvedCountryName ¶ added in v1.5.0
func ResolvedCountryName(ui ControllerOptions, code string) string
ResolvedCountryName resolves a country code to a human-readable name, falling back to the ISO code or "Unknown".
func StatCardUI ¶
StatCardUI creates a card displaying a single statistic
func StrTruncate ¶
StrTruncate truncates a string to the specified length and adds ellipsis if needed
func TimeParse ¶ added in v1.5.0
TimeParse attempts to parse a timestamp using several common layouts.
func UrlPageViewActivity ¶ added in v0.7.0
func UrlSettings ¶ added in v1.10.0
func UrlVisitorActivity ¶
Types ¶
type Breadcrumb ¶
Breadcrumb represents a navigation breadcrumb
type ContextKey ¶
type ContextKey string
ContextKey is a custom type for context keys to avoid collisions
const ( KeyAdminHomeURL ContextKey = "admin_home_url" KeyEndpoint ContextKey = "endpoint" )
Context keys
type ControllerOptions ¶
type ControllerOptions struct {
Logger *slog.Logger
Store statsstore.StoreInterface
Layout LayoutInterface
HomeURL string
WebsiteUrl string
CountryNameByIso2 func(iso2Code string) (string, error)
}
ControllerOptions contains the options for creating a new admin controller
type FilterFieldDef ¶ added in v1.10.0
type FilterFieldDef struct {
Name string // query param name (e.g. "range", "country")
Label string // display label
Type string // "select" or "text"
Options []FilterSelectOption // only for Type == "select"
Value string // current value (pre-populated)
}
FilterFieldDef defines a single filter field rendered in the filter modal.
type FilterModalConfig ¶ added in v1.10.0
type FilterModalConfig struct {
ModalID string
Title string
Fields []FilterFieldDef
}
FilterModalConfig configures the filter modal.
type FilterSelectOption ¶ added in v1.10.0
FilterSelectOption represents an option in a select dropdown within the filter modal.
func DeviceFilterOptions ¶ added in v1.10.0
func DeviceFilterOptions() []FilterSelectOption
DeviceFilterOptions returns the standard device select options.
func RangeFilterOptions ¶ added in v1.10.0
func RangeFilterOptions() []FilterSelectOption
RangeFilterOptions returns the standard time-range select options.
type LayoutInterface ¶
type LayoutInterface interface {
SetTitle(title string)
SetScriptURLs(scripts []string)
SetScripts(scripts []string)
SetStyleURLs(styles []string)
SetStyles(styles []string)
SetBody(string)
// SetCountryNameByIso2 provides country lookup helpers used by the admin UI.
SetCountryNameByIso2(func(iso2Code string) (string, error))
Render(w http.ResponseWriter, r *http.Request) string
}
LayoutInterface defines the layout methods needed by controllers