Testing with groups and htmx
This commit is contained in:
parent
6a1c822420
commit
2f420bc5ce
3 changed files with 23 additions and 5 deletions
|
|
@ -1,3 +1,11 @@
|
||||||
<div>
|
<head>
|
||||||
<span>Content goes here</span>
|
|
||||||
</div>
|
<script src="https://unpkg.com/htmx.org@2.0.4" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script>
|
||||||
|
</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,7 +5,15 @@ 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 songs = try queries.entityQueryResult(request, queries.loadQuery(.song, .entities), .{});
|
const htmx_query = (try request.queryParams()).getT(.string, "s");
|
||||||
|
|
||||||
|
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, .artistlist, .scrobbles};
|
const columns: ColumnChoices = &.{.song, .album, .artistlist, .scrobbles};
|
||||||
}
|
}
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
|
|
@ -8,8 +8,10 @@
|
||||||
<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>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue