diff --git a/build.zig.zon b/build.zig.zon
index c06a1ac..f2e5778 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -17,12 +17,12 @@
// internet connectivity.
.dependencies = .{
.jetzig = .{
- .url = "https://github.com/jetzig-framework/jetzig/archive/1feb18fb74e626fe068ec67532318640a9cb83be.tar.gz",
- .hash = "jetzig-0.0.0-IpAgLfMzDwDyAqZ05btcLDd9dfE_bxUbfOI_Wx7a19ed",
+ .url = "https://github.com/jetzig-framework/jetzig/archive/a298192bb0cddf9c45d7d0d976a9852804457de2.tar.gz",
+ .hash = "jetzig-0.0.0-IpAgLf5aDwB4UOKMhIjtK22zBsPfbWEwCYgHT0hayyT-",
},
.zeit = .{
- .url = "https://github.com/rockorager/zeit/archive/refs/heads/main.tar.gz",
- .hash = "zeit-0.6.0-5I6bk5daAgC-P60TjxRqW0bYknfCGxJp-03eS9UjGrO7",
+ .url = "https://github.com/rockorager/zeit/archive/refs/tags/v0.6.0.tar.gz",
+ .hash = "zeit-0.0.0-5I6bk_pZAgB03N1p1GmVOZ--gOFwwQSRKj1UXb5tnaKS",
},
},
.paths = .{
diff --git a/src/app/views/albums.zig b/src/app/views/albums.zig
index 06d6831..1264dac 100644
--- a/src/app/views/albums.zig
+++ b/src/app/views/albums.zig
@@ -29,19 +29,19 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
if (album.id == prev_album_id) {
var artist_info = try prev_artist_infos.?.append(.object);
try artist_info.put("name", album.artist_name);
- try artist_info.put("url", album.artist_id);
+ try artist_info.put("id", album.artist_id);
continue :blk;
}
var album_view = try albums_view.append(.object);
+ try album_view.put("name", album.name);
+ try album_view.put("id", album.id);
+ try album_view.put("scrobbles", album.scrobbles);
+
var artist_infos = try album_view.put("artist_info", .array);
var artist_info = try artist_infos.append(.object);
try artist_info.put("name", album.artist_name);
- try artist_info.put("url", album.artist_id);
-
- try album_view.put("name", album.name);
- try album_view.put("url", album.id);
- try album_view.put("scrobbles", album.scrobbles);
+ try artist_info.put("id", album.artist_id);
prev_artist_infos = artist_infos;
prev_album_id = album.id;
@@ -74,7 +74,7 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
const song = try song_row.to(Song, .{ .dupe = true, .allocator = request.allocator });
var song_view = try songs_view.append(.object);
try song_view.put("name", song.name);
- try song_view.put("url", song.id);
+ try song_view.put("id", song.id);
try song_view.put("scrobbles", song.scrobbles);
}
return request.render(.ok);
diff --git a/src/app/views/albums/get.zmpl b/src/app/views/albums/get.zmpl
index 8084038..3a1641b 100644
--- a/src/app/views/albums/get.zmpl
+++ b/src/app/views/albums/get.zmpl
@@ -1,3 +1,8 @@
+@zig {
+ const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date};
+ const columns: ColumnChoices = &.{.song, .scrobbles};
+}
+
@@ -5,15 +10,6 @@
@partial partials/header
{{.album}}
-
-
-| Name |
-@for (.songs) |song| {
-
- | {{song.name}} |
- {{song.scrobbles}} |
-
-}
-
+@partial partials/newtable(T: ColumnChoices, table_data: .songs, columns: columns)
\ No newline at end of file
diff --git a/src/app/views/albums/index.zmpl b/src/app/views/albums/index.zmpl
index e5536eb..43ff1de 100644
--- a/src/app/views/albums/index.zmpl
+++ b/src/app/views/albums/index.zmpl
@@ -1,40 +1,15 @@
+@zig {
+ const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date};
+ const columns: ColumnChoices = &.{.album, .artistlist, .scrobbles};
+}
+
-
@partial partials/header
Albums
-
-
-
-| Name |
-Artist(s) |
-Scrobbles |
-
-
-
-@for (.albums) |album| {
-
- | {{album.name}} |
-
- @for (album.get("artist_info").?) |ai| {
- {{ai.name}}
- }
- |
- {{album.scrobbles}} |
-
-}
-
-
-
-
+@partial partials/newtable(T: ColumnChoices, table_data: .albums, columns: columns)
\ No newline at end of file
diff --git a/src/app/views/artists.zig b/src/app/views/artists.zig
index 4164fc1..34cea3e 100644
--- a/src/app/views/artists.zig
+++ b/src/app/views/artists.zig
@@ -138,19 +138,23 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
defer first_last_songs_jq_result.deinit();
// These look backwards, but it's correct this way
+ var last_song_view = try root.put("last", .object);
+
if (try first_last_songs_jq_result.postgresql.result.next()) |last_song_row| {
const last_song = try last_song_row.to(ScrobbleResult, .{ .dupe = true, .allocator = request.allocator });
- try root.put("last_song_name", last_song.name);
- try root.put("last_song_id", last_song.id);
- try root.put("last_song_date", (try dateFmt(request.allocator, last_song.date)));
- }
+ try last_song_view.put("name", last_song.name);
+ try last_song_view.put("id", last_song.id);
+ try last_song_view.put("date", (try dateFmt(request.allocator, last_song.date)));
+ } else unreachable;
+
+ var first_song_view = try root.put("first", .object);
if (try first_last_songs_jq_result.postgresql.result.next()) |first_song_row| {
const first_song = try first_song_row.to(ScrobbleResult, .{ .dupe = true, .allocator = request.allocator });
- try root.put("first_song_name", first_song.name);
- try root.put("first_song_id", first_song.id);
- try root.put("first_song_date", (try dateFmt(request.allocator, first_song.date)));
- }
+ try first_song_view.put("name", first_song.name);
+ try first_song_view.put("id", first_song.id);
+ try first_song_view.put("date", (try dateFmt(request.allocator, first_song.date)));
+ } else unreachable;
try first_last_songs_jq_result.drain();
diff --git a/src/app/views/artists/get.zmpl b/src/app/views/artists/get.zmpl
index adf6158..48c1c25 100644
--- a/src/app/views/artists/get.zmpl
+++ b/src/app/views/artists/get.zmpl
@@ -1,53 +1,22 @@
+@zig {
+ const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date};
+ const columns: ColumnChoices = &.{.album, .scrobbles};
+}
+
-
@partial partials/header
{{.artist.name}}
-{{.artist.scrobbles}} scrobbles ({{.artist.rank}} place)
-
-First listen: {{.first_song_name}} ({{.first_song_date}})
-
-Most recent listen: {{.last_song_name}} ({{.last_song_date}})
+@partial partials/firstlast_listens(scrobbles: .artist.scrobbles, rank: .artist.rank, last_song: .last, first_song: .first)
+
Albums
-
-
-
-| Name | Scrobbles |
-
-
-
-@for (.albums) |album| {
-
- | {{album.name}} |
- {{album.scrobbles}} |
-
-}
-
-
+@partial partials/newtable(T: ColumnChoices, table_data: .albums, columns: columns)
+
Albums Featured On
-
-
-
- | Name | Scrobbles |
-
-
-
- @for (.appears) |album| {
-
- | {{album.name}} |
- {{album.scrobbles}} |
-
- }
-
-
-
-
+@partial partials/newtable(T: ColumnChoices, table_data: .appears, columns: columns)
+
\ No newline at end of file
diff --git a/src/app/views/partials/_firstlast_listens.zmpl b/src/app/views/partials/_firstlast_listens.zmpl
new file mode 100644
index 0000000..322a0e8
--- /dev/null
+++ b/src/app/views/partials/_firstlast_listens.zmpl
@@ -0,0 +1,9 @@
+@args scrobbles: i64, rank: []const u8, last_song: *ZmplValue, first_song: *ZmplValue
+
+
\ No newline at end of file
diff --git a/src/app/views/partials/_newtable.zmpl b/src/app/views/partials/_newtable.zmpl
index bee43c1..8960e21 100644
--- a/src/app/views/partials/_newtable.zmpl
+++ b/src/app/views/partials/_newtable.zmpl
@@ -1,18 +1,29 @@
-@args table_data *ZmplValue, table_headers: []enum{Song, Album, Artist, Scrobbles, Date}
+@args T: type, table_data: *ZmplValue, columns: T
@zig {
- for (table_headers) |header| {
+ for (columns) |header| {
switch (header) {
- .Artist => {
+ .song => {
+ | Song |
+ },
+ .album => {
+ Album |
+ },
+ .artist => {
+ Artist |
+ },
+ .artistlist => {
Artist(s) |
},
- inline else => |other| {
- const h = @tagName(other);
- {{h}} |
+ .scrobbles => {
+ Scrobbles |
},
+ .date => {
+ Date |
+ }
}
}
}
@@ -20,35 +31,38 @@
@zig {
- for (table_data) |data| {
+ const array = table_data.items(.array);
+ for (array) |ent| {
- for (table_header) |header| {
+ for (columns) |header| {
switch (header) {
- .Song => {
+ .song, .album, .artist => {
+ const path = switch (header) {
+ .song => "songs",
+ .album => "albums",
+ .artist => "artists",
+ else => unreachable
+ };
|
- {{data.name}}
+ {{ent.name}}
|
},
- .Album => {
+ .artistlist => {
- {{data.name}}
- |
- },
- .Artist => {
-
- @for (data.get("artist_info").?) |ai| {
- {{ai.name}}
+ @for (ent.get("artist_info").?) |artist| {
+ {{artist.name}}
}
|
},
- .Scrobbles => {
- {{data.scrobbles}} |
+ .scrobbles => {
+ {{ent.scrobbles}} |
},
- .Date =>{
- {{data.date}} |
+ .date =>{
+ {{ent.date}} |
}
- };
+ }
}
+
}
}
diff --git a/src/types.zig b/src/types.zig
index 2574610..455f282 100644
--- a/src/types.zig
+++ b/src/types.zig
@@ -62,10 +62,13 @@ pub const Rules = struct {
rules: []const Rule,
};
-pub const Headers = []enum {
- Song,
- Album,
- Artist,
- Scrobbles,
- Date,
-};
+// Can't import types in .zmpl files, so defining this here
+// doesn't really do much (except maybe in the .zig file for views?)
+//pub const HeaderTypes = []enum {
+// song,
+// album,
+// artist,
+// artistlist,
+// scrobbles,
+// date,
+//};