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