blob: d0c09b1d0e39e48f3409d4ba412a23a40c8d915f (
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::ItemCard};
use crate::library::{Library, Node};
use rocket::{get, State};
use std::collections::VecDeque;
#[get("/items")]
pub fn r_all_items(_sess: Session, library: &State<Library>) -> Result<DynLayoutPage<'_>, MyError> {
let mut dirs = VecDeque::from_iter(Some(library.root.get_directory().unwrap()));
let mut items = Vec::new();
while let Some(d) = dirs.pop_front() {
for e in &d.children {
match e.as_ref() {
Node::Directory(d) => dirs.push_back(d.clone()),
Node::Item(i) => items.push(i.clone()),
}
}
}
Ok(super::layout::LayoutPage {
title: "All Items".to_owned(),
content: markup::new! {
.page.dir {
h1 { "All Items" }
ul.directorylisting { @for item in &items {
li { @ItemCard { item: &item } }
}}
}
},
..Default::default()
})
}
|