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