Compare commits
No commits in common. "df8f01525e0d148c79050f54a2ba561ae6dc5ede" and "a8a4ed27c46baeb213b687f89fbb8fb71cdc04f6" have entirely different histories.
df8f01525e
...
a8a4ed27c4
4 changed files with 8 additions and 42 deletions
|
|
@ -1,11 +1,3 @@
|
||||||
<head>
|
<div>
|
||||||
|
<span>Content goes here</span>
|
||||||
<script src="https://unpkg.com/htmx.org@2.0.4" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script>
|
</div>
|
||||||
</head>
|
|
||||||
@partial partials/header
|
|
||||||
|
|
||||||
<h1>Merge Songs</h1>
|
|
||||||
<form hx-get="/songs" hx-target="#response-div">
|
|
||||||
<label>Song name <input name="s" type="text"></label>
|
|
||||||
</form>
|
|
||||||
<div id="response-div"></div>
|
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,7 @@ const queries = @import("../../queries.zig");
|
||||||
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);
|
||||||
|
|
||||||
const htmx_query = (try request.queryParams()).getT(.string, "s");
|
const songs = try queries.entityQueryResult(request, queries.loadQuery(.song, .entities), .{});
|
||||||
|
|
||||||
try root.put("htmx", htmx_query != null);
|
|
||||||
|
|
||||||
const songs = if (htmx_query) |name|
|
|
||||||
try queries.entityQueryResult(request, queries.loadQuery(.song, .entities_by_name), .{name})
|
|
||||||
else
|
|
||||||
try queries.entityQueryResult(request, queries.loadQuery(.song, .entities), .{});
|
|
||||||
|
|
||||||
try root.put("songs", songs);
|
try root.put("songs", songs);
|
||||||
|
|
||||||
return request.render(.ok);
|
return request.render(.ok);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
@zig {
|
@zig {
|
||||||
const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date};
|
const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date};
|
||||||
const columns: ColumnChoices = &.{.song, .album, .artistlist, .scrobbles};
|
const columns: ColumnChoices = &.{.song, .artistlist, .scrobbles};
|
||||||
}
|
}
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
|
|
@ -8,10 +8,8 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@if (! $.htmx)
|
|
||||||
@partial partials/header
|
@partial partials/header
|
||||||
<h1>Songs</h1>
|
<h1>Songs</h1>
|
||||||
@end
|
|
||||||
@partial partials/newtable(T: ColumnChoices, table_data: .songs, columns: columns)
|
@partial partials/newtable(T: ColumnChoices, table_data: .songs, columns: columns)
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
@ -49,7 +49,7 @@ pub fn entityQueryResult(request: *jetzig.Request, query: GeneratedQuery, args:
|
||||||
}
|
}
|
||||||
|
|
||||||
const EntityType = enum { scrobble, song, album, artist };
|
const EntityType = enum { scrobble, song, album, artist };
|
||||||
const QueryTypeEnum = enum { firstlast, timescale, entities, get_songs, get_albums, get_scrobbles, appears, entity_info, datestreak, entities_by_name };
|
const QueryTypeEnum = enum { firstlast, timescale, entities, get_songs, get_albums, get_scrobbles, appears, entity_info, datestreak };
|
||||||
|
|
||||||
const GeneratedQuery = struct {
|
const GeneratedQuery = struct {
|
||||||
entity: EntityType,
|
entity: EntityType,
|
||||||
|
|
@ -209,14 +209,13 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
|
||||||
\\ORDER BY scrobbles.datetime ASC
|
\\ORDER BY scrobbles.datetime ASC
|
||||||
,
|
,
|
||||||
.song =>
|
.song =>
|
||||||
\\SELECT songs.name AS song_name, songs.id AS song_id, albums.name AS album_name, albums.id AS album_id, artists.name AS artist_name, artists.id AS artist_id, COUNT(scrobbles) AS scrobbles
|
\\SELECT songs.name AS song_name, songs.id AS song_id, artists.name AS artist_name, artists.id AS artist_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
|
||||||
\\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id
|
\\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id
|
||||||
\\INNER JOIN artists ON artists.id = albumsongsartists.artist_id
|
\\INNER JOIN artists ON artists.id = albumsongsartists.artist_id
|
||||||
\\INNER JOIN albums ON albums.id = albumsongs.album_id
|
\\GROUP BY songs.id, artists.id
|
||||||
\\GROUP BY songs.id, albums.id, artists.id
|
|
||||||
\\ORDER BY scrobbles DESC, songs.name ASC
|
\\ORDER BY scrobbles DESC, songs.name ASC
|
||||||
,
|
,
|
||||||
.album =>
|
.album =>
|
||||||
|
|
@ -420,21 +419,6 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
|
||||||
,
|
,
|
||||||
.scrobble => unreachable,
|
.scrobble => unreachable,
|
||||||
},
|
},
|
||||||
.entities_by_name => switch (entity) {
|
|
||||||
.song =>
|
|
||||||
\\SELECT songs.name AS song_name, songs.id AS song_id, albums.name AS album_name, albums.id AS album_id, artists.name AS artist_name, artists.id AS artist_id, COUNT(scrobbles) AS scrobbles
|
|
||||||
\\FROM albumsongs
|
|
||||||
\\INNER JOIN songs ON albumsongs.song_id = songs.id
|
|
||||||
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
|
|
||||||
\\INNER JOIN albumsongsartists ON albumsongsartists.albumsong_id = albumsongs.id
|
|
||||||
\\INNER JOIN artists ON artists.id = albumsongsartists.artist_id
|
|
||||||
\\INNER JOIN albums ON albums.id = albumsongs.album_id
|
|
||||||
\\WHERE LOWER(songs.name) LIKE LOWER($1)
|
|
||||||
\\GROUP BY songs.id, albums.id, artists.id
|
|
||||||
\\ORDER BY songs.name ASC, scrobbles DESC;
|
|
||||||
,
|
|
||||||
else => unreachable,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue