refactor(systemviews): render views with templ
- commit
- a743a66cbcbf9a47d8ec1c076e2c17b6fd8d8f54
- author
- brice · · 2026-04-24 02:48 UTC
- parent
- 40aec41
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
14 files · +3255 -429
M Makefile +7 -2
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | # Makefile for dumber (Clean Architecture - puregotk) | |
| 2 | 2 | ||
| 3 | - | .PHONY: build build-systemviews build-quick install-local test lint clean install-tools dev generate help init man flatpak-deps flatpak-build flatpak-install flatpak-run flatpak-clean stress-omnibox-callbacks verify-purego check | |
| 3 | + | .PHONY: build build-systemviews generate-systemviews build-quick install-local test lint clean install-tools dev generate help init man flatpak-deps flatpak-build flatpak-install flatpak-run flatpak-clean stress-omnibox-callbacks verify-purego check | |
| 4 | 4 | ||
| 5 | 5 | # Load local overrides from .env.local if present (Makefile syntax) | |
| 6 | 6 | ifneq (,$(wildcard .env.local)) | |
| @@ -46,7 +46,12 @@ build: build-systemviews ## Build the application (pure Go, no CGO) | |||
| 46 | 46 | @rm -f $(DIST_DIR)/cef-helper | |
| 47 | 47 | @echo "Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)" | |
| 48 | 48 | ||
| 49 | - | build-systemviews: ## Build the WASM systemviews runtime | |
| 49 | + | generate-systemviews: ## Generate Go code from systemviews templ components | |
| 50 | + | @echo "Generating systemviews templ components..." | |
| 51 | + | go tool templ generate -path internal/ui/systemviews -include-version=false | |
| 52 | + | @echo "Systemviews templ generation complete" | |
| 53 | + | ||
| 54 | + | build-systemviews: generate-systemviews ## Build the WASM systemviews runtime | |
| 50 | 55 | @echo "Building systemviews wasm assets..." | |
| 51 | 56 | @mkdir -p assets/systemviews | |
| 52 | 57 | @cp "$$(go env GOROOT)/lib/wasm/wasm_exec.js" assets/systemviews/wasm_exec.js | |
| @@ -1,6 +1,6 @@ | |||||
| 1 | # Makefile for dumber (Clean Architecture - puregotk) | 1 | # Makefile for dumber (Clean Architecture - puregotk) | ||
| 2 | 2 | ||||
| 3 | - | .PHONY: build build-systemviews build-quick install-local test lint clean install-tools dev generate help init man flatpak-deps flatpak-build flatpak-install flatpak-run flatpak-clean stress-omnibox-callbacks verify-purego check | 3 | + | .PHONY: build build-systemviews generate-systemviews build-quick install-local test lint clean install-tools dev generate help init man flatpak-deps flatpak-build flatpak-install flatpak-run flatpak-clean stress-omnibox-callbacks verify-purego check |
| 4 | 4 | ||||
| 5 | # Load local overrides from .env.local if present (Makefile syntax) | 5 | # Load local overrides from .env.local if present (Makefile syntax) | ||
| 6 | ifneq (,$(wildcard .env.local)) | 6 | ifneq (,$(wildcard .env.local)) | ||
| @@ -46,7 +46,12 @@ build: build-systemviews ## Build the application (pure Go, no CGO) | |||||
| 46 | @rm -f $(DIST_DIR)/cef-helper | 46 | @rm -f $(DIST_DIR)/cef-helper | ||
| 47 | @echo "Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)" | 47 | @echo "Build successful! Binary: $(DIST_DIR)/$(BINARY_NAME)" | ||
| 48 | 48 | ||||
| 49 | - | build-systemviews: ## Build the WASM systemviews runtime | 49 | + | generate-systemviews: ## Generate Go code from systemviews templ components |
| 50 | + | @echo "Generating systemviews templ components..." | |||
| 51 | + | go tool templ generate -path internal/ui/systemviews -include-version=false | |||
| 52 | + | @echo "Systemviews templ generation complete" | |||
| 53 | + | ||||
| 54 | + | build-systemviews: generate-systemviews ## Build the WASM systemviews runtime | |||
| 50 | @echo "Building systemviews wasm assets..." | 55 | @echo "Building systemviews wasm assets..." | ||
| 51 | @mkdir -p assets/systemviews | 56 | @mkdir -p assets/systemviews | ||
| 52 | @cp "$$(go env GOROOT)/lib/wasm/wasm_exec.js" assets/systemviews/wasm_exec.js | 57 | @cp "$$(go env GOROOT)/lib/wasm/wasm_exec.js" assets/systemviews/wasm_exec.js | ||
M go.mod +12 -0
| @@ -3,6 +3,7 @@ module github.com/bnema/dumber | |||
| 3 | 3 | go 1.26.1 | |
| 4 | 4 | ||
| 5 | 5 | require ( | |
| 6 | + | github.com/a-h/templ v0.3.1001 | |
| 6 | 7 | github.com/bnema/purego v0.11.0-bnema.2 | |
| 7 | 8 | github.com/bnema/purego-cef v0.10.2 | |
| 8 | 9 | github.com/bnema/purego-ffmpeg v0.3.1 | |
| @@ -27,18 +28,23 @@ require ( | |||
| 27 | 28 | ) | |
| 28 | 29 | ||
| 29 | 30 | require ( | |
| 31 | + | github.com/a-h/parse v0.0.0-20250122154542-74294addb73e // indirect | |
| 32 | + | github.com/andybalholm/brotli v1.2.0 // indirect | |
| 30 | 33 | github.com/atotto/clipboard v0.1.4 // indirect | |
| 31 | 34 | github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | |
| 35 | + | github.com/cenkalti/backoff/v4 v4.3.0 // indirect | |
| 32 | 36 | github.com/charmbracelet/colorprofile v0.4.1 // indirect | |
| 33 | 37 | github.com/charmbracelet/x/ansi v0.11.6 // indirect | |
| 34 | 38 | github.com/charmbracelet/x/cellbuf v0.0.15 // indirect | |
| 35 | 39 | github.com/charmbracelet/x/term v0.2.2 // indirect | |
| 40 | + | github.com/cli/browser v1.3.0 // indirect | |
| 36 | 41 | github.com/clipperhouse/displaywidth v0.9.0 // indirect | |
| 37 | 42 | github.com/clipperhouse/stringish v0.1.1 // indirect | |
| 38 | 43 | github.com/clipperhouse/uax29/v2 v2.5.0 // indirect | |
| 39 | 44 | github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect | |
| 40 | 45 | github.com/davecgh/go-spew v1.1.1 // indirect | |
| 41 | 46 | github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect | |
| 47 | + | github.com/fatih/color v1.16.0 // indirect | |
| 42 | 48 | github.com/go-viper/mapstructure/v2 v2.5.0 // indirect | |
| 43 | 49 | github.com/inconshreveable/mousetrap v1.1.0 // indirect | |
| 44 | 50 | github.com/lucasb-eyer/go-colorful v1.3.0 // indirect | |
| @@ -50,6 +56,7 @@ require ( | |||
| 50 | 56 | github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect | |
| 51 | 57 | github.com/muesli/cancelreader v0.2.2 // indirect | |
| 52 | 58 | github.com/muesli/termenv v0.16.0 // indirect | |
| 59 | + | github.com/natefinch/atomic v1.0.1 // indirect | |
| 53 | 60 | github.com/pmezard/go-difflib v1.0.0 // indirect | |
| 54 | 61 | github.com/rivo/uniseg v0.4.7 // indirect | |
| 55 | 62 | github.com/russross/blackfriday/v2 v2.1.0 // indirect | |
| @@ -64,8 +71,13 @@ require ( | |||
| 64 | 71 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect | |
| 65 | 72 | go.uber.org/multierr v1.11.0 // indirect | |
| 66 | 73 | go.yaml.in/yaml/v3 v3.0.4 // indirect | |
| 74 | + | golang.org/x/mod v0.34.0 // indirect | |
| 75 | + | golang.org/x/net v0.52.0 // indirect | |
| 67 | 76 | golang.org/x/sync v0.20.0 // indirect | |
| 68 | 77 | golang.org/x/text v0.36.0 // indirect | |
| 78 | + | golang.org/x/tools v0.43.0 // indirect | |
| 69 | 79 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | |
| 70 | 80 | modernc.org/sqlite v1.47.0 // indirect | |
| 71 | 81 | ) | |
| 82 | + | ||
| 83 | + | tool github.com/a-h/templ/cmd/templ | |
| @@ -3,6 +3,7 @@ module github.com/bnema/dumber | |||||
| 3 | go 1.26.1 | 3 | go 1.26.1 | ||
| 4 | 4 | ||||
| 5 | require ( | 5 | require ( | ||
| 6 | + | github.com/a-h/templ v0.3.1001 | |||
| 6 | github.com/bnema/purego v0.11.0-bnema.2 | 7 | github.com/bnema/purego v0.11.0-bnema.2 | ||
| 7 | github.com/bnema/purego-cef v0.10.2 | 8 | github.com/bnema/purego-cef v0.10.2 | ||
| 8 | github.com/bnema/purego-ffmpeg v0.3.1 | 9 | github.com/bnema/purego-ffmpeg v0.3.1 | ||
| @@ -27,18 +28,23 @@ require ( | |||||
| 27 | ) | 28 | ) | ||
| 28 | 29 | ||||
| 29 | require ( | 30 | require ( | ||
| 31 | + | github.com/a-h/parse v0.0.0-20250122154542-74294addb73e // indirect | |||
| 32 | + | github.com/andybalholm/brotli v1.2.0 // indirect | |||
| 30 | github.com/atotto/clipboard v0.1.4 // indirect | 33 | github.com/atotto/clipboard v0.1.4 // indirect | ||
| 31 | github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | 34 | github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect | ||
| 35 | + | github.com/cenkalti/backoff/v4 v4.3.0 // indirect | |||
| 32 | github.com/charmbracelet/colorprofile v0.4.1 // indirect | 36 | github.com/charmbracelet/colorprofile v0.4.1 // indirect | ||
| 33 | github.com/charmbracelet/x/ansi v0.11.6 // indirect | 37 | github.com/charmbracelet/x/ansi v0.11.6 // indirect | ||
| 34 | github.com/charmbracelet/x/cellbuf v0.0.15 // indirect | 38 | github.com/charmbracelet/x/cellbuf v0.0.15 // indirect | ||
| 35 | github.com/charmbracelet/x/term v0.2.2 // indirect | 39 | github.com/charmbracelet/x/term v0.2.2 // indirect | ||
| 40 | + | github.com/cli/browser v1.3.0 // indirect | |||
| 36 | github.com/clipperhouse/displaywidth v0.9.0 // indirect | 41 | github.com/clipperhouse/displaywidth v0.9.0 // indirect | ||
| 37 | github.com/clipperhouse/stringish v0.1.1 // indirect | 42 | github.com/clipperhouse/stringish v0.1.1 // indirect | ||
| 38 | github.com/clipperhouse/uax29/v2 v2.5.0 // indirect | 43 | github.com/clipperhouse/uax29/v2 v2.5.0 // indirect | ||
| 39 | github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect | 44 | github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect | ||
| 40 | github.com/davecgh/go-spew v1.1.1 // indirect | 45 | github.com/davecgh/go-spew v1.1.1 // indirect | ||
| 41 | github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect | 46 | github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect | ||
| 47 | + | github.com/fatih/color v1.16.0 // indirect | |||
| 42 | github.com/go-viper/mapstructure/v2 v2.5.0 // indirect | 48 | github.com/go-viper/mapstructure/v2 v2.5.0 // indirect | ||
| 43 | github.com/inconshreveable/mousetrap v1.1.0 // indirect | 49 | github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
| 44 | github.com/lucasb-eyer/go-colorful v1.3.0 // indirect | 50 | github.com/lucasb-eyer/go-colorful v1.3.0 // indirect | ||
| @@ -50,6 +56,7 @@ require ( | |||||
| 50 | github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect | 56 | github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect | ||
| 51 | github.com/muesli/cancelreader v0.2.2 // indirect | 57 | github.com/muesli/cancelreader v0.2.2 // indirect | ||
| 52 | github.com/muesli/termenv v0.16.0 // indirect | 58 | github.com/muesli/termenv v0.16.0 // indirect | ||
| 59 | + | github.com/natefinch/atomic v1.0.1 // indirect | |||
| 53 | github.com/pmezard/go-difflib v1.0.0 // indirect | 60 | github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| 54 | github.com/rivo/uniseg v0.4.7 // indirect | 61 | github.com/rivo/uniseg v0.4.7 // indirect | ||
| 55 | github.com/russross/blackfriday/v2 v2.1.0 // indirect | 62 | github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
| @@ -64,8 +71,13 @@ require ( | |||||
| 64 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect | 71 | github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect | ||
| 65 | go.uber.org/multierr v1.11.0 // indirect | 72 | go.uber.org/multierr v1.11.0 // indirect | ||
| 66 | go.yaml.in/yaml/v3 v3.0.4 // indirect | 73 | go.yaml.in/yaml/v3 v3.0.4 // indirect | ||
| 74 | + | golang.org/x/mod v0.34.0 // indirect | |||
| 75 | + | golang.org/x/net v0.52.0 // indirect | |||
| 67 | golang.org/x/sync v0.20.0 // indirect | 76 | golang.org/x/sync v0.20.0 // indirect | ||
| 68 | golang.org/x/text v0.36.0 // indirect | 77 | golang.org/x/text v0.36.0 // indirect | ||
| 78 | + | golang.org/x/tools v0.43.0 // indirect | |||
| 69 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | 79 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | ||
| 70 | modernc.org/sqlite v1.47.0 // indirect | 80 | modernc.org/sqlite v1.47.0 // indirect | ||
| 71 | ) | 81 | ) | ||
| 82 | + | ||||
| 83 | + | tool github.com/a-h/templ/cmd/templ | |||
M go.sum +22 -0 generated file: collapsed
A internal/ui/systemviews/components.templ +77 -0
| @@ -0,0 +1,77 @@ | |||
| 1 | + | package systemviews | |
| 2 | + | ||
| 3 | + | templ appFrameComponent(page renderedPage, theme shellTheme, body templ.Component) { | |
| 4 | + | <div class={ appRootClass(theme) } data-route={ string(page.route) } | |
| 5 | + | if theme.InlineVars != "" { | |
| 6 | + | style={ theme.InlineVars } | |
| 7 | + | } | |
| 8 | + | > | |
| 9 | + | <div class="sv-shell"> | |
| 10 | + | if page.subtitle != "" { | |
| 11 | + | <h1 class="sv-title">{ page.subtitle }</h1> | |
| 12 | + | } | |
| 13 | + | <div class="sv-content"> | |
| 14 | + | @body | |
| 15 | + | </div> | |
| 16 | + | </div> | |
| 17 | + | </div> | |
| 18 | + | } | |
| 19 | + | ||
| 20 | + | templ Section(className string, title string) { | |
| 21 | + | <section class={ sectionClass(className) }> | |
| 22 | + | <h2>{ title }</h2> | |
| 23 | + | { children... } | |
| 24 | + | </section> | |
| 25 | + | } | |
| 26 | + | ||
| 27 | + | templ Meta(text string) { | |
| 28 | + | <p class="sv-meta">{ text }</p> | |
| 29 | + | } | |
| 30 | + | ||
| 31 | + | templ EmptyState(message string) { | |
| 32 | + | <div class="sv-empty"><p>{ message }</p></div> | |
| 33 | + | } | |
| 34 | + | ||
| 35 | + | templ Alert(kind string, message string) { | |
| 36 | + | if message != "" { | |
| 37 | + | <div class={ alertClass(kind) } role={ alertRole(kind) }>{ message }</div> | |
| 38 | + | } | |
| 39 | + | } | |
| 40 | + | ||
| 41 | + | templ List(emptyMessage string) { | |
| 42 | + | <ul class="sv-list"> | |
| 43 | + | { children... } | |
| 44 | + | </ul> | |
| 45 | + | } | |
| 46 | + | ||
| 47 | + | templ ListRow() { | |
| 48 | + | <li class="sv-list-row"> | |
| 49 | + | { children... } | |
| 50 | + | </li> | |
| 51 | + | } | |
| 52 | + | ||
| 53 | + | templ Button(label string, action string, classes string, attrs templ.Attributes, disabled bool) { | |
| 54 | + | <button type="button" class={ buttonClass(classes) } data-sv-action={ action } disabled?={ disabled } { attrs... }>{ label }</button> | |
| 55 | + | } | |
| 56 | + | ||
| 57 | + | templ KeyList(keys []string) { | |
| 58 | + | if len(keys) == 0 { | |
| 59 | + | <span class="sv-key sv-key-empty">Unassigned</span> | |
| 60 | + | } else { | |
| 61 | + | for _, key := range keys { | |
| 62 | + | <span class="sv-key">{ key }</span> | |
| 63 | + | } | |
| 64 | + | } | |
| 65 | + | } | |
| 66 | + | ||
| 67 | + | templ KV(rows []kvPair) { | |
| 68 | + | if len(rows) == 0 { | |
| 69 | + | @EmptyState("No configuration details") | |
| 70 | + | } else { | |
| 71 | + | <dl class="sv-kv"> | |
| 72 | + | for _, row := range rows { | |
| 73 | + | <div class="sv-kv-row"><dt>{ row.Label }</dt><dd>{ row.Value }</dd></div> | |
| 74 | + | } | |
| 75 | + | </dl> | |
| 76 | + | } | |
| 77 | + | } | |
| @@ -0,0 +1,77 @@ | |||||
| 1 | + | package systemviews | |||
| 2 | + | ||||
| 3 | + | templ appFrameComponent(page renderedPage, theme shellTheme, body templ.Component) { | |||
| 4 | + | <div class={ appRootClass(theme) } data-route={ string(page.route) } | |||
| 5 | + | if theme.InlineVars != "" { | |||
| 6 | + | style={ theme.InlineVars } | |||
| 7 | + | } | |||
| 8 | + | > | |||
| 9 | + | <div class="sv-shell"> | |||
| 10 | + | if page.subtitle != "" { | |||
| 11 | + | <h1 class="sv-title">{ page.subtitle }</h1> | |||
| 12 | + | } | |||
| 13 | + | <div class="sv-content"> | |||
| 14 | + | @body | |||
| 15 | + | </div> | |||
| 16 | + | </div> | |||
| 17 | + | </div> | |||
| 18 | + | } | |||
| 19 | + | ||||
| 20 | + | templ Section(className string, title string) { | |||
| 21 | + | <section class={ sectionClass(className) }> | |||
| 22 | + | <h2>{ title }</h2> | |||
| 23 | + | { children... } | |||
| 24 | + | </section> | |||
| 25 | + | } | |||
| 26 | + | ||||
| 27 | + | templ Meta(text string) { | |||
| 28 | + | <p class="sv-meta">{ text }</p> | |||
| 29 | + | } | |||
| 30 | + | ||||
| 31 | + | templ EmptyState(message string) { | |||
| 32 | + | <div class="sv-empty"><p>{ message }</p></div> | |||
| 33 | + | } | |||
| 34 | + | ||||
| 35 | + | templ Alert(kind string, message string) { | |||
| 36 | + | if message != "" { | |||
| 37 | + | <div class={ alertClass(kind) } role={ alertRole(kind) }>{ message }</div> | |||
| 38 | + | } | |||
| 39 | + | } | |||
| 40 | + | ||||
| 41 | + | templ List(emptyMessage string) { | |||
| 42 | + | <ul class="sv-list"> | |||
| 43 | + | { children... } | |||
| 44 | + | </ul> | |||
| 45 | + | } | |||
| 46 | + | ||||
| 47 | + | templ ListRow() { | |||
| 48 | + | <li class="sv-list-row"> | |||
| 49 | + | { children... } | |||
| 50 | + | </li> | |||
| 51 | + | } | |||
| 52 | + | ||||
| 53 | + | templ Button(label string, action string, classes string, attrs templ.Attributes, disabled bool) { | |||
| 54 | + | <button type="button" class={ buttonClass(classes) } data-sv-action={ action } disabled?={ disabled } { attrs... }>{ label }</button> | |||
| 55 | + | } | |||
| 56 | + | ||||
| 57 | + | templ KeyList(keys []string) { | |||
| 58 | + | if len(keys) == 0 { | |||
| 59 | + | <span class="sv-key sv-key-empty">Unassigned</span> | |||
| 60 | + | } else { | |||
| 61 | + | for _, key := range keys { | |||
| 62 | + | <span class="sv-key">{ key }</span> | |||
| 63 | + | } | |||
| 64 | + | } | |||
| 65 | + | } | |||
| 66 | + | ||||
| 67 | + | templ KV(rows []kvPair) { | |||
| 68 | + | if len(rows) == 0 { | |||
| 69 | + | @EmptyState("No configuration details") | |||
| 70 | + | } else { | |||
| 71 | + | <dl class="sv-kv"> | |||
| 72 | + | for _, row := range rows { | |||
| 73 | + | <div class="sv-kv-row"><dt>{ row.Label }</dt><dd>{ row.Value }</dd></div> | |||
| 74 | + | } | |||
| 75 | + | </dl> | |||
| 76 | + | } | |||
| 77 | + | } | |||
A internal/ui/systemviews/components_templ.go +635 -0 generated file: collapsed
A internal/ui/systemviews/favorites.templ +199 -0
| @@ -0,0 +1,199 @@ | |||
| 1 | + | package systemviews | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "fmt" | |
| 5 | + | "github.com/bnema/dumber/internal/domain/entity" | |
| 6 | + | ) | |
| 7 | + | ||
| 8 | + | templ FavoritesView(data favoritesRenderData) { | |
| 9 | + | @Alert("success", data.Notice) | |
| 10 | + | @Alert("error", data.Error) | |
| 11 | + | @Section("sv-favorites-controls", "Manage favorites") { | |
| 12 | + | @FavoritesControls(data) | |
| 13 | + | } | |
| 14 | + | @Section("sv-favorites-list", "Favorites") { | |
| 15 | + | @Meta(favoritesSummary(data)) | |
| 16 | + | if len(data.Favorites) == 0 { | |
| 17 | + | @EmptyState("No favorites") | |
| 18 | + | } else { | |
| 19 | + | <ul class="sv-list"> | |
| 20 | + | for _, favorite := range data.Favorites { | |
| 21 | + | if favorite != nil { | |
| 22 | + | @FavoriteItem(favorite, data.Folders, data.Tags) | |
| 23 | + | } | |
| 24 | + | } | |
| 25 | + | </ul> | |
| 26 | + | } | |
| 27 | + | } | |
| 28 | + | @Section("sv-folders-list", "Folders") { | |
| 29 | + | @Meta(foldersSummary(data)) | |
| 30 | + | @FolderCreateForm() | |
| 31 | + | if len(data.Folders) == 0 { | |
| 32 | + | @EmptyState("No folders") | |
| 33 | + | } else { | |
| 34 | + | <ul class="sv-list"> | |
| 35 | + | for _, folder := range data.Folders { | |
| 36 | + | if folder != nil { | |
| 37 | + | @FolderItem(folder) | |
| 38 | + | } | |
| 39 | + | } | |
| 40 | + | </ul> | |
| 41 | + | } | |
| 42 | + | } | |
| 43 | + | @Section("sv-tags-list", "Tags") { | |
| 44 | + | @Meta(tagsSummary(data)) | |
| 45 | + | @TagCreateForm() | |
| 46 | + | if len(data.Tags) == 0 { | |
| 47 | + | @EmptyState("No tags") | |
| 48 | + | } else { | |
| 49 | + | <ul class="sv-list"> | |
| 50 | + | for _, tag := range data.Tags { | |
| 51 | + | if tag != nil { | |
| 52 | + | @TagItem(tag) | |
| 53 | + | } | |
| 54 | + | } | |
| 55 | + | </ul> | |
| 56 | + | } | |
| 57 | + | } | |
| 58 | + | } | |
| 59 | + | ||
| 60 | + | templ FavoritesControls(data favoritesRenderData) { | |
| 61 | + | <form class="sv-card-form" data-sv-action="favorite.create"> | |
| 62 | + | <label><span>URL</span><input name="url" type="url" placeholder="https://example.com" required/></label> | |
| 63 | + | <label><span>Title</span><input name="title" type="text" placeholder="Optional title"/></label> | |
| 64 | + | @FolderSelect("folder_id", data.Folders, nil, "Folder") | |
| 65 | + | <button class="sv-button" type="submit">Add favorite</button> | |
| 66 | + | </form> | |
| 67 | + | <div class="sv-filter-panel"> | |
| 68 | + | <div class="sv-button-row"> | |
| 69 | + | <span class="sv-meta">Folders</span> | |
| 70 | + | <button type="button" class={ favoriteFilterClass(favoriteAllFilterActive(data)) } data-sv-action="favorite.clearFilters">All</button> | |
| 71 | + | <button type="button" class={ favoriteFilterClass(favoriteFolderFilterActive(data, entity.FolderID(0))) } data-sv-action="favorite.filterFolder" data-folder-id="root">Unfiled</button> | |
| 72 | + | for _, folder := range data.Folders { | |
| 73 | + | if folder != nil { | |
| 74 | + | <button type="button" class={ favoriteFilterClass(favoriteFolderFilterActive(data, folder.ID)) } data-sv-action="favorite.filterFolder" data-folder-id={ fmt.Sprintf("%d", folder.ID) }>{ folderDisplayName(folder) }</button> | |
| 75 | + | } | |
| 76 | + | } | |
| 77 | + | </div> | |
| 78 | + | <div class="sv-button-row"> | |
| 79 | + | <span class="sv-meta">Tags</span> | |
| 80 | + | for _, tag := range data.Tags { | |
| 81 | + | if tag != nil { | |
| 82 | + | <button type="button" class={ favoriteFilterClass(favoriteTagFilterActive(data, tag.ID)) } data-sv-action="favorite.filterTag" data-tag-id={ fmt.Sprintf("%d", tag.ID) }> | |
| 83 | + | <span class="sv-tag-dot" style={ "background:" + tag.Color }></span>{ tag.Name } | |
| 84 | + | </button> | |
| 85 | + | } | |
| 86 | + | } | |
| 87 | + | </div> | |
| 88 | + | </div> | |
| 89 | + | <p class="sv-meta sv-key-hints">Keys: <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>e</kbd> edit title, <kbd>d</kbd> delete focused favorite.</p> | |
| 90 | + | } | |
| 91 | + | ||
| 92 | + | templ FavoriteItem(favorite *entity.Favorite, folders []*entity.Folder, tags []*entity.Tag) { | |
| 93 | + | <li class="sv-list-row"> | |
| 94 | + | <article class="sv-favorite-item" data-sv-favorite-row data-favorite-id={ fmt.Sprintf("%d", favorite.ID) }> | |
| 95 | + | <div class="sv-favorite-header"> | |
| 96 | + | <div> | |
| 97 | + | <a class="sv-link sv-favorite-open" href={ templ.SafeURL(sanitizeHref(favorite.URL)) }>{ favoriteItemLabel(favorite) }</a> | |
| 98 | + | <p class="sv-history-url">{ favorite.URL }</p> | |
| 99 | + | if favoriteMetaText(favorite, folders) != "" { | |
| 100 | + | <p class="sv-meta">{ favoriteMetaText(favorite, folders) }</p> | |
| 101 | + | } | |
| 102 | + | </div> | |
| 103 | + | <div class="sv-history-row-actions"> | |
| 104 | + | <a class="sv-button sv-button-secondary" href={ templ.SafeURL(sanitizeHref(favorite.URL)) }>Open</a> | |
| 105 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="favorite.delete" data-id={ fmt.Sprintf("%d", favorite.ID) } data-sv-confirm="Delete this favorite?">Delete</button> | |
| 106 | + | </div> | |
| 107 | + | </div> | |
| 108 | + | @FavoriteEditForm(favorite, folders) | |
| 109 | + | @FavoriteTagControls(favorite, tags) | |
| 110 | + | </article> | |
| 111 | + | </li> | |
| 112 | + | } | |
| 113 | + | ||
| 114 | + | templ FavoriteEditForm(favorite *entity.Favorite, folders []*entity.Folder) { | |
| 115 | + | <form class="sv-inline-form" data-sv-action="favorite.update"> | |
| 116 | + | <input type="hidden" name="id" value={ fmt.Sprintf("%d", favorite.ID) }/> | |
| 117 | + | <label><span>Title</span><input name="title" type="text" value={ favorite.Title }/></label> | |
| 118 | + | <label><span>Favicon</span><input name="favicon_url" type="url" value={ favorite.FaviconURL }/></label> | |
| 119 | + | @FolderSelect("folder_id", folders, favorite.FolderID, "Folder") | |
| 120 | + | @ShortcutSelect(favorite.ShortcutKey) | |
| 121 | + | <button class="sv-button sv-button-secondary" type="submit">Save</button> | |
| 122 | + | </form> | |
| 123 | + | } | |
| 124 | + | ||
| 125 | + | templ FavoriteTagControls(favorite *entity.Favorite, tags []*entity.Tag) { | |
| 126 | + | if len(tags) > 0 { | |
| 127 | + | <div class="sv-tag-controls"> | |
| 128 | + | <span class="sv-meta">Tags</span> | |
| 129 | + | for _, tag := range tags { | |
| 130 | + | if tag != nil { | |
| 131 | + | <button type="button" class={ favoriteTagButtonClass(favorite, tag) } data-sv-action={ favoriteTagButtonAction(favorite, tag) } data-favorite-id={ fmt.Sprintf("%d", favorite.ID) } data-tag-id={ fmt.Sprintf("%d", tag.ID) }> | |
| 132 | + | <span class="sv-tag-dot" style={ "background:" + tag.Color }></span>{ favoriteTagButtonLabel(favorite, tag) } | |
| 133 | + | </button> | |
| 134 | + | } | |
| 135 | + | } | |
| 136 | + | </div> | |
| 137 | + | } | |
| 138 | + | } | |
| 139 | + | ||
| 140 | + | templ FolderCreateForm() { | |
| 141 | + | <form class="sv-inline-form" data-sv-action="folder.create"> | |
| 142 | + | <label><span>Name</span><input name="name" type="text" required/></label> | |
| 143 | + | <label><span>Icon</span><input name="icon" type="text" placeholder="Optional"/></label> | |
| 144 | + | <button class="sv-button sv-button-secondary" type="submit">Create folder</button> | |
| 145 | + | </form> | |
| 146 | + | } | |
| 147 | + | ||
| 148 | + | templ FolderItem(folder *entity.Folder) { | |
| 149 | + | <li class="sv-list-row"> | |
| 150 | + | <form class="sv-inline-form" data-sv-action="folder.update"> | |
| 151 | + | <input type="hidden" name="id" value={ fmt.Sprintf("%d", folder.ID) }/> | |
| 152 | + | <label><span>Name</span><input name="name" type="text" value={ folder.Name } required/></label> | |
| 153 | + | <label><span>Icon</span><input name="icon" type="text" value={ folder.Icon }/></label> | |
| 154 | + | <button class="sv-button sv-button-secondary" type="submit">Save</button> | |
| 155 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="folder.delete" data-id={ fmt.Sprintf("%d", folder.ID) } data-sv-confirm="Delete this folder? Favorites will move out of it.">Delete</button> | |
| 156 | + | </form> | |
| 157 | + | </li> | |
| 158 | + | } | |
| 159 | + | ||
| 160 | + | templ TagCreateForm() { | |
| 161 | + | <form class="sv-inline-form" data-sv-action="tag.create"> | |
| 162 | + | <label><span>Name</span><input name="name" type="text" required/></label> | |
| 163 | + | <label><span>Color</span><input name="color" type="text" placeholder="#808080"/></label> | |
| 164 | + | <button class="sv-button sv-button-secondary" type="submit">Create tag</button> | |
| 165 | + | </form> | |
| 166 | + | } | |
| 167 | + | ||
| 168 | + | templ TagItem(tag *entity.Tag) { | |
| 169 | + | <li class="sv-list-row"> | |
| 170 | + | <form class="sv-inline-form" data-sv-action="tag.update"> | |
| 171 | + | <input type="hidden" name="id" value={ fmt.Sprintf("%d", tag.ID) }/> | |
| 172 | + | <span class="sv-tag-dot" style={ "background:" + tag.Color }></span> | |
| 173 | + | <label><span>Name</span><input name="name" type="text" value={ tag.Name } required/></label> | |
| 174 | + | <label><span>Color</span><input name="color" type="text" value={ tag.Color }/></label> | |
| 175 | + | <button class="sv-button sv-button-secondary" type="submit">Save</button> | |
| 176 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="tag.delete" data-id={ fmt.Sprintf("%d", tag.ID) } data-sv-confirm="Delete this tag?">Delete</button> | |
| 177 | + | </form> | |
| 178 | + | </li> | |
| 179 | + | } | |
| 180 | + | ||
| 181 | + | templ FolderSelect(name string, folders []*entity.Folder, selected *entity.FolderID, label string) { | |
| 182 | + | <label><span>{ label }</span><select name={ name }> | |
| 183 | + | <option value="">Unfiled</option> | |
| 184 | + | for _, folder := range folders { | |
| 185 | + | if folder != nil { | |
| 186 | + | <option value={ fmt.Sprintf("%d", folder.ID) } selected?={ folderSelected(selected, folder.ID) }>{ folderDisplayName(folder) }</option> | |
| 187 | + | } | |
| 188 | + | } | |
| 189 | + | </select></label> | |
| 190 | + | } | |
| 191 | + | ||
| 192 | + | templ ShortcutSelect(selected *int) { | |
| 193 | + | <label><span>Shortcut</span><select name="shortcut_key"> | |
| 194 | + | <option value="">None</option> | |
| 195 | + | for i := 1; i <= 9; i++ { | |
| 196 | + | <option value={ fmt.Sprintf("%d", i) } selected?={ shortcutSelected(selected, i) }>{ fmt.Sprintf("%d", i) }</option> | |
| 197 | + | } | |
| 198 | + | </select></label> | |
| 199 | + | } | |
| @@ -0,0 +1,199 @@ | |||||
| 1 | + | package systemviews | |||
| 2 | + | ||||
| 3 | + | import ( | |||
| 4 | + | "fmt" | |||
| 5 | + | "github.com/bnema/dumber/internal/domain/entity" | |||
| 6 | + | ) | |||
| 7 | + | ||||
| 8 | + | templ FavoritesView(data favoritesRenderData) { | |||
| 9 | + | @Alert("success", data.Notice) | |||
| 10 | + | @Alert("error", data.Error) | |||
| 11 | + | @Section("sv-favorites-controls", "Manage favorites") { | |||
| 12 | + | @FavoritesControls(data) | |||
| 13 | + | } | |||
| 14 | + | @Section("sv-favorites-list", "Favorites") { | |||
| 15 | + | @Meta(favoritesSummary(data)) | |||
| 16 | + | if len(data.Favorites) == 0 { | |||
| 17 | + | @EmptyState("No favorites") | |||
| 18 | + | } else { | |||
| 19 | + | <ul class="sv-list"> | |||
| 20 | + | for _, favorite := range data.Favorites { | |||
| 21 | + | if favorite != nil { | |||
| 22 | + | @FavoriteItem(favorite, data.Folders, data.Tags) | |||
| 23 | + | } | |||
| 24 | + | } | |||
| 25 | + | </ul> | |||
| 26 | + | } | |||
| 27 | + | } | |||
| 28 | + | @Section("sv-folders-list", "Folders") { | |||
| 29 | + | @Meta(foldersSummary(data)) | |||
| 30 | + | @FolderCreateForm() | |||
| 31 | + | if len(data.Folders) == 0 { | |||
| 32 | + | @EmptyState("No folders") | |||
| 33 | + | } else { | |||
| 34 | + | <ul class="sv-list"> | |||
| 35 | + | for _, folder := range data.Folders { | |||
| 36 | + | if folder != nil { | |||
| 37 | + | @FolderItem(folder) | |||
| 38 | + | } | |||
| 39 | + | } | |||
| 40 | + | </ul> | |||
| 41 | + | } | |||
| 42 | + | } | |||
| 43 | + | @Section("sv-tags-list", "Tags") { | |||
| 44 | + | @Meta(tagsSummary(data)) | |||
| 45 | + | @TagCreateForm() | |||
| 46 | + | if len(data.Tags) == 0 { | |||
| 47 | + | @EmptyState("No tags") | |||
| 48 | + | } else { | |||
| 49 | + | <ul class="sv-list"> | |||
| 50 | + | for _, tag := range data.Tags { | |||
| 51 | + | if tag != nil { | |||
| 52 | + | @TagItem(tag) | |||
| 53 | + | } | |||
| 54 | + | } | |||
| 55 | + | </ul> | |||
| 56 | + | } | |||
| 57 | + | } | |||
| 58 | + | } | |||
| 59 | + | ||||
| 60 | + | templ FavoritesControls(data favoritesRenderData) { | |||
| 61 | + | <form class="sv-card-form" data-sv-action="favorite.create"> | |||
| 62 | + | <label><span>URL</span><input name="url" type="url" placeholder="https://example.com" required/></label> | |||
| 63 | + | <label><span>Title</span><input name="title" type="text" placeholder="Optional title"/></label> | |||
| 64 | + | @FolderSelect("folder_id", data.Folders, nil, "Folder") | |||
| 65 | + | <button class="sv-button" type="submit">Add favorite</button> | |||
| 66 | + | </form> | |||
| 67 | + | <div class="sv-filter-panel"> | |||
| 68 | + | <div class="sv-button-row"> | |||
| 69 | + | <span class="sv-meta">Folders</span> | |||
| 70 | + | <button type="button" class={ favoriteFilterClass(favoriteAllFilterActive(data)) } data-sv-action="favorite.clearFilters">All</button> | |||
| 71 | + | <button type="button" class={ favoriteFilterClass(favoriteFolderFilterActive(data, entity.FolderID(0))) } data-sv-action="favorite.filterFolder" data-folder-id="root">Unfiled</button> | |||
| 72 | + | for _, folder := range data.Folders { | |||
| 73 | + | if folder != nil { | |||
| 74 | + | <button type="button" class={ favoriteFilterClass(favoriteFolderFilterActive(data, folder.ID)) } data-sv-action="favorite.filterFolder" data-folder-id={ fmt.Sprintf("%d", folder.ID) }>{ folderDisplayName(folder) }</button> | |||
| 75 | + | } | |||
| 76 | + | } | |||
| 77 | + | </div> | |||
| 78 | + | <div class="sv-button-row"> | |||
| 79 | + | <span class="sv-meta">Tags</span> | |||
| 80 | + | for _, tag := range data.Tags { | |||
| 81 | + | if tag != nil { | |||
| 82 | + | <button type="button" class={ favoriteFilterClass(favoriteTagFilterActive(data, tag.ID)) } data-sv-action="favorite.filterTag" data-tag-id={ fmt.Sprintf("%d", tag.ID) }> | |||
| 83 | + | <span class="sv-tag-dot" style={ "background:" + tag.Color }></span>{ tag.Name } | |||
| 84 | + | </button> | |||
| 85 | + | } | |||
| 86 | + | } | |||
| 87 | + | </div> | |||
| 88 | + | </div> | |||
| 89 | + | <p class="sv-meta sv-key-hints">Keys: <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>e</kbd> edit title, <kbd>d</kbd> delete focused favorite.</p> | |||
| 90 | + | } | |||
| 91 | + | ||||
| 92 | + | templ FavoriteItem(favorite *entity.Favorite, folders []*entity.Folder, tags []*entity.Tag) { | |||
| 93 | + | <li class="sv-list-row"> | |||
| 94 | + | <article class="sv-favorite-item" data-sv-favorite-row data-favorite-id={ fmt.Sprintf("%d", favorite.ID) }> | |||
| 95 | + | <div class="sv-favorite-header"> | |||
| 96 | + | <div> | |||
| 97 | + | <a class="sv-link sv-favorite-open" href={ templ.SafeURL(sanitizeHref(favorite.URL)) }>{ favoriteItemLabel(favorite) }</a> | |||
| 98 | + | <p class="sv-history-url">{ favorite.URL }</p> | |||
| 99 | + | if favoriteMetaText(favorite, folders) != "" { | |||
| 100 | + | <p class="sv-meta">{ favoriteMetaText(favorite, folders) }</p> | |||
| 101 | + | } | |||
| 102 | + | </div> | |||
| 103 | + | <div class="sv-history-row-actions"> | |||
| 104 | + | <a class="sv-button sv-button-secondary" href={ templ.SafeURL(sanitizeHref(favorite.URL)) }>Open</a> | |||
| 105 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="favorite.delete" data-id={ fmt.Sprintf("%d", favorite.ID) } data-sv-confirm="Delete this favorite?">Delete</button> | |||
| 106 | + | </div> | |||
| 107 | + | </div> | |||
| 108 | + | @FavoriteEditForm(favorite, folders) | |||
| 109 | + | @FavoriteTagControls(favorite, tags) | |||
| 110 | + | </article> | |||
| 111 | + | </li> | |||
| 112 | + | } | |||
| 113 | + | ||||
| 114 | + | templ FavoriteEditForm(favorite *entity.Favorite, folders []*entity.Folder) { | |||
| 115 | + | <form class="sv-inline-form" data-sv-action="favorite.update"> | |||
| 116 | + | <input type="hidden" name="id" value={ fmt.Sprintf("%d", favorite.ID) }/> | |||
| 117 | + | <label><span>Title</span><input name="title" type="text" value={ favorite.Title }/></label> | |||
| 118 | + | <label><span>Favicon</span><input name="favicon_url" type="url" value={ favorite.FaviconURL }/></label> | |||
| 119 | + | @FolderSelect("folder_id", folders, favorite.FolderID, "Folder") | |||
| 120 | + | @ShortcutSelect(favorite.ShortcutKey) | |||
| 121 | + | <button class="sv-button sv-button-secondary" type="submit">Save</button> | |||
| 122 | + | </form> | |||
| 123 | + | } | |||
| 124 | + | ||||
| 125 | + | templ FavoriteTagControls(favorite *entity.Favorite, tags []*entity.Tag) { | |||
| 126 | + | if len(tags) > 0 { | |||
| 127 | + | <div class="sv-tag-controls"> | |||
| 128 | + | <span class="sv-meta">Tags</span> | |||
| 129 | + | for _, tag := range tags { | |||
| 130 | + | if tag != nil { | |||
| 131 | + | <button type="button" class={ favoriteTagButtonClass(favorite, tag) } data-sv-action={ favoriteTagButtonAction(favorite, tag) } data-favorite-id={ fmt.Sprintf("%d", favorite.ID) } data-tag-id={ fmt.Sprintf("%d", tag.ID) }> | |||
| 132 | + | <span class="sv-tag-dot" style={ "background:" + tag.Color }></span>{ favoriteTagButtonLabel(favorite, tag) } | |||
| 133 | + | </button> | |||
| 134 | + | } | |||
| 135 | + | } | |||
| 136 | + | </div> | |||
| 137 | + | } | |||
| 138 | + | } | |||
| 139 | + | ||||
| 140 | + | templ FolderCreateForm() { | |||
| 141 | + | <form class="sv-inline-form" data-sv-action="folder.create"> | |||
| 142 | + | <label><span>Name</span><input name="name" type="text" required/></label> | |||
| 143 | + | <label><span>Icon</span><input name="icon" type="text" placeholder="Optional"/></label> | |||
| 144 | + | <button class="sv-button sv-button-secondary" type="submit">Create folder</button> | |||
| 145 | + | </form> | |||
| 146 | + | } | |||
| 147 | + | ||||
| 148 | + | templ FolderItem(folder *entity.Folder) { | |||
| 149 | + | <li class="sv-list-row"> | |||
| 150 | + | <form class="sv-inline-form" data-sv-action="folder.update"> | |||
| 151 | + | <input type="hidden" name="id" value={ fmt.Sprintf("%d", folder.ID) }/> | |||
| 152 | + | <label><span>Name</span><input name="name" type="text" value={ folder.Name } required/></label> | |||
| 153 | + | <label><span>Icon</span><input name="icon" type="text" value={ folder.Icon }/></label> | |||
| 154 | + | <button class="sv-button sv-button-secondary" type="submit">Save</button> | |||
| 155 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="folder.delete" data-id={ fmt.Sprintf("%d", folder.ID) } data-sv-confirm="Delete this folder? Favorites will move out of it.">Delete</button> | |||
| 156 | + | </form> | |||
| 157 | + | </li> | |||
| 158 | + | } | |||
| 159 | + | ||||
| 160 | + | templ TagCreateForm() { | |||
| 161 | + | <form class="sv-inline-form" data-sv-action="tag.create"> | |||
| 162 | + | <label><span>Name</span><input name="name" type="text" required/></label> | |||
| 163 | + | <label><span>Color</span><input name="color" type="text" placeholder="#808080"/></label> | |||
| 164 | + | <button class="sv-button sv-button-secondary" type="submit">Create tag</button> | |||
| 165 | + | </form> | |||
| 166 | + | } | |||
| 167 | + | ||||
| 168 | + | templ TagItem(tag *entity.Tag) { | |||
| 169 | + | <li class="sv-list-row"> | |||
| 170 | + | <form class="sv-inline-form" data-sv-action="tag.update"> | |||
| 171 | + | <input type="hidden" name="id" value={ fmt.Sprintf("%d", tag.ID) }/> | |||
| 172 | + | <span class="sv-tag-dot" style={ "background:" + tag.Color }></span> | |||
| 173 | + | <label><span>Name</span><input name="name" type="text" value={ tag.Name } required/></label> | |||
| 174 | + | <label><span>Color</span><input name="color" type="text" value={ tag.Color }/></label> | |||
| 175 | + | <button class="sv-button sv-button-secondary" type="submit">Save</button> | |||
| 176 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="tag.delete" data-id={ fmt.Sprintf("%d", tag.ID) } data-sv-confirm="Delete this tag?">Delete</button> | |||
| 177 | + | </form> | |||
| 178 | + | </li> | |||
| 179 | + | } | |||
| 180 | + | ||||
| 181 | + | templ FolderSelect(name string, folders []*entity.Folder, selected *entity.FolderID, label string) { | |||
| 182 | + | <label><span>{ label }</span><select name={ name }> | |||
| 183 | + | <option value="">Unfiled</option> | |||
| 184 | + | for _, folder := range folders { | |||
| 185 | + | if folder != nil { | |||
| 186 | + | <option value={ fmt.Sprintf("%d", folder.ID) } selected?={ folderSelected(selected, folder.ID) }>{ folderDisplayName(folder) }</option> | |||
| 187 | + | } | |||
| 188 | + | } | |||
| 189 | + | </select></label> | |||
| 190 | + | } | |||
| 191 | + | ||||
| 192 | + | templ ShortcutSelect(selected *int) { | |||
| 193 | + | <label><span>Shortcut</span><select name="shortcut_key"> | |||
| 194 | + | <option value="">None</option> | |||
| 195 | + | for i := 1; i <= 9; i++ { | |||
| 196 | + | <option value={ fmt.Sprintf("%d", i) } selected?={ shortcutSelected(selected, i) }>{ fmt.Sprintf("%d", i) }</option> | |||
| 197 | + | } | |||
| 198 | + | </select></label> | |||
| 199 | + | } | |||
A internal/ui/systemviews/favorites_templ.go +1198 -0 generated file: collapsed
M internal/ui/systemviews/favorites_view.go +53 -201
| @@ -2,7 +2,6 @@ package systemviews | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "fmt" | |
| 5 | - | "html" | |
| 6 | 5 | "strings" | |
| 7 | 6 | ||
| 8 | 7 | "github.com/bnema/dumber/internal/domain/entity" | |
| @@ -19,112 +18,56 @@ type favoritesRenderData struct { | |||
| 19 | 18 | } | |
| 20 | 19 | ||
| 21 | 20 | func favoritesHTML(data favoritesRenderData) string { | |
| 22 | - | favoritesSummary := fmt.Sprintf("%d favorites · %d folders · %d tags", len(data.Favorites), len(data.Folders), len(data.Tags)) | |
| 23 | - | foldersSummary := fmt.Sprintf("%d folders", len(data.Folders)) | |
| 24 | - | tagsSummary := fmt.Sprintf("%d tags", len(data.Tags)) | |
| 25 | - | sections := []string{ | |
| 26 | - | favoritesStatusHTML(data), | |
| 27 | - | sectionHTML("sv-favorites-controls", "Manage favorites", favoritesControlsHTML(data)), | |
| 28 | - | sectionHTML("sv-favorites-list", "Favorites", metaHTML(favoritesSummary)+listHTML(favoriteItemsHTML(data.Favorites, data.Folders, data.Tags), "No favorites")), | |
| 29 | - | sectionHTML("sv-folders-list", "Folders", metaHTML(foldersSummary)+folderCreateHTML()+listHTML(folderItemsHTML(data.Folders), "No folders")), | |
| 30 | - | sectionHTML("sv-tags-list", "Tags", metaHTML(tagsSummary)+tagCreateHTML()+listHTML(tagItemsHTML(data.Tags), "No tags")), | |
| 31 | - | } | |
| 32 | - | return strings.Join(sections, "") | |
| 21 | + | return mustRenderComponent(FavoritesView(data)) | |
| 33 | 22 | } | |
| 34 | 23 | ||
| 35 | - | func favoritesStatusHTML(data favoritesRenderData) string { | |
| 36 | - | var out strings.Builder | |
| 37 | - | if strings.TrimSpace(data.Notice) != "" { | |
| 38 | - | out.WriteString(fmt.Sprintf(`<div class="sv-alert sv-alert-success" role="status">%s</div>`, html.EscapeString(data.Notice))) | |
| 39 | - | } | |
| 40 | - | if strings.TrimSpace(data.Error) != "" { | |
| 41 | - | out.WriteString(fmt.Sprintf(`<div class="sv-alert sv-alert-error" role="alert">%s</div>`, html.EscapeString(data.Error))) | |
| 42 | - | } | |
| 43 | - | return out.String() | |
| 24 | + | func favoritesSummary(data favoritesRenderData) string { | |
| 25 | + | return fmt.Sprintf("%d favorites · %d folders · %d tags", len(data.Favorites), len(data.Folders), len(data.Tags)) | |
| 44 | 26 | } | |
| 45 | 27 | ||
| 46 | - | func favoritesControlsHTML(data favoritesRenderData) string { | |
| 47 | - | var out strings.Builder | |
| 48 | - | out.WriteString(`<form class="sv-card-form" data-sv-action="favorite.create">`) | |
| 49 | - | out.WriteString(`<label><span>URL</span><input name="url" type="url" placeholder="https://example.com" required></label>`) | |
| 50 | - | out.WriteString(`<label><span>Title</span><input name="title" type="text" placeholder="Optional title"></label>`) | |
| 51 | - | out.WriteString(folderSelectHTML("folder_id", data.Folders, nil, "Folder")) | |
| 52 | - | out.WriteString(`<button class="sv-button" type="submit">Add favorite</button>`) | |
| 53 | - | out.WriteString(`</form>`) | |
| 54 | - | ||
| 55 | - | out.WriteString(`<div class="sv-filter-panel">`) | |
| 56 | - | out.WriteString(`<div class="sv-button-row"><span class="sv-meta">Folders</span>`) | |
| 57 | - | out.WriteString(favoriteFilterButton("All", "favorite.clearFilters", nil, "", data.FolderFilter == nil && data.TagFilter == nil)) | |
| 58 | - | out.WriteString(favoriteFilterButton("Unfiled", "favorite.filterFolder", map[string]string{"folder_id": "root"}, "", data.FolderFilter != nil && *data.FolderFilter == 0)) | |
| 59 | - | for _, folder := range data.Folders { | |
| 60 | - | if folder == nil { | |
| 61 | - | continue | |
| 62 | - | } | |
| 63 | - | active := data.FolderFilter != nil && *data.FolderFilter == folder.ID | |
| 64 | - | out.WriteString(favoriteFilterButton(folderDisplayName(folder), "favorite.filterFolder", map[string]string{"folder_id": fmt.Sprintf("%d", folder.ID)}, "", active)) | |
| 65 | - | } | |
| 66 | - | out.WriteString(`</div>`) | |
| 28 | + | func foldersSummary(data favoritesRenderData) string { | |
| 29 | + | return fmt.Sprintf("%d folders", len(data.Folders)) | |
| 30 | + | } | |
| 67 | 31 | ||
| 68 | - | out.WriteString(`<div class="sv-button-row"><span class="sv-meta">Tags</span>`) | |
| 69 | - | for _, tag := range data.Tags { | |
| 70 | - | if tag == nil { | |
| 71 | - | continue | |
| 72 | - | } | |
| 73 | - | active := data.TagFilter != nil && *data.TagFilter == tag.ID | |
| 74 | - | out.WriteString(favoriteFilterButton(tag.Name, "favorite.filterTag", map[string]string{"tag_id": fmt.Sprintf("%d", tag.ID)}, tag.Color, active)) | |
| 75 | - | } | |
| 76 | - | out.WriteString(`</div></div>`) | |
| 77 | - | out.WriteString(`<p class="sv-meta sv-key-hints">Keys: <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>e</kbd> edit title, <kbd>d</kbd> delete focused favorite.</p>`) | |
| 78 | - | return out.String() | |
| 32 | + | func tagsSummary(data favoritesRenderData) string { | |
| 33 | + | return fmt.Sprintf("%d tags", len(data.Tags)) | |
| 79 | 34 | } | |
| 80 | 35 | ||
| 81 | - | func favoriteFilterButton(label, action string, data map[string]string, color string, active bool) string { | |
| 36 | + | func favoriteFilterClass(active bool) string { | |
| 82 | 37 | classes := "sv-button sv-button-secondary" | |
| 83 | 38 | if active { | |
| 84 | 39 | classes += " sv-button-active" | |
| 85 | 40 | } | |
| 86 | - | attrs := []string{`type="button"`, fmt.Sprintf(`class="%s"`, html.EscapeString(classes)), fmt.Sprintf(`data-sv-action="%s"`, html.EscapeString(action))} | |
| 87 | - | for key, value := range data { | |
| 88 | - | attrs = append(attrs, fmt.Sprintf(`data-%s="%s"`, html.EscapeString(kebabDataKey(key)), html.EscapeString(value))) | |
| 89 | - | } | |
| 90 | - | style := "" | |
| 91 | - | if strings.TrimSpace(color) != "" { | |
| 92 | - | style = fmt.Sprintf(`<span class="sv-tag-dot" style="background:%s"></span>`, html.EscapeString(color)) | |
| 93 | - | } | |
| 94 | - | return fmt.Sprintf(`<button %s>%s%s</button>`, strings.Join(attrs, " "), style, html.EscapeString(label)) | |
| 41 | + | return classes | |
| 95 | 42 | } | |
| 96 | 43 | ||
| 97 | - | func favoriteItemsHTML(favorites []*entity.Favorite, folders []*entity.Folder, tags []*entity.Tag) string { | |
| 98 | - | var items strings.Builder | |
| 99 | - | for _, favorite := range favorites { | |
| 100 | - | if favorite == nil { | |
| 101 | - | continue | |
| 102 | - | } | |
| 103 | - | items.WriteString(listRowHTML(favoriteItemHTML(favorite, folders, tags))) | |
| 104 | - | } | |
| 105 | - | return items.String() | |
| 44 | + | func favoriteFolderFilterActive(data favoritesRenderData, folderID entity.FolderID) bool { | |
| 45 | + | return data.FolderFilter != nil && *data.FolderFilter == folderID | |
| 46 | + | } | |
| 47 | + | ||
| 48 | + | func favoriteAllFilterActive(data favoritesRenderData) bool { | |
| 49 | + | return data.FolderFilter == nil && data.TagFilter == nil | |
| 50 | + | } | |
| 51 | + | ||
| 52 | + | func favoriteTagFilterActive(data favoritesRenderData, tagID entity.TagID) bool { | |
| 53 | + | return data.TagFilter != nil && *data.TagFilter == tagID | |
| 106 | 54 | } | |
| 107 | 55 | ||
| 108 | - | func favoriteItemHTML(favorite *entity.Favorite, folders []*entity.Folder, tags []*entity.Tag) string { | |
| 56 | + | func favoriteItemLabel(favorite *entity.Favorite) string { | |
| 57 | + | if favorite == nil { | |
| 58 | + | return "" | |
| 59 | + | } | |
| 109 | 60 | label := strings.TrimSpace(favorite.Title) | |
| 110 | 61 | if label == "" { | |
| 111 | 62 | label = favorite.URL | |
| 112 | 63 | } | |
| 113 | - | ||
| 114 | - | return fmt.Sprintf(`<article class="sv-favorite-item" data-sv-favorite-row data-favorite-id="%d"><div class="sv-favorite-header"><div><a class="sv-link sv-favorite-open" href="%s">%s</a><p class="sv-history-url">%s</p>%s</div><div class="sv-history-row-actions"><a class="sv-button sv-button-secondary" href="%s">Open</a><button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="favorite.delete" data-id="%d" data-sv-confirm="Delete this favorite?">Delete</button></div></div>%s%s</article>`, | |
| 115 | - | favorite.ID, | |
| 116 | - | html.EscapeString(sanitizeHref(favorite.URL)), | |
| 117 | - | html.EscapeString(label), | |
| 118 | - | html.EscapeString(favorite.URL), | |
| 119 | - | favoriteMetaHTML(favorite, folders), | |
| 120 | - | html.EscapeString(sanitizeHref(favorite.URL)), | |
| 121 | - | favorite.ID, | |
| 122 | - | favoriteEditHTML(favorite, folders), | |
| 123 | - | favoriteTagControlsHTML(favorite, tags), | |
| 124 | - | ) | |
| 64 | + | return label | |
| 125 | 65 | } | |
| 126 | 66 | ||
| 127 | - | func favoriteMetaHTML(favorite *entity.Favorite, folders []*entity.Folder) string { | |
| 67 | + | func favoriteMetaText(favorite *entity.Favorite, folders []*entity.Folder) string { | |
| 68 | + | if favorite == nil { | |
| 69 | + | return "" | |
| 70 | + | } | |
| 128 | 71 | parts := []string{} | |
| 129 | 72 | if favorite.ShortcutKey != nil { | |
| 130 | 73 | parts = append(parts, fmt.Sprintf("Shortcut %d", *favorite.ShortcutKey)) | |
| @@ -132,131 +75,32 @@ func favoriteMetaHTML(favorite *entity.Favorite, folders []*entity.Folder) strin | |||
| 132 | 75 | if name := folderNameForID(folders, favorite.FolderID); name != "" { | |
| 133 | 76 | parts = append(parts, "Folder "+name) | |
| 134 | 77 | } | |
| 135 | - | if len(parts) == 0 { | |
| 136 | - | return "" | |
| 137 | - | } | |
| 138 | - | return `<p class="sv-meta">` + html.EscapeString(strings.Join(parts, " · ")) + `</p>` | |
| 139 | - | } | |
| 140 | - | ||
| 141 | - | func favoriteEditHTML(favorite *entity.Favorite, folders []*entity.Folder) string { | |
| 142 | - | return fmt.Sprintf(`<form class="sv-inline-form" data-sv-action="favorite.update"><input type="hidden" name="id" value="%d"><label><span>Title</span><input name="title" type="text" value="%s"></label><label><span>Favicon</span><input name="favicon_url" type="url" value="%s"></label>%s%s<button class="sv-button sv-button-secondary" type="submit">Save</button></form>`, | |
| 143 | - | favorite.ID, | |
| 144 | - | html.EscapeString(favorite.Title), | |
| 145 | - | html.EscapeString(favorite.FaviconURL), | |
| 146 | - | folderSelectHTML("folder_id", folders, favorite.FolderID, "Folder"), | |
| 147 | - | shortcutSelectHTML(favorite.ShortcutKey), | |
| 148 | - | ) | |
| 149 | - | } | |
| 150 | - | ||
| 151 | - | func favoriteTagControlsHTML(favorite *entity.Favorite, tags []*entity.Tag) string { | |
| 152 | - | if len(tags) == 0 { | |
| 153 | - | return "" | |
| 154 | - | } | |
| 155 | - | var out strings.Builder | |
| 156 | - | out.WriteString(`<div class="sv-tag-controls"><span class="sv-meta">Tags</span>`) | |
| 157 | - | for _, tag := range tags { | |
| 158 | - | if tag == nil { | |
| 159 | - | continue | |
| 160 | - | } | |
| 161 | - | action := "tag.assign" | |
| 162 | - | label := "+ " + tag.Name | |
| 163 | - | classes := "sv-button sv-button-secondary" | |
| 164 | - | if favorite.HasTag(tag.ID) { | |
| 165 | - | action = "tag.remove" | |
| 166 | - | label = "✓ " + tag.Name | |
| 167 | - | classes += " sv-button-active" | |
| 168 | - | } | |
| 169 | - | out.WriteString(fmt.Sprintf(`<button type="button" class="%s" data-sv-action="%s" data-favorite-id="%d" data-tag-id="%d"><span class="sv-tag-dot" style="background:%s"></span>%s</button>`, | |
| 170 | - | html.EscapeString(classes), | |
| 171 | - | html.EscapeString(action), | |
| 172 | - | favorite.ID, | |
| 173 | - | tag.ID, | |
| 174 | - | html.EscapeString(tag.Color), | |
| 175 | - | html.EscapeString(label), | |
| 176 | - | )) | |
| 177 | - | } | |
| 178 | - | out.WriteString(`</div>`) | |
| 179 | - | return out.String() | |
| 180 | - | } | |
| 181 | - | ||
| 182 | - | func folderCreateHTML() string { | |
| 183 | - | return `<form class="sv-inline-form" data-sv-action="folder.create"><label><span>Name</span><input name="name" type="text" required></label><label><span>Icon</span><input name="icon" type="text" placeholder="Optional"></label><button class="sv-button sv-button-secondary" type="submit">Create folder</button></form>` | |
| 78 | + | return strings.Join(parts, " · ") | |
| 184 | 79 | } | |
| 185 | 80 | ||
| 186 | - | func folderItemsHTML(folders []*entity.Folder) string { | |
| 187 | - | var items strings.Builder | |
| 188 | - | for _, folder := range folders { | |
| 189 | - | if folder == nil { | |
| 190 | - | continue | |
| 191 | - | } | |
| 192 | - | items.WriteString(listRowHTML(folderItemHTML(folder))) | |
| 81 | + | func favoriteTagButtonAction(favorite *entity.Favorite, tag *entity.Tag) string { | |
| 82 | + | if favorite != nil && tag != nil && favorite.HasTag(tag.ID) { | |
| 83 | + | return tagActionRemove | |
| 193 | 84 | } | |
| 194 | - | return items.String() | |
| 195 | - | } | |
| 196 | - | ||
| 197 | - | func folderItemHTML(folder *entity.Folder) string { | |
| 198 | - | return fmt.Sprintf(`<form class="sv-inline-form" data-sv-action="folder.update"><input type="hidden" name="id" value="%d"><label><span>Name</span><input name="name" type="text" value="%s" required></label><label><span>Icon</span><input name="icon" type="text" value="%s"></label><button class="sv-button sv-button-secondary" type="submit">Save</button><button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="folder.delete" data-id="%d" data-sv-confirm="Delete this folder? Favorites will move out of it.">Delete</button></form>`, | |
| 199 | - | folder.ID, | |
| 200 | - | html.EscapeString(folder.Name), | |
| 201 | - | html.EscapeString(folder.Icon), | |
| 202 | - | folder.ID, | |
| 203 | - | ) | |
| 85 | + | return tagActionAssign | |
| 204 | 86 | } | |
| 205 | 87 | ||
| 206 | - | func tagCreateHTML() string { | |
| 207 | - | return `<form class="sv-inline-form" data-sv-action="tag.create"><label><span>Name</span><input name="name" type="text" required></label><label><span>Color</span><input name="color" type="text" placeholder="#808080"></label><button class="sv-button sv-button-secondary" type="submit">Create tag</button></form>` | |
| 208 | - | } | |
| 209 | - | ||
| 210 | - | func tagItemsHTML(tags []*entity.Tag) string { | |
| 211 | - | var items strings.Builder | |
| 212 | - | for _, tag := range tags { | |
| 213 | - | if tag == nil { | |
| 214 | - | continue | |
| 215 | - | } | |
| 216 | - | items.WriteString(listRowHTML(tagItemHTML(tag))) | |
| 88 | + | func favoriteTagButtonLabel(favorite *entity.Favorite, tag *entity.Tag) string { | |
| 89 | + | if tag == nil { | |
| 90 | + | return "" | |
| 217 | 91 | } | |
| 218 | - | return items.String() | |
| 219 | - | } | |
| 220 | - | ||
| 221 | - | func tagItemHTML(tag *entity.Tag) string { | |
| 222 | - | return fmt.Sprintf(`<form class="sv-inline-form" data-sv-action="tag.update"><input type="hidden" name="id" value="%d"><span class="sv-tag-dot" style="background:%s"></span><label><span>Name</span><input name="name" type="text" value="%s" required></label><label><span>Color</span><input name="color" type="text" value="%s"></label><button class="sv-button sv-button-secondary" type="submit">Save</button><button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="tag.delete" data-id="%d" data-sv-confirm="Delete this tag?">Delete</button></form>`, | |
| 223 | - | tag.ID, | |
| 224 | - | html.EscapeString(tag.Color), | |
| 225 | - | html.EscapeString(tag.Name), | |
| 226 | - | html.EscapeString(tag.Color), | |
| 227 | - | tag.ID, | |
| 228 | - | ) | |
| 229 | - | } | |
| 230 | - | ||
| 231 | - | func folderSelectHTML(name string, folders []*entity.Folder, selected *entity.FolderID, label string) string { | |
| 232 | - | var out strings.Builder | |
| 233 | - | out.WriteString(fmt.Sprintf(`<label><span>%s</span><select name="%s"><option value="">Unfiled</option>`, html.EscapeString(label), html.EscapeString(name))) | |
| 234 | - | for _, folder := range folders { | |
| 235 | - | if folder == nil { | |
| 236 | - | continue | |
| 237 | - | } | |
| 238 | - | selectedAttr := "" | |
| 239 | - | if selected != nil && *selected == folder.ID { | |
| 240 | - | selectedAttr = ` selected` | |
| 241 | - | } | |
| 242 | - | out.WriteString(fmt.Sprintf(`<option value="%d"%s>%s</option>`, folder.ID, selectedAttr, html.EscapeString(folderDisplayName(folder)))) | |
| 92 | + | if favorite != nil && favorite.HasTag(tag.ID) { | |
| 93 | + | return "✓ " + tag.Name | |
| 243 | 94 | } | |
| 244 | - | out.WriteString(`</select></label>`) | |
| 245 | - | return out.String() | |
| 95 | + | return "+ " + tag.Name | |
| 246 | 96 | } | |
| 247 | 97 | ||
| 248 | - | func shortcutSelectHTML(selected *int) string { | |
| 249 | - | var out strings.Builder | |
| 250 | - | out.WriteString(`<label><span>Shortcut</span><select name="shortcut_key"><option value="">None</option>`) | |
| 251 | - | for i := 1; i <= 9; i++ { | |
| 252 | - | selectedAttr := "" | |
| 253 | - | if selected != nil && *selected == i { | |
| 254 | - | selectedAttr = ` selected` | |
| 255 | - | } | |
| 256 | - | out.WriteString(fmt.Sprintf(`<option value="%d"%s>%d</option>`, i, selectedAttr, i)) | |
| 98 | + | func favoriteTagButtonClass(favorite *entity.Favorite, tag *entity.Tag) string { | |
| 99 | + | classes := "sv-button sv-button-secondary" | |
| 100 | + | if favorite != nil && tag != nil && favorite.HasTag(tag.ID) { | |
| 101 | + | classes += " sv-button-active" | |
| 257 | 102 | } | |
| 258 | - | out.WriteString(`</select></label>`) | |
| 259 | - | return out.String() | |
| 103 | + | return classes | |
| 260 | 104 | } | |
| 261 | 105 | ||
| 262 | 106 | func folderDisplayName(folder *entity.Folder) string { | |
| @@ -281,6 +125,14 @@ func folderNameForID(folders []*entity.Folder, id *entity.FolderID) string { | |||
| 281 | 125 | return "Unknown" | |
| 282 | 126 | } | |
| 283 | 127 | ||
| 128 | + | func folderSelected(selected *entity.FolderID, folderID entity.FolderID) bool { | |
| 129 | + | return selected != nil && *selected == folderID | |
| 130 | + | } | |
| 131 | + | ||
| 132 | + | func shortcutSelected(selected *int, value int) bool { | |
| 133 | + | return selected != nil && *selected == value | |
| 134 | + | } | |
| 135 | + | ||
| 284 | 136 | func filterFavorites(favorites []*entity.Favorite, folderID *entity.FolderID, tagID *entity.TagID) []*entity.Favorite { | |
| 285 | 137 | if folderID == nil && tagID == nil { | |
| 286 | 138 | return favorites | |
| @@ -2,7 +2,6 @@ package systemviews | |||||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | "fmt" | 4 | "fmt" | ||
| 5 | - | "html" | |||
| 6 | "strings" | 5 | "strings" | ||
| 7 | 6 | ||||
| 8 | "github.com/bnema/dumber/internal/domain/entity" | 7 | "github.com/bnema/dumber/internal/domain/entity" | ||
| @@ -19,112 +18,56 @@ type favoritesRenderData struct { | |||||
| 19 | } | 18 | } | ||
| 20 | 19 | ||||
| 21 | func favoritesHTML(data favoritesRenderData) string { | 20 | func favoritesHTML(data favoritesRenderData) string { | ||
| 22 | - | favoritesSummary := fmt.Sprintf("%d favorites · %d folders · %d tags", len(data.Favorites), len(data.Folders), len(data.Tags)) | 21 | + | return mustRenderComponent(FavoritesView(data)) |
| 23 | - | foldersSummary := fmt.Sprintf("%d folders", len(data.Folders)) | |||
| 24 | - | tagsSummary := fmt.Sprintf("%d tags", len(data.Tags)) | |||
| 25 | - | sections := []string{ | |||
| 26 | - | favoritesStatusHTML(data), | |||
| 27 | - | sectionHTML("sv-favorites-controls", "Manage favorites", favoritesControlsHTML(data)), | |||
| 28 | - | sectionHTML("sv-favorites-list", "Favorites", metaHTML(favoritesSummary)+listHTML(favoriteItemsHTML(data.Favorites, data.Folders, data.Tags), "No favorites")), | |||
| 29 | - | sectionHTML("sv-folders-list", "Folders", metaHTML(foldersSummary)+folderCreateHTML()+listHTML(folderItemsHTML(data.Folders), "No folders")), | |||
| 30 | - | sectionHTML("sv-tags-list", "Tags", metaHTML(tagsSummary)+tagCreateHTML()+listHTML(tagItemsHTML(data.Tags), "No tags")), | |||
| 31 | - | } | |||
| 32 | - | return strings.Join(sections, "") | |||
| 33 | } | 22 | } | ||
| 34 | 23 | ||||
| 35 | - | func favoritesStatusHTML(data favoritesRenderData) string { | 24 | + | func favoritesSummary(data favoritesRenderData) string { |
| 36 | - | var out strings.Builder | 25 | + | return fmt.Sprintf("%d favorites · %d folders · %d tags", len(data.Favorites), len(data.Folders), len(data.Tags)) |
| 37 | - | if strings.TrimSpace(data.Notice) != "" { | |||
| 38 | - | out.WriteString(fmt.Sprintf(`<div class="sv-alert sv-alert-success" role="status">%s</div>`, html.EscapeString(data.Notice))) | |||
| 39 | - | } | |||
| 40 | - | if strings.TrimSpace(data.Error) != "" { | |||
| 41 | - | out.WriteString(fmt.Sprintf(`<div class="sv-alert sv-alert-error" role="alert">%s</div>`, html.EscapeString(data.Error))) | |||
| 42 | - | } | |||
| 43 | - | return out.String() | |||
| 44 | } | 26 | } | ||
| 45 | 27 | ||||
| 46 | - | func favoritesControlsHTML(data favoritesRenderData) string { | 28 | + | func foldersSummary(data favoritesRenderData) string { |
| 47 | - | var out strings.Builder | 29 | + | return fmt.Sprintf("%d folders", len(data.Folders)) |
| 48 | - | out.WriteString(`<form class="sv-card-form" data-sv-action="favorite.create">`) | 30 | + | } |
| 49 | - | out.WriteString(`<label><span>URL</span><input name="url" type="url" placeholder="https://example.com" required></label>`) | |||
| 50 | - | out.WriteString(`<label><span>Title</span><input name="title" type="text" placeholder="Optional title"></label>`) | |||
| 51 | - | out.WriteString(folderSelectHTML("folder_id", data.Folders, nil, "Folder")) | |||
| 52 | - | out.WriteString(`<button class="sv-button" type="submit">Add favorite</button>`) | |||
| 53 | - | out.WriteString(`</form>`) | |||
| 54 | - | ||||
| 55 | - | out.WriteString(`<div class="sv-filter-panel">`) | |||
| 56 | - | out.WriteString(`<div class="sv-button-row"><span class="sv-meta">Folders</span>`) | |||
| 57 | - | out.WriteString(favoriteFilterButton("All", "favorite.clearFilters", nil, "", data.FolderFilter == nil && data.TagFilter == nil)) | |||
| 58 | - | out.WriteString(favoriteFilterButton("Unfiled", "favorite.filterFolder", map[string]string{"folder_id": "root"}, "", data.FolderFilter != nil && *data.FolderFilter == 0)) | |||
| 59 | - | for _, folder := range data.Folders { | |||
| 60 | - | if folder == nil { | |||
| 61 | - | continue | |||
| 62 | - | } | |||
| 63 | - | active := data.FolderFilter != nil && *data.FolderFilter == folder.ID | |||
| 64 | - | out.WriteString(favoriteFilterButton(folderDisplayName(folder), "favorite.filterFolder", map[string]string{"folder_id": fmt.Sprintf("%d", folder.ID)}, "", active)) | |||
| 65 | - | } | |||
| 66 | - | out.WriteString(`</div>`) | |||
| 67 | 31 | ||||
| 68 | - | out.WriteString(`<div class="sv-button-row"><span class="sv-meta">Tags</span>`) | 32 | + | func tagsSummary(data favoritesRenderData) string { |
| 69 | - | for _, tag := range data.Tags { | 33 | + | return fmt.Sprintf("%d tags", len(data.Tags)) |
| 70 | - | if tag == nil { | |||
| 71 | - | continue | |||
| 72 | - | } | |||
| 73 | - | active := data.TagFilter != nil && *data.TagFilter == tag.ID | |||
| 74 | - | out.WriteString(favoriteFilterButton(tag.Name, "favorite.filterTag", map[string]string{"tag_id": fmt.Sprintf("%d", tag.ID)}, tag.Color, active)) | |||
| 75 | - | } | |||
| 76 | - | out.WriteString(`</div></div>`) | |||
| 77 | - | out.WriteString(`<p class="sv-meta sv-key-hints">Keys: <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>e</kbd> edit title, <kbd>d</kbd> delete focused favorite.</p>`) | |||
| 78 | - | return out.String() | |||
| 79 | } | 34 | } | ||
| 80 | 35 | ||||
| 81 | - | func favoriteFilterButton(label, action string, data map[string]string, color string, active bool) string { | 36 | + | func favoriteFilterClass(active bool) string { |
| 82 | classes := "sv-button sv-button-secondary" | 37 | classes := "sv-button sv-button-secondary" | ||
| 83 | if active { | 38 | if active { | ||
| 84 | classes += " sv-button-active" | 39 | classes += " sv-button-active" | ||
| 85 | } | 40 | } | ||
| 86 | - | attrs := []string{`type="button"`, fmt.Sprintf(`class="%s"`, html.EscapeString(classes)), fmt.Sprintf(`data-sv-action="%s"`, html.EscapeString(action))} | 41 | + | return classes |
| 87 | - | for key, value := range data { | |||
| 88 | - | attrs = append(attrs, fmt.Sprintf(`data-%s="%s"`, html.EscapeString(kebabDataKey(key)), html.EscapeString(value))) | |||
| 89 | - | } | |||
| 90 | - | style := "" | |||
| 91 | - | if strings.TrimSpace(color) != "" { | |||
| 92 | - | style = fmt.Sprintf(`<span class="sv-tag-dot" style="background:%s"></span>`, html.EscapeString(color)) | |||
| 93 | - | } | |||
| 94 | - | return fmt.Sprintf(`<button %s>%s%s</button>`, strings.Join(attrs, " "), style, html.EscapeString(label)) | |||
| 95 | } | 42 | } | ||
| 96 | 43 | ||||
| 97 | - | func favoriteItemsHTML(favorites []*entity.Favorite, folders []*entity.Folder, tags []*entity.Tag) string { | 44 | + | func favoriteFolderFilterActive(data favoritesRenderData, folderID entity.FolderID) bool { |
| 98 | - | var items strings.Builder | 45 | + | return data.FolderFilter != nil && *data.FolderFilter == folderID |
| 99 | - | for _, favorite := range favorites { | 46 | + | } |
| 100 | - | if favorite == nil { | 47 | + | |
| 101 | - | continue | 48 | + | func favoriteAllFilterActive(data favoritesRenderData) bool { |
| 102 | - | } | 49 | + | return data.FolderFilter == nil && data.TagFilter == nil |
| 103 | - | items.WriteString(listRowHTML(favoriteItemHTML(favorite, folders, tags))) | 50 | + | } |
| 104 | - | } | 51 | + | |
| 105 | - | return items.String() | 52 | + | func favoriteTagFilterActive(data favoritesRenderData, tagID entity.TagID) bool { |
| 53 | + | return data.TagFilter != nil && *data.TagFilter == tagID | |||
| 106 | } | 54 | } | ||
| 107 | 55 | ||||
| 108 | - | func favoriteItemHTML(favorite *entity.Favorite, folders []*entity.Folder, tags []*entity.Tag) string { | 56 | + | func favoriteItemLabel(favorite *entity.Favorite) string { |
| 57 | + | if favorite == nil { | |||
| 58 | + | return "" | |||
| 59 | + | } | |||
| 109 | label := strings.TrimSpace(favorite.Title) | 60 | label := strings.TrimSpace(favorite.Title) | ||
| 110 | if label == "" { | 61 | if label == "" { | ||
| 111 | label = favorite.URL | 62 | label = favorite.URL | ||
| 112 | } | 63 | } | ||
| 113 | - | 64 | + | return label | |
| 114 | - | return fmt.Sprintf(`<article class="sv-favorite-item" data-sv-favorite-row data-favorite-id="%d"><div class="sv-favorite-header"><div><a class="sv-link sv-favorite-open" href="%s">%s</a><p class="sv-history-url">%s</p>%s</div><div class="sv-history-row-actions"><a class="sv-button sv-button-secondary" href="%s">Open</a><button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="favorite.delete" data-id="%d" data-sv-confirm="Delete this favorite?">Delete</button></div></div>%s%s</article>`, | |||
| 115 | - | favorite.ID, | |||
| 116 | - | html.EscapeString(sanitizeHref(favorite.URL)), | |||
| 117 | - | html.EscapeString(label), | |||
| 118 | - | html.EscapeString(favorite.URL), | |||
| 119 | - | favoriteMetaHTML(favorite, folders), | |||
| 120 | - | html.EscapeString(sanitizeHref(favorite.URL)), | |||
| 121 | - | favorite.ID, | |||
| 122 | - | favoriteEditHTML(favorite, folders), | |||
| 123 | - | favoriteTagControlsHTML(favorite, tags), | |||
| 124 | - | ) | |||
| 125 | } | 65 | } | ||
| 126 | 66 | ||||
| 127 | - | func favoriteMetaHTML(favorite *entity.Favorite, folders []*entity.Folder) string { | 67 | + | func favoriteMetaText(favorite *entity.Favorite, folders []*entity.Folder) string { |
| 68 | + | if favorite == nil { | |||
| 69 | + | return "" | |||
| 70 | + | } | |||
| 128 | parts := []string{} | 71 | parts := []string{} | ||
| 129 | if favorite.ShortcutKey != nil { | 72 | if favorite.ShortcutKey != nil { | ||
| 130 | parts = append(parts, fmt.Sprintf("Shortcut %d", *favorite.ShortcutKey)) | 73 | parts = append(parts, fmt.Sprintf("Shortcut %d", *favorite.ShortcutKey)) | ||
| @@ -132,131 +75,32 @@ func favoriteMetaHTML(favorite *entity.Favorite, folders []*entity.Folder) strin | |||||
| 132 | if name := folderNameForID(folders, favorite.FolderID); name != "" { | 75 | if name := folderNameForID(folders, favorite.FolderID); name != "" { | ||
| 133 | parts = append(parts, "Folder "+name) | 76 | parts = append(parts, "Folder "+name) | ||
| 134 | } | 77 | } | ||
| 135 | - | if len(parts) == 0 { | 78 | + | return strings.Join(parts, " · ") |
| 136 | - | return "" | |||
| 137 | - | } | |||
| 138 | - | return `<p class="sv-meta">` + html.EscapeString(strings.Join(parts, " · ")) + `</p>` | |||
| 139 | - | } | |||
| 140 | - | ||||
| 141 | - | func favoriteEditHTML(favorite *entity.Favorite, folders []*entity.Folder) string { | |||
| 142 | - | return fmt.Sprintf(`<form class="sv-inline-form" data-sv-action="favorite.update"><input type="hidden" name="id" value="%d"><label><span>Title</span><input name="title" type="text" value="%s"></label><label><span>Favicon</span><input name="favicon_url" type="url" value="%s"></label>%s%s<button class="sv-button sv-button-secondary" type="submit">Save</button></form>`, | |||
| 143 | - | favorite.ID, | |||
| 144 | - | html.EscapeString(favorite.Title), | |||
| 145 | - | html.EscapeString(favorite.FaviconURL), | |||
| 146 | - | folderSelectHTML("folder_id", folders, favorite.FolderID, "Folder"), | |||
| 147 | - | shortcutSelectHTML(favorite.ShortcutKey), | |||
| 148 | - | ) | |||
| 149 | - | } | |||
| 150 | - | ||||
| 151 | - | func favoriteTagControlsHTML(favorite *entity.Favorite, tags []*entity.Tag) string { | |||
| 152 | - | if len(tags) == 0 { | |||
| 153 | - | return "" | |||
| 154 | - | } | |||
| 155 | - | var out strings.Builder | |||
| 156 | - | out.WriteString(`<div class="sv-tag-controls"><span class="sv-meta">Tags</span>`) | |||
| 157 | - | for _, tag := range tags { | |||
| 158 | - | if tag == nil { | |||
| 159 | - | continue | |||
| 160 | - | } | |||
| 161 | - | action := "tag.assign" | |||
| 162 | - | label := "+ " + tag.Name | |||
| 163 | - | classes := "sv-button sv-button-secondary" | |||
| 164 | - | if favorite.HasTag(tag.ID) { | |||
| 165 | - | action = "tag.remove" | |||
| 166 | - | label = "✓ " + tag.Name | |||
| 167 | - | classes += " sv-button-active" | |||
| 168 | - | } | |||
| 169 | - | out.WriteString(fmt.Sprintf(`<button type="button" class="%s" data-sv-action="%s" data-favorite-id="%d" data-tag-id="%d"><span class="sv-tag-dot" style="background:%s"></span>%s</button>`, | |||
| 170 | - | html.EscapeString(classes), | |||
| 171 | - | html.EscapeString(action), | |||
| 172 | - | favorite.ID, | |||
| 173 | - | tag.ID, | |||
| 174 | - | html.EscapeString(tag.Color), | |||
| 175 | - | html.EscapeString(label), | |||
| 176 | - | )) | |||
| 177 | - | } | |||
| 178 | - | out.WriteString(`</div>`) | |||
| 179 | - | return out.String() | |||
| 180 | - | } | |||
| 181 | - | ||||
| 182 | - | func folderCreateHTML() string { | |||
| 183 | - | return `<form class="sv-inline-form" data-sv-action="folder.create"><label><span>Name</span><input name="name" type="text" required></label><label><span>Icon</span><input name="icon" type="text" placeholder="Optional"></label><button class="sv-button sv-button-secondary" type="submit">Create folder</button></form>` | |||
| 184 | } | 79 | } | ||
| 185 | 80 | ||||
| 186 | - | func folderItemsHTML(folders []*entity.Folder) string { | 81 | + | func favoriteTagButtonAction(favorite *entity.Favorite, tag *entity.Tag) string { |
| 187 | - | var items strings.Builder | 82 | + | if favorite != nil && tag != nil && favorite.HasTag(tag.ID) { |
| 188 | - | for _, folder := range folders { | 83 | + | return tagActionRemove |
| 189 | - | if folder == nil { | |||
| 190 | - | continue | |||
| 191 | - | } | |||
| 192 | - | items.WriteString(listRowHTML(folderItemHTML(folder))) | |||
| 193 | } | 84 | } | ||
| 194 | - | return items.String() | 85 | + | return tagActionAssign |
| 195 | - | } | |||
| 196 | - | ||||
| 197 | - | func folderItemHTML(folder *entity.Folder) string { | |||
| 198 | - | return fmt.Sprintf(`<form class="sv-inline-form" data-sv-action="folder.update"><input type="hidden" name="id" value="%d"><label><span>Name</span><input name="name" type="text" value="%s" required></label><label><span>Icon</span><input name="icon" type="text" value="%s"></label><button class="sv-button sv-button-secondary" type="submit">Save</button><button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="folder.delete" data-id="%d" data-sv-confirm="Delete this folder? Favorites will move out of it.">Delete</button></form>`, | |||
| 199 | - | folder.ID, | |||
| 200 | - | html.EscapeString(folder.Name), | |||
| 201 | - | html.EscapeString(folder.Icon), | |||
| 202 | - | folder.ID, | |||
| 203 | - | ) | |||
| 204 | } | 86 | } | ||
| 205 | 87 | ||||
| 206 | - | func tagCreateHTML() string { | 88 | + | func favoriteTagButtonLabel(favorite *entity.Favorite, tag *entity.Tag) string { |
| 207 | - | return `<form class="sv-inline-form" data-sv-action="tag.create"><label><span>Name</span><input name="name" type="text" required></label><label><span>Color</span><input name="color" type="text" placeholder="#808080"></label><button class="sv-button sv-button-secondary" type="submit">Create tag</button></form>` | 89 | + | if tag == nil { |
| 208 | - | } | 90 | + | return "" |
| 209 | - | ||||
| 210 | - | func tagItemsHTML(tags []*entity.Tag) string { | |||
| 211 | - | var items strings.Builder | |||
| 212 | - | for _, tag := range tags { | |||
| 213 | - | if tag == nil { | |||
| 214 | - | continue | |||
| 215 | - | } | |||
| 216 | - | items.WriteString(listRowHTML(tagItemHTML(tag))) | |||
| 217 | } | 91 | } | ||
| 218 | - | return items.String() | 92 | + | if favorite != nil && favorite.HasTag(tag.ID) { |
| 219 | - | } | 93 | + | return "✓ " + tag.Name |
| 220 | - | ||||
| 221 | - | func tagItemHTML(tag *entity.Tag) string { | |||
| 222 | - | return fmt.Sprintf(`<form class="sv-inline-form" data-sv-action="tag.update"><input type="hidden" name="id" value="%d"><span class="sv-tag-dot" style="background:%s"></span><label><span>Name</span><input name="name" type="text" value="%s" required></label><label><span>Color</span><input name="color" type="text" value="%s"></label><button class="sv-button sv-button-secondary" type="submit">Save</button><button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="tag.delete" data-id="%d" data-sv-confirm="Delete this tag?">Delete</button></form>`, | |||
| 223 | - | tag.ID, | |||
| 224 | - | html.EscapeString(tag.Color), | |||
| 225 | - | html.EscapeString(tag.Name), | |||
| 226 | - | html.EscapeString(tag.Color), | |||
| 227 | - | tag.ID, | |||
| 228 | - | ) | |||
| 229 | - | } | |||
| 230 | - | ||||
| 231 | - | func folderSelectHTML(name string, folders []*entity.Folder, selected *entity.FolderID, label string) string { | |||
| 232 | - | var out strings.Builder | |||
| 233 | - | out.WriteString(fmt.Sprintf(`<label><span>%s</span><select name="%s"><option value="">Unfiled</option>`, html.EscapeString(label), html.EscapeString(name))) | |||
| 234 | - | for _, folder := range folders { | |||
| 235 | - | if folder == nil { | |||
| 236 | - | continue | |||
| 237 | - | } | |||
| 238 | - | selectedAttr := "" | |||
| 239 | - | if selected != nil && *selected == folder.ID { | |||
| 240 | - | selectedAttr = ` selected` | |||
| 241 | - | } | |||
| 242 | - | out.WriteString(fmt.Sprintf(`<option value="%d"%s>%s</option>`, folder.ID, selectedAttr, html.EscapeString(folderDisplayName(folder)))) | |||
| 243 | } | 94 | } | ||
| 244 | - | out.WriteString(`</select></label>`) | 95 | + | return "+ " + tag.Name |
| 245 | - | return out.String() | |||
| 246 | } | 96 | } | ||
| 247 | 97 | ||||
| 248 | - | func shortcutSelectHTML(selected *int) string { | 98 | + | func favoriteTagButtonClass(favorite *entity.Favorite, tag *entity.Tag) string { |
| 249 | - | var out strings.Builder | 99 | + | classes := "sv-button sv-button-secondary" |
| 250 | - | out.WriteString(`<label><span>Shortcut</span><select name="shortcut_key"><option value="">None</option>`) | 100 | + | if favorite != nil && tag != nil && favorite.HasTag(tag.ID) { |
| 251 | - | for i := 1; i <= 9; i++ { | 101 | + | classes += " sv-button-active" |
| 252 | - | selectedAttr := "" | |||
| 253 | - | if selected != nil && *selected == i { | |||
| 254 | - | selectedAttr = ` selected` | |||
| 255 | - | } | |||
| 256 | - | out.WriteString(fmt.Sprintf(`<option value="%d"%s>%d</option>`, i, selectedAttr, i)) | |||
| 257 | } | 102 | } | ||
| 258 | - | out.WriteString(`</select></label>`) | 103 | + | return classes |
| 259 | - | return out.String() | |||
| 260 | } | 104 | } | ||
| 261 | 105 | ||||
| 262 | func folderDisplayName(folder *entity.Folder) string { | 106 | func folderDisplayName(folder *entity.Folder) string { | ||
| @@ -281,6 +125,14 @@ func folderNameForID(folders []*entity.Folder, id *entity.FolderID) string { | |||||
| 281 | return "Unknown" | 125 | return "Unknown" | ||
| 282 | } | 126 | } | ||
| 283 | 127 | ||||
| 128 | + | func folderSelected(selected *entity.FolderID, folderID entity.FolderID) bool { | |||
| 129 | + | return selected != nil && *selected == folderID | |||
| 130 | + | } | |||
| 131 | + | ||||
| 132 | + | func shortcutSelected(selected *int, value int) bool { | |||
| 133 | + | return selected != nil && *selected == value | |||
| 134 | + | } | |||
| 135 | + | ||||
| 284 | func filterFavorites(favorites []*entity.Favorite, folderID *entity.FolderID, tagID *entity.TagID) []*entity.Favorite { | 136 | func filterFavorites(favorites []*entity.Favorite, folderID *entity.FolderID, tagID *entity.TagID) []*entity.Favorite { | ||
| 285 | if folderID == nil && tagID == nil { | 137 | if folderID == nil && tagID == nil { | ||
| 286 | return favorites | 138 | return favorites | ||
A internal/ui/systemviews/history.templ +126 -0
| @@ -0,0 +1,126 @@ | |||
| 1 | + | package systemviews | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "fmt" | |
| 5 | + | "github.com/bnema/dumber/internal/domain/entity" | |
| 6 | + | ) | |
| 7 | + | ||
| 8 | + | templ HistoryView(data historyRenderData) { | |
| 9 | + | @Alert("success", data.Notice) | |
| 10 | + | @Alert("error", data.Error) | |
| 11 | + | @Section("sv-history-controls", "Manage history") { | |
| 12 | + | @HistoryControls(data) | |
| 13 | + | } | |
| 14 | + | @Section("sv-history-summary", "History") { | |
| 15 | + | @HistorySummary(data) | |
| 16 | + | } | |
| 17 | + | @Section("sv-history-domains", "Top domains") { | |
| 18 | + | @HistoryDomains(data) | |
| 19 | + | } | |
| 20 | + | @Section("sv-history-timeline", "Recent visits") { | |
| 21 | + | @HistoryTimeline(data) | |
| 22 | + | } | |
| 23 | + | } | |
| 24 | + | ||
| 25 | + | templ HistoryControls(data historyRenderData) { | |
| 26 | + | <form class="sv-toolbar sv-history-search" data-sv-action="history.search"> | |
| 27 | + | <label class="sv-search-label"> | |
| 28 | + | <span>Search</span> | |
| 29 | + | <input data-sv-history-search name="query" type="search" value={ data.Query } placeholder="Search title or URL" autocomplete="off"/> | |
| 30 | + | </label> | |
| 31 | + | <button class="sv-button" type="submit">Search</button> | |
| 32 | + | <button class="sv-button sv-button-secondary" type="button" data-sv-action="history.clear">Clear</button> | |
| 33 | + | </form> | |
| 34 | + | if showHistoryFilters(data) { | |
| 35 | + | <div class="sv-active-filters"> | |
| 36 | + | if data.Query != "" { | |
| 37 | + | <span class="sv-filter-chip">Query: { data.Query }</span> | |
| 38 | + | } | |
| 39 | + | if data.DomainFilter != "" { | |
| 40 | + | <span class="sv-filter-chip">Domain: { data.DomainFilter } <button type="button" data-sv-action="history.clearDomain" aria-label="Clear domain filter">×</button></span> | |
| 41 | + | } | |
| 42 | + | </div> | |
| 43 | + | } | |
| 44 | + | <div class="sv-history-actions-panel"> | |
| 45 | + | <div class="sv-button-row" aria-label="History pagination"> | |
| 46 | + | <button type="button" class="sv-button sv-button-secondary" data-sv-action="history.page" data-offset={ fmt.Sprintf("%d", previousHistoryOffset(data)) } disabled?={ disableHistoryPrev(data) }>Previous</button> | |
| 47 | + | <span class="sv-meta">Showing { fmt.Sprintf("%d", countHistoryEntries(data.Entries)) } item{ pluralSuffix(countHistoryEntries(data.Entries)) }{ historyOffsetLabel(data.Offset, data.Query) }</span> | |
| 48 | + | <button type="button" class="sv-button sv-button-secondary" data-sv-action="history.page" data-offset={ fmt.Sprintf("%d", nextHistoryOffset(data)) } disabled?={ disableHistoryNext(data) }>Next</button> | |
| 49 | + | </div> | |
| 50 | + | <div class="sv-button-row" aria-label="History cleanup"> | |
| 51 | + | <span class="sv-meta">Clean up</span> | |
| 52 | + | for _, item := range historyCleanupItems() { | |
| 53 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="history.deleteRange" data-range={ item.RangeID } data-sv-confirm={ item.Confirm }>{ item.Label }</button> | |
| 54 | + | } | |
| 55 | + | </div> | |
| 56 | + | </div> | |
| 57 | + | <p class="sv-meta sv-key-hints">Keys: <kbd>/</kbd> search, <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>d</kbd> delete focused entry.</p> | |
| 58 | + | } | |
| 59 | + | ||
| 60 | + | templ HistorySummary(data historyRenderData) { | |
| 61 | + | {{ entries, visits, days := historySummaryValues(data) }} | |
| 62 | + | <div class="sv-stat-grid"> | |
| 63 | + | @HistoryStatCard("Entries", entries) | |
| 64 | + | @HistoryStatCard("Visits", visits) | |
| 65 | + | @HistoryStatCard("Days", days) | |
| 66 | + | </div> | |
| 67 | + | } | |
| 68 | + | ||
| 69 | + | templ HistoryStatCard(label string, value int64) { | |
| 70 | + | <div class="sv-stat-card"><span class="sv-stat-value">{ fmt.Sprintf("%d", value) }</span><span class="sv-stat-label">{ label }</span></div> | |
| 71 | + | } | |
| 72 | + | ||
| 73 | + | templ HistoryDomains(data historyRenderData) { | |
| 74 | + | if len(data.Domains) == 0 { | |
| 75 | + | @EmptyState("No domain statistics yet") | |
| 76 | + | } else { | |
| 77 | + | <div class="sv-domain-list"> | |
| 78 | + | for _, domain := range data.Domains { | |
| 79 | + | if domain != nil && domain.Domain != "" { | |
| 80 | + | {{ displayDomain := displayHistoryDomain(domain.Domain) }} | |
| 81 | + | <span class="sv-domain-chip"> | |
| 82 | + | <button type="button" class="sv-domain-filter" data-sv-action="history.filterDomain" data-domain={ displayDomain }>{ displayDomain }</button> | |
| 83 | + | <span class="sv-domain-meta">{ fmt.Sprintf("%d pages · %d visits", domain.PageCount, domain.TotalVisits) }</span> | |
| 84 | + | <button type="button" class="sv-icon-button sv-danger" data-sv-action="history.deleteDomain" data-domain={ displayDomain } data-sv-confirm={ "Delete all history for " + displayDomain + "?" } aria-label={ "Delete history for " + displayDomain }>×</button> | |
| 85 | + | </span> | |
| 86 | + | } | |
| 87 | + | } | |
| 88 | + | </div> | |
| 89 | + | } | |
| 90 | + | } | |
| 91 | + | ||
| 92 | + | templ HistoryTimeline(data historyRenderData) { | |
| 93 | + | {{ groups := groupHistoryEntries(data.Entries) }} | |
| 94 | + | if len(groups) == 0 { | |
| 95 | + | @EmptyState(historyTimelineEmptyMessage(data)) | |
| 96 | + | } else { | |
| 97 | + | for _, group := range groups { | |
| 98 | + | <section class="sv-timeline-group"> | |
| 99 | + | <h3>{ group.Label }</h3> | |
| 100 | + | <ul class="sv-list"> | |
| 101 | + | for _, entry := range group.Entries { | |
| 102 | + | if entry != nil { | |
| 103 | + | @HistoryItem(entry) | |
| 104 | + | } | |
| 105 | + | } | |
| 106 | + | </ul> | |
| 107 | + | </section> | |
| 108 | + | } | |
| 109 | + | } | |
| 110 | + | } | |
| 111 | + | ||
| 112 | + | templ HistoryItem(entry *entity.HistoryEntry) { | |
| 113 | + | <li class="sv-list-row"> | |
| 114 | + | <article class="sv-history-item" data-sv-history-row data-history-id={ fmt.Sprintf("%d", entry.ID) }> | |
| 115 | + | <div class="sv-history-main"> | |
| 116 | + | <a class="sv-link sv-history-open" href={ templ.SafeURL(sanitizeHref(entry.URL)) }>{ historyItemLabel(entry) }</a> | |
| 117 | + | <p class="sv-history-url">{ entry.URL }</p> | |
| 118 | + | <p class="sv-history-meta">{ historyItemMeta(entry) }</p> | |
| 119 | + | </div> | |
| 120 | + | <div class="sv-history-row-actions"> | |
| 121 | + | <a class="sv-button sv-button-secondary" href={ templ.SafeURL(sanitizeHref(entry.URL)) }>Open</a> | |
| 122 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="history.deleteEntry" data-id={ fmt.Sprintf("%d", entry.ID) } data-sv-confirm="Delete this history entry?" disabled?={ entry.ID <= 0 }>Delete</button> | |
| 123 | + | </div> | |
| 124 | + | </article> | |
| 125 | + | </li> | |
| 126 | + | } | |
| @@ -0,0 +1,126 @@ | |||||
| 1 | + | package systemviews | |||
| 2 | + | ||||
| 3 | + | import ( | |||
| 4 | + | "fmt" | |||
| 5 | + | "github.com/bnema/dumber/internal/domain/entity" | |||
| 6 | + | ) | |||
| 7 | + | ||||
| 8 | + | templ HistoryView(data historyRenderData) { | |||
| 9 | + | @Alert("success", data.Notice) | |||
| 10 | + | @Alert("error", data.Error) | |||
| 11 | + | @Section("sv-history-controls", "Manage history") { | |||
| 12 | + | @HistoryControls(data) | |||
| 13 | + | } | |||
| 14 | + | @Section("sv-history-summary", "History") { | |||
| 15 | + | @HistorySummary(data) | |||
| 16 | + | } | |||
| 17 | + | @Section("sv-history-domains", "Top domains") { | |||
| 18 | + | @HistoryDomains(data) | |||
| 19 | + | } | |||
| 20 | + | @Section("sv-history-timeline", "Recent visits") { | |||
| 21 | + | @HistoryTimeline(data) | |||
| 22 | + | } | |||
| 23 | + | } | |||
| 24 | + | ||||
| 25 | + | templ HistoryControls(data historyRenderData) { | |||
| 26 | + | <form class="sv-toolbar sv-history-search" data-sv-action="history.search"> | |||
| 27 | + | <label class="sv-search-label"> | |||
| 28 | + | <span>Search</span> | |||
| 29 | + | <input data-sv-history-search name="query" type="search" value={ data.Query } placeholder="Search title or URL" autocomplete="off"/> | |||
| 30 | + | </label> | |||
| 31 | + | <button class="sv-button" type="submit">Search</button> | |||
| 32 | + | <button class="sv-button sv-button-secondary" type="button" data-sv-action="history.clear">Clear</button> | |||
| 33 | + | </form> | |||
| 34 | + | if showHistoryFilters(data) { | |||
| 35 | + | <div class="sv-active-filters"> | |||
| 36 | + | if data.Query != "" { | |||
| 37 | + | <span class="sv-filter-chip">Query: { data.Query }</span> | |||
| 38 | + | } | |||
| 39 | + | if data.DomainFilter != "" { | |||
| 40 | + | <span class="sv-filter-chip">Domain: { data.DomainFilter } <button type="button" data-sv-action="history.clearDomain" aria-label="Clear domain filter">×</button></span> | |||
| 41 | + | } | |||
| 42 | + | </div> | |||
| 43 | + | } | |||
| 44 | + | <div class="sv-history-actions-panel"> | |||
| 45 | + | <div class="sv-button-row" aria-label="History pagination"> | |||
| 46 | + | <button type="button" class="sv-button sv-button-secondary" data-sv-action="history.page" data-offset={ fmt.Sprintf("%d", previousHistoryOffset(data)) } disabled?={ disableHistoryPrev(data) }>Previous</button> | |||
| 47 | + | <span class="sv-meta">Showing { fmt.Sprintf("%d", countHistoryEntries(data.Entries)) } item{ pluralSuffix(countHistoryEntries(data.Entries)) }{ historyOffsetLabel(data.Offset, data.Query) }</span> | |||
| 48 | + | <button type="button" class="sv-button sv-button-secondary" data-sv-action="history.page" data-offset={ fmt.Sprintf("%d", nextHistoryOffset(data)) } disabled?={ disableHistoryNext(data) }>Next</button> | |||
| 49 | + | </div> | |||
| 50 | + | <div class="sv-button-row" aria-label="History cleanup"> | |||
| 51 | + | <span class="sv-meta">Clean up</span> | |||
| 52 | + | for _, item := range historyCleanupItems() { | |||
| 53 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="history.deleteRange" data-range={ item.RangeID } data-sv-confirm={ item.Confirm }>{ item.Label }</button> | |||
| 54 | + | } | |||
| 55 | + | </div> | |||
| 56 | + | </div> | |||
| 57 | + | <p class="sv-meta sv-key-hints">Keys: <kbd>/</kbd> search, <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>d</kbd> delete focused entry.</p> | |||
| 58 | + | } | |||
| 59 | + | ||||
| 60 | + | templ HistorySummary(data historyRenderData) { | |||
| 61 | + | {{ entries, visits, days := historySummaryValues(data) }} | |||
| 62 | + | <div class="sv-stat-grid"> | |||
| 63 | + | @HistoryStatCard("Entries", entries) | |||
| 64 | + | @HistoryStatCard("Visits", visits) | |||
| 65 | + | @HistoryStatCard("Days", days) | |||
| 66 | + | </div> | |||
| 67 | + | } | |||
| 68 | + | ||||
| 69 | + | templ HistoryStatCard(label string, value int64) { | |||
| 70 | + | <div class="sv-stat-card"><span class="sv-stat-value">{ fmt.Sprintf("%d", value) }</span><span class="sv-stat-label">{ label }</span></div> | |||
| 71 | + | } | |||
| 72 | + | ||||
| 73 | + | templ HistoryDomains(data historyRenderData) { | |||
| 74 | + | if len(data.Domains) == 0 { | |||
| 75 | + | @EmptyState("No domain statistics yet") | |||
| 76 | + | } else { | |||
| 77 | + | <div class="sv-domain-list"> | |||
| 78 | + | for _, domain := range data.Domains { | |||
| 79 | + | if domain != nil && domain.Domain != "" { | |||
| 80 | + | {{ displayDomain := displayHistoryDomain(domain.Domain) }} | |||
| 81 | + | <span class="sv-domain-chip"> | |||
| 82 | + | <button type="button" class="sv-domain-filter" data-sv-action="history.filterDomain" data-domain={ displayDomain }>{ displayDomain }</button> | |||
| 83 | + | <span class="sv-domain-meta">{ fmt.Sprintf("%d pages · %d visits", domain.PageCount, domain.TotalVisits) }</span> | |||
| 84 | + | <button type="button" class="sv-icon-button sv-danger" data-sv-action="history.deleteDomain" data-domain={ displayDomain } data-sv-confirm={ "Delete all history for " + displayDomain + "?" } aria-label={ "Delete history for " + displayDomain }>×</button> | |||
| 85 | + | </span> | |||
| 86 | + | } | |||
| 87 | + | } | |||
| 88 | + | </div> | |||
| 89 | + | } | |||
| 90 | + | } | |||
| 91 | + | ||||
| 92 | + | templ HistoryTimeline(data historyRenderData) { | |||
| 93 | + | {{ groups := groupHistoryEntries(data.Entries) }} | |||
| 94 | + | if len(groups) == 0 { | |||
| 95 | + | @EmptyState(historyTimelineEmptyMessage(data)) | |||
| 96 | + | } else { | |||
| 97 | + | for _, group := range groups { | |||
| 98 | + | <section class="sv-timeline-group"> | |||
| 99 | + | <h3>{ group.Label }</h3> | |||
| 100 | + | <ul class="sv-list"> | |||
| 101 | + | for _, entry := range group.Entries { | |||
| 102 | + | if entry != nil { | |||
| 103 | + | @HistoryItem(entry) | |||
| 104 | + | } | |||
| 105 | + | } | |||
| 106 | + | </ul> | |||
| 107 | + | </section> | |||
| 108 | + | } | |||
| 109 | + | } | |||
| 110 | + | } | |||
| 111 | + | ||||
| 112 | + | templ HistoryItem(entry *entity.HistoryEntry) { | |||
| 113 | + | <li class="sv-list-row"> | |||
| 114 | + | <article class="sv-history-item" data-sv-history-row data-history-id={ fmt.Sprintf("%d", entry.ID) }> | |||
| 115 | + | <div class="sv-history-main"> | |||
| 116 | + | <a class="sv-link sv-history-open" href={ templ.SafeURL(sanitizeHref(entry.URL)) }>{ historyItemLabel(entry) }</a> | |||
| 117 | + | <p class="sv-history-url">{ entry.URL }</p> | |||
| 118 | + | <p class="sv-history-meta">{ historyItemMeta(entry) }</p> | |||
| 119 | + | </div> | |||
| 120 | + | <div class="sv-history-row-actions"> | |||
| 121 | + | <a class="sv-button sv-button-secondary" href={ templ.SafeURL(sanitizeHref(entry.URL)) }>Open</a> | |||
| 122 | + | <button type="button" class="sv-button sv-button-secondary sv-button-danger" data-sv-action="history.deleteEntry" data-id={ fmt.Sprintf("%d", entry.ID) } data-sv-confirm="Delete this history entry?" disabled?={ entry.ID <= 0 }>Delete</button> | |||
| 123 | + | </div> | |||
| 124 | + | </article> | |||
| 125 | + | </li> | |||
| 126 | + | } | |||
A internal/ui/systemviews/history_templ.go +782 -0
| @@ -0,0 +1,782 @@ | |||
| 1 | + | // Code generated by templ - DO NOT EDIT. | |
| 2 | + | ||
| 3 | + | package systemviews | |
| 4 | + | ||
| 5 | + | //lint:file-ignore SA4006 This context is only used if a nested component is present. | |
| 6 | + | ||
| 7 | + | import "github.com/a-h/templ" | |
| 8 | + | import templruntime "github.com/a-h/templ/runtime" | |
| 9 | + | ||
| 10 | + | import ( | |
| 11 | + | "fmt" | |
| 12 | + | "github.com/bnema/dumber/internal/domain/entity" | |
| 13 | + | ) | |
| 14 | + | ||
| 15 | + | func HistoryView(data historyRenderData) templ.Component { | |
| 16 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 17 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 18 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |
| 19 | + | return templ_7745c5c3_CtxErr | |
| 20 | + | } | |
| 21 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 22 | + | if !templ_7745c5c3_IsBuffer { | |
| 23 | + | defer func() { | |
| 24 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 25 | + | if templ_7745c5c3_Err == nil { | |
| 26 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 27 | + | } | |
| 28 | + | }() | |
| 29 | + | } | |
| 30 | + | ctx = templ.InitializeContext(ctx) | |
| 31 | + | templ_7745c5c3_Var1 := templ.GetChildren(ctx) | |
| 32 | + | if templ_7745c5c3_Var1 == nil { | |
| 33 | + | templ_7745c5c3_Var1 = templ.NopComponent | |
| 34 | + | } | |
| 35 | + | ctx = templ.ClearChildren(ctx) | |
| 36 | + | templ_7745c5c3_Err = Alert("success", data.Notice).Render(ctx, templ_7745c5c3_Buffer) | |
| 37 | + | if templ_7745c5c3_Err != nil { | |
| 38 | + | return templ_7745c5c3_Err | |
| 39 | + | } | |
| 40 | + | templ_7745c5c3_Err = Alert("error", data.Error).Render(ctx, templ_7745c5c3_Buffer) | |
| 41 | + | if templ_7745c5c3_Err != nil { | |
| 42 | + | return templ_7745c5c3_Err | |
| 43 | + | } | |
| 44 | + | templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 45 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 46 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 47 | + | if !templ_7745c5c3_IsBuffer { | |
| 48 | + | defer func() { | |
| 49 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 50 | + | if templ_7745c5c3_Err == nil { | |
| 51 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 52 | + | } | |
| 53 | + | }() | |
| 54 | + | } | |
| 55 | + | ctx = templ.InitializeContext(ctx) | |
| 56 | + | templ_7745c5c3_Err = HistoryControls(data).Render(ctx, templ_7745c5c3_Buffer) | |
| 57 | + | if templ_7745c5c3_Err != nil { | |
| 58 | + | return templ_7745c5c3_Err | |
| 59 | + | } | |
| 60 | + | return nil | |
| 61 | + | }) | |
| 62 | + | templ_7745c5c3_Err = Section("sv-history-controls", "Manage history").Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) | |
| 63 | + | if templ_7745c5c3_Err != nil { | |
| 64 | + | return templ_7745c5c3_Err | |
| 65 | + | } | |
| 66 | + | templ_7745c5c3_Var3 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 67 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 68 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 69 | + | if !templ_7745c5c3_IsBuffer { | |
| 70 | + | defer func() { | |
| 71 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 72 | + | if templ_7745c5c3_Err == nil { | |
| 73 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 74 | + | } | |
| 75 | + | }() | |
| 76 | + | } | |
| 77 | + | ctx = templ.InitializeContext(ctx) | |
| 78 | + | templ_7745c5c3_Err = HistorySummary(data).Render(ctx, templ_7745c5c3_Buffer) | |
| 79 | + | if templ_7745c5c3_Err != nil { | |
| 80 | + | return templ_7745c5c3_Err | |
| 81 | + | } | |
| 82 | + | return nil | |
| 83 | + | }) | |
| 84 | + | templ_7745c5c3_Err = Section("sv-history-summary", "History").Render(templ.WithChildren(ctx, templ_7745c5c3_Var3), templ_7745c5c3_Buffer) | |
| 85 | + | if templ_7745c5c3_Err != nil { | |
| 86 | + | return templ_7745c5c3_Err | |
| 87 | + | } | |
| 88 | + | templ_7745c5c3_Var4 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 89 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 90 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 91 | + | if !templ_7745c5c3_IsBuffer { | |
| 92 | + | defer func() { | |
| 93 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 94 | + | if templ_7745c5c3_Err == nil { | |
| 95 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 96 | + | } | |
| 97 | + | }() | |
| 98 | + | } | |
| 99 | + | ctx = templ.InitializeContext(ctx) | |
| 100 | + | templ_7745c5c3_Err = HistoryDomains(data).Render(ctx, templ_7745c5c3_Buffer) | |
| 101 | + | if templ_7745c5c3_Err != nil { | |
| 102 | + | return templ_7745c5c3_Err | |
| 103 | + | } | |
| 104 | + | return nil | |
| 105 | + | }) | |
| 106 | + | templ_7745c5c3_Err = Section("sv-history-domains", "Top domains").Render(templ.WithChildren(ctx, templ_7745c5c3_Var4), templ_7745c5c3_Buffer) | |
| 107 | + | if templ_7745c5c3_Err != nil { | |
| 108 | + | return templ_7745c5c3_Err | |
| 109 | + | } | |
| 110 | + | templ_7745c5c3_Var5 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 111 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 112 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 113 | + | if !templ_7745c5c3_IsBuffer { | |
| 114 | + | defer func() { | |
| 115 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 116 | + | if templ_7745c5c3_Err == nil { | |
| 117 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 118 | + | } | |
| 119 | + | }() | |
| 120 | + | } | |
| 121 | + | ctx = templ.InitializeContext(ctx) | |
| 122 | + | templ_7745c5c3_Err = HistoryTimeline(data).Render(ctx, templ_7745c5c3_Buffer) | |
| 123 | + | if templ_7745c5c3_Err != nil { | |
| 124 | + | return templ_7745c5c3_Err | |
| 125 | + | } | |
| 126 | + | return nil | |
| 127 | + | }) | |
| 128 | + | templ_7745c5c3_Err = Section("sv-history-timeline", "Recent visits").Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer) | |
| 129 | + | if templ_7745c5c3_Err != nil { | |
| 130 | + | return templ_7745c5c3_Err | |
| 131 | + | } | |
| 132 | + | return nil | |
| 133 | + | }) | |
| 134 | + | } | |
| 135 | + | ||
| 136 | + | func HistoryControls(data historyRenderData) templ.Component { | |
| 137 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 138 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 139 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |
| 140 | + | return templ_7745c5c3_CtxErr | |
| 141 | + | } | |
| 142 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 143 | + | if !templ_7745c5c3_IsBuffer { | |
| 144 | + | defer func() { | |
| 145 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 146 | + | if templ_7745c5c3_Err == nil { | |
| 147 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 148 | + | } | |
| 149 | + | }() | |
| 150 | + | } | |
| 151 | + | ctx = templ.InitializeContext(ctx) | |
| 152 | + | templ_7745c5c3_Var6 := templ.GetChildren(ctx) | |
| 153 | + | if templ_7745c5c3_Var6 == nil { | |
| 154 | + | templ_7745c5c3_Var6 = templ.NopComponent | |
| 155 | + | } | |
| 156 | + | ctx = templ.ClearChildren(ctx) | |
| 157 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<form class=\"sv-toolbar sv-history-search\" data-sv-action=\"history.search\"><label class=\"sv-search-label\"><span>Search</span> <input data-sv-history-search name=\"query\" type=\"search\" value=\"") | |
| 158 | + | if templ_7745c5c3_Err != nil { | |
| 159 | + | return templ_7745c5c3_Err | |
| 160 | + | } | |
| 161 | + | var templ_7745c5c3_Var7 string | |
| 162 | + | templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(data.Query) | |
| 163 | + | if templ_7745c5c3_Err != nil { | |
| 164 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 29, Col: 78} | |
| 165 | + | } | |
| 166 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) | |
| 167 | + | if templ_7745c5c3_Err != nil { | |
| 168 | + | return templ_7745c5c3_Err | |
| 169 | + | } | |
| 170 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\" placeholder=\"Search title or URL\" autocomplete=\"off\"></label> <button class=\"sv-button\" type=\"submit\">Search</button> <button class=\"sv-button sv-button-secondary\" type=\"button\" data-sv-action=\"history.clear\">Clear</button></form>") | |
| 171 | + | if templ_7745c5c3_Err != nil { | |
| 172 | + | return templ_7745c5c3_Err | |
| 173 | + | } | |
| 174 | + | if showHistoryFilters(data) { | |
| 175 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<div class=\"sv-active-filters\">") | |
| 176 | + | if templ_7745c5c3_Err != nil { | |
| 177 | + | return templ_7745c5c3_Err | |
| 178 | + | } | |
| 179 | + | if data.Query != "" { | |
| 180 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<span class=\"sv-filter-chip\">Query: ") | |
| 181 | + | if templ_7745c5c3_Err != nil { | |
| 182 | + | return templ_7745c5c3_Err | |
| 183 | + | } | |
| 184 | + | var templ_7745c5c3_Var8 string | |
| 185 | + | templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(data.Query) | |
| 186 | + | if templ_7745c5c3_Err != nil { | |
| 187 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 37, Col: 52} | |
| 188 | + | } | |
| 189 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) | |
| 190 | + | if templ_7745c5c3_Err != nil { | |
| 191 | + | return templ_7745c5c3_Err | |
| 192 | + | } | |
| 193 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</span> ") | |
| 194 | + | if templ_7745c5c3_Err != nil { | |
| 195 | + | return templ_7745c5c3_Err | |
| 196 | + | } | |
| 197 | + | } | |
| 198 | + | if data.DomainFilter != "" { | |
| 199 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<span class=\"sv-filter-chip\">Domain: ") | |
| 200 | + | if templ_7745c5c3_Err != nil { | |
| 201 | + | return templ_7745c5c3_Err | |
| 202 | + | } | |
| 203 | + | var templ_7745c5c3_Var9 string | |
| 204 | + | templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(data.DomainFilter) | |
| 205 | + | if templ_7745c5c3_Err != nil { | |
| 206 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 40, Col: 60} | |
| 207 | + | } | |
| 208 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) | |
| 209 | + | if templ_7745c5c3_Err != nil { | |
| 210 | + | return templ_7745c5c3_Err | |
| 211 | + | } | |
| 212 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " <button type=\"button\" data-sv-action=\"history.clearDomain\" aria-label=\"Clear domain filter\">×</button></span>") | |
| 213 | + | if templ_7745c5c3_Err != nil { | |
| 214 | + | return templ_7745c5c3_Err | |
| 215 | + | } | |
| 216 | + | } | |
| 217 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "</div>") | |
| 218 | + | if templ_7745c5c3_Err != nil { | |
| 219 | + | return templ_7745c5c3_Err | |
| 220 | + | } | |
| 221 | + | } | |
| 222 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<div class=\"sv-history-actions-panel\"><div class=\"sv-button-row\" aria-label=\"History pagination\"><button type=\"button\" class=\"sv-button sv-button-secondary\" data-sv-action=\"history.page\" data-offset=\"") | |
| 223 | + | if templ_7745c5c3_Err != nil { | |
| 224 | + | return templ_7745c5c3_Err | |
| 225 | + | } | |
| 226 | + | var templ_7745c5c3_Var10 string | |
| 227 | + | templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", previousHistoryOffset(data))) | |
| 228 | + | if templ_7745c5c3_Err != nil { | |
| 229 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 46, Col: 153} | |
| 230 | + | } | |
| 231 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) | |
| 232 | + | if templ_7745c5c3_Err != nil { | |
| 233 | + | return templ_7745c5c3_Err | |
| 234 | + | } | |
| 235 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\"") | |
| 236 | + | if templ_7745c5c3_Err != nil { | |
| 237 | + | return templ_7745c5c3_Err | |
| 238 | + | } | |
| 239 | + | if disableHistoryPrev(data) { | |
| 240 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, " disabled") | |
| 241 | + | if templ_7745c5c3_Err != nil { | |
| 242 | + | return templ_7745c5c3_Err | |
| 243 | + | } | |
| 244 | + | } | |
| 245 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, ">Previous</button> <span class=\"sv-meta\">Showing ") | |
| 246 | + | if templ_7745c5c3_Err != nil { | |
| 247 | + | return templ_7745c5c3_Err | |
| 248 | + | } | |
| 249 | + | var templ_7745c5c3_Var11 string | |
| 250 | + | templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", countHistoryEntries(data.Entries))) | |
| 251 | + | if templ_7745c5c3_Err != nil { | |
| 252 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 47, Col: 87} | |
| 253 | + | } | |
| 254 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) | |
| 255 | + | if templ_7745c5c3_Err != nil { | |
| 256 | + | return templ_7745c5c3_Err | |
| 257 | + | } | |
| 258 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, " item") | |
| 259 | + | if templ_7745c5c3_Err != nil { | |
| 260 | + | return templ_7745c5c3_Err | |
| 261 | + | } | |
| 262 | + | var templ_7745c5c3_Var12 string | |
| 263 | + | templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(pluralSuffix(countHistoryEntries(data.Entries))) | |
| 264 | + | if templ_7745c5c3_Err != nil { | |
| 265 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 47, Col: 143} | |
| 266 | + | } | |
| 267 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) | |
| 268 | + | if templ_7745c5c3_Err != nil { | |
| 269 | + | return templ_7745c5c3_Err | |
| 270 | + | } | |
| 271 | + | var templ_7745c5c3_Var13 string | |
| 272 | + | templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(historyOffsetLabel(data.Offset, data.Query)) | |
| 273 | + | if templ_7745c5c3_Err != nil { | |
| 274 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 47, Col: 190} | |
| 275 | + | } | |
| 276 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) | |
| 277 | + | if templ_7745c5c3_Err != nil { | |
| 278 | + | return templ_7745c5c3_Err | |
| 279 | + | } | |
| 280 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</span> <button type=\"button\" class=\"sv-button sv-button-secondary\" data-sv-action=\"history.page\" data-offset=\"") | |
| 281 | + | if templ_7745c5c3_Err != nil { | |
| 282 | + | return templ_7745c5c3_Err | |
| 283 | + | } | |
| 284 | + | var templ_7745c5c3_Var14 string | |
| 285 | + | templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", nextHistoryOffset(data))) | |
| 286 | + | if templ_7745c5c3_Err != nil { | |
| 287 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 48, Col: 149} | |
| 288 | + | } | |
| 289 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) | |
| 290 | + | if templ_7745c5c3_Err != nil { | |
| 291 | + | return templ_7745c5c3_Err | |
| 292 | + | } | |
| 293 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "\"") | |
| 294 | + | if templ_7745c5c3_Err != nil { | |
| 295 | + | return templ_7745c5c3_Err | |
| 296 | + | } | |
| 297 | + | if disableHistoryNext(data) { | |
| 298 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, " disabled") | |
| 299 | + | if templ_7745c5c3_Err != nil { | |
| 300 | + | return templ_7745c5c3_Err | |
| 301 | + | } | |
| 302 | + | } | |
| 303 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, ">Next</button></div><div class=\"sv-button-row\" aria-label=\"History cleanup\"><span class=\"sv-meta\">Clean up</span> ") | |
| 304 | + | if templ_7745c5c3_Err != nil { | |
| 305 | + | return templ_7745c5c3_Err | |
| 306 | + | } | |
| 307 | + | for _, item := range historyCleanupItems() { | |
| 308 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<button type=\"button\" class=\"sv-button sv-button-secondary sv-button-danger\" data-sv-action=\"history.deleteRange\" data-range=\"") | |
| 309 | + | if templ_7745c5c3_Err != nil { | |
| 310 | + | return templ_7745c5c3_Err | |
| 311 | + | } | |
| 312 | + | var templ_7745c5c3_Var15 string | |
| 313 | + | templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(item.RangeID) | |
| 314 | + | if templ_7745c5c3_Err != nil { | |
| 315 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 53, Col: 143} | |
| 316 | + | } | |
| 317 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) | |
| 318 | + | if templ_7745c5c3_Err != nil { | |
| 319 | + | return templ_7745c5c3_Err | |
| 320 | + | } | |
| 321 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\" data-sv-confirm=\"") | |
| 322 | + | if templ_7745c5c3_Err != nil { | |
| 323 | + | return templ_7745c5c3_Err | |
| 324 | + | } | |
| 325 | + | var templ_7745c5c3_Var16 string | |
| 326 | + | templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(item.Confirm) | |
| 327 | + | if templ_7745c5c3_Err != nil { | |
| 328 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 53, Col: 176} | |
| 329 | + | } | |
| 330 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) | |
| 331 | + | if templ_7745c5c3_Err != nil { | |
| 332 | + | return templ_7745c5c3_Err | |
| 333 | + | } | |
| 334 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\">") | |
| 335 | + | if templ_7745c5c3_Err != nil { | |
| 336 | + | return templ_7745c5c3_Err | |
| 337 | + | } | |
| 338 | + | var templ_7745c5c3_Var17 string | |
| 339 | + | templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(item.Label) | |
| 340 | + | if templ_7745c5c3_Err != nil { | |
| 341 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 53, Col: 191} | |
| 342 | + | } | |
| 343 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) | |
| 344 | + | if templ_7745c5c3_Err != nil { | |
| 345 | + | return templ_7745c5c3_Err | |
| 346 | + | } | |
| 347 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</button>") | |
| 348 | + | if templ_7745c5c3_Err != nil { | |
| 349 | + | return templ_7745c5c3_Err | |
| 350 | + | } | |
| 351 | + | } | |
| 352 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</div></div><p class=\"sv-meta sv-key-hints\">Keys: <kbd>/</kbd> search, <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>d</kbd> delete focused entry.</p>") | |
| 353 | + | if templ_7745c5c3_Err != nil { | |
| 354 | + | return templ_7745c5c3_Err | |
| 355 | + | } | |
| 356 | + | return nil | |
| 357 | + | }) | |
| 358 | + | } | |
| 359 | + | ||
| 360 | + | func HistorySummary(data historyRenderData) templ.Component { | |
| 361 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 362 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 363 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |
| 364 | + | return templ_7745c5c3_CtxErr | |
| 365 | + | } | |
| 366 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 367 | + | if !templ_7745c5c3_IsBuffer { | |
| 368 | + | defer func() { | |
| 369 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 370 | + | if templ_7745c5c3_Err == nil { | |
| 371 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 372 | + | } | |
| 373 | + | }() | |
| 374 | + | } | |
| 375 | + | ctx = templ.InitializeContext(ctx) | |
| 376 | + | templ_7745c5c3_Var18 := templ.GetChildren(ctx) | |
| 377 | + | if templ_7745c5c3_Var18 == nil { | |
| 378 | + | templ_7745c5c3_Var18 = templ.NopComponent | |
| 379 | + | } | |
| 380 | + | ctx = templ.ClearChildren(ctx) | |
| 381 | + | entries, visits, days := historySummaryValues(data) | |
| 382 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "<div class=\"sv-stat-grid\">") | |
| 383 | + | if templ_7745c5c3_Err != nil { | |
| 384 | + | return templ_7745c5c3_Err | |
| 385 | + | } | |
| 386 | + | templ_7745c5c3_Err = HistoryStatCard("Entries", entries).Render(ctx, templ_7745c5c3_Buffer) | |
| 387 | + | if templ_7745c5c3_Err != nil { | |
| 388 | + | return templ_7745c5c3_Err | |
| 389 | + | } | |
| 390 | + | templ_7745c5c3_Err = HistoryStatCard("Visits", visits).Render(ctx, templ_7745c5c3_Buffer) | |
| 391 | + | if templ_7745c5c3_Err != nil { | |
| 392 | + | return templ_7745c5c3_Err | |
| 393 | + | } | |
| 394 | + | templ_7745c5c3_Err = HistoryStatCard("Days", days).Render(ctx, templ_7745c5c3_Buffer) | |
| 395 | + | if templ_7745c5c3_Err != nil { | |
| 396 | + | return templ_7745c5c3_Err | |
| 397 | + | } | |
| 398 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</div>") | |
| 399 | + | if templ_7745c5c3_Err != nil { | |
| 400 | + | return templ_7745c5c3_Err | |
| 401 | + | } | |
| 402 | + | return nil | |
| 403 | + | }) | |
| 404 | + | } | |
| 405 | + | ||
| 406 | + | func HistoryStatCard(label string, value int64) templ.Component { | |
| 407 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 408 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 409 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |
| 410 | + | return templ_7745c5c3_CtxErr | |
| 411 | + | } | |
| 412 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 413 | + | if !templ_7745c5c3_IsBuffer { | |
| 414 | + | defer func() { | |
| 415 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 416 | + | if templ_7745c5c3_Err == nil { | |
| 417 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 418 | + | } | |
| 419 | + | }() | |
| 420 | + | } | |
| 421 | + | ctx = templ.InitializeContext(ctx) | |
| 422 | + | templ_7745c5c3_Var19 := templ.GetChildren(ctx) | |
| 423 | + | if templ_7745c5c3_Var19 == nil { | |
| 424 | + | templ_7745c5c3_Var19 = templ.NopComponent | |
| 425 | + | } | |
| 426 | + | ctx = templ.ClearChildren(ctx) | |
| 427 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "<div class=\"sv-stat-card\"><span class=\"sv-stat-value\">") | |
| 428 | + | if templ_7745c5c3_Err != nil { | |
| 429 | + | return templ_7745c5c3_Err | |
| 430 | + | } | |
| 431 | + | var templ_7745c5c3_Var20 string | |
| 432 | + | templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", value)) | |
| 433 | + | if templ_7745c5c3_Err != nil { | |
| 434 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 70, Col: 81} | |
| 435 | + | } | |
| 436 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) | |
| 437 | + | if templ_7745c5c3_Err != nil { | |
| 438 | + | return templ_7745c5c3_Err | |
| 439 | + | } | |
| 440 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "</span><span class=\"sv-stat-label\">") | |
| 441 | + | if templ_7745c5c3_Err != nil { | |
| 442 | + | return templ_7745c5c3_Err | |
| 443 | + | } | |
| 444 | + | var templ_7745c5c3_Var21 string | |
| 445 | + | templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(label) | |
| 446 | + | if templ_7745c5c3_Err != nil { | |
| 447 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 70, Col: 125} | |
| 448 | + | } | |
| 449 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21)) | |
| 450 | + | if templ_7745c5c3_Err != nil { | |
| 451 | + | return templ_7745c5c3_Err | |
| 452 | + | } | |
| 453 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "</span></div>") | |
| 454 | + | if templ_7745c5c3_Err != nil { | |
| 455 | + | return templ_7745c5c3_Err | |
| 456 | + | } | |
| 457 | + | return nil | |
| 458 | + | }) | |
| 459 | + | } | |
| 460 | + | ||
| 461 | + | func HistoryDomains(data historyRenderData) templ.Component { | |
| 462 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 463 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 464 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |
| 465 | + | return templ_7745c5c3_CtxErr | |
| 466 | + | } | |
| 467 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 468 | + | if !templ_7745c5c3_IsBuffer { | |
| 469 | + | defer func() { | |
| 470 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 471 | + | if templ_7745c5c3_Err == nil { | |
| 472 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 473 | + | } | |
| 474 | + | }() | |
| 475 | + | } | |
| 476 | + | ctx = templ.InitializeContext(ctx) | |
| 477 | + | templ_7745c5c3_Var22 := templ.GetChildren(ctx) | |
| 478 | + | if templ_7745c5c3_Var22 == nil { | |
| 479 | + | templ_7745c5c3_Var22 = templ.NopComponent | |
| 480 | + | } | |
| 481 | + | ctx = templ.ClearChildren(ctx) | |
| 482 | + | if len(data.Domains) == 0 { | |
| 483 | + | templ_7745c5c3_Err = EmptyState("No domain statistics yet").Render(ctx, templ_7745c5c3_Buffer) | |
| 484 | + | if templ_7745c5c3_Err != nil { | |
| 485 | + | return templ_7745c5c3_Err | |
| 486 | + | } | |
| 487 | + | } else { | |
| 488 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<div class=\"sv-domain-list\">") | |
| 489 | + | if templ_7745c5c3_Err != nil { | |
| 490 | + | return templ_7745c5c3_Err | |
| 491 | + | } | |
| 492 | + | for _, domain := range data.Domains { | |
| 493 | + | if domain != nil && domain.Domain != "" { | |
| 494 | + | displayDomain := displayHistoryDomain(domain.Domain) | |
| 495 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "<span class=\"sv-domain-chip\"><button type=\"button\" class=\"sv-domain-filter\" data-sv-action=\"history.filterDomain\" data-domain=\"") | |
| 496 | + | if templ_7745c5c3_Err != nil { | |
| 497 | + | return templ_7745c5c3_Err | |
| 498 | + | } | |
| 499 | + | var templ_7745c5c3_Var23 string | |
| 500 | + | templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(displayDomain) | |
| 501 | + | if templ_7745c5c3_Err != nil { | |
| 502 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 82, Col: 118} | |
| 503 | + | } | |
| 504 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) | |
| 505 | + | if templ_7745c5c3_Err != nil { | |
| 506 | + | return templ_7745c5c3_Err | |
| 507 | + | } | |
| 508 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "\">") | |
| 509 | + | if templ_7745c5c3_Err != nil { | |
| 510 | + | return templ_7745c5c3_Err | |
| 511 | + | } | |
| 512 | + | var templ_7745c5c3_Var24 string | |
| 513 | + | templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(displayDomain) | |
| 514 | + | if templ_7745c5c3_Err != nil { | |
| 515 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 82, Col: 136} | |
| 516 | + | } | |
| 517 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24)) | |
| 518 | + | if templ_7745c5c3_Err != nil { | |
| 519 | + | return templ_7745c5c3_Err | |
| 520 | + | } | |
| 521 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "</button> <span class=\"sv-domain-meta\">") | |
| 522 | + | if templ_7745c5c3_Err != nil { | |
| 523 | + | return templ_7745c5c3_Err | |
| 524 | + | } | |
| 525 | + | var templ_7745c5c3_Var25 string | |
| 526 | + | templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d pages · %d visits", domain.PageCount, domain.TotalVisits)) | |
| 527 | + | if templ_7745c5c3_Err != nil { | |
| 528 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 83, Col: 111} | |
| 529 | + | } | |
| 530 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) | |
| 531 | + | if templ_7745c5c3_Err != nil { | |
| 532 | + | return templ_7745c5c3_Err | |
| 533 | + | } | |
| 534 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "</span> <button type=\"button\" class=\"sv-icon-button sv-danger\" data-sv-action=\"history.deleteDomain\" data-domain=\"") | |
| 535 | + | if templ_7745c5c3_Err != nil { | |
| 536 | + | return templ_7745c5c3_Err | |
| 537 | + | } | |
| 538 | + | var templ_7745c5c3_Var26 string | |
| 539 | + | templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(displayDomain) | |
| 540 | + | if templ_7745c5c3_Err != nil { | |
| 541 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 84, Col: 126} | |
| 542 | + | } | |
| 543 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) | |
| 544 | + | if templ_7745c5c3_Err != nil { | |
| 545 | + | return templ_7745c5c3_Err | |
| 546 | + | } | |
| 547 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "\" data-sv-confirm=\"") | |
| 548 | + | if templ_7745c5c3_Err != nil { | |
| 549 | + | return templ_7745c5c3_Err | |
| 550 | + | } | |
| 551 | + | var templ_7745c5c3_Var27 string | |
| 552 | + | templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs("Delete all history for " + displayDomain + "?") | |
| 553 | + | if templ_7745c5c3_Err != nil { | |
| 554 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 84, Col: 194} | |
| 555 | + | } | |
| 556 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) | |
| 557 | + | if templ_7745c5c3_Err != nil { | |
| 558 | + | return templ_7745c5c3_Err | |
| 559 | + | } | |
| 560 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "\" aria-label=\"") | |
| 561 | + | if templ_7745c5c3_Err != nil { | |
| 562 | + | return templ_7745c5c3_Err | |
| 563 | + | } | |
| 564 | + | var templ_7745c5c3_Var28 string | |
| 565 | + | templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs("Delete history for " + displayDomain) | |
| 566 | + | if templ_7745c5c3_Err != nil { | |
| 567 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 84, Col: 247} | |
| 568 | + | } | |
| 569 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28)) | |
| 570 | + | if templ_7745c5c3_Err != nil { | |
| 571 | + | return templ_7745c5c3_Err | |
| 572 | + | } | |
| 573 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "\">×</button></span>") | |
| 574 | + | if templ_7745c5c3_Err != nil { | |
| 575 | + | return templ_7745c5c3_Err | |
| 576 | + | } | |
| 577 | + | } | |
| 578 | + | } | |
| 579 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "</div>") | |
| 580 | + | if templ_7745c5c3_Err != nil { | |
| 581 | + | return templ_7745c5c3_Err | |
| 582 | + | } | |
| 583 | + | } | |
| 584 | + | return nil | |
| 585 | + | }) | |
| 586 | + | } | |
| 587 | + | ||
| 588 | + | func HistoryTimeline(data historyRenderData) templ.Component { | |
| 589 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 590 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 591 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |
| 592 | + | return templ_7745c5c3_CtxErr | |
| 593 | + | } | |
| 594 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 595 | + | if !templ_7745c5c3_IsBuffer { | |
| 596 | + | defer func() { | |
| 597 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 598 | + | if templ_7745c5c3_Err == nil { | |
| 599 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 600 | + | } | |
| 601 | + | }() | |
| 602 | + | } | |
| 603 | + | ctx = templ.InitializeContext(ctx) | |
| 604 | + | templ_7745c5c3_Var29 := templ.GetChildren(ctx) | |
| 605 | + | if templ_7745c5c3_Var29 == nil { | |
| 606 | + | templ_7745c5c3_Var29 = templ.NopComponent | |
| 607 | + | } | |
| 608 | + | ctx = templ.ClearChildren(ctx) | |
| 609 | + | groups := groupHistoryEntries(data.Entries) | |
| 610 | + | if len(groups) == 0 { | |
| 611 | + | templ_7745c5c3_Err = EmptyState(historyTimelineEmptyMessage(data)).Render(ctx, templ_7745c5c3_Buffer) | |
| 612 | + | if templ_7745c5c3_Err != nil { | |
| 613 | + | return templ_7745c5c3_Err | |
| 614 | + | } | |
| 615 | + | } else { | |
| 616 | + | for _, group := range groups { | |
| 617 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "<section class=\"sv-timeline-group\"><h3>") | |
| 618 | + | if templ_7745c5c3_Err != nil { | |
| 619 | + | return templ_7745c5c3_Err | |
| 620 | + | } | |
| 621 | + | var templ_7745c5c3_Var30 string | |
| 622 | + | templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(group.Label) | |
| 623 | + | if templ_7745c5c3_Err != nil { | |
| 624 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 99, Col: 21} | |
| 625 | + | } | |
| 626 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) | |
| 627 | + | if templ_7745c5c3_Err != nil { | |
| 628 | + | return templ_7745c5c3_Err | |
| 629 | + | } | |
| 630 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "</h3><ul class=\"sv-list\">") | |
| 631 | + | if templ_7745c5c3_Err != nil { | |
| 632 | + | return templ_7745c5c3_Err | |
| 633 | + | } | |
| 634 | + | for _, entry := range group.Entries { | |
| 635 | + | if entry != nil { | |
| 636 | + | templ_7745c5c3_Err = HistoryItem(entry).Render(ctx, templ_7745c5c3_Buffer) | |
| 637 | + | if templ_7745c5c3_Err != nil { | |
| 638 | + | return templ_7745c5c3_Err | |
| 639 | + | } | |
| 640 | + | } | |
| 641 | + | } | |
| 642 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "</ul></section>") | |
| 643 | + | if templ_7745c5c3_Err != nil { | |
| 644 | + | return templ_7745c5c3_Err | |
| 645 | + | } | |
| 646 | + | } | |
| 647 | + | } | |
| 648 | + | return nil | |
| 649 | + | }) | |
| 650 | + | } | |
| 651 | + | ||
| 652 | + | func HistoryItem(entry *entity.HistoryEntry) templ.Component { | |
| 653 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |
| 654 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |
| 655 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |
| 656 | + | return templ_7745c5c3_CtxErr | |
| 657 | + | } | |
| 658 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |
| 659 | + | if !templ_7745c5c3_IsBuffer { | |
| 660 | + | defer func() { | |
| 661 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |
| 662 | + | if templ_7745c5c3_Err == nil { | |
| 663 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |
| 664 | + | } | |
| 665 | + | }() | |
| 666 | + | } | |
| 667 | + | ctx = templ.InitializeContext(ctx) | |
| 668 | + | templ_7745c5c3_Var31 := templ.GetChildren(ctx) | |
| 669 | + | if templ_7745c5c3_Var31 == nil { | |
| 670 | + | templ_7745c5c3_Var31 = templ.NopComponent | |
| 671 | + | } | |
| 672 | + | ctx = templ.ClearChildren(ctx) | |
| 673 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "<li class=\"sv-list-row\"><article class=\"sv-history-item\" data-sv-history-row data-history-id=\"") | |
| 674 | + | if templ_7745c5c3_Err != nil { | |
| 675 | + | return templ_7745c5c3_Err | |
| 676 | + | } | |
| 677 | + | var templ_7745c5c3_Var32 string | |
| 678 | + | templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", entry.ID)) | |
| 679 | + | if templ_7745c5c3_Err != nil { | |
| 680 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 114, Col: 100} | |
| 681 | + | } | |
| 682 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) | |
| 683 | + | if templ_7745c5c3_Err != nil { | |
| 684 | + | return templ_7745c5c3_Err | |
| 685 | + | } | |
| 686 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "\"><div class=\"sv-history-main\"><a class=\"sv-link sv-history-open\" href=\"") | |
| 687 | + | if templ_7745c5c3_Err != nil { | |
| 688 | + | return templ_7745c5c3_Err | |
| 689 | + | } | |
| 690 | + | var templ_7745c5c3_Var33 templ.SafeURL | |
| 691 | + | templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(sanitizeHref(entry.URL))) | |
| 692 | + | if templ_7745c5c3_Err != nil { | |
| 693 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 116, Col: 84} | |
| 694 | + | } | |
| 695 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33)) | |
| 696 | + | if templ_7745c5c3_Err != nil { | |
| 697 | + | return templ_7745c5c3_Err | |
| 698 | + | } | |
| 699 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "\">") | |
| 700 | + | if templ_7745c5c3_Err != nil { | |
| 701 | + | return templ_7745c5c3_Err | |
| 702 | + | } | |
| 703 | + | var templ_7745c5c3_Var34 string | |
| 704 | + | templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(historyItemLabel(entry)) | |
| 705 | + | if templ_7745c5c3_Err != nil { | |
| 706 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 116, Col: 112} | |
| 707 | + | } | |
| 708 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34)) | |
| 709 | + | if templ_7745c5c3_Err != nil { | |
| 710 | + | return templ_7745c5c3_Err | |
| 711 | + | } | |
| 712 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "</a><p class=\"sv-history-url\">") | |
| 713 | + | if templ_7745c5c3_Err != nil { | |
| 714 | + | return templ_7745c5c3_Err | |
| 715 | + | } | |
| 716 | + | var templ_7745c5c3_Var35 string | |
| 717 | + | templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(entry.URL) | |
| 718 | + | if templ_7745c5c3_Err != nil { | |
| 719 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 117, Col: 41} | |
| 720 | + | } | |
| 721 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35)) | |
| 722 | + | if templ_7745c5c3_Err != nil { | |
| 723 | + | return templ_7745c5c3_Err | |
| 724 | + | } | |
| 725 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "</p><p class=\"sv-history-meta\">") | |
| 726 | + | if templ_7745c5c3_Err != nil { | |
| 727 | + | return templ_7745c5c3_Err | |
| 728 | + | } | |
| 729 | + | var templ_7745c5c3_Var36 string | |
| 730 | + | templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(historyItemMeta(entry)) | |
| 731 | + | if templ_7745c5c3_Err != nil { | |
| 732 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 118, Col: 55} | |
| 733 | + | } | |
| 734 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36)) | |
| 735 | + | if templ_7745c5c3_Err != nil { | |
| 736 | + | return templ_7745c5c3_Err | |
| 737 | + | } | |
| 738 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "</p></div><div class=\"sv-history-row-actions\"><a class=\"sv-button sv-button-secondary\" href=\"") | |
| 739 | + | if templ_7745c5c3_Err != nil { | |
| 740 | + | return templ_7745c5c3_Err | |
| 741 | + | } | |
| 742 | + | var templ_7745c5c3_Var37 templ.SafeURL | |
| 743 | + | templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(sanitizeHref(entry.URL))) | |
| 744 | + | if templ_7745c5c3_Err != nil { | |
| 745 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 121, Col: 90} | |
| 746 | + | } | |
| 747 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37)) | |
| 748 | + | if templ_7745c5c3_Err != nil { | |
| 749 | + | return templ_7745c5c3_Err | |
| 750 | + | } | |
| 751 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "\">Open</a> <button type=\"button\" class=\"sv-button sv-button-secondary sv-button-danger\" data-sv-action=\"history.deleteEntry\" data-id=\"") | |
| 752 | + | if templ_7745c5c3_Err != nil { | |
| 753 | + | return templ_7745c5c3_Err | |
| 754 | + | } | |
| 755 | + | var templ_7745c5c3_Var38 string | |
| 756 | + | templ_7745c5c3_Var38, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", entry.ID)) | |
| 757 | + | if templ_7745c5c3_Err != nil { | |
| 758 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 122, Col: 155} | |
| 759 | + | } | |
| 760 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var38)) | |
| 761 | + | if templ_7745c5c3_Err != nil { | |
| 762 | + | return templ_7745c5c3_Err | |
| 763 | + | } | |
| 764 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "\" data-sv-confirm=\"Delete this history entry?\"") | |
| 765 | + | if templ_7745c5c3_Err != nil { | |
| 766 | + | return templ_7745c5c3_Err | |
| 767 | + | } | |
| 768 | + | if entry.ID <= 0 { | |
| 769 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, " disabled") | |
| 770 | + | if templ_7745c5c3_Err != nil { | |
| 771 | + | return templ_7745c5c3_Err | |
| 772 | + | } | |
| 773 | + | } | |
| 774 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, ">Delete</button></div></article></li>") | |
| 775 | + | if templ_7745c5c3_Err != nil { | |
| 776 | + | return templ_7745c5c3_Err | |
| 777 | + | } | |
| 778 | + | return nil | |
| 779 | + | }) | |
| 780 | + | } | |
| 781 | + | ||
| 782 | + | var _ = templruntime.GeneratedTemplate | |
| @@ -0,0 +1,782 @@ | |||||
| 1 | + | // Code generated by templ - DO NOT EDIT. | |||
| 2 | + | ||||
| 3 | + | package systemviews | |||
| 4 | + | ||||
| 5 | + | //lint:file-ignore SA4006 This context is only used if a nested component is present. | |||
| 6 | + | ||||
| 7 | + | import "github.com/a-h/templ" | |||
| 8 | + | import templruntime "github.com/a-h/templ/runtime" | |||
| 9 | + | ||||
| 10 | + | import ( | |||
| 11 | + | "fmt" | |||
| 12 | + | "github.com/bnema/dumber/internal/domain/entity" | |||
| 13 | + | ) | |||
| 14 | + | ||||
| 15 | + | func HistoryView(data historyRenderData) templ.Component { | |||
| 16 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 17 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 18 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |||
| 19 | + | return templ_7745c5c3_CtxErr | |||
| 20 | + | } | |||
| 21 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 22 | + | if !templ_7745c5c3_IsBuffer { | |||
| 23 | + | defer func() { | |||
| 24 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 25 | + | if templ_7745c5c3_Err == nil { | |||
| 26 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 27 | + | } | |||
| 28 | + | }() | |||
| 29 | + | } | |||
| 30 | + | ctx = templ.InitializeContext(ctx) | |||
| 31 | + | templ_7745c5c3_Var1 := templ.GetChildren(ctx) | |||
| 32 | + | if templ_7745c5c3_Var1 == nil { | |||
| 33 | + | templ_7745c5c3_Var1 = templ.NopComponent | |||
| 34 | + | } | |||
| 35 | + | ctx = templ.ClearChildren(ctx) | |||
| 36 | + | templ_7745c5c3_Err = Alert("success", data.Notice).Render(ctx, templ_7745c5c3_Buffer) | |||
| 37 | + | if templ_7745c5c3_Err != nil { | |||
| 38 | + | return templ_7745c5c3_Err | |||
| 39 | + | } | |||
| 40 | + | templ_7745c5c3_Err = Alert("error", data.Error).Render(ctx, templ_7745c5c3_Buffer) | |||
| 41 | + | if templ_7745c5c3_Err != nil { | |||
| 42 | + | return templ_7745c5c3_Err | |||
| 43 | + | } | |||
| 44 | + | templ_7745c5c3_Var2 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 45 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 46 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 47 | + | if !templ_7745c5c3_IsBuffer { | |||
| 48 | + | defer func() { | |||
| 49 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 50 | + | if templ_7745c5c3_Err == nil { | |||
| 51 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 52 | + | } | |||
| 53 | + | }() | |||
| 54 | + | } | |||
| 55 | + | ctx = templ.InitializeContext(ctx) | |||
| 56 | + | templ_7745c5c3_Err = HistoryControls(data).Render(ctx, templ_7745c5c3_Buffer) | |||
| 57 | + | if templ_7745c5c3_Err != nil { | |||
| 58 | + | return templ_7745c5c3_Err | |||
| 59 | + | } | |||
| 60 | + | return nil | |||
| 61 | + | }) | |||
| 62 | + | templ_7745c5c3_Err = Section("sv-history-controls", "Manage history").Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer) | |||
| 63 | + | if templ_7745c5c3_Err != nil { | |||
| 64 | + | return templ_7745c5c3_Err | |||
| 65 | + | } | |||
| 66 | + | templ_7745c5c3_Var3 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 67 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 68 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 69 | + | if !templ_7745c5c3_IsBuffer { | |||
| 70 | + | defer func() { | |||
| 71 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 72 | + | if templ_7745c5c3_Err == nil { | |||
| 73 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 74 | + | } | |||
| 75 | + | }() | |||
| 76 | + | } | |||
| 77 | + | ctx = templ.InitializeContext(ctx) | |||
| 78 | + | templ_7745c5c3_Err = HistorySummary(data).Render(ctx, templ_7745c5c3_Buffer) | |||
| 79 | + | if templ_7745c5c3_Err != nil { | |||
| 80 | + | return templ_7745c5c3_Err | |||
| 81 | + | } | |||
| 82 | + | return nil | |||
| 83 | + | }) | |||
| 84 | + | templ_7745c5c3_Err = Section("sv-history-summary", "History").Render(templ.WithChildren(ctx, templ_7745c5c3_Var3), templ_7745c5c3_Buffer) | |||
| 85 | + | if templ_7745c5c3_Err != nil { | |||
| 86 | + | return templ_7745c5c3_Err | |||
| 87 | + | } | |||
| 88 | + | templ_7745c5c3_Var4 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 89 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 90 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 91 | + | if !templ_7745c5c3_IsBuffer { | |||
| 92 | + | defer func() { | |||
| 93 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 94 | + | if templ_7745c5c3_Err == nil { | |||
| 95 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 96 | + | } | |||
| 97 | + | }() | |||
| 98 | + | } | |||
| 99 | + | ctx = templ.InitializeContext(ctx) | |||
| 100 | + | templ_7745c5c3_Err = HistoryDomains(data).Render(ctx, templ_7745c5c3_Buffer) | |||
| 101 | + | if templ_7745c5c3_Err != nil { | |||
| 102 | + | return templ_7745c5c3_Err | |||
| 103 | + | } | |||
| 104 | + | return nil | |||
| 105 | + | }) | |||
| 106 | + | templ_7745c5c3_Err = Section("sv-history-domains", "Top domains").Render(templ.WithChildren(ctx, templ_7745c5c3_Var4), templ_7745c5c3_Buffer) | |||
| 107 | + | if templ_7745c5c3_Err != nil { | |||
| 108 | + | return templ_7745c5c3_Err | |||
| 109 | + | } | |||
| 110 | + | templ_7745c5c3_Var5 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 111 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 112 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 113 | + | if !templ_7745c5c3_IsBuffer { | |||
| 114 | + | defer func() { | |||
| 115 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 116 | + | if templ_7745c5c3_Err == nil { | |||
| 117 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 118 | + | } | |||
| 119 | + | }() | |||
| 120 | + | } | |||
| 121 | + | ctx = templ.InitializeContext(ctx) | |||
| 122 | + | templ_7745c5c3_Err = HistoryTimeline(data).Render(ctx, templ_7745c5c3_Buffer) | |||
| 123 | + | if templ_7745c5c3_Err != nil { | |||
| 124 | + | return templ_7745c5c3_Err | |||
| 125 | + | } | |||
| 126 | + | return nil | |||
| 127 | + | }) | |||
| 128 | + | templ_7745c5c3_Err = Section("sv-history-timeline", "Recent visits").Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer) | |||
| 129 | + | if templ_7745c5c3_Err != nil { | |||
| 130 | + | return templ_7745c5c3_Err | |||
| 131 | + | } | |||
| 132 | + | return nil | |||
| 133 | + | }) | |||
| 134 | + | } | |||
| 135 | + | ||||
| 136 | + | func HistoryControls(data historyRenderData) templ.Component { | |||
| 137 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 138 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 139 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |||
| 140 | + | return templ_7745c5c3_CtxErr | |||
| 141 | + | } | |||
| 142 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 143 | + | if !templ_7745c5c3_IsBuffer { | |||
| 144 | + | defer func() { | |||
| 145 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 146 | + | if templ_7745c5c3_Err == nil { | |||
| 147 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 148 | + | } | |||
| 149 | + | }() | |||
| 150 | + | } | |||
| 151 | + | ctx = templ.InitializeContext(ctx) | |||
| 152 | + | templ_7745c5c3_Var6 := templ.GetChildren(ctx) | |||
| 153 | + | if templ_7745c5c3_Var6 == nil { | |||
| 154 | + | templ_7745c5c3_Var6 = templ.NopComponent | |||
| 155 | + | } | |||
| 156 | + | ctx = templ.ClearChildren(ctx) | |||
| 157 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<form class=\"sv-toolbar sv-history-search\" data-sv-action=\"history.search\"><label class=\"sv-search-label\"><span>Search</span> <input data-sv-history-search name=\"query\" type=\"search\" value=\"") | |||
| 158 | + | if templ_7745c5c3_Err != nil { | |||
| 159 | + | return templ_7745c5c3_Err | |||
| 160 | + | } | |||
| 161 | + | var templ_7745c5c3_Var7 string | |||
| 162 | + | templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(data.Query) | |||
| 163 | + | if templ_7745c5c3_Err != nil { | |||
| 164 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 29, Col: 78} | |||
| 165 | + | } | |||
| 166 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) | |||
| 167 | + | if templ_7745c5c3_Err != nil { | |||
| 168 | + | return templ_7745c5c3_Err | |||
| 169 | + | } | |||
| 170 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\" placeholder=\"Search title or URL\" autocomplete=\"off\"></label> <button class=\"sv-button\" type=\"submit\">Search</button> <button class=\"sv-button sv-button-secondary\" type=\"button\" data-sv-action=\"history.clear\">Clear</button></form>") | |||
| 171 | + | if templ_7745c5c3_Err != nil { | |||
| 172 | + | return templ_7745c5c3_Err | |||
| 173 | + | } | |||
| 174 | + | if showHistoryFilters(data) { | |||
| 175 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<div class=\"sv-active-filters\">") | |||
| 176 | + | if templ_7745c5c3_Err != nil { | |||
| 177 | + | return templ_7745c5c3_Err | |||
| 178 | + | } | |||
| 179 | + | if data.Query != "" { | |||
| 180 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<span class=\"sv-filter-chip\">Query: ") | |||
| 181 | + | if templ_7745c5c3_Err != nil { | |||
| 182 | + | return templ_7745c5c3_Err | |||
| 183 | + | } | |||
| 184 | + | var templ_7745c5c3_Var8 string | |||
| 185 | + | templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(data.Query) | |||
| 186 | + | if templ_7745c5c3_Err != nil { | |||
| 187 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 37, Col: 52} | |||
| 188 | + | } | |||
| 189 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) | |||
| 190 | + | if templ_7745c5c3_Err != nil { | |||
| 191 | + | return templ_7745c5c3_Err | |||
| 192 | + | } | |||
| 193 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</span> ") | |||
| 194 | + | if templ_7745c5c3_Err != nil { | |||
| 195 | + | return templ_7745c5c3_Err | |||
| 196 | + | } | |||
| 197 | + | } | |||
| 198 | + | if data.DomainFilter != "" { | |||
| 199 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<span class=\"sv-filter-chip\">Domain: ") | |||
| 200 | + | if templ_7745c5c3_Err != nil { | |||
| 201 | + | return templ_7745c5c3_Err | |||
| 202 | + | } | |||
| 203 | + | var templ_7745c5c3_Var9 string | |||
| 204 | + | templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(data.DomainFilter) | |||
| 205 | + | if templ_7745c5c3_Err != nil { | |||
| 206 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 40, Col: 60} | |||
| 207 | + | } | |||
| 208 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) | |||
| 209 | + | if templ_7745c5c3_Err != nil { | |||
| 210 | + | return templ_7745c5c3_Err | |||
| 211 | + | } | |||
| 212 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " <button type=\"button\" data-sv-action=\"history.clearDomain\" aria-label=\"Clear domain filter\">×</button></span>") | |||
| 213 | + | if templ_7745c5c3_Err != nil { | |||
| 214 | + | return templ_7745c5c3_Err | |||
| 215 | + | } | |||
| 216 | + | } | |||
| 217 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "</div>") | |||
| 218 | + | if templ_7745c5c3_Err != nil { | |||
| 219 | + | return templ_7745c5c3_Err | |||
| 220 | + | } | |||
| 221 | + | } | |||
| 222 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "<div class=\"sv-history-actions-panel\"><div class=\"sv-button-row\" aria-label=\"History pagination\"><button type=\"button\" class=\"sv-button sv-button-secondary\" data-sv-action=\"history.page\" data-offset=\"") | |||
| 223 | + | if templ_7745c5c3_Err != nil { | |||
| 224 | + | return templ_7745c5c3_Err | |||
| 225 | + | } | |||
| 226 | + | var templ_7745c5c3_Var10 string | |||
| 227 | + | templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", previousHistoryOffset(data))) | |||
| 228 | + | if templ_7745c5c3_Err != nil { | |||
| 229 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 46, Col: 153} | |||
| 230 | + | } | |||
| 231 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) | |||
| 232 | + | if templ_7745c5c3_Err != nil { | |||
| 233 | + | return templ_7745c5c3_Err | |||
| 234 | + | } | |||
| 235 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\"") | |||
| 236 | + | if templ_7745c5c3_Err != nil { | |||
| 237 | + | return templ_7745c5c3_Err | |||
| 238 | + | } | |||
| 239 | + | if disableHistoryPrev(data) { | |||
| 240 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, " disabled") | |||
| 241 | + | if templ_7745c5c3_Err != nil { | |||
| 242 | + | return templ_7745c5c3_Err | |||
| 243 | + | } | |||
| 244 | + | } | |||
| 245 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, ">Previous</button> <span class=\"sv-meta\">Showing ") | |||
| 246 | + | if templ_7745c5c3_Err != nil { | |||
| 247 | + | return templ_7745c5c3_Err | |||
| 248 | + | } | |||
| 249 | + | var templ_7745c5c3_Var11 string | |||
| 250 | + | templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", countHistoryEntries(data.Entries))) | |||
| 251 | + | if templ_7745c5c3_Err != nil { | |||
| 252 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 47, Col: 87} | |||
| 253 | + | } | |||
| 254 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) | |||
| 255 | + | if templ_7745c5c3_Err != nil { | |||
| 256 | + | return templ_7745c5c3_Err | |||
| 257 | + | } | |||
| 258 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, " item") | |||
| 259 | + | if templ_7745c5c3_Err != nil { | |||
| 260 | + | return templ_7745c5c3_Err | |||
| 261 | + | } | |||
| 262 | + | var templ_7745c5c3_Var12 string | |||
| 263 | + | templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(pluralSuffix(countHistoryEntries(data.Entries))) | |||
| 264 | + | if templ_7745c5c3_Err != nil { | |||
| 265 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 47, Col: 143} | |||
| 266 | + | } | |||
| 267 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) | |||
| 268 | + | if templ_7745c5c3_Err != nil { | |||
| 269 | + | return templ_7745c5c3_Err | |||
| 270 | + | } | |||
| 271 | + | var templ_7745c5c3_Var13 string | |||
| 272 | + | templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(historyOffsetLabel(data.Offset, data.Query)) | |||
| 273 | + | if templ_7745c5c3_Err != nil { | |||
| 274 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 47, Col: 190} | |||
| 275 | + | } | |||
| 276 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) | |||
| 277 | + | if templ_7745c5c3_Err != nil { | |||
| 278 | + | return templ_7745c5c3_Err | |||
| 279 | + | } | |||
| 280 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</span> <button type=\"button\" class=\"sv-button sv-button-secondary\" data-sv-action=\"history.page\" data-offset=\"") | |||
| 281 | + | if templ_7745c5c3_Err != nil { | |||
| 282 | + | return templ_7745c5c3_Err | |||
| 283 | + | } | |||
| 284 | + | var templ_7745c5c3_Var14 string | |||
| 285 | + | templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", nextHistoryOffset(data))) | |||
| 286 | + | if templ_7745c5c3_Err != nil { | |||
| 287 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 48, Col: 149} | |||
| 288 | + | } | |||
| 289 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14)) | |||
| 290 | + | if templ_7745c5c3_Err != nil { | |||
| 291 | + | return templ_7745c5c3_Err | |||
| 292 | + | } | |||
| 293 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "\"") | |||
| 294 | + | if templ_7745c5c3_Err != nil { | |||
| 295 | + | return templ_7745c5c3_Err | |||
| 296 | + | } | |||
| 297 | + | if disableHistoryNext(data) { | |||
| 298 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, " disabled") | |||
| 299 | + | if templ_7745c5c3_Err != nil { | |||
| 300 | + | return templ_7745c5c3_Err | |||
| 301 | + | } | |||
| 302 | + | } | |||
| 303 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, ">Next</button></div><div class=\"sv-button-row\" aria-label=\"History cleanup\"><span class=\"sv-meta\">Clean up</span> ") | |||
| 304 | + | if templ_7745c5c3_Err != nil { | |||
| 305 | + | return templ_7745c5c3_Err | |||
| 306 | + | } | |||
| 307 | + | for _, item := range historyCleanupItems() { | |||
| 308 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<button type=\"button\" class=\"sv-button sv-button-secondary sv-button-danger\" data-sv-action=\"history.deleteRange\" data-range=\"") | |||
| 309 | + | if templ_7745c5c3_Err != nil { | |||
| 310 | + | return templ_7745c5c3_Err | |||
| 311 | + | } | |||
| 312 | + | var templ_7745c5c3_Var15 string | |||
| 313 | + | templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(item.RangeID) | |||
| 314 | + | if templ_7745c5c3_Err != nil { | |||
| 315 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 53, Col: 143} | |||
| 316 | + | } | |||
| 317 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) | |||
| 318 | + | if templ_7745c5c3_Err != nil { | |||
| 319 | + | return templ_7745c5c3_Err | |||
| 320 | + | } | |||
| 321 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\" data-sv-confirm=\"") | |||
| 322 | + | if templ_7745c5c3_Err != nil { | |||
| 323 | + | return templ_7745c5c3_Err | |||
| 324 | + | } | |||
| 325 | + | var templ_7745c5c3_Var16 string | |||
| 326 | + | templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(item.Confirm) | |||
| 327 | + | if templ_7745c5c3_Err != nil { | |||
| 328 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 53, Col: 176} | |||
| 329 | + | } | |||
| 330 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16)) | |||
| 331 | + | if templ_7745c5c3_Err != nil { | |||
| 332 | + | return templ_7745c5c3_Err | |||
| 333 | + | } | |||
| 334 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\">") | |||
| 335 | + | if templ_7745c5c3_Err != nil { | |||
| 336 | + | return templ_7745c5c3_Err | |||
| 337 | + | } | |||
| 338 | + | var templ_7745c5c3_Var17 string | |||
| 339 | + | templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(item.Label) | |||
| 340 | + | if templ_7745c5c3_Err != nil { | |||
| 341 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 53, Col: 191} | |||
| 342 | + | } | |||
| 343 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) | |||
| 344 | + | if templ_7745c5c3_Err != nil { | |||
| 345 | + | return templ_7745c5c3_Err | |||
| 346 | + | } | |||
| 347 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "</button>") | |||
| 348 | + | if templ_7745c5c3_Err != nil { | |||
| 349 | + | return templ_7745c5c3_Err | |||
| 350 | + | } | |||
| 351 | + | } | |||
| 352 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "</div></div><p class=\"sv-meta sv-key-hints\">Keys: <kbd>/</kbd> search, <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>d</kbd> delete focused entry.</p>") | |||
| 353 | + | if templ_7745c5c3_Err != nil { | |||
| 354 | + | return templ_7745c5c3_Err | |||
| 355 | + | } | |||
| 356 | + | return nil | |||
| 357 | + | }) | |||
| 358 | + | } | |||
| 359 | + | ||||
| 360 | + | func HistorySummary(data historyRenderData) templ.Component { | |||
| 361 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 362 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 363 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |||
| 364 | + | return templ_7745c5c3_CtxErr | |||
| 365 | + | } | |||
| 366 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 367 | + | if !templ_7745c5c3_IsBuffer { | |||
| 368 | + | defer func() { | |||
| 369 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 370 | + | if templ_7745c5c3_Err == nil { | |||
| 371 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 372 | + | } | |||
| 373 | + | }() | |||
| 374 | + | } | |||
| 375 | + | ctx = templ.InitializeContext(ctx) | |||
| 376 | + | templ_7745c5c3_Var18 := templ.GetChildren(ctx) | |||
| 377 | + | if templ_7745c5c3_Var18 == nil { | |||
| 378 | + | templ_7745c5c3_Var18 = templ.NopComponent | |||
| 379 | + | } | |||
| 380 | + | ctx = templ.ClearChildren(ctx) | |||
| 381 | + | entries, visits, days := historySummaryValues(data) | |||
| 382 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "<div class=\"sv-stat-grid\">") | |||
| 383 | + | if templ_7745c5c3_Err != nil { | |||
| 384 | + | return templ_7745c5c3_Err | |||
| 385 | + | } | |||
| 386 | + | templ_7745c5c3_Err = HistoryStatCard("Entries", entries).Render(ctx, templ_7745c5c3_Buffer) | |||
| 387 | + | if templ_7745c5c3_Err != nil { | |||
| 388 | + | return templ_7745c5c3_Err | |||
| 389 | + | } | |||
| 390 | + | templ_7745c5c3_Err = HistoryStatCard("Visits", visits).Render(ctx, templ_7745c5c3_Buffer) | |||
| 391 | + | if templ_7745c5c3_Err != nil { | |||
| 392 | + | return templ_7745c5c3_Err | |||
| 393 | + | } | |||
| 394 | + | templ_7745c5c3_Err = HistoryStatCard("Days", days).Render(ctx, templ_7745c5c3_Buffer) | |||
| 395 | + | if templ_7745c5c3_Err != nil { | |||
| 396 | + | return templ_7745c5c3_Err | |||
| 397 | + | } | |||
| 398 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</div>") | |||
| 399 | + | if templ_7745c5c3_Err != nil { | |||
| 400 | + | return templ_7745c5c3_Err | |||
| 401 | + | } | |||
| 402 | + | return nil | |||
| 403 | + | }) | |||
| 404 | + | } | |||
| 405 | + | ||||
| 406 | + | func HistoryStatCard(label string, value int64) templ.Component { | |||
| 407 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 408 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 409 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |||
| 410 | + | return templ_7745c5c3_CtxErr | |||
| 411 | + | } | |||
| 412 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 413 | + | if !templ_7745c5c3_IsBuffer { | |||
| 414 | + | defer func() { | |||
| 415 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 416 | + | if templ_7745c5c3_Err == nil { | |||
| 417 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 418 | + | } | |||
| 419 | + | }() | |||
| 420 | + | } | |||
| 421 | + | ctx = templ.InitializeContext(ctx) | |||
| 422 | + | templ_7745c5c3_Var19 := templ.GetChildren(ctx) | |||
| 423 | + | if templ_7745c5c3_Var19 == nil { | |||
| 424 | + | templ_7745c5c3_Var19 = templ.NopComponent | |||
| 425 | + | } | |||
| 426 | + | ctx = templ.ClearChildren(ctx) | |||
| 427 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "<div class=\"sv-stat-card\"><span class=\"sv-stat-value\">") | |||
| 428 | + | if templ_7745c5c3_Err != nil { | |||
| 429 | + | return templ_7745c5c3_Err | |||
| 430 | + | } | |||
| 431 | + | var templ_7745c5c3_Var20 string | |||
| 432 | + | templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", value)) | |||
| 433 | + | if templ_7745c5c3_Err != nil { | |||
| 434 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 70, Col: 81} | |||
| 435 | + | } | |||
| 436 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20)) | |||
| 437 | + | if templ_7745c5c3_Err != nil { | |||
| 438 | + | return templ_7745c5c3_Err | |||
| 439 | + | } | |||
| 440 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "</span><span class=\"sv-stat-label\">") | |||
| 441 | + | if templ_7745c5c3_Err != nil { | |||
| 442 | + | return templ_7745c5c3_Err | |||
| 443 | + | } | |||
| 444 | + | var templ_7745c5c3_Var21 string | |||
| 445 | + | templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(label) | |||
| 446 | + | if templ_7745c5c3_Err != nil { | |||
| 447 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 70, Col: 125} | |||
| 448 | + | } | |||
| 449 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21)) | |||
| 450 | + | if templ_7745c5c3_Err != nil { | |||
| 451 | + | return templ_7745c5c3_Err | |||
| 452 | + | } | |||
| 453 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "</span></div>") | |||
| 454 | + | if templ_7745c5c3_Err != nil { | |||
| 455 | + | return templ_7745c5c3_Err | |||
| 456 | + | } | |||
| 457 | + | return nil | |||
| 458 | + | }) | |||
| 459 | + | } | |||
| 460 | + | ||||
| 461 | + | func HistoryDomains(data historyRenderData) templ.Component { | |||
| 462 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 463 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 464 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |||
| 465 | + | return templ_7745c5c3_CtxErr | |||
| 466 | + | } | |||
| 467 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 468 | + | if !templ_7745c5c3_IsBuffer { | |||
| 469 | + | defer func() { | |||
| 470 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 471 | + | if templ_7745c5c3_Err == nil { | |||
| 472 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 473 | + | } | |||
| 474 | + | }() | |||
| 475 | + | } | |||
| 476 | + | ctx = templ.InitializeContext(ctx) | |||
| 477 | + | templ_7745c5c3_Var22 := templ.GetChildren(ctx) | |||
| 478 | + | if templ_7745c5c3_Var22 == nil { | |||
| 479 | + | templ_7745c5c3_Var22 = templ.NopComponent | |||
| 480 | + | } | |||
| 481 | + | ctx = templ.ClearChildren(ctx) | |||
| 482 | + | if len(data.Domains) == 0 { | |||
| 483 | + | templ_7745c5c3_Err = EmptyState("No domain statistics yet").Render(ctx, templ_7745c5c3_Buffer) | |||
| 484 | + | if templ_7745c5c3_Err != nil { | |||
| 485 | + | return templ_7745c5c3_Err | |||
| 486 | + | } | |||
| 487 | + | } else { | |||
| 488 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<div class=\"sv-domain-list\">") | |||
| 489 | + | if templ_7745c5c3_Err != nil { | |||
| 490 | + | return templ_7745c5c3_Err | |||
| 491 | + | } | |||
| 492 | + | for _, domain := range data.Domains { | |||
| 493 | + | if domain != nil && domain.Domain != "" { | |||
| 494 | + | displayDomain := displayHistoryDomain(domain.Domain) | |||
| 495 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "<span class=\"sv-domain-chip\"><button type=\"button\" class=\"sv-domain-filter\" data-sv-action=\"history.filterDomain\" data-domain=\"") | |||
| 496 | + | if templ_7745c5c3_Err != nil { | |||
| 497 | + | return templ_7745c5c3_Err | |||
| 498 | + | } | |||
| 499 | + | var templ_7745c5c3_Var23 string | |||
| 500 | + | templ_7745c5c3_Var23, templ_7745c5c3_Err = templ.JoinStringErrs(displayDomain) | |||
| 501 | + | if templ_7745c5c3_Err != nil { | |||
| 502 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 82, Col: 118} | |||
| 503 | + | } | |||
| 504 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var23)) | |||
| 505 | + | if templ_7745c5c3_Err != nil { | |||
| 506 | + | return templ_7745c5c3_Err | |||
| 507 | + | } | |||
| 508 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "\">") | |||
| 509 | + | if templ_7745c5c3_Err != nil { | |||
| 510 | + | return templ_7745c5c3_Err | |||
| 511 | + | } | |||
| 512 | + | var templ_7745c5c3_Var24 string | |||
| 513 | + | templ_7745c5c3_Var24, templ_7745c5c3_Err = templ.JoinStringErrs(displayDomain) | |||
| 514 | + | if templ_7745c5c3_Err != nil { | |||
| 515 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 82, Col: 136} | |||
| 516 | + | } | |||
| 517 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var24)) | |||
| 518 | + | if templ_7745c5c3_Err != nil { | |||
| 519 | + | return templ_7745c5c3_Err | |||
| 520 | + | } | |||
| 521 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 31, "</button> <span class=\"sv-domain-meta\">") | |||
| 522 | + | if templ_7745c5c3_Err != nil { | |||
| 523 | + | return templ_7745c5c3_Err | |||
| 524 | + | } | |||
| 525 | + | var templ_7745c5c3_Var25 string | |||
| 526 | + | templ_7745c5c3_Var25, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d pages · %d visits", domain.PageCount, domain.TotalVisits)) | |||
| 527 | + | if templ_7745c5c3_Err != nil { | |||
| 528 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 83, Col: 111} | |||
| 529 | + | } | |||
| 530 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var25)) | |||
| 531 | + | if templ_7745c5c3_Err != nil { | |||
| 532 | + | return templ_7745c5c3_Err | |||
| 533 | + | } | |||
| 534 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 32, "</span> <button type=\"button\" class=\"sv-icon-button sv-danger\" data-sv-action=\"history.deleteDomain\" data-domain=\"") | |||
| 535 | + | if templ_7745c5c3_Err != nil { | |||
| 536 | + | return templ_7745c5c3_Err | |||
| 537 | + | } | |||
| 538 | + | var templ_7745c5c3_Var26 string | |||
| 539 | + | templ_7745c5c3_Var26, templ_7745c5c3_Err = templ.JoinStringErrs(displayDomain) | |||
| 540 | + | if templ_7745c5c3_Err != nil { | |||
| 541 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 84, Col: 126} | |||
| 542 | + | } | |||
| 543 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var26)) | |||
| 544 | + | if templ_7745c5c3_Err != nil { | |||
| 545 | + | return templ_7745c5c3_Err | |||
| 546 | + | } | |||
| 547 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 33, "\" data-sv-confirm=\"") | |||
| 548 | + | if templ_7745c5c3_Err != nil { | |||
| 549 | + | return templ_7745c5c3_Err | |||
| 550 | + | } | |||
| 551 | + | var templ_7745c5c3_Var27 string | |||
| 552 | + | templ_7745c5c3_Var27, templ_7745c5c3_Err = templ.JoinStringErrs("Delete all history for " + displayDomain + "?") | |||
| 553 | + | if templ_7745c5c3_Err != nil { | |||
| 554 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 84, Col: 194} | |||
| 555 | + | } | |||
| 556 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var27)) | |||
| 557 | + | if templ_7745c5c3_Err != nil { | |||
| 558 | + | return templ_7745c5c3_Err | |||
| 559 | + | } | |||
| 560 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 34, "\" aria-label=\"") | |||
| 561 | + | if templ_7745c5c3_Err != nil { | |||
| 562 | + | return templ_7745c5c3_Err | |||
| 563 | + | } | |||
| 564 | + | var templ_7745c5c3_Var28 string | |||
| 565 | + | templ_7745c5c3_Var28, templ_7745c5c3_Err = templ.JoinStringErrs("Delete history for " + displayDomain) | |||
| 566 | + | if templ_7745c5c3_Err != nil { | |||
| 567 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 84, Col: 247} | |||
| 568 | + | } | |||
| 569 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var28)) | |||
| 570 | + | if templ_7745c5c3_Err != nil { | |||
| 571 | + | return templ_7745c5c3_Err | |||
| 572 | + | } | |||
| 573 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 35, "\">×</button></span>") | |||
| 574 | + | if templ_7745c5c3_Err != nil { | |||
| 575 | + | return templ_7745c5c3_Err | |||
| 576 | + | } | |||
| 577 | + | } | |||
| 578 | + | } | |||
| 579 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 36, "</div>") | |||
| 580 | + | if templ_7745c5c3_Err != nil { | |||
| 581 | + | return templ_7745c5c3_Err | |||
| 582 | + | } | |||
| 583 | + | } | |||
| 584 | + | return nil | |||
| 585 | + | }) | |||
| 586 | + | } | |||
| 587 | + | ||||
| 588 | + | func HistoryTimeline(data historyRenderData) templ.Component { | |||
| 589 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 590 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 591 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |||
| 592 | + | return templ_7745c5c3_CtxErr | |||
| 593 | + | } | |||
| 594 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 595 | + | if !templ_7745c5c3_IsBuffer { | |||
| 596 | + | defer func() { | |||
| 597 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 598 | + | if templ_7745c5c3_Err == nil { | |||
| 599 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 600 | + | } | |||
| 601 | + | }() | |||
| 602 | + | } | |||
| 603 | + | ctx = templ.InitializeContext(ctx) | |||
| 604 | + | templ_7745c5c3_Var29 := templ.GetChildren(ctx) | |||
| 605 | + | if templ_7745c5c3_Var29 == nil { | |||
| 606 | + | templ_7745c5c3_Var29 = templ.NopComponent | |||
| 607 | + | } | |||
| 608 | + | ctx = templ.ClearChildren(ctx) | |||
| 609 | + | groups := groupHistoryEntries(data.Entries) | |||
| 610 | + | if len(groups) == 0 { | |||
| 611 | + | templ_7745c5c3_Err = EmptyState(historyTimelineEmptyMessage(data)).Render(ctx, templ_7745c5c3_Buffer) | |||
| 612 | + | if templ_7745c5c3_Err != nil { | |||
| 613 | + | return templ_7745c5c3_Err | |||
| 614 | + | } | |||
| 615 | + | } else { | |||
| 616 | + | for _, group := range groups { | |||
| 617 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "<section class=\"sv-timeline-group\"><h3>") | |||
| 618 | + | if templ_7745c5c3_Err != nil { | |||
| 619 | + | return templ_7745c5c3_Err | |||
| 620 | + | } | |||
| 621 | + | var templ_7745c5c3_Var30 string | |||
| 622 | + | templ_7745c5c3_Var30, templ_7745c5c3_Err = templ.JoinStringErrs(group.Label) | |||
| 623 | + | if templ_7745c5c3_Err != nil { | |||
| 624 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 99, Col: 21} | |||
| 625 | + | } | |||
| 626 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var30)) | |||
| 627 | + | if templ_7745c5c3_Err != nil { | |||
| 628 | + | return templ_7745c5c3_Err | |||
| 629 | + | } | |||
| 630 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 38, "</h3><ul class=\"sv-list\">") | |||
| 631 | + | if templ_7745c5c3_Err != nil { | |||
| 632 | + | return templ_7745c5c3_Err | |||
| 633 | + | } | |||
| 634 | + | for _, entry := range group.Entries { | |||
| 635 | + | if entry != nil { | |||
| 636 | + | templ_7745c5c3_Err = HistoryItem(entry).Render(ctx, templ_7745c5c3_Buffer) | |||
| 637 | + | if templ_7745c5c3_Err != nil { | |||
| 638 | + | return templ_7745c5c3_Err | |||
| 639 | + | } | |||
| 640 | + | } | |||
| 641 | + | } | |||
| 642 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "</ul></section>") | |||
| 643 | + | if templ_7745c5c3_Err != nil { | |||
| 644 | + | return templ_7745c5c3_Err | |||
| 645 | + | } | |||
| 646 | + | } | |||
| 647 | + | } | |||
| 648 | + | return nil | |||
| 649 | + | }) | |||
| 650 | + | } | |||
| 651 | + | ||||
| 652 | + | func HistoryItem(entry *entity.HistoryEntry) templ.Component { | |||
| 653 | + | return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { | |||
| 654 | + | templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context | |||
| 655 | + | if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { | |||
| 656 | + | return templ_7745c5c3_CtxErr | |||
| 657 | + | } | |||
| 658 | + | templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) | |||
| 659 | + | if !templ_7745c5c3_IsBuffer { | |||
| 660 | + | defer func() { | |||
| 661 | + | templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer) | |||
| 662 | + | if templ_7745c5c3_Err == nil { | |||
| 663 | + | templ_7745c5c3_Err = templ_7745c5c3_BufErr | |||
| 664 | + | } | |||
| 665 | + | }() | |||
| 666 | + | } | |||
| 667 | + | ctx = templ.InitializeContext(ctx) | |||
| 668 | + | templ_7745c5c3_Var31 := templ.GetChildren(ctx) | |||
| 669 | + | if templ_7745c5c3_Var31 == nil { | |||
| 670 | + | templ_7745c5c3_Var31 = templ.NopComponent | |||
| 671 | + | } | |||
| 672 | + | ctx = templ.ClearChildren(ctx) | |||
| 673 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, "<li class=\"sv-list-row\"><article class=\"sv-history-item\" data-sv-history-row data-history-id=\"") | |||
| 674 | + | if templ_7745c5c3_Err != nil { | |||
| 675 | + | return templ_7745c5c3_Err | |||
| 676 | + | } | |||
| 677 | + | var templ_7745c5c3_Var32 string | |||
| 678 | + | templ_7745c5c3_Var32, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", entry.ID)) | |||
| 679 | + | if templ_7745c5c3_Err != nil { | |||
| 680 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 114, Col: 100} | |||
| 681 | + | } | |||
| 682 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var32)) | |||
| 683 | + | if templ_7745c5c3_Err != nil { | |||
| 684 | + | return templ_7745c5c3_Err | |||
| 685 | + | } | |||
| 686 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 41, "\"><div class=\"sv-history-main\"><a class=\"sv-link sv-history-open\" href=\"") | |||
| 687 | + | if templ_7745c5c3_Err != nil { | |||
| 688 | + | return templ_7745c5c3_Err | |||
| 689 | + | } | |||
| 690 | + | var templ_7745c5c3_Var33 templ.SafeURL | |||
| 691 | + | templ_7745c5c3_Var33, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(sanitizeHref(entry.URL))) | |||
| 692 | + | if templ_7745c5c3_Err != nil { | |||
| 693 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 116, Col: 84} | |||
| 694 | + | } | |||
| 695 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var33)) | |||
| 696 | + | if templ_7745c5c3_Err != nil { | |||
| 697 | + | return templ_7745c5c3_Err | |||
| 698 | + | } | |||
| 699 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 42, "\">") | |||
| 700 | + | if templ_7745c5c3_Err != nil { | |||
| 701 | + | return templ_7745c5c3_Err | |||
| 702 | + | } | |||
| 703 | + | var templ_7745c5c3_Var34 string | |||
| 704 | + | templ_7745c5c3_Var34, templ_7745c5c3_Err = templ.JoinStringErrs(historyItemLabel(entry)) | |||
| 705 | + | if templ_7745c5c3_Err != nil { | |||
| 706 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 116, Col: 112} | |||
| 707 | + | } | |||
| 708 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var34)) | |||
| 709 | + | if templ_7745c5c3_Err != nil { | |||
| 710 | + | return templ_7745c5c3_Err | |||
| 711 | + | } | |||
| 712 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 43, "</a><p class=\"sv-history-url\">") | |||
| 713 | + | if templ_7745c5c3_Err != nil { | |||
| 714 | + | return templ_7745c5c3_Err | |||
| 715 | + | } | |||
| 716 | + | var templ_7745c5c3_Var35 string | |||
| 717 | + | templ_7745c5c3_Var35, templ_7745c5c3_Err = templ.JoinStringErrs(entry.URL) | |||
| 718 | + | if templ_7745c5c3_Err != nil { | |||
| 719 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 117, Col: 41} | |||
| 720 | + | } | |||
| 721 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var35)) | |||
| 722 | + | if templ_7745c5c3_Err != nil { | |||
| 723 | + | return templ_7745c5c3_Err | |||
| 724 | + | } | |||
| 725 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "</p><p class=\"sv-history-meta\">") | |||
| 726 | + | if templ_7745c5c3_Err != nil { | |||
| 727 | + | return templ_7745c5c3_Err | |||
| 728 | + | } | |||
| 729 | + | var templ_7745c5c3_Var36 string | |||
| 730 | + | templ_7745c5c3_Var36, templ_7745c5c3_Err = templ.JoinStringErrs(historyItemMeta(entry)) | |||
| 731 | + | if templ_7745c5c3_Err != nil { | |||
| 732 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 118, Col: 55} | |||
| 733 | + | } | |||
| 734 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var36)) | |||
| 735 | + | if templ_7745c5c3_Err != nil { | |||
| 736 | + | return templ_7745c5c3_Err | |||
| 737 | + | } | |||
| 738 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "</p></div><div class=\"sv-history-row-actions\"><a class=\"sv-button sv-button-secondary\" href=\"") | |||
| 739 | + | if templ_7745c5c3_Err != nil { | |||
| 740 | + | return templ_7745c5c3_Err | |||
| 741 | + | } | |||
| 742 | + | var templ_7745c5c3_Var37 templ.SafeURL | |||
| 743 | + | templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(sanitizeHref(entry.URL))) | |||
| 744 | + | if templ_7745c5c3_Err != nil { | |||
| 745 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 121, Col: 90} | |||
| 746 | + | } | |||
| 747 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37)) | |||
| 748 | + | if templ_7745c5c3_Err != nil { | |||
| 749 | + | return templ_7745c5c3_Err | |||
| 750 | + | } | |||
| 751 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 46, "\">Open</a> <button type=\"button\" class=\"sv-button sv-button-secondary sv-button-danger\" data-sv-action=\"history.deleteEntry\" data-id=\"") | |||
| 752 | + | if templ_7745c5c3_Err != nil { | |||
| 753 | + | return templ_7745c5c3_Err | |||
| 754 | + | } | |||
| 755 | + | var templ_7745c5c3_Var38 string | |||
| 756 | + | templ_7745c5c3_Var38, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", entry.ID)) | |||
| 757 | + | if templ_7745c5c3_Err != nil { | |||
| 758 | + | return templ.Error{Err: templ_7745c5c3_Err, FileName: `history.templ`, Line: 122, Col: 155} | |||
| 759 | + | } | |||
| 760 | + | _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var38)) | |||
| 761 | + | if templ_7745c5c3_Err != nil { | |||
| 762 | + | return templ_7745c5c3_Err | |||
| 763 | + | } | |||
| 764 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "\" data-sv-confirm=\"Delete this history entry?\"") | |||
| 765 | + | if templ_7745c5c3_Err != nil { | |||
| 766 | + | return templ_7745c5c3_Err | |||
| 767 | + | } | |||
| 768 | + | if entry.ID <= 0 { | |||
| 769 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, " disabled") | |||
| 770 | + | if templ_7745c5c3_Err != nil { | |||
| 771 | + | return templ_7745c5c3_Err | |||
| 772 | + | } | |||
| 773 | + | } | |||
| 774 | + | templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 49, ">Delete</button></div></article></li>") | |||
| 775 | + | if templ_7745c5c3_Err != nil { | |||
| 776 | + | return templ_7745c5c3_Err | |||
| 777 | + | } | |||
| 778 | + | return nil | |||
| 779 | + | }) | |||
| 780 | + | } | |||
| 781 | + | ||||
| 782 | + | var _ = templruntime.GeneratedTemplate | |||
M internal/ui/systemviews/history_view.go +79 -206
| @@ -2,7 +2,6 @@ package systemviews | |||
| 2 | 2 | ||
| 3 | 3 | import ( | |
| 4 | 4 | "fmt" | |
| 5 | - | "html" | |
| 6 | 5 | "net/url" | |
| 7 | 6 | "strings" | |
| 8 | 7 | "time" | |
| @@ -22,92 +21,61 @@ type historyRenderData struct { | |||
| 22 | 21 | Error string | |
| 23 | 22 | } | |
| 24 | 23 | ||
| 24 | + | type historyTimelineGroup struct { | |
| 25 | + | Date string | |
| 26 | + | Label string | |
| 27 | + | Entries []*entity.HistoryEntry | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | type historyCleanupItem struct { | |
| 31 | + | Label string | |
| 32 | + | RangeID string | |
| 33 | + | Confirm string | |
| 34 | + | } | |
| 35 | + | ||
| 25 | 36 | func historyHTML(data historyRenderData) string { | |
| 26 | - | sections := []string{ | |
| 27 | - | historyStatusHTML(data), | |
| 28 | - | sectionHTML("sv-history-controls", "Manage history", historyControlsHTML(data)), | |
| 29 | - | sectionHTML("sv-history-summary", "History", historySummaryHTML(data)), | |
| 30 | - | sectionHTML("sv-history-domains", "Top domains", historyDomainsHTML(data.Domains)), | |
| 31 | - | sectionHTML("sv-history-timeline", "Recent visits", historyTimelineHTML(data)), | |
| 32 | - | } | |
| 33 | - | return strings.Join(sections, "") | |
| 37 | + | return mustRenderComponent(HistoryView(data)) | |
| 34 | 38 | } | |
| 35 | 39 | ||
| 36 | - | func historyStatusHTML(data historyRenderData) string { | |
| 37 | - | var out strings.Builder | |
| 38 | - | if strings.TrimSpace(data.Notice) != "" { | |
| 39 | - | out.WriteString(fmt.Sprintf(`<div class="sv-alert sv-alert-success" role="status">%s</div>`, html.EscapeString(data.Notice))) | |
| 40 | + | func historyCleanupItems() []historyCleanupItem { | |
| 41 | + | return []historyCleanupItem{ | |
| 42 | + | {Label: "Last hour", RangeID: "hour", Confirm: "Delete history for last hour?"}, | |
| 43 | + | {Label: "Today", RangeID: "day", Confirm: "Delete history for today?"}, | |
| 44 | + | {Label: "Week", RangeID: "week", Confirm: "Delete history for week?"}, | |
| 45 | + | {Label: "Month", RangeID: "month", Confirm: "Delete history for month?"}, | |
| 46 | + | {Label: "All", RangeID: "all", Confirm: "Delete all browsing history?"}, | |
| 40 | 47 | } | |
| 41 | - | if strings.TrimSpace(data.Error) != "" { | |
| 42 | - | out.WriteString(fmt.Sprintf(`<div class="sv-alert sv-alert-error" role="alert">%s</div>`, html.EscapeString(data.Error))) | |
| 43 | - | } | |
| 44 | - | return out.String() | |
| 45 | 48 | } | |
| 46 | 49 | ||
| 47 | - | func historyControlsHTML(data historyRenderData) string { | |
| 48 | - | query := strings.TrimSpace(data.Query) | |
| 49 | - | domain := strings.TrimSpace(data.DomainFilter) | |
| 50 | - | limit := data.Limit | |
| 51 | - | if limit <= 0 { | |
| 52 | - | limit = historyTimelineLimit | |
| 50 | + | func historyLimit(data historyRenderData) int { | |
| 51 | + | if data.Limit <= 0 { | |
| 52 | + | return historyTimelineLimit | |
| 53 | 53 | } | |
| 54 | - | offset := data.Offset | |
| 54 | + | return data.Limit | |
| 55 | + | } | |
| 56 | + | ||
| 57 | + | func previousHistoryOffset(data historyRenderData) int { | |
| 58 | + | offset := data.Offset - historyLimit(data) | |
| 55 | 59 | if offset < 0 { | |
| 56 | - | offset = 0 | |
| 60 | + | return 0 | |
| 57 | 61 | } | |
| 62 | + | return offset | |
| 63 | + | } | |
| 58 | 64 | ||
| 59 | - | var out strings.Builder | |
| 60 | - | out.WriteString(`<form class="sv-toolbar sv-history-search" data-sv-action="history.search">`) | |
| 61 | - | out.WriteString(fmt.Sprintf(`<label class="sv-search-label"><span>Search</span><input data-sv-history-search name="query" type="search" value="%s" placeholder="Search title or URL" autocomplete="off"></label>`, html.EscapeString(query))) | |
| 62 | - | out.WriteString(`<button class="sv-button" type="submit">Search</button>`) | |
| 63 | - | out.WriteString(`<button class="sv-button sv-button-secondary" type="button" data-sv-action="history.clear">Clear</button>`) | |
| 64 | - | out.WriteString(`</form>`) | |
| 65 | - | ||
| 66 | - | if query != "" || domain != "" { | |
| 67 | - | out.WriteString(`<div class="sv-active-filters">`) | |
| 68 | - | if query != "" { | |
| 69 | - | out.WriteString(fmt.Sprintf(`<span class="sv-filter-chip">Query: %s</span>`, html.EscapeString(query))) | |
| 70 | - | } | |
| 71 | - | if domain != "" { | |
| 72 | - | out.WriteString(fmt.Sprintf(`<span class="sv-filter-chip">Domain: %s <button type="button" data-sv-action="history.clearDomain" aria-label="Clear domain filter">×</button></span>`, html.EscapeString(domain))) | |
| 73 | - | } | |
| 74 | - | out.WriteString(`</div>`) | |
| 75 | - | } | |
| 65 | + | func nextHistoryOffset(data historyRenderData) int { | |
| 66 | + | return max(data.Offset, 0) + historyLimit(data) | |
| 67 | + | } | |
| 76 | 68 | ||
| 77 | - | out.WriteString(`<div class="sv-history-actions-panel">`) | |
| 78 | - | out.WriteString(`<div class="sv-button-row" aria-label="History pagination">`) | |
| 79 | - | prevOffset := offset - limit | |
| 80 | - | if prevOffset < 0 { | |
| 81 | - | prevOffset = 0 | |
| 82 | - | } | |
| 83 | - | out.WriteString(historyActionButton("Previous", historyActionPage, map[string]string{"offset": fmt.Sprintf("%d", prevOffset)}, false, offset == 0 || query != "")) | |
| 84 | - | out.WriteString(fmt.Sprintf(`<span class="sv-meta">Showing %d item%s%s</span>`, countHistoryEntries(data.Entries), pluralSuffix(countHistoryEntries(data.Entries)), historyOffsetLabel(offset, query))) | |
| 85 | - | out.WriteString(historyActionButton("Next", historyActionPage, map[string]string{"offset": fmt.Sprintf("%d", offset+limit)}, false, query != "" || countHistoryEntries(data.Entries) < limit)) | |
| 86 | - | out.WriteString(`</div>`) | |
| 69 | + | func disableHistoryPrev(data historyRenderData) bool { | |
| 70 | + | return data.Offset <= 0 || strings.TrimSpace(data.Query) != "" | |
| 71 | + | } | |
| 87 | 72 | ||
| 88 | - | out.WriteString(`<div class="sv-button-row" aria-label="History cleanup">`) | |
| 89 | - | out.WriteString(`<span class="sv-meta">Clean up</span>`) | |
| 90 | - | for _, item := range []struct { | |
| 91 | - | label string | |
| 92 | - | rangeID string | |
| 93 | - | }{ | |
| 94 | - | {label: "Last hour", rangeID: "hour"}, | |
| 95 | - | {label: "Today", rangeID: "day"}, | |
| 96 | - | {label: "Week", rangeID: "week"}, | |
| 97 | - | {label: "Month", rangeID: "month"}, | |
| 98 | - | {label: "All", rangeID: "all"}, | |
| 99 | - | } { | |
| 100 | - | confirm := "Delete history for " + strings.ToLower(item.label) + "?" | |
| 101 | - | if item.rangeID == "all" { | |
| 102 | - | confirm = "Delete all browsing history?" | |
| 103 | - | } | |
| 104 | - | out.WriteString(historyActionButton(item.label, historyActionDeleteRange, map[string]string{"range": item.rangeID, "sv-confirm": confirm}, true, false)) | |
| 105 | - | } | |
| 106 | - | out.WriteString(`</div>`) | |
| 107 | - | out.WriteString(`</div>`) | |
| 73 | + | func disableHistoryNext(data historyRenderData) bool { | |
| 74 | + | return strings.TrimSpace(data.Query) != "" || countHistoryEntries(data.Entries) < historyLimit(data) | |
| 75 | + | } | |
| 108 | 76 | ||
| 109 | - | out.WriteString(`<p class="sv-meta sv-key-hints">Keys: <kbd>/</kbd> search, <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>d</kbd> delete focused entry.</p>`) | |
| 110 | - | return out.String() | |
| 77 | + | func showHistoryFilters(data historyRenderData) bool { | |
| 78 | + | return strings.TrimSpace(data.Query) != "" || strings.TrimSpace(data.DomainFilter) != "" | |
| 111 | 79 | } | |
| 112 | 80 | ||
| 113 | 81 | func historyOffsetLabel(offset int, query string) string { | |
| @@ -120,29 +88,6 @@ func historyOffsetLabel(offset int, query string) string { | |||
| 120 | 88 | return fmt.Sprintf(" from offset %d", offset) | |
| 121 | 89 | } | |
| 122 | 90 | ||
| 123 | - | func historyActionButton(label, action string, data map[string]string, danger, disabled bool) string { | |
| 124 | - | classes := "sv-button sv-button-secondary" | |
| 125 | - | if danger { | |
| 126 | - | classes += " sv-button-danger" | |
| 127 | - | } | |
| 128 | - | attrs := []string{ | |
| 129 | - | `type="button"`, | |
| 130 | - | fmt.Sprintf(`class="%s"`, html.EscapeString(classes)), | |
| 131 | - | fmt.Sprintf(`data-sv-action="%s"`, html.EscapeString(action)), | |
| 132 | - | } | |
| 133 | - | if disabled { | |
| 134 | - | attrs = append(attrs, `disabled aria-disabled="true"`) | |
| 135 | - | } | |
| 136 | - | for key, value := range data { | |
| 137 | - | attrs = append(attrs, fmt.Sprintf(`data-%s="%s"`, html.EscapeString(kebabDataKey(key)), html.EscapeString(value))) | |
| 138 | - | } | |
| 139 | - | return fmt.Sprintf(`<button %s>%s</button>`, strings.Join(attrs, " "), html.EscapeString(label)) | |
| 140 | - | } | |
| 141 | - | ||
| 142 | - | func kebabDataKey(key string) string { | |
| 143 | - | return strings.ReplaceAll(key, "_", "-") | |
| 144 | - | } | |
| 145 | - | ||
| 146 | 91 | func pluralSuffix(count int) string { | |
| 147 | 92 | if count == 1 { | |
| 148 | 93 | return "" | |
| @@ -150,124 +95,24 @@ func pluralSuffix(count int) string { | |||
| 150 | 95 | return "s" | |
| 151 | 96 | } | |
| 152 | 97 | ||
| 153 | - | func historySummaryHTML(data historyRenderData) string { | |
| 154 | - | entries := int64(countHistoryEntries(data.Entries)) | |
| 155 | - | visits := sumHistoryVisits(data.Entries) | |
| 156 | - | uniqueDays := countUniqueHistoryDays(data.Entries) | |
| 98 | + | func historySummaryValues(data historyRenderData) (entries, visits, uniqueDays int64) { | |
| 99 | + | entries = int64(countHistoryEntries(data.Entries)) | |
| 100 | + | visits = sumHistoryVisits(data.Entries) | |
| 101 | + | uniqueDays = countUniqueHistoryDays(data.Entries) | |
| 157 | 102 | ||
| 158 | 103 | if data.Analytics != nil { | |
| 159 | 104 | entries = data.Analytics.TotalEntries | |
| 160 | 105 | visits = data.Analytics.TotalVisits | |
| 161 | 106 | uniqueDays = data.Analytics.UniqueDays | |
| 162 | 107 | } | |
| 163 | - | ||
| 164 | - | return fmt.Sprintf(`<div class="sv-stat-grid">%s%s%s</div>`, | |
| 165 | - | historyStatCardHTML("Entries", entries), | |
| 166 | - | historyStatCardHTML("Visits", visits), | |
| 167 | - | historyStatCardHTML("Days", uniqueDays), | |
| 168 | - | ) | |
| 169 | - | } | |
| 170 | - | ||
| 171 | - | func historyStatCardHTML(label string, value int64) string { | |
| 172 | - | return fmt.Sprintf(`<div class="sv-stat-card"><span class="sv-stat-value">%d</span><span class="sv-stat-label">%s</span></div>`, value, html.EscapeString(label)) | |
| 108 | + | return entries, visits, uniqueDays | |
| 173 | 109 | } | |
| 174 | 110 | ||
| 175 | - | func historyDomainsHTML(domains []*entity.DomainStat) string { | |
| 176 | - | var chips strings.Builder | |
| 177 | - | for _, domain := range domains { | |
| 178 | - | if domain == nil || strings.TrimSpace(domain.Domain) == "" { | |
| 179 | - | continue | |
| 180 | - | } | |
| 181 | - | displayDomain := strings.TrimPrefix(domain.Domain, "www.") | |
| 182 | - | chips.WriteString(`<span class="sv-domain-chip">`) | |
| 183 | - | chips.WriteString(fmt.Sprintf( | |
| 184 | - | `<button type="button" class="sv-domain-filter" data-sv-action="history.filterDomain" data-domain="%s">%s</button>`, | |
| 185 | - | html.EscapeString(displayDomain), | |
| 186 | - | html.EscapeString(displayDomain), | |
| 187 | - | )) | |
| 188 | - | chips.WriteString(fmt.Sprintf(`<span class="sv-domain-meta">%d pages · %d visits</span>`, domain.PageCount, domain.TotalVisits)) | |
| 189 | - | chips.WriteString(fmt.Sprintf( | |
| 190 | - | `<button type="button" class="sv-icon-button sv-danger" data-sv-action="history.deleteDomain" data-domain="%s" data-sv-confirm="Delete all history for %s?" aria-label="Delete history for %s">×</button>`, | |
| 191 | - | html.EscapeString(displayDomain), | |
| 192 | - | html.EscapeString(displayDomain), | |
| 193 | - | html.EscapeString(displayDomain), | |
| 194 | - | )) | |
| 195 | - | chips.WriteString(`</span>`) | |
| 196 | - | } | |
| 197 | - | if chips.Len() == 0 { | |
| 198 | - | return emptyStateHTML("No domain statistics yet") | |
| 111 | + | func historyTimelineEmptyMessage(data historyRenderData) string { | |
| 112 | + | if strings.TrimSpace(data.Query) != "" || strings.TrimSpace(data.DomainFilter) != "" { | |
| 113 | + | return "No history entries match the current filters" | |
| 199 | 114 | } | |
| 200 | - | return `<div class="sv-domain-list">` + chips.String() + `</div>` | |
| 201 | - | } | |
| 202 | - | ||
| 203 | - | func historyTimelineHTML(data historyRenderData) string { | |
| 204 | - | groups := groupHistoryEntries(data.Entries) | |
| 205 | - | if len(groups) == 0 { | |
| 206 | - | if strings.TrimSpace(data.Query) != "" || strings.TrimSpace(data.DomainFilter) != "" { | |
| 207 | - | return emptyStateHTML("No history entries match the current filters") | |
| 208 | - | } | |
| 209 | - | return emptyStateHTML("No history entries") | |
| 210 | - | } | |
| 211 | - | ||
| 212 | - | var body strings.Builder | |
| 213 | - | for _, group := range groups { | |
| 214 | - | body.WriteString(`<section class="sv-timeline-group">`) | |
| 215 | - | body.WriteString(`<h3>` + html.EscapeString(group.Label) + `</h3>`) | |
| 216 | - | body.WriteString(listHTML(historyItemsHTML(group.Entries), "No history entries")) | |
| 217 | - | body.WriteString(`</section>`) | |
| 218 | - | } | |
| 219 | - | return body.String() | |
| 220 | - | } | |
| 221 | - | ||
| 222 | - | func historyItemsHTML(entries []*entity.HistoryEntry) string { | |
| 223 | - | var items strings.Builder | |
| 224 | - | for _, entry := range entries { | |
| 225 | - | if entry == nil { | |
| 226 | - | continue | |
| 227 | - | } | |
| 228 | - | items.WriteString(listRowHTML(historyItemHTML(entry))) | |
| 229 | - | } | |
| 230 | - | ||
| 231 | - | return items.String() | |
| 232 | - | } | |
| 233 | - | ||
| 234 | - | func historyItemHTML(entry *entity.HistoryEntry) string { | |
| 235 | - | label := strings.TrimSpace(entry.Title) | |
| 236 | - | if label == "" { | |
| 237 | - | label = displayHistoryDomain(entry.URL) | |
| 238 | - | } | |
| 239 | - | if label == "" { | |
| 240 | - | label = entry.URL | |
| 241 | - | } | |
| 242 | - | ||
| 243 | - | meta := []string{displayHistoryDomain(entry.URL)} | |
| 244 | - | if entry.VisitCount > 1 { | |
| 245 | - | meta = append(meta, fmt.Sprintf("%dx", entry.VisitCount)) | |
| 246 | - | } | |
| 247 | - | if !entry.LastVisited.IsZero() { | |
| 248 | - | meta = append(meta, formatHistoryTime(entry.LastVisited)) | |
| 249 | - | } | |
| 250 | - | ||
| 251 | - | deleteButton := historyActionButton("Delete", historyActionDeleteEntry, map[string]string{ | |
| 252 | - | "id": fmt.Sprintf("%d", entry.ID), | |
| 253 | - | "sv-confirm": "Delete this history entry?", | |
| 254 | - | }, true, entry.ID <= 0) | |
| 255 | - | ||
| 256 | - | return fmt.Sprintf(`<article class="sv-history-item" data-sv-history-row data-history-id="%d"><div class="sv-history-main"><a class="sv-link sv-history-open" href="%s">%s</a><p class="sv-history-url">%s</p><p class="sv-history-meta">%s</p></div><div class="sv-history-row-actions"><a class="sv-button sv-button-secondary" href="%s">Open</a>%s</div></article>`, | |
| 257 | - | entry.ID, | |
| 258 | - | html.EscapeString(sanitizeHref(entry.URL)), | |
| 259 | - | html.EscapeString(label), | |
| 260 | - | html.EscapeString(entry.URL), | |
| 261 | - | html.EscapeString(strings.Join(nonEmptyStrings(meta), " · ")), | |
| 262 | - | html.EscapeString(sanitizeHref(entry.URL)), | |
| 263 | - | deleteButton, | |
| 264 | - | ) | |
| 265 | - | } | |
| 266 | - | ||
| 267 | - | type historyTimelineGroup struct { | |
| 268 | - | Date string | |
| 269 | - | Label string | |
| 270 | - | Entries []*entity.HistoryEntry | |
| 115 | + | return "No history entries" | |
| 271 | 116 | } | |
| 272 | 117 | ||
| 273 | 118 | func groupHistoryEntries(entries []*entity.HistoryEntry) []historyTimelineGroup { | |
| @@ -380,6 +225,34 @@ func formatHistoryTime(ts time.Time) string { | |||
| 380 | 225 | return ts.Local().Format("15:04") | |
| 381 | 226 | } | |
| 382 | 227 | ||
| 228 | + | func historyItemLabel(entry *entity.HistoryEntry) string { | |
| 229 | + | if entry == nil { | |
| 230 | + | return "" | |
| 231 | + | } | |
| 232 | + | label := strings.TrimSpace(entry.Title) | |
| 233 | + | if label == "" { | |
| 234 | + | label = displayHistoryDomain(entry.URL) | |
| 235 | + | } | |
| 236 | + | if label == "" { | |
| 237 | + | label = entry.URL | |
| 238 | + | } | |
| 239 | + | return label | |
| 240 | + | } | |
| 241 | + | ||
| 242 | + | func historyItemMeta(entry *entity.HistoryEntry) string { | |
| 243 | + | if entry == nil { | |
| 244 | + | return "" | |
| 245 | + | } | |
| 246 | + | meta := []string{displayHistoryDomain(entry.URL)} | |
| 247 | + | if entry.VisitCount > 1 { | |
| 248 | + | meta = append(meta, fmt.Sprintf("%dx", entry.VisitCount)) | |
| 249 | + | } | |
| 250 | + | if !entry.LastVisited.IsZero() { | |
| 251 | + | meta = append(meta, formatHistoryTime(entry.LastVisited)) | |
| 252 | + | } | |
| 253 | + | return strings.Join(nonEmptyStrings(meta), " · ") | |
| 254 | + | } | |
| 255 | + | ||
| 383 | 256 | func nonEmptyStrings(values []string) []string { | |
| 384 | 257 | out := values[:0] | |
| 385 | 258 | for _, value := range values { | |
| @@ -2,7 +2,6 @@ package systemviews | |||||
| 2 | 2 | ||||
| 3 | import ( | 3 | import ( | ||
| 4 | "fmt" | 4 | "fmt" | ||
| 5 | - | "html" | |||
| 6 | "net/url" | 5 | "net/url" | ||
| 7 | "strings" | 6 | "strings" | ||
| 8 | "time" | 7 | "time" | ||
| @@ -22,92 +21,61 @@ type historyRenderData struct { | |||||
| 22 | Error string | 21 | Error string | ||
| 23 | } | 22 | } | ||
| 24 | 23 | ||||
| 24 | + | type historyTimelineGroup struct { | |||
| 25 | + | Date string | |||
| 26 | + | Label string | |||
| 27 | + | Entries []*entity.HistoryEntry | |||
| 28 | + | } | |||
| 29 | + | ||||
| 30 | + | type historyCleanupItem struct { | |||
| 31 | + | Label string | |||
| 32 | + | RangeID string | |||
| 33 | + | Confirm string | |||
| 34 | + | } | |||
| 35 | + | ||||
| 25 | func historyHTML(data historyRenderData) string { | 36 | func historyHTML(data historyRenderData) string { | ||
| 26 | - | sections := []string{ | 37 | + | return mustRenderComponent(HistoryView(data)) |
| 27 | - | historyStatusHTML(data), | |||
| 28 | - | sectionHTML("sv-history-controls", "Manage history", historyControlsHTML(data)), | |||
| 29 | - | sectionHTML("sv-history-summary", "History", historySummaryHTML(data)), | |||
| 30 | - | sectionHTML("sv-history-domains", "Top domains", historyDomainsHTML(data.Domains)), | |||
| 31 | - | sectionHTML("sv-history-timeline", "Recent visits", historyTimelineHTML(data)), | |||
| 32 | - | } | |||
| 33 | - | return strings.Join(sections, "") | |||
| 34 | } | 38 | } | ||
| 35 | 39 | ||||
| 36 | - | func historyStatusHTML(data historyRenderData) string { | 40 | + | func historyCleanupItems() []historyCleanupItem { |
| 37 | - | var out strings.Builder | 41 | + | return []historyCleanupItem{ |
| 38 | - | if strings.TrimSpace(data.Notice) != "" { | 42 | + | {Label: "Last hour", RangeID: "hour", Confirm: "Delete history for last hour?"}, |
| 39 | - | out.WriteString(fmt.Sprintf(`<div class="sv-alert sv-alert-success" role="status">%s</div>`, html.EscapeString(data.Notice))) | 43 | + | {Label: "Today", RangeID: "day", Confirm: "Delete history for today?"}, |
| 44 | + | {Label: "Week", RangeID: "week", Confirm: "Delete history for week?"}, | |||
| 45 | + | {Label: "Month", RangeID: "month", Confirm: "Delete history for month?"}, | |||
| 46 | + | {Label: "All", RangeID: "all", Confirm: "Delete all browsing history?"}, | |||
| 40 | } | 47 | } | ||
| 41 | - | if strings.TrimSpace(data.Error) != "" { | |||
| 42 | - | out.WriteString(fmt.Sprintf(`<div class="sv-alert sv-alert-error" role="alert">%s</div>`, html.EscapeString(data.Error))) | |||
| 43 | - | } | |||
| 44 | - | return out.String() | |||
| 45 | } | 48 | } | ||
| 46 | 49 | ||||
| 47 | - | func historyControlsHTML(data historyRenderData) string { | 50 | + | func historyLimit(data historyRenderData) int { |
| 48 | - | query := strings.TrimSpace(data.Query) | 51 | + | if data.Limit <= 0 { |
| 49 | - | domain := strings.TrimSpace(data.DomainFilter) | 52 | + | return historyTimelineLimit |
| 50 | - | limit := data.Limit | |||
| 51 | - | if limit <= 0 { | |||
| 52 | - | limit = historyTimelineLimit | |||
| 53 | } | 53 | } | ||
| 54 | - | offset := data.Offset | 54 | + | return data.Limit |
| 55 | + | } | |||
| 56 | + | ||||
| 57 | + | func previousHistoryOffset(data historyRenderData) int { | |||
| 58 | + | offset := data.Offset - historyLimit(data) | |||
| 55 | if offset < 0 { | 59 | if offset < 0 { | ||
| 56 | - | offset = 0 | 60 | + | return 0 |
| 57 | } | 61 | } | ||
| 62 | + | return offset | |||
| 63 | + | } | |||
| 58 | 64 | ||||
| 59 | - | var out strings.Builder | 65 | + | func nextHistoryOffset(data historyRenderData) int { |
| 60 | - | out.WriteString(`<form class="sv-toolbar sv-history-search" data-sv-action="history.search">`) | 66 | + | return max(data.Offset, 0) + historyLimit(data) |
| 61 | - | out.WriteString(fmt.Sprintf(`<label class="sv-search-label"><span>Search</span><input data-sv-history-search name="query" type="search" value="%s" placeholder="Search title or URL" autocomplete="off"></label>`, html.EscapeString(query))) | 67 | + | } |
| 62 | - | out.WriteString(`<button class="sv-button" type="submit">Search</button>`) | |||
| 63 | - | out.WriteString(`<button class="sv-button sv-button-secondary" type="button" data-sv-action="history.clear">Clear</button>`) | |||
| 64 | - | out.WriteString(`</form>`) | |||
| 65 | - | ||||
| 66 | - | if query != "" || domain != "" { | |||
| 67 | - | out.WriteString(`<div class="sv-active-filters">`) | |||
| 68 | - | if query != "" { | |||
| 69 | - | out.WriteString(fmt.Sprintf(`<span class="sv-filter-chip">Query: %s</span>`, html.EscapeString(query))) | |||
| 70 | - | } | |||
| 71 | - | if domain != "" { | |||
| 72 | - | out.WriteString(fmt.Sprintf(`<span class="sv-filter-chip">Domain: %s <button type="button" data-sv-action="history.clearDomain" aria-label="Clear domain filter">×</button></span>`, html.EscapeString(domain))) | |||
| 73 | - | } | |||
| 74 | - | out.WriteString(`</div>`) | |||
| 75 | - | } | |||
| 76 | 68 | ||||
| 77 | - | out.WriteString(`<div class="sv-history-actions-panel">`) | 69 | + | func disableHistoryPrev(data historyRenderData) bool { |
| 78 | - | out.WriteString(`<div class="sv-button-row" aria-label="History pagination">`) | 70 | + | return data.Offset <= 0 || strings.TrimSpace(data.Query) != "" |
| 79 | - | prevOffset := offset - limit | 71 | + | } |
| 80 | - | if prevOffset < 0 { | |||
| 81 | - | prevOffset = 0 | |||
| 82 | - | } | |||
| 83 | - | out.WriteString(historyActionButton("Previous", historyActionPage, map[string]string{"offset": fmt.Sprintf("%d", prevOffset)}, false, offset == 0 || query != "")) | |||
| 84 | - | out.WriteString(fmt.Sprintf(`<span class="sv-meta">Showing %d item%s%s</span>`, countHistoryEntries(data.Entries), pluralSuffix(countHistoryEntries(data.Entries)), historyOffsetLabel(offset, query))) | |||
| 85 | - | out.WriteString(historyActionButton("Next", historyActionPage, map[string]string{"offset": fmt.Sprintf("%d", offset+limit)}, false, query != "" || countHistoryEntries(data.Entries) < limit)) | |||
| 86 | - | out.WriteString(`</div>`) | |||
| 87 | 72 | ||||
| 88 | - | out.WriteString(`<div class="sv-button-row" aria-label="History cleanup">`) | 73 | + | func disableHistoryNext(data historyRenderData) bool { |
| 89 | - | out.WriteString(`<span class="sv-meta">Clean up</span>`) | 74 | + | return strings.TrimSpace(data.Query) != "" || countHistoryEntries(data.Entries) < historyLimit(data) |
| 90 | - | for _, item := range []struct { | 75 | + | } |
| 91 | - | label string | |||
| 92 | - | rangeID string | |||
| 93 | - | }{ | |||
| 94 | - | {label: "Last hour", rangeID: "hour"}, | |||
| 95 | - | {label: "Today", rangeID: "day"}, | |||
| 96 | - | {label: "Week", rangeID: "week"}, | |||
| 97 | - | {label: "Month", rangeID: "month"}, | |||
| 98 | - | {label: "All", rangeID: "all"}, | |||
| 99 | - | } { | |||
| 100 | - | confirm := "Delete history for " + strings.ToLower(item.label) + "?" | |||
| 101 | - | if item.rangeID == "all" { | |||
| 102 | - | confirm = "Delete all browsing history?" | |||
| 103 | - | } | |||
| 104 | - | out.WriteString(historyActionButton(item.label, historyActionDeleteRange, map[string]string{"range": item.rangeID, "sv-confirm": confirm}, true, false)) | |||
| 105 | - | } | |||
| 106 | - | out.WriteString(`</div>`) | |||
| 107 | - | out.WriteString(`</div>`) | |||
| 108 | 76 | ||||
| 109 | - | out.WriteString(`<p class="sv-meta sv-key-hints">Keys: <kbd>/</kbd> search, <kbd>j</kbd>/<kbd>k</kbd> move, <kbd>Enter</kbd> open, <kbd>d</kbd> delete focused entry.</p>`) | 77 | + | func showHistoryFilters(data historyRenderData) bool { |
| 110 | - | return out.String() | 78 | + | return strings.TrimSpace(data.Query) != "" || strings.TrimSpace(data.DomainFilter) != "" |
| 111 | } | 79 | } | ||
| 112 | 80 | ||||
| 113 | func historyOffsetLabel(offset int, query string) string { | 81 | func historyOffsetLabel(offset int, query string) string { | ||
| @@ -120,29 +88,6 @@ func historyOffsetLabel(offset int, query string) string { | |||||
| 120 | return fmt.Sprintf(" from offset %d", offset) | 88 | return fmt.Sprintf(" from offset %d", offset) | ||
| 121 | } | 89 | } | ||
| 122 | 90 | ||||
| 123 | - | func historyActionButton(label, action string, data map[string]string, danger, disabled bool) string { | |||
| 124 | - | classes := "sv-button sv-button-secondary" | |||
| 125 | - | if danger { | |||
| 126 | - | classes += " sv-button-danger" | |||
| 127 | - | } | |||
| 128 | - | attrs := []string{ | |||
| 129 | - | `type="button"`, | |||
| 130 | - | fmt.Sprintf(`class="%s"`, html.EscapeString(classes)), | |||
| 131 | - | fmt.Sprintf(`data-sv-action="%s"`, html.EscapeString(action)), | |||
| 132 | - | } | |||
| 133 | - | if disabled { | |||
| 134 | - | attrs = append(attrs, `disabled aria-disabled="true"`) | |||
| 135 | - | } | |||
| 136 | - | for key, value := range data { | |||
| 137 | - | attrs = append(attrs, fmt.Sprintf(`data-%s="%s"`, html.EscapeString(kebabDataKey(key)), html.EscapeString(value))) | |||
| 138 | - | } | |||
| 139 | - | return fmt.Sprintf(`<button %s>%s</button>`, strings.Join(attrs, " "), html.EscapeString(label)) | |||
| 140 | - | } | |||
| 141 | - | ||||
| 142 | - | func kebabDataKey(key string) string { | |||
| 143 | - | return strings.ReplaceAll(key, "_", "-") | |||
| 144 | - | } | |||
| 145 | - | ||||
| 146 | func pluralSuffix(count int) string { | 91 | func pluralSuffix(count int) string { | ||
| 147 | if count == 1 { | 92 | if count == 1 { | ||
| 148 | return "" | 93 | return "" | ||
| @@ -150,124 +95,24 @@ func pluralSuffix(count int) string { | |||||
| 150 | return "s" | 95 | return "s" | ||
| 151 | } | 96 | } | ||
| 152 | 97 | ||||
| 153 | - | func historySummaryHTML(data historyRenderData) string { | 98 | + | func historySummaryValues(data historyRenderData) (entries, visits, uniqueDays int64) { |
| 154 | - | entries := int64(countHistoryEntries(data.Entries)) | 99 | + | entries = int64(countHistoryEntries(data.Entries)) |
| 155 | - | visits := sumHistoryVisits(data.Entries) | 100 | + | visits = sumHistoryVisits(data.Entries) |
| 156 | - | uniqueDays := countUniqueHistoryDays(data.Entries) | 101 | + | uniqueDays = countUniqueHistoryDays(data.Entries) |
| 157 | 102 | ||||
| 158 | if data.Analytics != nil { | 103 | if data.Analytics != nil { | ||
| 159 | entries = data.Analytics.TotalEntries | 104 | entries = data.Analytics.TotalEntries | ||
| 160 | visits = data.Analytics.TotalVisits | 105 | visits = data.Analytics.TotalVisits | ||
| 161 | uniqueDays = data.Analytics.UniqueDays | 106 | uniqueDays = data.Analytics.UniqueDays | ||
| 162 | } | 107 | } | ||
| 163 | - | 108 | + | return entries, visits, uniqueDays | |
| 164 | - | return fmt.Sprintf(`<div class="sv-stat-grid">%s%s%s</div>`, | |||
| 165 | - | historyStatCardHTML("Entries", entries), | |||
| 166 | - | historyStatCardHTML("Visits", visits), | |||
| 167 | - | historyStatCardHTML("Days", uniqueDays), | |||
| 168 | - | ) | |||
| 169 | - | } | |||
| 170 | - | ||||
| 171 | - | func historyStatCardHTML(label string, value int64) string { | |||
| 172 | - | return fmt.Sprintf(`<div class="sv-stat-card"><span class="sv-stat-value">%d</span><span class="sv-stat-label">%s</span></div>`, value, html.EscapeString(label)) | |||
| 173 | } | 109 | } | ||
| 174 | 110 | ||||
| 175 | - | func historyDomainsHTML(domains []*entity.DomainStat) string { | 111 | + | func historyTimelineEmptyMessage(data historyRenderData) string { |
| 176 | - | var chips strings.Builder | 112 | + | if strings.TrimSpace(data.Query) != "" || strings.TrimSpace(data.DomainFilter) != "" { |
| 177 | - | for _, domain := range domains { | 113 | + | return "No history entries match the current filters" |
| 178 | - | if domain == nil || strings.TrimSpace(domain.Domain) == "" { | |||
| 179 | - | continue | |||
| 180 | - | } | |||
| 181 | - | displayDomain := strings.TrimPrefix(domain.Domain, "www.") | |||
| 182 | - | chips.WriteString(`<span class="sv-domain-chip">`) | |||
| 183 | - | chips.WriteString(fmt.Sprintf( | |||
| 184 | - | `<button type="button" class="sv-domain-filter" data-sv-action="history.filterDomain" data-domain="%s">%s</button>`, | |||
| 185 | - | html.EscapeString(displayDomain), | |||
| 186 | - | html.EscapeString(displayDomain), | |||
| 187 | - | )) | |||
| 188 | - | chips.WriteString(fmt.Sprintf(`<span class="sv-domain-meta">%d pages · %d visits</span>`, domain.PageCount, domain.TotalVisits)) | |||
| 189 | - | chips.WriteString(fmt.Sprintf( | |||
| 190 | - | `<button type="button" class="sv-icon-button sv-danger" data-sv-action="history.deleteDomain" data-domain="%s" data-sv-confirm="Delete all history for %s?" aria-label="Delete history for %s">×</button>`, | |||
| 191 | - | html.EscapeString(displayDomain), | |||
| 192 | - | html.EscapeString(displayDomain), | |||
| 193 | - | html.EscapeString(displayDomain), | |||
| 194 | - | )) | |||
| 195 | - | chips.WriteString(`</span>`) | |||
| 196 | - | } | |||
| 197 | - | if chips.Len() == 0 { | |||
| 198 | - | return emptyStateHTML("No domain statistics yet") | |||
| 199 | } | 114 | } | ||
| 200 | - | return `<div class="sv-domain-list">` + chips.String() + `</div>` | 115 | + | return "No history entries" |
| 201 | - | } | |||
| 202 | - | ||||
| 203 | - | func historyTimelineHTML(data historyRenderData) string { | |||
| 204 | - | groups := groupHistoryEntries(data.Entries) | |||
| 205 | - | if len(groups) == 0 { | |||
| 206 | - | if strings.TrimSpace(data.Query) != "" || strings.TrimSpace(data.DomainFilter) != "" { | |||
| 207 | - | return emptyStateHTML("No history entries match the current filters") | |||
| 208 | - | } | |||
| 209 | - | return emptyStateHTML("No history entries") | |||
| 210 | - | } | |||
| 211 | - | ||||
| 212 | - | var body strings.Builder | |||
| 213 | - | for _, group := range groups { | |||
| 214 | - | body.WriteString(`<section class="sv-timeline-group">`) | |||
| 215 | - | body.WriteString(`<h3>` + html.EscapeString(group.Label) + `</h3>`) | |||
| 216 | - | body.WriteString(listHTML(historyItemsHTML(group.Entries), "No history entries")) | |||
| 217 | - | body.WriteString(`</section>`) | |||
| 218 | - | } | |||
| 219 | - | return body.String() | |||
| 220 | - | } | |||
| 221 | - | ||||
| 222 | - | func historyItemsHTML(entries []*entity.HistoryEntry) string { | |||
| 223 | - | var items strings.Builder | |||
| 224 | - | for _, entry := range entries { | |||
| 225 | - | if entry == nil { | |||
| 226 | - | continue | |||
| 227 | - | } | |||
| 228 | - | items.WriteString(listRowHTML(historyItemHTML(entry))) | |||
| 229 | - | } | |||
| 230 | - | ||||
| 231 | - | return items.String() | |||
| 232 | - | } | |||
| 233 | - | ||||
| 234 | - | func historyItemHTML(entry *entity.HistoryEntry) string { | |||
| 235 | - | label := strings.TrimSpace(entry.Title) | |||
| 236 | - | if label == "" { | |||
| 237 | - | label = displayHistoryDomain(entry.URL) | |||
| 238 | - | } | |||
| 239 | - | if label == "" { | |||
| 240 | - | label = entry.URL | |||
| 241 | - | } | |||
| 242 | - | ||||
| 243 | - | meta := []string{displayHistoryDomain(entry.URL)} | |||
| 244 | - | if entry.VisitCount > 1 { | |||
| 245 | - | meta = append(meta, fmt.Sprintf("%dx", entry.VisitCount)) | |||
| 246 | - | } | |||
| 247 | - | if !entry.LastVisited.IsZero() { | |||
| 248 | - | meta = append(meta, formatHistoryTime(entry.LastVisited)) | |||
| 249 | - | } | |||
| 250 | - | ||||
| 251 | - | deleteButton := historyActionButton("Delete", historyActionDeleteEntry, map[string]string{ | |||
| 252 | - | "id": fmt.Sprintf("%d", entry.ID), | |||
| 253 | - | "sv-confirm": "Delete this history entry?", | |||
| 254 | - | }, true, entry.ID <= 0) | |||
| 255 | - | ||||
| 256 | - | return fmt.Sprintf(`<article class="sv-history-item" data-sv-history-row data-history-id="%d"><div class="sv-history-main"><a class="sv-link sv-history-open" href="%s">%s</a><p class="sv-history-url">%s</p><p class="sv-history-meta">%s</p></div><div class="sv-history-row-actions"><a class="sv-button sv-button-secondary" href="%s">Open</a>%s</div></article>`, | |||
| 257 | - | entry.ID, | |||
| 258 | - | html.EscapeString(sanitizeHref(entry.URL)), | |||
| 259 | - | html.EscapeString(label), | |||
| 260 | - | html.EscapeString(entry.URL), | |||
| 261 | - | html.EscapeString(strings.Join(nonEmptyStrings(meta), " · ")), | |||
| 262 | - | html.EscapeString(sanitizeHref(entry.URL)), | |||
| 263 | - | deleteButton, | |||
| 264 | - | ) | |||
| 265 | - | } | |||
| 266 | - | ||||
| 267 | - | type historyTimelineGroup struct { | |||
| 268 | - | Date string | |||
| 269 | - | Label string | |||
| 270 | - | Entries []*entity.HistoryEntry | |||
| 271 | } | 116 | } | ||
| 272 | 117 | ||||
| 273 | func groupHistoryEntries(entries []*entity.HistoryEntry) []historyTimelineGroup { | 118 | func groupHistoryEntries(entries []*entity.HistoryEntry) []historyTimelineGroup { | ||
| @@ -380,6 +225,34 @@ func formatHistoryTime(ts time.Time) string { | |||||
| 380 | return ts.Local().Format("15:04") | 225 | return ts.Local().Format("15:04") | ||
| 381 | } | 226 | } | ||
| 382 | 227 | ||||
| 228 | + | func historyItemLabel(entry *entity.HistoryEntry) string { | |||
| 229 | + | if entry == nil { | |||
| 230 | + | return "" | |||
| 231 | + | } | |||
| 232 | + | label := strings.TrimSpace(entry.Title) | |||
| 233 | + | if label == "" { | |||
| 234 | + | label = displayHistoryDomain(entry.URL) | |||
| 235 | + | } | |||
| 236 | + | if label == "" { | |||
| 237 | + | label = entry.URL | |||
| 238 | + | } | |||
| 239 | + | return label | |||
| 240 | + | } | |||
| 241 | + | ||||
| 242 | + | func historyItemMeta(entry *entity.HistoryEntry) string { | |||
| 243 | + | if entry == nil { | |||
| 244 | + | return "" | |||
| 245 | + | } | |||
| 246 | + | meta := []string{displayHistoryDomain(entry.URL)} | |||
| 247 | + | if entry.VisitCount > 1 { | |||
| 248 | + | meta = append(meta, fmt.Sprintf("%dx", entry.VisitCount)) | |||
| 249 | + | } | |||
| 250 | + | if !entry.LastVisited.IsZero() { | |||
| 251 | + | meta = append(meta, formatHistoryTime(entry.LastVisited)) | |||
| 252 | + | } | |||
| 253 | + | return strings.Join(nonEmptyStrings(meta), " · ") | |||
| 254 | + | } | |||
| 255 | + | ||||
| 383 | func nonEmptyStrings(values []string) []string { | 256 | func nonEmptyStrings(values []string) []string { | ||
| 384 | out := values[:0] | 257 | out := values[:0] | ||
| 385 | for _, value := range values { | 258 | for _, value := range values { | ||
M internal/ui/systemviews/href_test.go +2 -2
| @@ -24,10 +24,10 @@ func TestHistoryHTMLSanitizesHrefSchemes(t *testing.T) { | |||
| 24 | 24 | func TestFavoriteItemsHTMLSanitizesHrefSchemes(t *testing.T) { | |
| 25 | 25 | t.Parallel() | |
| 26 | 26 | ||
| 27 | - | html := favoriteItemsHTML([]*entity.Favorite{ | |
| 27 | + | html := favoritesHTML(favoritesRenderData{Favorites: []*entity.Favorite{ | |
| 28 | 28 | {URL: "javascript:alert(1)", Title: "Bad"}, | |
| 29 | 29 | {URL: "https://example.com", Title: "Good"}, | |
| 30 | - | }, nil, nil) | |
| 30 | + | }}) | |
| 31 | 31 | ||
| 32 | 32 | require.NotContains(t, html, `href="javascript:alert(1)"`) | |
| 33 | 33 | assert.Contains(t, html, `href="#"`) | |
| @@ -24,10 +24,10 @@ func TestHistoryHTMLSanitizesHrefSchemes(t *testing.T) { | |||||
| 24 | func TestFavoriteItemsHTMLSanitizesHrefSchemes(t *testing.T) { | 24 | func TestFavoriteItemsHTMLSanitizesHrefSchemes(t *testing.T) { | ||
| 25 | t.Parallel() | 25 | t.Parallel() | ||
| 26 | 26 | ||||
| 27 | - | html := favoriteItemsHTML([]*entity.Favorite{ | 27 | + | html := favoritesHTML(favoritesRenderData{Favorites: []*entity.Favorite{ |
| 28 | {URL: "javascript:alert(1)", Title: "Bad"}, | 28 | {URL: "javascript:alert(1)", Title: "Bad"}, | ||
| 29 | {URL: "https://example.com", Title: "Good"}, | 29 | {URL: "https://example.com", Title: "Good"}, | ||
| 30 | - | }, nil, nil) | 30 | + | }}) |
| 31 | 31 | ||||
| 32 | require.NotContains(t, html, `href="javascript:alert(1)"`) | 32 | require.NotContains(t, html, `href="javascript:alert(1)"`) | ||
| 33 | assert.Contains(t, html, `href="#"`) | 33 | assert.Contains(t, html, `href="#"`) | ||
A internal/ui/systemviews/render.go +27 -0
| @@ -0,0 +1,27 @@ | |||
| 1 | + | package systemviews | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "bytes" | |
| 5 | + | "context" | |
| 6 | + | ||
| 7 | + | "github.com/a-h/templ" | |
| 8 | + | ) | |
| 9 | + | ||
| 10 | + | func renderComponent(ctx context.Context, component templ.Component) (string, error) { | |
| 11 | + | var buf bytes.Buffer | |
| 12 | + | if component == nil { | |
| 13 | + | return "", nil | |
| 14 | + | } | |
| 15 | + | if err := component.Render(ctx, &buf); err != nil { | |
| 16 | + | return "", err | |
| 17 | + | } | |
| 18 | + | return buf.String(), nil | |
| 19 | + | } | |
| 20 | + | ||
| 21 | + | func mustRenderComponent(component templ.Component) string { | |
| 22 | + | html, err := renderComponent(context.Background(), component) | |
| 23 | + | if err != nil { | |
| 24 | + | return errorStateHTML(err.Error()) | |
| 25 | + | } | |
| 26 | + | return html | |
| 27 | + | } | |
| @@ -0,0 +1,27 @@ | |||||
| 1 | + | package systemviews | |||
| 2 | + | ||||
| 3 | + | import ( | |||
| 4 | + | "bytes" | |||
| 5 | + | "context" | |||
| 6 | + | ||||
| 7 | + | "github.com/a-h/templ" | |||
| 8 | + | ) | |||
| 9 | + | ||||
| 10 | + | func renderComponent(ctx context.Context, component templ.Component) (string, error) { | |||
| 11 | + | var buf bytes.Buffer | |||
| 12 | + | if component == nil { | |||
| 13 | + | return "", nil | |||
| 14 | + | } | |||
| 15 | + | if err := component.Render(ctx, &buf); err != nil { | |||
| 16 | + | return "", err | |||
| 17 | + | } | |||
| 18 | + | return buf.String(), nil | |||
| 19 | + | } | |||
| 20 | + | ||||
| 21 | + | func mustRenderComponent(component templ.Component) string { | |||
| 22 | + | html, err := renderComponent(context.Background(), component) | |||
| 23 | + | if err != nil { | |||
| 24 | + | return errorStateHTML(err.Error()) | |||
| 25 | + | } | |||
| 26 | + | return html | |||
| 27 | + | } | |||
M internal/ui/systemviews/shell.go +36 -18
| @@ -4,6 +4,8 @@ import ( | |||
| 4 | 4 | "fmt" | |
| 5 | 5 | "html" | |
| 6 | 6 | "strings" | |
| 7 | + | ||
| 8 | + | "github.com/a-h/templ" | |
| 7 | 9 | ) | |
| 8 | 10 | ||
| 9 | 11 | type kvPair struct { | |
| @@ -22,34 +24,50 @@ type renderedPage struct { | |||
| 22 | 24 | // renderAppFrame produces a self-contained HTML fragment (no <html>, <head>, | |
| 23 | 25 | // or <body>) that wraps route content in the shared shell. | |
| 24 | 26 | func renderAppFrame(page renderedPage, theme shellTheme) string { | |
| 25 | - | rootClass := "sv-app" | |
| 27 | + | return mustRenderComponent(appFrameComponent(page, theme, templ.Raw(page.body))) | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | func appRootClass(theme shellTheme) string { | |
| 26 | 31 | themeClass := theme.RootClass | |
| 27 | 32 | if themeClass == "" { | |
| 28 | 33 | themeClass = "sv-dark" | |
| 29 | 34 | } | |
| 30 | - | rootClass += " " + themeClass | |
| 35 | + | return "sv-app " + themeClass | |
| 36 | + | } | |
| 31 | 37 | ||
| 32 | - | var styleAttr string | |
| 33 | - | if theme.InlineVars != "" { | |
| 34 | - | styleAttr = fmt.Sprintf(` style=%q`, html.EscapeString(theme.InlineVars)) | |
| 38 | + | func sectionClass(className string) string { | |
| 39 | + | classes := "sv-section" | |
| 40 | + | if strings.TrimSpace(className) != "" { | |
| 41 | + | classes += " " + strings.TrimSpace(className) | |
| 35 | 42 | } | |
| 43 | + | return classes | |
| 44 | + | } | |
| 36 | 45 | ||
| 37 | - | routeAttr := html.EscapeString(string(page.route)) | |
| 46 | + | func alertClass(kind string) string { | |
| 47 | + | classes := "sv-alert" | |
| 48 | + | switch kind { | |
| 49 | + | case "error": | |
| 50 | + | return classes + " sv-alert-error" | |
| 51 | + | case "success": | |
| 52 | + | return classes + " sv-alert-success" | |
| 53 | + | default: | |
| 54 | + | return classes | |
| 55 | + | } | |
| 56 | + | } | |
| 38 | 57 | ||
| 39 | - | var subtitle string | |
| 40 | - | if page.subtitle != "" { | |
| 41 | - | subtitle = fmt.Sprintf(`<h1 class="sv-title">%s</h1>`, html.EscapeString(page.subtitle)) | |
| 58 | + | func alertRole(kind string) string { | |
| 59 | + | if kind == "error" { | |
| 60 | + | return "alert" | |
| 42 | 61 | } | |
| 62 | + | return "status" | |
| 63 | + | } | |
| 43 | 64 | ||
| 44 | - | return fmt.Sprintf(`<div class=%q data-route=%q%s><div class=%q>%s<div class=%q>%s</div></div></div>`, | |
| 45 | - | html.EscapeString(rootClass), | |
| 46 | - | routeAttr, | |
| 47 | - | styleAttr, | |
| 48 | - | "sv-shell", | |
| 49 | - | subtitle, | |
| 50 | - | "sv-content", | |
| 51 | - | page.body, | |
| 52 | - | ) | |
| 65 | + | func buttonClass(extra string) string { | |
| 66 | + | classes := strings.TrimSpace("sv-button " + strings.TrimSpace(extra)) | |
| 67 | + | if classes == "" { | |
| 68 | + | return "sv-button" | |
| 69 | + | } | |
| 70 | + | return classes | |
| 53 | 71 | } | |
| 54 | 72 | ||
| 55 | 73 | func listHTML(rows, emptyMessage string) string { | |
| @@ -4,6 +4,8 @@ import ( | |||||
| 4 | "fmt" | 4 | "fmt" | ||
| 5 | "html" | 5 | "html" | ||
| 6 | "strings" | 6 | "strings" | ||
| 7 | + | ||||
| 8 | + | "github.com/a-h/templ" | |||
| 7 | ) | 9 | ) | ||
| 8 | 10 | ||||
| 9 | type kvPair struct { | 11 | type kvPair struct { | ||
| @@ -22,34 +24,50 @@ type renderedPage struct { | |||||
| 22 | // renderAppFrame produces a self-contained HTML fragment (no <html>, <head>, | 24 | // renderAppFrame produces a self-contained HTML fragment (no <html>, <head>, | ||
| 23 | // or <body>) that wraps route content in the shared shell. | 25 | // or <body>) that wraps route content in the shared shell. | ||
| 24 | func renderAppFrame(page renderedPage, theme shellTheme) string { | 26 | func renderAppFrame(page renderedPage, theme shellTheme) string { | ||
| 25 | - | rootClass := "sv-app" | 27 | + | return mustRenderComponent(appFrameComponent(page, theme, templ.Raw(page.body))) |
| 28 | + | } | |||
| 29 | + | ||||
| 30 | + | func appRootClass(theme shellTheme) string { | |||
| 26 | themeClass := theme.RootClass | 31 | themeClass := theme.RootClass | ||
| 27 | if themeClass == "" { | 32 | if themeClass == "" { | ||
| 28 | themeClass = "sv-dark" | 33 | themeClass = "sv-dark" | ||
| 29 | } | 34 | } | ||
| 30 | - | rootClass += " " + themeClass | 35 | + | return "sv-app " + themeClass |
| 36 | + | } | |||
| 31 | 37 | ||||
| 32 | - | var styleAttr string | 38 | + | func sectionClass(className string) string { |
| 33 | - | if theme.InlineVars != "" { | 39 | + | classes := "sv-section" |
| 34 | - | styleAttr = fmt.Sprintf(` style=%q`, html.EscapeString(theme.InlineVars)) | 40 | + | if strings.TrimSpace(className) != "" { |
| 41 | + | classes += " " + strings.TrimSpace(className) | |||
| 35 | } | 42 | } | ||
| 43 | + | return classes | |||
| 44 | + | } | |||
| 36 | 45 | ||||
| 37 | - | routeAttr := html.EscapeString(string(page.route)) | 46 | + | func alertClass(kind string) string { |
| 47 | + | classes := "sv-alert" | |||
| 48 | + | switch kind { | |||
| 49 | + | case "error": | |||
| 50 | + | return classes + " sv-alert-error" | |||
| 51 | + | case "success": | |||
| 52 | + | return classes + " sv-alert-success" | |||
| 53 | + | default: | |||
| 54 | + | return classes | |||
| 55 | + | } | |||
| 56 | + | } | |||
| 38 | 57 | ||||
| 39 | - | var subtitle string | 58 | + | func alertRole(kind string) string { |
| 40 | - | if page.subtitle != "" { | 59 | + | if kind == "error" { |
| 41 | - | subtitle = fmt.Sprintf(`<h1 class="sv-title">%s</h1>`, html.EscapeString(page.subtitle)) | 60 | + | return "alert" |
| 42 | } | 61 | } | ||
| 62 | + | return "status" | |||
| 63 | + | } | |||
| 43 | 64 | ||||
| 44 | - | return fmt.Sprintf(`<div class=%q data-route=%q%s><div class=%q>%s<div class=%q>%s</div></div></div>`, | 65 | + | func buttonClass(extra string) string { |
| 45 | - | html.EscapeString(rootClass), | 66 | + | classes := strings.TrimSpace("sv-button " + strings.TrimSpace(extra)) |
| 46 | - | routeAttr, | 67 | + | if classes == "" { |
| 47 | - | styleAttr, | 68 | + | return "sv-button" |
| 48 | - | "sv-shell", | 69 | + | } |
| 49 | - | subtitle, | 70 | + | return classes |
| 50 | - | "sv-content", | |||
| 51 | - | page.body, | |||
| 52 | - | ) | |||
| 53 | } | 71 | } | ||
| 54 | 72 | ||||
| 55 | func listHTML(rows, emptyMessage string) string { | 73 | func listHTML(rows, emptyMessage string) string { | ||