Skip to content

Commit cf2ea8c

Browse files
committed
web: extract patch row into its own template
Factor the per-row markup out of patchListPage into a patchRow template to reduce nesting depth. Move the toolbar toggle and pagination scripts after the form for cleaner ordering. Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent c75f402 commit cf2ea8c

1 file changed

Lines changed: 65 additions & 59 deletions

File tree

‎pkg/web/patches.templ‎

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -143,51 +143,7 @@ templ patchListPage(d patchListData) {
143143
<tbody>
144144
for _, p := range d.Patches {
145145
<tr>
146-
if d.PC.User != nil {
147-
<td class="checkbox"><input type="checkbox" name="patch_id" value={ fmt.Sprintf("%d", p.ID) }/></td>
148-
}
149-
<td>
150-
<a href={ templ.SafeURL(patchURL(d.Project.Linkname, p.Msgid)) }>
151-
{ truncate(p.Name, 100) }
152-
</a>
153-
</td>
154-
<td>
155-
if p.SeriesID != nil {
156-
<a href={ templ.SafeURL(fmt.Sprintf("/project/%s/list/?series=%d", d.Project.Linkname, *p.SeriesID)) }>
157-
if name, ok := d.SeriesNames[*p.SeriesID]; ok && name != "" {
158-
{ truncate(name, 80) }
159-
} else {
160-
{ fmt.Sprintf("#%d", *p.SeriesID) }
161-
}
162-
</a>
163-
}
164-
</td>
165-
<td>
166-
@tagCounts(d.TagAbbrevs, p.Tags)
167-
</td>
168-
<td>
169-
@checkCounts(p.CheckCounts)
170-
</td>
171-
<td>{ p.Date.Format("2006-01-02") }</td>
172-
<td>
173-
if p.Submitter != nil {
174-
<a href={ templ.SafeURL(fmt.Sprintf("/project/%s/list/?submitter=%d", d.Project.Linkname, p.SubmitterID)) }>
175-
{ personName(p.Submitter) }
176-
</a>
177-
}
178-
</td>
179-
<td>
180-
if p.Delegate != nil {
181-
<a href={ templ.SafeURL(fmt.Sprintf("/project/%s/list/?delegate=%d", d.Project.Linkname, *p.DelegateID)) }>
182-
{ p.Delegate.Username }
183-
</a>
184-
}
185-
</td>
186-
<td>
187-
if p.State != nil {
188-
{ p.State.Name }
189-
}
190-
</td>
146+
@patchRow(&d, &p)
191147
</tr>
192148
}
193149
if len(d.Patches) == 0 {
@@ -199,6 +155,20 @@ templ patchListPage(d patchListData) {
199155
</table>
200156
</patch-list>
201157
</form>
158+
if d.TotalPages > 1 {
159+
@pagination(d.Page, d.TotalPages, d.BaseQuery)
160+
}
161+
<script>
162+
(function() {
163+
var btn = document.getElementById("toggle-toolbar");
164+
var els = document.querySelectorAll(".toolbar");
165+
btn.addEventListener("click", function() {
166+
var show = els[0].style.display === "none";
167+
els.forEach(function(el) { el.style.display = show ? "" : "none"; });
168+
btn.innerHTML = show ? "Filters &amp; Actions &#9652;" : "Filters &amp; Actions &#9662;";
169+
});
170+
})();
171+
</script>
202172
if d.PC.User != nil {
203173
<script>
204174
(function() {
@@ -223,23 +193,59 @@ templ patchListPage(d patchListData) {
223193
})();
224194
</script>
225195
}
226-
if d.TotalPages > 1 {
227-
@pagination(d.Page, d.TotalPages, d.BaseQuery)
228-
}
229-
<script>
230-
(function() {
231-
var btn = document.getElementById("toggle-toolbar");
232-
var els = document.querySelectorAll(".toolbar");
233-
btn.addEventListener("click", function() {
234-
var show = els[0].style.display === "none";
235-
els.forEach(function(el) { el.style.display = show ? "" : "none"; });
236-
btn.innerHTML = show ? "Filters &amp; Actions &#9652;" : "Filters &amp; Actions &#9662;";
237-
});
238-
})();
239-
</script>
240196
}
241197
}
242198

199+
templ patchRow(d *patchListData, p *db.Patch) {
200+
if d.PC.User != nil {
201+
<td class="checkbox">
202+
<input type="checkbox" name="patch_id" value={ fmt.Sprintf("%d", p.ID) }/>
203+
</td>
204+
}
205+
<td>
206+
<a href={ templ.SafeURL(patchURL(d.Project.Linkname, p.Msgid)) }>
207+
{ truncate(p.Name, 100) }
208+
</a>
209+
</td>
210+
<td>
211+
if p.SeriesID != nil {
212+
<a href={ templ.SafeURL(fmt.Sprintf("/project/%s/list/?series=%d", d.Project.Linkname, *p.SeriesID)) }>
213+
if name, ok := d.SeriesNames[*p.SeriesID]; ok && name != "" {
214+
{ truncate(name, 80) }
215+
} else {
216+
{ fmt.Sprintf("#%d", *p.SeriesID) }
217+
}
218+
</a>
219+
}
220+
</td>
221+
<td>
222+
@tagCounts(d.TagAbbrevs, p.Tags)
223+
</td>
224+
<td>
225+
@checkCounts(p.CheckCounts)
226+
</td>
227+
<td>{ p.Date.Format("2006-01-02") }</td>
228+
<td>
229+
if p.Submitter != nil {
230+
<a href={ templ.SafeURL(fmt.Sprintf("/project/%s/list/?submitter=%d", d.Project.Linkname, p.SubmitterID)) }>
231+
{ personName(p.Submitter) }
232+
</a>
233+
}
234+
</td>
235+
<td>
236+
if p.Delegate != nil {
237+
<a href={ templ.SafeURL(fmt.Sprintf("/project/%s/list/?delegate=%d", d.Project.Linkname, *p.DelegateID)) }>
238+
{ p.Delegate.Username }
239+
</a>
240+
}
241+
</td>
242+
<td>
243+
if p.State != nil {
244+
{ p.State.Name }
245+
}
246+
</td>
247+
}
248+
243249
templ tagCounts(abbrevs []string, tags map[string]int) {
244250
for _, a := range abbrevs {
245251
<pill>

0 commit comments

Comments
 (0)