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}
71
72// Link is a plain label + href pair.
73type Link struct{ Label, Href string }
74
75// HomeRow is one repository in the home list.
76type HomeRow struct {
77 ID string
78 Name string
79 Href string
80 Desc string
81 Pushed string
82 PushedAt string // RFC 3339, "" when never pushed
83 Branch string
84 Tag string
85 Cursor bool
86 // Fresh marks a row that a push just updated (live updates only).
87 Fresh bool
88}
89
90// SortCol is a column header of the home list; it links to its sort order.
91type SortCol struct {
92 Label string
93 Href string
94 Dir string // "ascending" | "descending" | "none"
95 Mark string
96 Class string
97}
98
99// HomePage is the repository list.
100type HomePage struct {
101 Cols []SortCol
102 Rows []HomeRow
103}
104
105// Fact is one key/value row of the facts block.
106type Fact struct {
107 Key, Val, ID, Time string
108}
109
110// Clone is a block of copyable shell lines, one [copy] button per line.
111type Clone struct {
112 ID string
113 Lines []string
114}
115
116// Heading is one README outline entry.
117type Heading struct {
118 Level int
119 ID string
120 Text string
121}
122
123// Readme is a rendered README. HTML comes from the Markdown renderer (raw
124// HTML dropped, URLs filtered) or is escaped plain text.
125type Readme struct {
126 Name string
127 HTML template.HTML
128 // Note replaces the content when the file is not rendered (too large).
129 Note string
130}
131
132// CommitRow is one commit in the commit table.
133type CommitRow struct {
134 ID string
135 Short string
136 Subject string
137 CHref string
138 Author string
139 When string
140 WhenAt string
141 Merge bool
142 Branches []string
143 Tags []string
144 Cursor bool
145 // Checks is the combined state of the CI checks of the commit; empty when
146 // it has none.
147 Checks ChecksSummary
148}
149
150// SummaryPage is the repository summary.
151type SummaryPage struct {
152 Facts []Fact
153 Clone Clone
154 Recent []CommitRow
155 Readme *Readme
156 Outline []Heading
157 AllHref string
158 // Latest is the newest tag, nil when the repository has none.
159 Latest *LatestTag
160 // Actions is the recent runs of the rail, nil when the viewer cannot read
161 // CI (or the server runs none).
162 Actions *RecentActions
163}
164
165// RecentActions is the "Recent actions" block of the summary rail: the newest
166// runs. With no run the block is in the page but hidden, so that the first
167// run reaches it live.
168type RecentActions struct {
169 Runs []RunRow
170 AllHref string
171}
172
173// LatestTag is the newest tag of a repository, shown in the summary rail.
174// Name is empty when there are too many tags to date them; Count and
175// RefsHref still lead to the full list.
176type LatestTag struct {
177 Name, Href, Subject, When, WhenAt string
178 Count int
179 RefsHref string
180}
181
182// RefRow is a branch or a tag in the refs table.
183type RefRow struct {
184 Name, Href, Short, CHref, Subject, When, WhenAt string
185 Default, Cursor bool
186 // Checks is the combined state of the CI checks of the commit.
187 Checks ChecksSummary
188}
189
190// RefsPage lists the branches and tags of a repository.
191type RefsPage struct {
192 Branches []RefRow
193 Tags []RefRow
194 Latest string
195 Default string
196 // Note says the lists were cut.
197 Note string
198}
199
200// StatePage is a 404, 500 or empty-repository state.
201type StatePage struct {
202 Code string // "404", "500", "empty"
203 Title string
204 Lines []string
205 Clone *Clone
206 Back []Link
207}
208
209// LoginPage is the confirmation of a login link: a form with one button.
210type LoginPage struct {
211 Title string
212 Lines []string
213 Action string // where the form posts
214 Button string
215}
216
217// PasskeyLoginPage is the sign-in page: one button the script drives.
218type PasskeyLoginPage struct {
219 Title string
220 Lines []string
221 Button string
222 // Begin and Finish are the endpoints the script posts to.
223 Begin, Finish string
224}
225
226// PasskeyRow is one passkey on the passkeys page.
227type PasskeyRow struct {
228 Name string
229 // Created and LastUsed are relative ("3d ago"); the At fields are the
230 // RFC 3339 forms, "" when never.
231 Created, CreatedAt string
232 LastUsed, LastUsedAt string
233 Synced bool
234 // Remove is where the remove form posts.
235 Remove string
236}
237
238// PasskeysPage lists the passkeys and adds one.
239type PasskeysPage struct {
240 Rows []PasskeyRow
241 Begin, Finish string
242 // Full tells that no more passkeys can be added.
243 Full bool
244 Max int
245}