Create partial for view agnostic table
This commit is contained in:
parent
3345b20f1f
commit
762a4fd51e
2 changed files with 63 additions and 0 deletions
55
src/app/views/partials/_newtable.zmpl
Normal file
55
src/app/views/partials/_newtable.zmpl
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
@args table_data *ZmplValue, table_headers: []enum{Song, Album, Artist, Scrobbles, Date}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@zig {
|
||||
for (table_headers) |header| {
|
||||
switch (header) {
|
||||
.Artist => {
|
||||
<th>Artist(s)</th>
|
||||
},
|
||||
inline else => |other| {
|
||||
const h = @tagName(other);
|
||||
<th>{{h}}</th>
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@zig {
|
||||
for (table_data) |data| {
|
||||
<tr>
|
||||
for (table_header) |header| {
|
||||
switch (header) {
|
||||
.Song => {
|
||||
<td class=cell>
|
||||
<a href="/songs/{{data.id}}">{{data.name}}</a>
|
||||
</td>
|
||||
},
|
||||
.Album => {
|
||||
<td class=cell>
|
||||
<a href="/albums/{{data.id}}">{{data.name}}</a>
|
||||
</td>
|
||||
},
|
||||
.Artist => {
|
||||
<td class=cell>
|
||||
@for (data.get("artist_info").?) |ai| {
|
||||
<a href="/artists/{{ai.id}}">{{ai.name}}</a>
|
||||
}
|
||||
</td>
|
||||
},
|
||||
.Scrobbles => {
|
||||
<td class=cell>{{data.scrobbles}}</td>
|
||||
},
|
||||
.Date =>{
|
||||
<td class=cell>{{data.date}}</td>
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -61,3 +61,11 @@ pub const Rule = struct {
|
|||
pub const Rules = struct {
|
||||
rules: []const Rule,
|
||||
};
|
||||
|
||||
pub const Headers = []enum {
|
||||
Song,
|
||||
Album,
|
||||
Artist,
|
||||
Scrobbles,
|
||||
Date,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue