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}
24
25// RefItem is a branch or tag in the ref switcher.
26type RefItem struct {
27 Name string
28 Href string
29 Current bool
30}
31
32// CmdItem is one target of the ":" command line.
33type CmdItem struct{ Kind, Label, Href string }
34
35// Layout is the input of the page shell.
36type Layout struct {
37 Title string
38 Instance string
39 Version string
40 SourceURL string
41 Assets Assets
42 Crumbs []Crumb
43 Ref string // ref shown in the header, "" outside a repo view
44 Short string // short sha shown after the ref
45 Sections []Section
46 Repo string
47 SHA string // full sha of the ref, for the permalink key
48 RefPath string // the URL segment that `y` rewrites: the ref name
49 Heads []RefItem
50 Tags []RefItem
51 Cmd []CmdItem
52 HasRail bool
53 // Lede is a line above the content and the rail, so both start level.
54 Lede string
55 // Live connects the page to the event stream (/-/events).
56 Live bool
57 // LiveURL is the stream the page follows, with its query.
58 LiveURL string
59 // PathsURL is the list of the file paths of the commit the page shows
60 // (/{repo}/paths/{sha}) and BlobBase the URL its file links start with;
61 // both are "" when the page has no commit to search.
62 PathsURL, BlobBase string
63 // Passkeys tells that the passkey routes exist: the header then links to
64 // them.
65 Passkeys bool
66}
67
68// Link is a plain label + href pair.
69type Link struct{ Label, Href string }
70
71// HomeRow is one repository in the home list.
72type HomeRow struct {
73 ID string
74 Name string
75 Href string
76 Desc string
77 Pushed string
78 PushedAt string // RFC 3339, "" when never pushed
79 Branch string
80 Tag string
81 Cursor bool
82 // Fresh marks a row that a push just updated (live updates only).
83 Fresh bool
84}
85
86// SortCol is a column header of the home list; it links to its sort order.
87type SortCol struct {
88 Label string
89 Href string
90 Dir string // "ascending" | "descending" | "none"
91 Mark string
92 Class string
93}
94
95// HomePage is the repository list.
96type HomePage struct {
97 Cols []SortCol
98 Rows []HomeRow
99}
100
101// Fact is one key/value row of the facts block.
102type Fact struct {
103 Key, Val, ID, Time string
104}
105
106// Clone is a block of copyable shell lines, one [copy] button per line.
107type Clone struct {
108 ID string
109 Lines []string
110}
111
112// Heading is one README outline entry.
113type Heading struct {
114 Level int
115 ID string
116 Text string
117}
118
119// Readme is a rendered README. HTML comes from the Markdown renderer (raw
120// HTML dropped, URLs filtered) or is escaped plain text.
121type Readme struct {
122 Name string
123 HTML template.HTML
124 // Note replaces the content when the file is not rendered (too large).
125 Note string
126}
127
128// CommitRow is one commit in the commit table.
129type CommitRow struct {
130 ID string
131 Short string
132 Subject string
133 CHref string
134 Author string
135 When string
136 WhenAt string
137 Merge bool
138 Branches []string
139 Tags []string
140 Cursor bool
141 // Checks is the combined state of the CI checks of the commit; empty when
142 // it has none.
143 Checks ChecksSummary
144}
145
146// SummaryPage is the repository summary.
147type SummaryPage struct {
148 Facts []Fact
149 Clone Clone
150 Recent []CommitRow
151 Readme *Readme
152 Outline []Heading
153 AllHref string
154 // Latest is the newest tag, nil when the repository has none.
155 Latest *LatestTag
156}
157
158// LatestTag is the newest tag of a repository, shown in the summary rail.
159// Name is empty when there are too many tags to date them; Count and
160// RefsHref still lead to the full list.
161type LatestTag struct {
162 Name, Href, Subject, When, WhenAt string
163 Count int
164 RefsHref string
165}
166
167// RefRow is a branch or a tag in the refs table.
168type RefRow struct {
169 Name, Href, Short, CHref, Subject, When, WhenAt string
170 Default, Cursor bool
171 // Checks is the combined state of the CI checks of the commit.
172 Checks ChecksSummary
173}
174
175// RefsPage lists the branches and tags of a repository.
176type RefsPage struct {
177 Branches []RefRow
178 Tags []RefRow
179 Latest string
180 Default string
181 // Note says the lists were cut.
182 Note string
183}
184
185// StatePage is a 404, 500 or empty-repository state.
186type StatePage struct {
187 Code string // "404", "500", "empty"
188 Title string
189 Lines []string
190 Clone *Clone
191 Back []Link
192}
193
194// LoginPage is the confirmation of a login link: a form with one button.
195type LoginPage struct {
196 Title string
197 Lines []string
198 Action string // where the form posts
199 Button string
200}
201
202// PasskeyLoginPage is the sign-in page: one button the script drives.
203type PasskeyLoginPage struct {
204 Title string
205 Lines []string
206 Button string
207 // Begin and Finish are the endpoints the script posts to.
208 Begin, Finish string
209}
210
211// PasskeyRow is one passkey on the passkeys page.
212type PasskeyRow struct {
213 Name string
214 // Created and LastUsed are relative ("3d ago"); the At fields are the
215 // RFC 3339 forms, "" when never.
216 Created, CreatedAt string
217 LastUsed, LastUsedAt string
218 Synced bool
219 // Remove is where the remove form posts.
220 Remove string
221}
222
223// PasskeysPage lists the passkeys and adds one.
224type PasskeysPage struct {
225 Rows []PasskeyRow
226 Begin, Finish string
227 // Full tells that no more passkeys can be added.
228 Full bool
229 Max int
230}