shared

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ControllerHome             = "home"
	ControllerVisitorActivity  = "visitor-activity"
	ControllerVisitorPaths     = "visitor-paths"
	ControllerPageViewActivity = "page-view-activity"
)

Controller name constants

View Source
const (
	PathHome             = "/admin/home"
	PathVisitorActivity  = "/admin/visitor-activity"
	PathVisitorPaths     = "/admin/visitor-paths"
	PathPageViewActivity = "/admin/page-view-activity"
)

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(r *http.Request, pageBreadcrumbs []Breadcrumb) hb.TagInterface

Breadcrumbs creates a breadcrumb navigation component

func BreadcrumbsUI(breadcrumbs []Breadcrumb) hb.TagInterface

BreadcrumbsUI generates the UI for breadcrumbs

func CardUI

func CardUI(title string, body hb.TagInterface) hb.TagInterface

CardUI creates a standard card component

func HTTPBuildQuery

func HTTPBuildQuery(queryData urlpkg.Values) string

HTTPBuildQuery converts URL values to a query string

func NavCardUI(title string, href string, icon string, description string) hb.TagInterface

NavCardUI creates a navigation card with icon and description

func PaginationUI

func PaginationUI(currentPage int, totalPages int, urlFunc func(page int) string) hb.TagInterface

PaginationUI creates a pagination component

func Query

func Query(queryData map[string]string) string

Query generates a query string from a map of parameters

func StatCardUI

func StatCardUI(title string, value string, icon string, color string) hb.TagInterface

StatCardUI creates a card displaying a single statistic

func StrTruncate

func StrTruncate(s string, maxLength int) string

StrTruncate truncates a string to the specified length and adds ellipsis if needed

func URL

func URL(r *http.Request, path string, params map[string]string) string

URL generates a URL with the given path and parameters

func UrlHome

func UrlHome(r *http.Request, params ...map[string]string) string

func UrlPageViewActivity added in v0.7.0

func UrlPageViewActivity(r *http.Request, params ...map[string]string) string

func UrlVisitorActivity

func UrlVisitorActivity(r *http.Request, params ...map[string]string) string

func UrlVisitorPaths

func UrlVisitorPaths(r *http.Request, params ...map[string]string) string

Types

type Breadcrumb struct {
	Name string
	URL  string
}

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 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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL