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