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
This commit is contained in:
mitteneer 2025-03-26 00:42:07 -04:00
parent 4adbd59e12
commit 11ddf40131
7 changed files with 116 additions and 18 deletions

View file

@ -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);
}