view

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package view holds the types shared by the shell, components and pages: page metadata, the user's appearance preferences, status values and date formatting. Pages receive plain view models; they never query services.

Index

Constants

View Source
const (
	LayoutA Layout = "a" // narrow sidebar
	LayoutB Layout = "b" // standard sidebar
	LayoutC Layout = "c" // no sidebar

	ThemeLight  Theme = "light"
	ThemeDark   Theme = "dark"
	ThemeSystem Theme = "system"

	DensityComfortable Density = "comfortable"
	DensityCompact     Density = "compact"
)

Allowed values.

View Source
const PrefsCookie = "myownpki_ui"

PrefsCookie stores the appearance preferences. It holds no secret, so it isn't signed; every value is checked against an allow-list when read. With TLS (phase 1) it gets the __Host- prefix and Secure.

Variables

Layouts, Themes and Densities list the allowed values in display order.

Functions

func ColonHex

func ColonHex(hex string) string

ColonHex formats hex digits as colon-separated byte pairs, like `openssl x509 -fingerprint` (78:3D:62:…). Input case and existing colons are ignored.

func Date

func Date(t time.Time) string

Date formats a time as an absolute UTC date (2027-01-04).

func DateTime

func DateTime(t time.Time) string

DateTime formats a time in UTC with minutes (2026-10-13 04:17 UTC).

func Fingerprint

func Fingerprint(hex string) string

Fingerprint formats a SHA-256 fingerprint like OpenSSL, split into two lines of 16 bytes so it fits a details column and can be compared line by line.

func Relative

func Relative(now, t time.Time) string

Relative describes t relative to now in whole days ("in 83 days", "44 days ago", "today").

Types

type ActivityRow

type ActivityRow struct {
	Time, Actor, Action, Target string
	Result                      Status
	ResultText                  string
}

ActivityRow is one audit entry in the recent-activity table.

type CertRow

type CertRow struct {
	ID, CommonName, Preset, CA string
	Serial                     string
	Expires, ExpiresRel        string
	Status                     Status
	StatusText                 string
}

CertRow is one certificate in a table (list, overview, CA details).

type Chart added in v0.3.8

type Chart struct {
	// ID is a constant of the calling page, not data: it builds the element
	// ids of the title and description (characters outside a-z, 0-9 and "-"
	// are dropped).
	ID   string
	Kind ChartKind
	// Title is the caption; Summary is the one sentence that tells what the
	// chart says (also the description for screen readers).
	Title, Summary string
	// Empty is shown instead of the chart when every value is zero.
	Empty string
	// CategoryHeader and ValueHeader head the numbers table (the value
	// column of the stacked kinds is one column per series, plus "Total").
	CategoryHeader, ValueHeader string
	// SeriesHeader adds a column to the table of the non-stacked kinds that
	// names the series of every category ("Window"): the same fact the color
	// shows, as text.
	SeriesHeader string
	// Legend draws the series as swatch plus text below the plot.
	Legend     bool
	Series     []ChartSeries
	Categories []ChartCategory
}

Chart is the plain description of a chart. Every string may be attacker-controlled (CA names come from operators, host names from agents): the component writes all of them through templ's escaping and clips them. The numbers of Values are the only input to the geometry.

type ChartCategory added in v0.3.8

type ChartCategory struct {
	// Label is the short text on the axis; Name the longer text for the
	// numbers table and the tooltip (defaults to Label).
	Label, Name string
	// Series is the index of the series that colors a category of the
	// kinds ChartColumns and ChartBars; the stacked kinds ignore it.
	Series int
	// Values: one value for ChartColumns and ChartBars, one per series for
	// the stacked kinds. Negative values count as zero.
	Values []int64
}

ChartCategory is one column or bar (a week, a CA, an agent state).

type ChartClass added in v0.3.8

type ChartClass string

ChartClass picks the color of a series. The status classes use the fixed status tokens (ADR-12); the three series classes are for data that has no status meaning (issuances by source) and carry a hatch pattern from the second one on, so color is never the only carrier.

const (
	ChartOK      ChartClass = "ok"
	ChartWarn    ChartClass = "warn"
	ChartCrit    ChartClass = "crit"
	ChartInfo    ChartClass = "info"
	ChartNeutral ChartClass = "neutral"
	ChartS1      ChartClass = "s1"
	ChartS2      ChartClass = "s2"
	ChartS3      ChartClass = "s3"
)

Chart classes.

type ChartKind added in v0.3.8

type ChartKind string

ChartKind is the shape of a server-rendered chart (docs/PHASE3.md D1).

const (
	// ChartColumns: one value per category; the series of the category
	// gives the color ("this week starts in the warning window").
	ChartColumns ChartKind = "columns"
	// ChartStacked: one value per series in every category, stacked.
	ChartStacked ChartKind = "stacked"
	// ChartBars: horizontal, one value per category.
	ChartBars ChartKind = "bars"
	// ChartStackedBars: horizontal, one value per series, stacked.
	ChartStackedBars ChartKind = "stackedbars"
)

Chart kinds. Vertical kinds draw one column per category, horizontal kinds one bar per category.

type ChartSeries added in v0.3.8

type ChartSeries struct {
	Label string
	Class ChartClass
}

ChartSeries is one legend entry: a text label and a color class.

type Crumb

type Crumb struct {
	Label, Href string
}

Crumb is one breadcrumb entry; an empty Href renders plain text.

type Density

type Density string

Density is the spacing of tables and controls.

type KV

type KV struct {
	Key, Value string
	Href       string
	Mono       bool
}

KV is one row of a key/value list.

type Layout

type Layout string

Layout is the shell variant (ADR-13).

type Message

type Message struct {
	Kind     MessageKind
	Text     string
	Href     string
	LinkText string
}

Message is one message bar, optionally with a link after the text.

type MessageKind

type MessageKind string

MessageKind selects the label of a message bar.

const (
	MessageInfo    MessageKind = "info"
	MessageSuccess MessageKind = "ok"
	MessageWarning MessageKind = "warn"
	MessageError   MessageKind = "crit"
)

Message kinds and their labels ("Warning:", "Error:" …).

func (MessageKind) Label

func (k MessageKind) Label() string

Label is the text label shown in front of the message.

type Option

type Option struct {
	Value, Label string
	Selected     bool
}

Option is one entry of a select or radio group.

type Page

type Page struct {
	Title       string
	Description string // optional one-line description under the title
	Status      Status // optional status next to the title
	StatusText  string
	Actions     templ.Component // optional command groups right of the title
	Section     string          // key of the active navigation entry
	Crumbs      []Crumb         // breadcrumb trail, without the current page
	Prefs       Prefs
	Dev         bool // show the DEV MODE banner
	Tenant      string
	Tenants     []string
	User        string
	Search      string // current value of the header search box

	// Session is the signed-in user of the real UI (phase 1 step 14); nil
	// in the prototype, which shows its placeholder user menu.
	Session *Session
	// Notices are shown above the page header on every page: the demo
	// warning and "signing is off" while sealed.
	Notices []Message
	// BuiltOnly hides navigation entries that don't exist yet.
	BuiltOnly bool

	// RefreshSeconds and RefreshURL make the page load RefreshURL after that
	// many seconds: a <meta http-equiv="refresh"> in the head, no script (the
	// UI ships none). RefreshURL is a local path; RefreshContent leaves the tag
	// out for anything else.
	RefreshSeconds int
	RefreshURL     string
}

Page is what every page passes to the application shell. The shell renders the page header – breadcrumb, title, status, description, actions – from it, so every page has the same header.

func (Page) HiddenNav

func (p Page) HiddenNav() map[string]bool

HiddenNav lists the navigation entries the signed-in user may not use.

func (Page) RefreshContent added in v0.3.5

func (p Page) RefreshContent() string

RefreshContent is the content of the refresh meta tag ("10;url=/hosts/add/x"), or "" when the page does not refresh or the URL is not a plain local path.

func (Page) WithActions

func (p Page) WithActions(c templ.Component) Page

WithActions returns a copy of p with the given header actions.

func (Page) WithStatus

func (p Page) WithStatus(s Status, text string) Page

WithStatus returns a copy of p with a status next to the title.

type Prefs

type Prefs struct {
	Layout  Layout
	Theme   Theme
	Density Density
}

Prefs are the per-user appearance settings.

func DefaultPrefs

func DefaultPrefs() Prefs

DefaultPrefs: standard sidebar, light, comfortable.

func ParsePrefs

func ParsePrefs(value string) Prefs

ParsePrefs reads the cookie value "layout.theme.density". Unknown or missing parts fall back to the default, so a tampered cookie can never inject anything into the page.

func PrefsFromRequest

func PrefsFromRequest(r *http.Request) Prefs

PrefsFromRequest returns the preferences of the request, or the defaults.

func (Prefs) Cookie

func (p Prefs) Cookie(secure bool) *http.Cookie

Cookie returns the cookie that stores p. secure must be true on TLS listeners.

func (Prefs) String

func (p Prefs) String() string

String is the cookie value.

type Session

type Session struct {
	Username string
	Roles    string // "admin of tenant default", for the user menu
	CSRF     string // token for the forms of the user menu
	CanSeal  bool   // instance admin: offer "Seal now"
	// CanIssue: the user may issue at one CA at least – otherwise "Issue
	// certificate" is not offered anywhere (no dead links, owner 2026-10-18).
	CanIssue bool
	// Hidden are navigation entries the user may not use (step 19).
	Hidden []string
}

Session is what the shell shows of the signed-in user.

type Status

type Status string

Status is the meaning of a status text. Colors are fixed tokens (ADR-12).

const (
	StatusOK      Status = "ok"
	StatusWarn    Status = "warn"
	StatusCrit    Status = "crit"
	StatusInfo    Status = "info"
	StatusNeutral Status = "neutral"
)

Statuses map to the CSS classes st-ok, st-warn, st-crit, st-info, st-neutral.

type Tab

type Tab struct {
	Label, Href string
	Active      bool
}

Tab is one tab of a tabbed detail page.

type Theme

type Theme string

Theme is the color scheme.

Jump to

Keyboard shortcuts

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