miniweb/rear/src/depot/context.rs

79 lines
2.3 KiB
Rust

use serde::{Deserialize, Serialize};
use super::repository::{RepositoryInfo, RepositoryItem, RepositoryList};
// representation of a Model in the template.
#[derive(Deserialize, Serialize)]
pub struct DepotModel {
pub key: String,
pub name: String,
pub model_url: String,
pub view_only: bool,
pub add_url: Option<String>,
}
// representation of a Section in the template.
#[derive(Deserialize, Serialize)]
pub struct DepotSection {
pub key: String,
pub name: String,
pub section_url: String,
pub models: Vec<DepotModel>,
}
#[derive(Serialize, Deserialize)]
pub struct DepotRequest {
pub path: String,
}
#[derive(Serialize)]
pub struct DepotContext {
pub base: Option<String>,
pub language_code: Option<String>,
pub language_bidi: Option<bool>,
pub user: Option<String>, // Todo: user type
pub depot_url: String,
pub site_url: Option<String>,
pub docsroot: Option<String>,
pub messages: Vec<String>, // Todo: message type
pub title: Option<String>,
pub subtitle: Option<String>,
pub content: String,
pub request: DepotRequest,
pub sections: Vec<DepotSection>,
pub item_model: Option<DepotModel>,
pub item_info: Option<RepositoryInfo>,
pub item_list: RepositoryList,
pub item: Option<RepositoryItem>,
}
impl Default for DepotContext {
fn default() -> Self {
DepotContext {
base: None, // TODO: what is this used for?
language_code: Some("en-us".to_string()), // Default language code
language_bidi: Some(false), // Default language bidi
user: None, //UserType::default(), // Assuming UserType has a Default impl
depot_url: "/depot".to_owned(),
site_url: None,
docsroot: None,
messages: Vec::new(), // Empty vector for messages
title: None,
subtitle: None,
content: String::new(), // Empty string for content
sections: Vec::new(),
request: DepotRequest {
path: "".to_owned(),
},
item_model: None,
item_info: None,
item_list: RepositoryList::Empty,
item: None,
}
}
}