From 11ddf4013133e0a0ff0257cfa93b0a85f71d562a Mon Sep 17 00:00:00 2001 From: mitteneer Date: Wed, 26 Mar 2025 00:42:07 -0400 Subject: [PATCH] Add DataTables to some views This is awesome. Unfrotunately, it's all rather slow, but I'm mostly blaming db stuff for that. Still, very awesome to see where this is going. Need to add DataTables to more views, and see what I can do about sate sorting in the Scrobbles view --- .gitignore | 1 + src/app/views/artists/get.zmpl | 14 ++++++++- src/app/views/artists/index.zmpl | 20 +++++++++++-- src/app/views/scrobbles.zig | 32 +++++++++++++++++++-- src/app/views/scrobbles/index.zmpl | 46 +++++++++++++++++++++++------- src/app/views/songs.zig | 2 ++ src/app/views/songs/index.zmpl | 19 ++++++++++-- 7 files changed, 116 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index ea7b5c1..70b0239 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ static/ src/app/database/data.db-journal src/app/database/old_migrations/ src/lib +src/app/scripts/ \ No newline at end of file diff --git a/src/app/views/artists/get.zmpl b/src/app/views/artists/get.zmpl index 931fe9c..9913061 100644 --- a/src/app/views/artists/get.zmpl +++ b/src/app/views/artists/get.zmpl @@ -1,20 +1,32 @@ + @partial partials/header

{{.artist}}

- +
+ + + + @for (.albums) |album| { } +
NameScrobbles
{{album.name}} {{album.scrobbles}}
+ + \ No newline at end of file diff --git a/src/app/views/artists/index.zmpl b/src/app/views/artists/index.zmpl index a122138..6854e07 100644 --- a/src/app/views/artists/index.zmpl +++ b/src/app/views/artists/index.zmpl @@ -1,20 +1,34 @@ - + @partial partials/header -

Artists

- +

Artists

+
+ + + + + @for (.artists) |artist| { } +
NameScrobbles
{{artist.name}} {{artist.scrobbles}}
+ + \ No newline at end of file diff --git a/src/app/views/scrobbles.zig b/src/app/views/scrobbles.zig index 5ce68e9..7bd4f19 100644 --- a/src/app/views/scrobbles.zig +++ b/src/app/views/scrobbles.zig @@ -1,8 +1,36 @@ const std = @import("std"); const jetzig = @import("jetzig"); -pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; +pub fn index(request: *jetzig.Request) !jetzig.View { + var root = try request.data(.object); + var scrobbles_view = try root.put("scrobbles", .array); + const query = jetzig.database.Query(.Scrobble).select(.{}) + .include(.song, .{ .select = .{ .id, .name } }) + .include(.album, .{ .select = .{ .id, .name } }) + .include(.scrobbleartists, .{ .select = .{.artist_id} }) + .orderBy(.{ .date = .desc }); + const scrobbles = try request.repo.all(query); + for (scrobbles) |scrobble| { + var scrobble_view = try scrobbles_view.append(.object); + + var artist_infos = try scrobble_view.put("artist_info", .array); + for (scrobble.scrobbleartists) |artist| { + var artist_info = try artist_infos.append(.object); + const artist_data = try jetzig.database.Query(.Artist).where(.{ .id = artist.artist_id }).all(request.repo); + for (artist_data) |ad| { + try artist_info.put("name", ad.name); + try artist_info.put("id", ad.id); + } + } + + try scrobble_view.put("song_name", scrobble.song.name); + try scrobble_view.put("song_id", scrobble.song.id); + try scrobble_view.put("artist_name", "placeholder"); + try scrobble_view.put("artist_id", "placeholder"); + try scrobble_view.put("album_name", scrobble.album.name); + try scrobble_view.put("album_id", scrobble.album.id); + try scrobble_view.put("date", scrobble.date); + } return request.render(.ok); } diff --git a/src/app/views/scrobbles/index.zmpl b/src/app/views/scrobbles/index.zmpl index 48b753a..377f50f 100644 --- a/src/app/views/scrobbles/index.zmpl +++ b/src/app/views/scrobbles/index.zmpl @@ -1,16 +1,42 @@ - + + @partial partials/header -
- Look for an artist -
-
- - - -
+

Scrobbles

+ + + + + + + + + + +@for (.scrobbles) |scrobble| { + + + + + + +} + +
SongArtist(s)AlbumDate
{{scrobble.song_name}} + @for (scrobble.get("artist_info").?) |ai| { + {{ai.name}} + } + {{scrobble.album_name}}{{scrobble.date}}
+ + - + \ No newline at end of file diff --git a/src/app/views/songs.zig b/src/app/views/songs.zig index efd9222..1da1d88 100644 --- a/src/app/views/songs.zig +++ b/src/app/views/songs.zig @@ -7,9 +7,11 @@ pub fn index(request: *jetzig.Request) !jetzig.View { const query = jetzig.database.Query(.Song).select(.{}).orderBy(.{ .name = .asc }); const songs = try request.repo.all(query); for (songs) |song| { + const scrobbles = try jetzig.database.Query(.Scrobble).where(.{ .song_id = song.id }).count().execute(request.repo); 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("scrobbles", scrobbles); } return request.render(.ok); } diff --git a/src/app/views/songs/index.zmpl b/src/app/views/songs/index.zmpl index 76fc323..7efdc2f 100644 --- a/src/app/views/songs/index.zmpl +++ b/src/app/views/songs/index.zmpl @@ -1,19 +1,34 @@ - + @partial partials/header

Songs

- +
+ + + + + @for (.songs) |song| { + } +
NameScrobbles
{{song.name}}{{song.scrobbles}}
+ + \ No newline at end of file