diff options
author | metamuffin <metamuffin@disroot.org> | 2024-01-23 18:56:52 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-01-23 18:56:52 +0100 |
commit | 3ca7df883ab71c278086a593ed25699ce6b1a608 (patch) | |
tree | f8f9d58ecc638c8d1d83ad029cc021e81c3cb533 | |
parent | 31675068c5ef1af1c4ae50693ace7ab1b6890393 (diff) | |
download | jellything-3ca7df883ab71c278086a593ed25699ce6b1a608.tar jellything-3ca7df883ab71c278086a593ed25699ce6b1a608.tar.bz2 jellything-3ca7df883ab71c278086a593ed25699ce6b1a608.tar.zst |
show node path
-rw-r--r-- | import/src/lib.rs | 8 | ||||
-rw-r--r-- | server/src/routes/ui/node.rs | 23 |
2 files changed, 27 insertions, 4 deletions
diff --git a/import/src/lib.rs b/import/src/lib.rs index bf3c48d..fd555b7 100644 --- a/import/src/lib.rs +++ b/import/src/lib.rs @@ -139,11 +139,13 @@ pub fn generate_node_paths(db: &DataAcid) -> anyhow::Result<()> { fn traverse(db: &DataAcid, c: String, mut path: Vec<String>) -> anyhow::Result<()> { let node = { let txn = db.inner.begin_write()?; - let table = txn.open_table(T_NODE)?; + let mut table = txn.open_table(T_NODE)?; let mut node = table .get(&*c)? - .ok_or(anyhow!("missing child when generating paths: {c:?} at {path:?}"))? + .ok_or(anyhow!( + "missing child when generating paths: {c:?} at {path:?}" + ))? .value() .0; @@ -151,6 +153,8 @@ pub fn generate_node_paths(db: &DataAcid) -> anyhow::Result<()> { node.public.path = path.clone(); } + table.insert(c.as_str(), Ser(node.clone()))?; + drop(table); txn.commit()?; node diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs index c9adfb6..1a84dc9 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -85,12 +85,28 @@ pub async fn r_library_node_filter<'a>( .into_iter() .collect(); + 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<_>>(); + filter_and_sort_nodes(&filter, &mut children); Ok(Either::Left(LayoutPage { title: node.title.clone().unwrap_or_default(), content: markup::new! { - @NodePage { node: &node, id: &id, udata: &udata, children: &children, filter: &filter, node_ext: &node_ext } + @NodePage { node: &node, id: &id, udata: &udata, children: &children, path: &path, filter: &filter, node_ext: &node_ext } }, ..Default::default() })) @@ -118,7 +134,7 @@ markup::define! { } } } - NodePage<'a>(id: &'a str, node: &'a NodePublic, node_ext: &'a ExtendedNode, udata: &'a NodeUserData, children: &'a Vec<(String, NodePublic, NodeUserData)>, filter: &'a NodeFilterSort) { + NodePage<'a>(id: &'a str, node: &'a NodePublic, node_ext: &'a ExtendedNode, udata: &'a NodeUserData, children: &'a [(String, NodePublic, NodeUserData)], path: &'a [(String, NodePublic)], filter: &'a NodeFilterSort) { @if !matches!(node.kind.unwrap_or_default(), NodeKind::Collection) { img.backdrop[src=uri!(r_item_assets(id, AssetRole::Backdrop, Some(2048))), loading="lazy"]; } @@ -128,6 +144,9 @@ markup::define! { } .title { h1 { @node.title } + span.path { @for (cid, cnode) in *path { + " / " a.component[href=uri!(r_library_node(cid))] { @cnode.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(_)) { |