1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5import "html/template"
6
7// View models handed to the templ components. Components only loop and
8// branch on these; the handlers build them from the use case results.
9
10// Crumb is one segment of the path in the header.
11type Crumb struct {
12 Label string
13 Href string
14 Current bool
15}
16
17// Section is a repository tab under the header, reached by its key.
18type Section struct {
19 Key string // mnemonic key
20 Label string
21 Href string
22 Current bool
23 // Count is shown after the label when it is not empty: the open merge
24 // requests.
25 Count string
26}
27
28// RefItem is a branch or tag in the ref switcher.
29type RefItem struct {
30 Name string
31 Href string
32 Current bool
33}
34
35// CmdItem is one target of the ":" command line.
36type CmdItem struct{ Kind, Label, Href string }
37
38// Layout is the input of the page shell.
39type Layout struct {
40 Title string
41 // Owner is the owner's name (ERMITE_OWNER), shown when signed in.
42 Owner string
43 Version string
44 SourceURL string
45 Assets Assets
46 Crumbs []Crumb
47 Ref string // ref shown in the header, "" outside a repo view
48 Short string // short sha shown after the ref
49 Sections []Section
50 Repo string
51 SHA string // full sha of the ref, for the permalink key
52 RefPath string // the URL segment that `y` rewrites: the ref name
53 Heads []RefItem
54 Tags []RefItem
55 Cmd []CmdItem
56 HasRail bool
57 // Lede is a line above the content and the rail, so both start level.
58 Lede string
59 // Live connects the page to the event stream (/-/events).
60 Live bool
61 // LiveURL is the stream the page follows, with its query.
62 LiveURL string
63 // PathsURL is the list of the file paths of the commit the page shows
64 // (/{repo}/paths/{sha}) and BlobBase the URL its file links start with;
65 // both are "" when the page has no commit to search.
66 PathsURL, BlobBase string
67 // Passkeys tells that the passkey routes exist: the header then links to
68 // them.
69 Passkeys bool
70 // MR loads the script of the merge request page (mr.js).
71 MR bool
72}
73
74// Link is a plain label + href pair.
75type Link struct{ Label, Href string }
76
77// HomeRow is one repository in the home list.
78type HomeRow struct {
79 ID string
80 Name string
81 Href string
82 Desc string
83 // Topics classify the repository, as on GitHub.
84 Topics []string
85 // Active is when the repository last changed (its last push or merge),
86 // ActiveAt its RFC 3339 form, "" when it never got a commit.
87 Active string
88 ActiveAt string
89 Cursor bool
90 // Stats are the figures of the row; nil when they could not be read.
91 Stats *HomeStats
92 // Private marks a private repository; only set for a signed-in visitor.
93 Private bool
94 // Fresh marks a row that a push just updated (live updates only).
95 Fresh bool
96 // Commits are the newest of the default branch. NoCommits says there is
97 // none (never pushed, or an empty branch); a failed read says nothing.
98 Commits []CommitRow
99 NoCommits bool
100 // CI is the latest run of the default branch, nil when there is none to
101 // show.
102 CI *HomeCI
103}
104
105// HomeStats are the figures of a home row: commits of the default branch,
106// those of the last 30 days, and the latest tag.
107type HomeStats struct {
108 Commits, Recent string
109 // Tag is the latest tag, "" without tags; TagHref links its tree, TagWhen
110 // tells when it was made.
111 Tag, TagHref, TagWhen string
112 // Pulse is the activity curve; nil when it could not be drawn.
113 Pulse *Heartbeat
114}
115
116// HomeCI is the state of the latest run of the default branch of a repository.
117type HomeCI struct {
118 Href string
119 Kind string // the mark: ok, bad, running, queued, skipped, cancelled
120 Label string // the word next to it
121 Title string
122}
123
124// SortLink is one way to order the home list; it links to that order.
125type SortLink struct {
126 Label string
127 Href string
128 Mark string // "▲" or "▼" on the current order, "" otherwise
129 // State says the current direction and what the link does, for screen
130 // readers (the mark is hidden from them); "" off the current order.
131 State string
132}
133
134// HomePage is the repository list.
135type HomePage struct {
136 Sorts []SortLink
137 Rows []HomeRow
138}
139
140// Fact is one key/value row of the facts block.
141type Fact struct {
142 Key, Val, ID, Time string
143}
144
145// Clone is a block of copyable shell lines, one [copy] button per line.
146type Clone struct {
147 ID string
148 Lines []string
149}
150
151// Heading is one README outline entry.
152type Heading struct {
153 Level int
154 ID string
155 Text string
156}
157
158// Readme is a rendered README. HTML comes from the Markdown renderer (raw
159// HTML dropped, URLs filtered) or is escaped plain text.
160type Readme struct {
161 Name string
162 HTML template.HTML
163 // Note replaces the content when the file is not rendered (too large).
164 Note string
165}
166
167// CommitRow is one commit in the commit table.
168type CommitRow struct {
169 ID string
170 Short string
171 Subject string
172 CHref string
173 Author string
174 When string
175 WhenAt string
176 Merge bool
177 Branches []string
178 Tags []string
179 Cursor bool
180 // Checks is the combined state of the CI checks of the commit; empty when
181 // it has none.
182 Checks ChecksSummary
183 // Sig is the signature badge, nil for an unchecked or unsigned commit.
184 Sig *SignatureBadge
185}
186
187// SummaryPage is the repository summary.
188type SummaryPage struct {
189 Facts []Fact
190 Clone Clone
191 Recent []CommitRow
192 Readme *Readme
193 Outline []Heading
194 AllHref string
195 // Latest is the newest tag, nil when the repository has none.
196 Latest *LatestTag
197 // Actions is the recent runs of the rail, nil when the viewer cannot read
198 // CI (or the server runs none).
199 Actions *RecentActions
200}
201
202// RecentActions is the "Recent actions" block of the summary rail: the newest
203// runs. With no run the block is in the page but hidden, so that the first
204// run reaches it live.
205type RecentActions struct {
206 Runs []RunRow
207 AllHref string
208}
209
210// LatestTag is the newest tag of a repository, shown in the summary rail.
211// Name is empty when there are too many tags to date them; Count and
212// RefsHref still lead to the full list.
213type LatestTag struct {
214 Name, Href, Subject, When, WhenAt string
215 Count int
216 RefsHref string
217}
218
219// RefRow is a branch or a tag in the refs table.
220type RefRow struct {
221 Name, Href, Short, CHref, Subject, When, WhenAt string
222 Default, Cursor bool
223 // Checks is the combined state of the CI checks of the commit.
224 Checks ChecksSummary
225}
226
227// RefsPage lists the branches and tags of a repository.
228type RefsPage struct {
229 Branches []RefRow
230 Tags []RefRow
231 Latest string
232 Default string
233 // Note says the lists were cut.
234 Note string
235}
236
237// StatePage is a 404, 500 or empty-repository state.
238type StatePage struct {
239 Code string // "404", "500", "empty"
240 Title string
241 Lines []string
242 Clone *Clone
243 Back []Link
244}
245
246// LoginPage is the confirmation of a login link: a form with one button.
247type LoginPage struct {
248 Title string
249 Lines []string
250 Action string // where the form posts
251 Button string
252}
253
254// PasskeyLoginPage is the sign-in page: one button the script drives.
255type PasskeyLoginPage struct {
256 Title string
257 Lines []string
258 Button string
259 // Begin and Finish are the endpoints the script posts to.
260 Begin, Finish string
261}
262
263// PasskeyRow is one passkey on the passkeys page.
264type PasskeyRow struct {
265 Name string
266 // Created and LastUsed are relative ("3d ago"); the At fields are the
267 // RFC 3339 forms, "" when never.
268 Created, CreatedAt string
269 LastUsed, LastUsedAt string
270 Synced bool
271 // Remove is where the remove form posts.
272 Remove string
273}
274
275// PasskeysPage lists the passkeys and adds one.
276type PasskeysPage struct {
277 Rows []PasskeyRow
278 Begin, Finish string
279 // Full tells that no more passkeys can be added.
280 Full bool
281 Max int
282}