init projectmycelium
This commit is contained in:
248
src/controllers/docs.rs
Normal file
248
src/controllers/docs.rs
Normal file
@@ -0,0 +1,248 @@
|
||||
use actix_web::{web, Result, Responder};
|
||||
use tera::Tera;
|
||||
use crate::utils::render_template;
|
||||
use crate::config::get_app_config;
|
||||
use actix_session::Session;
|
||||
|
||||
/// Controller for handling documentation-related routes
|
||||
pub struct DocsController;
|
||||
|
||||
impl DocsController {
|
||||
/// Renders the documentation index/overview page
|
||||
pub async fn index(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "overview");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user to context if available
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
// Keep the raw JSON for backward compatibility
|
||||
ctx.insert("user_json", &user_json);
|
||||
|
||||
// Parse the JSON into a User object
|
||||
match serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
Ok(user) => {
|
||||
ctx.insert("user", &user);
|
||||
},
|
||||
Err(e) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/index.html", &ctx)
|
||||
}
|
||||
|
||||
/// Renders the getting started documentation page
|
||||
pub async fn getting_started(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "getting_started");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/getting_started.html", &ctx)
|
||||
}
|
||||
|
||||
/// Renders the 3Nodes documentation page
|
||||
pub async fn three_nodes(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "3nodes");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/3nodes.html", &ctx)
|
||||
}
|
||||
|
||||
/// Renders the compute resources documentation page
|
||||
pub async fn compute(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "compute");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/compute.html", &ctx)
|
||||
}
|
||||
|
||||
/// Renders the gateways documentation page
|
||||
pub async fn gateways(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "gateways");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/gateways.html", &ctx)
|
||||
}
|
||||
|
||||
/// Renders the applications documentation page
|
||||
pub async fn applications(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "applications");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/applications.html", &ctx)
|
||||
}
|
||||
|
||||
/// Renders the services documentation page
|
||||
pub async fn services(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "services");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/services.html", &ctx)
|
||||
}
|
||||
|
||||
/// USD Credits documentation page
|
||||
pub async fn credits(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "credits");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/tfp.html", &ctx)
|
||||
}
|
||||
|
||||
/// Renders the slices documentation page
|
||||
pub async fn slices(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "slices");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/slices.html", &ctx)
|
||||
}
|
||||
|
||||
/// Renders the certification documentation page
|
||||
pub async fn certification(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "certification");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/certification.html", &ctx)
|
||||
}
|
||||
|
||||
/// Renders the API documentation page
|
||||
pub async fn api(tmpl: web::Data<Tera>, session: Session) -> Result<impl Responder> {
|
||||
let mut ctx = crate::models::builders::ContextBuilder::new()
|
||||
.active_page("docs")
|
||||
.build();
|
||||
ctx.insert("active_section", "api");
|
||||
|
||||
let config = get_app_config();
|
||||
ctx.insert("gitea_enabled", &config.is_gitea_enabled());
|
||||
|
||||
// Add user data to context
|
||||
if let Ok(Some(user_json)) = session.get::<String>("user") {
|
||||
ctx.insert("user_json", &user_json);
|
||||
if let Ok(user) = serde_json::from_str::<crate::models::user::User>(&user_json) {
|
||||
ctx.insert("user", &user);
|
||||
}
|
||||
}
|
||||
|
||||
render_template(&tmpl, "docs/api.html", &ctx)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user