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 // IssueForm loads the script of the public issue form (issue-form.js).
73 IssueForm bool
74}
75
76// Link is a plain label + href pair.
77type Link struct{ Label, Href string }
78
79// HomeRow is one repository in the home list.
80type HomeRow struct {
81 ID string
82 Name string
83 Href string
84 Desc string
85 // Topics classify the repository, as on GitHub.
86 Topics []string
87 // Active is when the repository last changed (its last push or merge),
88 // ActiveAt its RFC 3339 form, "" when it never got a commit.
89 Active string
90 ActiveAt string
91 Cursor bool
92 // Stats are the figures of the row; nil when they could not be read.
93 Stats *HomeStats
94 // Private marks a private repository; only set for a signed-in visitor.
95 Private bool
96 // Fresh marks a row that a push just updated (live updates only).
97 Fresh bool
98 // Commits are the newest of the default branch. NoCommits says there is
99 // none (never pushed, or an empty branch); a failed read says nothing.
100 Commits []CommitRow
101 NoCommits bool
102 // CI is the latest run of the default branch, nil when there is none to
103 // show.
104 CI *HomeCI
105}
106
107// HomeStats are the figures of a home row: commits of the default branch,
108// those of the last 30 days, and the latest tag.
109type HomeStats struct {
110 Commits, Recent string
111 // Tag is the latest tag, "" without tags; TagHref links its tree, TagWhen
112 // tells when it was made.
113 Tag, TagHref, TagWhen string
114 // Pulse is the activity curve; nil when it could not be drawn.
115 Pulse *Heartbeat
116}
117
118// HomeCI is the state of the latest run of the default branch of a repository.
119type HomeCI struct {
120 Href string
121 Kind string // the mark: ok, bad, running, queued, skipped, cancelled
122 Label string // the word next to it
123 Title string
124}
125
126// SortLink is one way to order the home list; it links to that order.
127type SortLink struct {
128 Label string
129 Href string
130 Mark string // "▲" or "▼" on the current order, "" otherwise
131 // State says the current direction and what the link does, for screen
132 // readers (the mark is hidden from them); "" off the current order.
133 State string
134}
135
136// HomePage is the repository list.
137type HomePage struct {
138 Sorts []SortLink
139 Rows []HomeRow
140 // Inbox is the button to the owner's inbox; nil unless the owner is signed
141 // in.
142 Inbox *InboxButton
143}
144
145// InboxButton is the link to the inbox with the number of open items; Count is
146// negative when it could not be read.
147type InboxButton struct {
148 Href string
149 Count int
150}
151
152// Fact is one key/value row of the facts block.
153type Fact struct {
154 Key, Val, ID, Time string
155}
156
157// Clone is a block of copyable shell lines, one [copy] button per line.
158type Clone struct {
159 ID string
160 Lines []string
161}
162
163// Heading is one README outline entry.
164type Heading struct {
165 Level int
166 ID string
167 Text string
168}
169
170// Readme is a rendered README. HTML comes from the Markdown renderer (raw
171// HTML dropped, URLs filtered) or is escaped plain text.
172type Readme struct {
173 Name string
174 HTML template.HTML
175 // Note replaces the content when the file is not rendered (too large).
176 Note string
177}
178
179// CommitRow is one commit in the commit table.
180type CommitRow struct {
181 ID string
182 Short string
183 Subject string
184 CHref string
185 Author string
186 When string
187 WhenAt string
188 Merge bool
189 Branches []string
190 Tags []string
191 Cursor bool
192 // Checks is the combined state of the CI checks of the commit; empty when
193 // it has none.
194 Checks ChecksSummary
195 // Sig is the signature badge, nil for an unchecked or unsigned commit.
196 Sig *SignatureBadge
197}
198
199// SummaryPage is the repository summary.
200type SummaryPage struct {
201 Facts []Fact
202 Clone Clone
203 Recent []CommitRow
204 Readme *Readme
205 Outline []Heading
206 AllHref string
207 // Latest is the newest tag, nil when the repository has none.
208 Latest *LatestTag
209 // Actions is the recent runs of the rail, nil when the viewer cannot read
210 // CI (or the server runs none).
211 Actions *RecentActions
212}
213
214// RecentActions is the "Recent actions" block of the summary rail: the newest
215// runs. With no run the block is in the page but hidden, so that the first
216// run reaches it live.
217type RecentActions struct {
218 Runs []RunRow
219 AllHref string
220}
221
222// LatestTag is the newest tag of a repository, shown in the summary rail.
223// Name is empty when there are too many tags to date them; Count and
224// RefsHref still lead to the full list.
225type LatestTag struct {
226 Name, Href, Subject, When, WhenAt string
227 Count int
228 RefsHref string
229}
230
231// RefRow is a branch or a tag in the refs table.
232type RefRow struct {
233 Name, Href, Short, CHref, Subject, When, WhenAt string
234 Default, Cursor bool
235 // Checks is the combined state of the CI checks of the commit.
236 Checks ChecksSummary
237}
238
239// RefsPage lists the branches and tags of a repository.
240type RefsPage struct {
241 Branches []RefRow
242 Tags []RefRow
243 Latest string
244 Default string
245 // Note says the lists were cut.
246 Note string
247}
248
249// StatePage is a 404, 500 or empty-repository state.
250type StatePage struct {
251 Code string // "404", "500", "empty"
252 Title string
253 Lines []string
254 Clone *Clone
255 Back []Link
256}
257
258// LoginPage is the confirmation of a login link: a form with one button.
259type LoginPage struct {
260 Title string
261 Lines []string
262 Action string // where the form posts
263 Button string
264}
265
266// PasskeyLoginPage is the sign-in page: one button the script drives.
267type PasskeyLoginPage struct {
268 Title string
269 Lines []string
270 Button string
271 // Begin and Finish are the endpoints the script posts to.
272 Begin, Finish string
273}
274
275// PasskeyRow is one passkey on the passkeys page.
276type PasskeyRow struct {
277 Name string
278 // Created and LastUsed are relative ("3d ago"); the At fields are the
279 // RFC 3339 forms, "" when never.
280 Created, CreatedAt string
281 LastUsed, LastUsedAt string
282 Synced bool
283 // Remove is where the remove form posts.
284 Remove string
285}
286
287// PasskeysPage lists the passkeys and adds one.
288type PasskeysPage struct {
289 Rows []PasskeyRow
290 Begin, Finish string
291 // Full tells that no more passkeys can be added.
292 Full bool
293 Max int
294}