aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/browser.rs
blob: 6e772d0ae911a2408cd3fca8a6139ac937448d9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
    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.
    Copyright (C) 2023 metamuffin <metamuffin.org>
*/
use super::{account::session::Session, error::MyError, layout::DynLayoutPage, node::NodeCard};
use crate::database::Database;
use anyhow::Context;
use jellycommon::{Node, NodeKind};
use rocket::{get, State};

#[get("/items")]
pub fn r_all_items(_sess: Session, db: &State<Database>) -> Result<DynLayoutPage<'_>, MyError> {
    let items = db
        .node
        .iter()
        .map(|e| e.context("listing"))
        .collect::<anyhow::Result<Vec<_>>>()?
        .into_iter()
        .filter(|(_, n)| matches!(n.public.kind, NodeKind::Movie | NodeKind::Series))
        .collect::<Vec<(String, Node)>>();

    Ok(super::layout::LayoutPage {
        title: "All Items".to_owned(),
        content: markup::new! {
            .page.dir {
                h1 { "All Items" }
                ul.children { @for (id, node) in &items {
                    li {@NodeCard { id, node: &node.public }}
                }}
            }
        },
        ..Default::default()
    })
}