Phase 1 (Infrastructure): - Docs: README.md, AGENTS.md, CHANGELOG.md - Tests: 26 tests (modes_test, filetree_api_test) - Examples: examples/sample.md, sample.json - CI/CD: .gitea/workflows/test.yml, release.yml - Runner: configuration scripts and guides Phase 2 (Quality): - Code quality: rustfmt/clippy config - Security: environment variables - Test coverage: 62 tests (+36) - Documentation: CONTRIBUTING.md, docs/api.yaml - Showcase: demo_features.md, developer_quickstart.md Test coverage: 75% Test pass rate: 100%
88 lines
2.4 KiB
Rust
88 lines
2.4 KiB
Rust
use async_trait::async_trait;
|
|
use serde_json::{json, Value};
|
|
|
|
use crate::filetree::mode::{DisplayMode, FilterOption, SortOption};
|
|
use crate::filetree::FileTree;
|
|
|
|
pub struct ListMode;
|
|
|
|
#[async_trait]
|
|
impl DisplayMode for ListMode {
|
|
fn name(&self) -> &'static str {
|
|
"list"
|
|
}
|
|
|
|
fn render(&self, tree: &FileTree) -> Value {
|
|
let nodes: Vec<Value> = tree
|
|
.nodes
|
|
.iter()
|
|
.map(|n| {
|
|
json!({
|
|
"node_id": n.node_id,
|
|
"label": n.label,
|
|
"aliases": n.aliases,
|
|
"file_uuid": n.file_uuid,
|
|
"sha256": n.sha256,
|
|
"parent_id": n.parent_id,
|
|
"node_type": n.node_type.as_str(),
|
|
"icon": n.icon,
|
|
"color": n.color,
|
|
"bg_color": n.bg_color,
|
|
"file_size": n.file_size,
|
|
"registered_at": n.registered_at,
|
|
"sort_order": n.sort_order,
|
|
})
|
|
})
|
|
.collect();
|
|
|
|
json!({
|
|
"mode": "list",
|
|
"user_id": tree.user_id,
|
|
"columns": ["icon", "label", "node_type", "updated_at"],
|
|
"nodes": nodes,
|
|
})
|
|
}
|
|
|
|
fn sort_options(&self) -> Vec<SortOption> {
|
|
vec![
|
|
SortOption {
|
|
key: "name_asc".into(),
|
|
label: "Name A-Z".into(),
|
|
},
|
|
SortOption {
|
|
key: "name_desc".into(),
|
|
label: "Name Z-A".into(),
|
|
},
|
|
SortOption {
|
|
key: "date_desc".into(),
|
|
label: "Newest First".into(),
|
|
},
|
|
SortOption {
|
|
key: "date_asc".into(),
|
|
label: "Oldest First".into(),
|
|
},
|
|
SortOption {
|
|
key: "type".into(),
|
|
label: "By Type".into(),
|
|
},
|
|
]
|
|
}
|
|
|
|
fn filter_options(&self) -> Vec<FilterOption> {
|
|
vec![
|
|
FilterOption {
|
|
key: "all".into(),
|
|
label: "All".into(),
|
|
},
|
|
FilterOption {
|
|
key: "folder".into(),
|
|
label: "Folders".into(),
|
|
},
|
|
FilterOption {
|
|
key: "file".into(),
|
|
label: "Files".into(),
|
|
},
|
|
]
|
|
}
|
|
}
|