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