diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-30 14:39:20 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-30 14:39:20 +0100 |
commit | 02bbb2741f2c463aadf9d07493ebaeac1d73c11a (patch) | |
tree | 07cfa4b5ba03bb992b745ff9339c69dc03fca9e9 /server/src/routes/ui/node.rs | |
parent | 570f24c99af8c9cd1b9050564c32adb85e2c9c0f (diff) | |
download | jellything-02bbb2741f2c463aadf9d07493ebaeac1d73c11a.tar jellything-02bbb2741f2c463aadf9d07493ebaeac1d73c11a.tar.bz2 jellything-02bbb2741f2c463aadf9d07493ebaeac1d73c11a.tar.zst |
import channel and children
Diffstat (limited to 'server/src/routes/ui/node.rs')
-rw-r--r-- | server/src/routes/ui/node.rs | 54 |
1 files changed, 21 insertions, 33 deletions
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index 3332483..121896e 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -1,5 +1,3 @@ -use std::sync::Arc; - /* This file is part of jellything (https://codeberg.org/metamuffin/jellything) which is licensed under the GNU Affero General Public License (version 3); see /COPYING. @@ -37,6 +35,7 @@ use jellycommon::{ Chapter, MediaInfo, Node, NodeID, NodeKind, PeopleGroup, Rating, SourceTrackKind, }; use rocket::{get, serde::json::Json, Either, State}; +use std::sync::Arc; /// This function is a stub and only useful for use in the uri! macro. #[get("/n/<id>")] @@ -44,43 +43,32 @@ pub fn r_library_node(id: String) { drop(id) } -#[get("/n/<id>?<filter..>")] +#[get("/n/<slug>?<filter..>")] pub async fn r_library_node_filter<'a>( session: Session, - id: &'a str, + slug: &'a str, db: &'a State<Database>, aj: AcceptJson, filter: NodeFilterSort, ) -> MyResult<Either<DynLayoutPage<'a>, Json<Node>>> { - let (node, udata) = db.get_node_with_userdata(NodeID::from_slug(id), &session)?; + let id = NodeID::from_slug(slug); + let (node, udata) = db.get_node_with_userdata(id, &session)?; if *aj { return Ok(Either::Right(Json((*node).clone()))); } - // let mut children = node - // .children - // .iter() - // .map(|c| db.get_node_with_userdata(c, &session)) - // .collect::<anyhow::Result<Vec<_>>>()? - // .into_iter() - // .collect(); + let mut children = db + .get_node_children(id)? + .into_iter() + .map(|c| db.get_node_with_userdata(c, &session)) + .collect::<anyhow::Result<Vec<_>>>()?; - // let path = node - // .path - // .iter() - // .map(|c| { - // Ok(( - // c.to_owned(), - // T_NODE - // .get(db, c.as_str())? - // .ok_or(anyhow!("parent node missing"))? - // .public, - // )) - // }) - // .collect::<anyhow::Result<Vec<_>>>()? - // .into_iter() - // .collect::<Vec<_>>(); + let parents = node + .parents + .iter() + .flat_map(|pid| db.get_node(*pid).transpose()) + .collect::<Result<Vec<_>, _>>()?; filter_and_sort_nodes( &filter, @@ -89,13 +77,13 @@ pub async fn r_library_node_filter<'a>( _ => (SortProperty::Title, SortOrder::Ascending), }, // TODO - &mut Vec::new(), + &mut children, ); Ok(Either::Left(LayoutPage { title: node.title.clone().unwrap_or_default(), content: markup::new! { - @NodePage { node: &node, id, udata: &udata, children: &[], path: &[], filter: &filter } + @NodePage { node: &node, id: slug, udata: &udata, children: &children, parents: &parents, filter: &filter } }, ..Default::default() })) @@ -128,7 +116,7 @@ markup::define! { } } } - NodePage<'a>(id: &'a str, node: &'a Node, udata: &'a NodeUserData, children: &'a [(Arc<Node>, NodeUserData)], path: &'a [(String, Node)], filter: &'a NodeFilterSort) { + NodePage<'a>(id: &'a str, node: &'a Node, udata: &'a NodeUserData, children: &'a [(Arc<Node>, NodeUserData)], parents: &'a [Arc<Node>], filter: &'a NodeFilterSort) { @if !matches!(node.kind.unwrap_or_default(), NodeKind::Collection) { img.backdrop[src=uri!(r_item_backdrop(id, Some(2048))), loading="lazy"]; } @@ -139,9 +127,9 @@ markup::define! { } .title { h1 { @node.title } - span.path { @for (cid, cnode) in *path { - " / " a.component[href=uri!(r_library_node(cid))] { @cnode.title } - }} + ul.parents { @for node in *parents { li { + a.component[href=uri!(r_library_node(&node.slug))] { @node.title } + }}} @if node.media.is_some() { a.play[href=&uri!(r_player(id, PlayerConfig::default()))] { "Watch now" }} @if !matches!(node.kind.unwrap_or_default(), NodeKind::Collection | NodeKind::Channel) { @if matches!(udata.watched, WatchedState::None | WatchedState::Pending | WatchedState::Progress(_)) { |