fragments.templ RawHistoryFolder
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3package web
4
5// The fragments of the live updates (events.go). Each is a top-level element
6// with an id: the page swaps the element that has the same id.
7
8// FactValue is the value of a fact; its id, when it has one, is the target of
9// the live updates ("last push").
10templ FactValue(f Fact) {
11 <dd
12 if f.ID != "" {
13 id={ f.ID }
14 }
15 >
16 if f.Time != "" {
17 <time datetime={ f.Time }>{ f.Val }</time>
18 } else {
19 { f.Val }
20 }
21 </dd>
22}
23
24// RepoGone replaces the row of a repository that is deleted or not visible
25// any more; the page removes the element.
26templ RepoGone(id string) {
27 <tr id={ id } data-gone hidden></tr>
28}
29
30// RefsBody is the rows of the refs table.
31templ RefsBody(p RefsPage) {
32 <tbody id="ref-rows" data-rows>
33 for _, b := range p.Branches {
34 @refRow("branch", b)
35 }
36 for _, t := range p.Tags {
37 @refRow("tag", t)
38 }
39 </tbody>
40}
41
42// RefsKV is the facts of the rail of the refs page.
43templ RefsKV(p RefsPage) {
44 <dl class="kv" id="refs-kv">
45 <dt>default</dt>
46 <dd>{ p.Default }</dd>
47 <dt>branches</dt>
48 <dd>{ itoa(len(p.Branches)) }</dd>
49 <dt>tags</dt>
50 <dd>{ itoa(len(p.Tags)) }</dd>
51 if p.Latest != "" {
52 <dt>latest tag</dt>
53 <dd>{ p.Latest }</dd>
54 }
55 </dl>
56}
57
58// CommitsSlot is the place of the banner of the commits page, empty.
59templ CommitsSlot() {
60 <div id="commits-head"></div>
61}
62
63// CommitsBanner announces new commits on the branch the page lists. It links
64// to the first page of the branch.
65templ CommitsBanner(text, href string) {
66 <div id="commits-head" class="live-banner" role="status">
67 <a href={ templ.SafeURL(href) }>{ text }</a>
68 </div>
69}
70
71// MRNotice tells a merge request page that it is out of date. The empty slot
72// of the page has the same id, so the first notice replaces it.
73templ MRNotice(text, href string) {
74 <div id="mr-notice" class="live-banner" role="status">
75 <a href={ templ.SafeURL(href) }>{ text }</a>
76 </div>
77}
78
79// Live is the connection state of the event stream, in the status bar.
80// Without a stream it reads "offline" and does nothing. The events of the
81// stream are fragments that ermiteLive (ermite.js) swaps in the page.
82templ Live(l Layout) {
83 if l.Live && l.LiveURL != "" {
84 <span
85 class="st-live"
86 data-state="offline"
87 role="status"
88 hx-sse:connect={ l.LiveURL }
89 hx-swap="none"
90 :text="data.state"
91 :title="data.state === 'live' ? 'receiving updates over SSE' : 'not connected to the event stream'"
92 hx-on="htmx:sse:after:connection -> data.state = 'live';
93 htmx:sse:close, htmx:sse:error -> data.state = 'offline';
94 home-list, repo-last-push, refs-list, commits-head, mr-notice -> ermiteLive.swap(event.detail.data);
95 gap -> ermiteLive.reload()"
96 >offline</span>
97 } else {
98 <span class="st-live" data-state="offline" role="status" title="not connected to the event stream">offline</span>
99 }
100}