diff options
Diffstat (limited to 'server/src/routes/ui/node.rs')
-rw-r--r-- | server/src/routes/ui/node.rs | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index 301f89c..13afbbe 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -3,7 +3,12 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2023 metamuffin <metamuffin.org> */ -use super::{assets::rocket_uri_macro_r_item_assets, error::MyError, player::player_uri}; +use super::{ + assets::rocket_uri_macro_r_item_assets, + error::MyError, + player::player_uri, + sort::{filter_and_sort_nodes, NodeFilterSort, NodeFilterSortForm}, +}; use crate::{ database::Database, routes::{ @@ -20,12 +25,19 @@ use anyhow::{anyhow, Context}; use jellycommon::{MediaInfo, NodeKind, NodePublic, Rating, SourceTrackKind}; use rocket::{get, serde::json::Json, Either, State}; +/// This function is a stub and only useful for use in the uri! macro. #[get("/n/<id>")] -pub async fn r_library_node( +pub fn r_library_node(id: String) { + drop(id) +} + +#[get("/n/<id>?<filter..>")] +pub async fn r_library_node_filter( _sess: Session, id: String, db: &State<Database>, aj: AcceptJson, + filter: NodeFilterSort, ) -> Result<Either<DynLayoutPage<'_>, Json<NodePublic>>, MyError> { let node = db .node @@ -38,7 +50,7 @@ pub async fn r_library_node( return Ok(Either::Right(Json(node))); } - let children = node + let mut children = node .children .iter() .map(|c| { @@ -54,11 +66,13 @@ pub async fn r_library_node( .into_iter() .collect(); + filter_and_sort_nodes(&filter, &mut children); + Ok(Either::Left(LayoutPage { title: node.title.to_string(), show_back: true, //- !matches!(node.kind, NodeKind::Collection), content: markup::new! { - @NodePage { node: &node, id: &id, children: &children } + @NodePage { node: &node, id: &id, children: &children, filter: &filter } }, ..Default::default() })) @@ -88,7 +102,7 @@ markup::define! { } } } - NodePage<'a>(id: &'a str, node: &'a NodePublic, children: &'a Vec<(String, NodePublic)>) { + NodePage<'a>(id: &'a str, node: &'a NodePublic, children: &'a Vec<(String, NodePublic)>, filter: &'a NodeFilterSort) { @if !matches!(node.kind, NodeKind::Collection) { img.backdrop[src=uri!(r_item_assets(id, AssetRole::Backdrop, Some(2048)))]; } @@ -110,6 +124,7 @@ markup::define! { @if let NodeKind::Collection = node.kind { @if let Some(parent) = &node.parent { a.dirup[href=uri!(r_library_node(parent))] { "Go up" } + @NodeFilterSortForm { f: filter } } } @match node.kind { |