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 API messages.
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}
64
65// Link is a plain label + href pair.
66type Link struct{ Label, Href string }
67
68// HomeRow is one repository in the home list.
69type HomeRow struct {
70 ID string
71 Name string
72 Href string
73 Desc string
74 Pushed string
75 PushedAt string // RFC 3339, "" when never pushed
76 Branch string
77 Tag string
78 Cursor bool
79 // Fresh marks a row that a push just updated (live updates only).
80 Fresh bool
81}
82
83// SortCol is a column header of the home list; it links to its sort order.
84type SortCol struct {
85 Label string
86 Href string
87 Dir string // "ascending" | "descending" | "none"
88 Mark string
89 Class string
90}
91
92// HomePage is the repository list.
93type HomePage struct {
94 Cols []SortCol
95 Rows []HomeRow
96}
97
98// Fact is one key/value row of the facts block.
99type Fact struct {
100 Key, Val, ID, Time string
101}
102
103// Clone is a block of copyable shell lines, one [copy] button per line.
104type Clone struct {
105 ID string
106 Lines []string
107}
108
109// Heading is one README outline entry.
110type Heading struct {
111 Level int
112 ID string
113 Text string
114}
115
116// Readme is a rendered README. HTML comes from the Markdown renderer (raw
117// HTML dropped, URLs filtered) or is escaped plain text.
118type Readme struct {
119 Name string
120 HTML template.HTML
121 // Note replaces the content when the file is not rendered (too large).
122 Note string
123}
124
125// CommitRow is one commit in the commit table.
126type CommitRow struct {
127 ID string
128 Short string
129 Subject string
130 CHref string
131 Author string
132 When string
133 WhenAt string
134 Merge bool
135 Branches []string
136 Tags []string
137 Cursor bool
138}
139
140// SummaryPage is the repository summary.
141type SummaryPage struct {
142 Facts []Fact
143 Clone Clone
144 Recent []CommitRow
145 Readme *Readme
146 Outline []Heading
147 AllHref string
148 // Latest is the newest tag, nil when the repository has none.
149 Latest *LatestTag
150}
151
152// LatestTag is the newest tag of a repository, shown in the summary rail.
153// Name is empty when there are too many tags to date them; Count and
154// RefsHref still lead to the full list.
155type LatestTag struct {
156 Name, Href, Subject, When, WhenAt string
157 Count int
158 RefsHref string
159}
160
161// RefRow is a branch or a tag in the refs table.
162type RefRow struct {
163 Name, Href, Short, CHref, Subject, When, WhenAt string
164 Default, Cursor bool
165}
166
167// RefsPage lists the branches and tags of a repository.
168type RefsPage struct {
169 Branches []RefRow
170 Tags []RefRow
171 Latest string
172 Default string
173 // Note says the lists were cut.
174 Note string
175}
176
177// StatePage is a 404, 500 or empty-repository state.
178type StatePage struct {
179 Code string // "404", "500", "empty"
180 Title string
181 Lines []string
182 Clone *Clone
183 Back []Link
184}
185
186// LoginPage is the confirmation of a login link: a form with one button.
187type LoginPage struct {
188 Title string
189 Lines []string
190 Action string // where the form posts
191 Button string
192}