Add more information to artists view, songs view, and format dates correctly in scrobbles view
This commit is contained in:
parent
01fe10f045
commit
65136a44d6
9 changed files with 82 additions and 34 deletions
|
|
@ -18,11 +18,14 @@ Licensed under MIT.
|
||||||
- [ ] List all songs on artist page, with respective album
|
- [ ] List all songs on artist page, with respective album
|
||||||
- [x] List all albums on artist page
|
- [x] List all albums on artist page
|
||||||
- [x] Include number of plays for each
|
- [x] Include number of plays for each
|
||||||
|
- [x] List albums features on
|
||||||
- [x] See all albums under "/albums"
|
- [x] See all albums under "/albums"
|
||||||
- [x] See all songs from album
|
- [x] See all songs from album
|
||||||
- [x] Include number of plays
|
- [x] Include number of plays
|
||||||
|
- [x] Include name of artist(s)
|
||||||
|
- [ ] Include artists features on each song
|
||||||
- [x] See all songs under "/songs"
|
- [x] See all songs under "/songs"
|
||||||
- [ ] Include respective artist(s)
|
- [x] Include respective artist(s)
|
||||||
- [ ] Include respective album[^10]
|
- [ ] Include respective album[^10]
|
||||||
- [x] Include number of plays
|
- [x] Include number of plays
|
||||||
- [ ] Create disambiguation pages
|
- [ ] Create disambiguation pages
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
continue :blk;
|
continue :blk;
|
||||||
}
|
}
|
||||||
var album_view = try albums_view.append(.object);
|
var album_view = try albums_view.append(.object);
|
||||||
|
|
||||||
var artist_infos = try album_view.put("artist_info", .array);
|
var artist_infos = try album_view.put("artist_info", .array);
|
||||||
var artist_info = try artist_infos.append(.object);
|
var artist_info = try artist_infos.append(.object);
|
||||||
try artist_info.put("name", album.artist_name);
|
try artist_info.put("name", album.artist_name);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
|
pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
|
||||||
var root = try request.data(.object);
|
var root = try request.data(.object);
|
||||||
var albums_view = try root.put("albums", .array);
|
var albums_view = try root.put("albums", .array);
|
||||||
|
var appears = try root.put("appears", .array);
|
||||||
const artist_name = try jetzig.database.Query(.Artist).find(id).select(.{ .id, .name }).execute(request.repo);
|
const artist_name = try jetzig.database.Query(.Artist).find(id).select(.{ .id, .name }).execute(request.repo);
|
||||||
_ = try root.put("artist", artist_name.?.name);
|
_ = try root.put("artist", artist_name.?.name);
|
||||||
const query =
|
const query =
|
||||||
|
|
@ -48,6 +49,18 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
|
||||||
\\ORDER BY scrobbles DESC
|
\\ORDER BY scrobbles DESC
|
||||||
;
|
;
|
||||||
|
|
||||||
|
const appears_query =
|
||||||
|
\\SELECT albums.name, albums.id, COUNT(scrobbles) AS scrobbles
|
||||||
|
\\FROM artistalbums
|
||||||
|
\\INNER JOIN albums ON albums.id = artistalbums.album_id
|
||||||
|
\\INNER JOIN albumsongs ON albumsongs.album_id = albums.id
|
||||||
|
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
||||||
|
\\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id
|
||||||
|
\\WHERE albumsongsartists.artist_id = $1 AND artistalbums.artist_id != $1
|
||||||
|
\\GROUP BY albums.id
|
||||||
|
\\ORDER BY scrobbles DESC;
|
||||||
|
;
|
||||||
|
|
||||||
var albums_jq_result = try request.repo.executeSql(query, .{id});
|
var albums_jq_result = try request.repo.executeSql(query, .{id});
|
||||||
defer albums_jq_result.deinit();
|
defer albums_jq_result.deinit();
|
||||||
|
|
||||||
|
|
@ -60,30 +73,18 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
|
||||||
try album_view.put("url", album.id);
|
try album_view.put("url", album.id);
|
||||||
try album_view.put("scrobbles", album.scrobbles);
|
try album_view.put("scrobbles", album.scrobbles);
|
||||||
}
|
}
|
||||||
//const artist = try jetzig.database.Query(.Artist)
|
|
||||||
// .find(id)
|
|
||||||
// .select(.{ .id, .name })
|
|
||||||
// .execute(request.repo);
|
|
||||||
//var root = try request.data(.object);
|
|
||||||
//try root.put("artist", artist.?.name);
|
|
||||||
//var albums_view = try root.put("albums", .array);
|
|
||||||
//const query = jetzig.database.Query(.Albumartist)
|
|
||||||
// .select(.{.id})
|
|
||||||
// .include(.album, .{ .select = .{ .name, .id } })
|
|
||||||
// .join(.inner, .artist)
|
|
||||||
// .where(.{ .artist = .{ .id = id } });
|
|
||||||
|
|
||||||
//const albums = try request.repo.all(query);
|
var appears_jq_result = try request.repo.executeSql(appears_query, .{id});
|
||||||
//for (albums) |album| {
|
defer appears_jq_result.deinit();
|
||||||
// const scrobbles = try jetzig.database.Query(.Scrobble)
|
|
||||||
// .where(.{ .album_id = album.album.id })
|
while (try appears_jq_result.postgresql.result.next()) |album_row| {
|
||||||
// .count()
|
const album = try album_row.to(Album, .{ .dupe = true, .allocator = request.allocator });
|
||||||
// .execute(request.repo);
|
var album_view = try appears.append(.object);
|
||||||
// var album_view = try albums_view.append(.object);
|
try album_view.put("name", album.name);
|
||||||
// try album_view.put("name", album.album.name);
|
try album_view.put("url", album.id);
|
||||||
// try album_view.put("url", album.album.id);
|
try album_view.put("scrobbles", album.scrobbles);
|
||||||
// try album_view.put("scrobbles", scrobbles);
|
}
|
||||||
//}
|
|
||||||
return request.render(.ok);
|
return request.render(.ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
<body>
|
<body>
|
||||||
@partial partials/header
|
@partial partials/header
|
||||||
<h1>{{.artist}}</h1>
|
<h1>{{.artist}}</h1>
|
||||||
|
<h2>Albums</h2>
|
||||||
<table id="myTable">
|
<table id="myTable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -21,6 +22,22 @@
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<h2>Albums Featured On</h2>
|
||||||
|
<table id="myTable">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th><th>Scrobbles</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@for (.appears) |album| {
|
||||||
|
<tr>
|
||||||
|
<td class=cell><a href="/albums/{{album.url}}">{{album.name}}</a></td>
|
||||||
|
<td class=cell>{{album.scrobbles}}</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
<table>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest" type="text/javascript"></script>
|
<script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest" type="text/javascript"></script>
|
||||||
<script>
|
<script>
|
||||||
const dataTable = new simpleDatatables.DataTable("#myTable", {
|
const dataTable = new simpleDatatables.DataTable("#myTable", {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const jetzig = @import("jetzig");
|
const jetzig = @import("jetzig");
|
||||||
|
const zeit = @import("zeit");
|
||||||
|
|
||||||
pub fn index(request: *jetzig.Request) !jetzig.View {
|
pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
var root = try request.data(.object);
|
var root = try request.data(.object);
|
||||||
|
|
@ -33,7 +34,9 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
try scrobble_view.put("song_id", scrobble.song_id);
|
try scrobble_view.put("song_id", scrobble.song_id);
|
||||||
try scrobble_view.put("album_name", scrobble.album_name);
|
try scrobble_view.put("album_name", scrobble.album_name);
|
||||||
try scrobble_view.put("album_id", scrobble.album_id);
|
try scrobble_view.put("album_id", scrobble.album_id);
|
||||||
try scrobble_view.put("date", scrobble.date);
|
var date = std.ArrayList(u8).init(request.allocator);
|
||||||
|
try (try zeit.instant(.{ .source = .{ .unix_timestamp = @divFloor(scrobble.date, 1_000_000) } })).time().strftime(date.writer(), "%d %b %Y, %H:%M");
|
||||||
|
try scrobble_view.put("date", date.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
//for (scrobbles) |scrobble| {
|
//for (scrobbles) |scrobble| {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Song</th>
|
<th>Song</th>
|
||||||
<th>Album</th>
|
<th>Album</th>
|
||||||
<th>Date</th>
|
<th data-type="date" data-format="DD MMM YYYY, HH:mm">Date</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
|
||||||
|
|
@ -12,25 +12,45 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
|
||||||
// .all(request.repo);
|
// .all(request.repo);
|
||||||
|
|
||||||
const query =
|
const query =
|
||||||
\\SELECT songs.name, songs.id, COUNT(scrobbles) AS scrobbles
|
\\SELECT songs.name, songs.id, artists.name, artists.id, COUNT(scrobbles) AS scrobbles
|
||||||
\\FROM albumsongs
|
\\FROM albumsongs
|
||||||
\\INNER JOIN songs ON albumsongs.song_id = songs.id
|
\\INNER JOIN songs ON albumsongs.song_id = songs.id
|
||||||
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
||||||
\\GROUP BY songs.id
|
\\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id
|
||||||
\\ORDER BY scrobbles DESC
|
\\INNER JOIN artists ON artists.id = albumsongsartists.artist_id
|
||||||
|
\\GROUP BY songs.id, artists.id
|
||||||
|
\\ORDER BY scrobbles DESC, songs.name ASC
|
||||||
;
|
;
|
||||||
|
|
||||||
var songs_js_result = try request.repo.executeSql(query, .{});
|
var songs_js_result = try request.repo.executeSql(query, .{});
|
||||||
defer songs_js_result.deinit();
|
defer songs_js_result.deinit();
|
||||||
|
|
||||||
const Song = struct { name: []const u8, id: i32, scrobbles: i64 };
|
const Song = struct { name: []const u8, id: i32, artist_name: []const u8, artist_id: i32, scrobbles: i64 };
|
||||||
|
|
||||||
while (try songs_js_result.postgresql.result.next()) |song_row| {
|
var prev_song_id: ?i32 = null;
|
||||||
|
var prev_artist_infos: ?*jetzig.zmpl.Data.Value = null;
|
||||||
|
|
||||||
|
blk: while (try songs_js_result.postgresql.result.next()) |song_row| {
|
||||||
const song = try song_row.to(Song, .{ .dupe = true, .allocator = request.allocator });
|
const song = try song_row.to(Song, .{ .dupe = true, .allocator = request.allocator });
|
||||||
|
if (song.id == prev_song_id) {
|
||||||
|
var artist_info = try prev_artist_infos.?.append(.object);
|
||||||
|
try artist_info.put("name", song.artist_name);
|
||||||
|
try artist_info.put("url", song.artist_id);
|
||||||
|
continue :blk;
|
||||||
|
}
|
||||||
var song_view = try songs_view.append(.object);
|
var song_view = try songs_view.append(.object);
|
||||||
|
|
||||||
|
var artist_infos = try song_view.put("artist_info", .array);
|
||||||
|
var artist_info = try artist_infos.append(.object);
|
||||||
|
try artist_info.put("name", song.artist_name);
|
||||||
|
try artist_info.put("url", song.artist_id);
|
||||||
|
|
||||||
try song_view.put("name", song.name);
|
try song_view.put("name", song.name);
|
||||||
try song_view.put("url", song.id);
|
try song_view.put("url", song.id);
|
||||||
try song_view.put("scrobbles", song.scrobbles);
|
try song_view.put("scrobbles", song.scrobbles);
|
||||||
|
|
||||||
|
prev_artist_infos = artist_infos;
|
||||||
|
prev_song_id = song.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
//for (songs) |song| {
|
//for (songs) |song| {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
|
<th>Artist(s)</th>
|
||||||
<th>Scrobbles</th>
|
<th>Scrobbles</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
@ -17,6 +18,11 @@
|
||||||
@for (.songs) |song| {
|
@for (.songs) |song| {
|
||||||
<tr>
|
<tr>
|
||||||
<td class=cell><a href="/songs/{{song.url}}">{{song.name}}</a></td>
|
<td class=cell><a href="/songs/{{song.url}}">{{song.name}}</a></td>
|
||||||
|
<td class=cell>
|
||||||
|
@for (song.get("artist_info").?) |ai| {
|
||||||
|
<a href="/artists/{{ai.url}}">{{ai.name}}</a>
|
||||||
|
}
|
||||||
|
</td>
|
||||||
<td class=cell>{{song.scrobbles}}</td>
|
<td class=cell>{{song.scrobbles}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,6 @@ pub fn applyScrobbleRule(allocator: std.mem.Allocator, scrobble: Data.ImportedSc
|
||||||
const list = try al.toOwnedSlice();
|
const list = try al.toOwnedSlice();
|
||||||
@field(output_scrobble, @tagName(on)) = list;
|
@field(output_scrobble, @tagName(on)) = list;
|
||||||
},
|
},
|
||||||
//else => {
|
|
||||||
// std.log.debug("Adding artists doesn't work yet", .{});
|
|
||||||
//},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.replace => switch (act.action_on) {
|
.replace => switch (act.action_on) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue