From 1b9e1215c9264f7a0ffd9447f89dce8384223f74 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Wed, 9 Nov 2022 13:32:06 +0530 Subject: [PATCH] feat: bootstrap dashboard homepage --- src/pages/dash/home.rs | 74 +++++++++++++++ src/pages/dash/mod.rs | 29 ++++++ templates/pages/dash/index.html | 160 ++++++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+) create mode 100644 src/pages/dash/home.rs create mode 100644 src/pages/dash/mod.rs create mode 100644 templates/pages/dash/index.html diff --git a/src/pages/dash/home.rs b/src/pages/dash/home.rs new file mode 100644 index 0000000..b5b1ca9 --- /dev/null +++ b/src/pages/dash/home.rs @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2022 Aravinth Manivannan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +use std::cell::RefCell; + +use actix_identity::Identity; +use actix_web::http::header::ContentType; +use tera::Context; + +use crate::api::v1::RedirectQuery; +use crate::ctx::api::v1::auth::Login as LoginPayload; +use crate::pages::errors::*; +use crate::settings::Settings; +use crate::AppCtx; + +pub use super::*; + +pub const DASH_HOME: TemplateFile = TemplateFile::new("dash_home", "pages/dash/index.html"); + +pub struct Home { + ctx: RefCell, +} + +impl CtxError for Home { + fn with_error(&self, e: &ReadableError) -> String { + self.ctx.borrow_mut().insert(ERROR_KEY, e); + self.render() + } +} + +impl Home { + pub fn new(settings: &Settings, payload: Option<&LoginPayload>) -> Self { + let ctx = RefCell::new(context(settings)); + if let Some(payload) = payload { + ctx.borrow_mut().insert(PAYLOAD_KEY, payload); + } + Self { ctx } + } + + pub fn render(&self) -> String { + TEMPLATES + .render(DASH_HOME.name, &self.ctx.borrow()) + .unwrap() + } + + pub fn page(s: &Settings) -> String { + let p = Self::new(s, None); + p.render() + } +} + +#[actix_web_codegen_const_routes::get(path = "PAGES.dash.home")] +pub async fn get_home(ctx: AppCtx) -> impl Responder { + let home = Home::page(&ctx.settings); + let html = ContentType::html(); + HttpResponse::Ok().content_type(html).body(home) +} + +pub fn services(cfg: &mut web::ServiceConfig) { + cfg.service(get_home); +} diff --git a/src/pages/dash/mod.rs b/src/pages/dash/mod.rs new file mode 100644 index 0000000..1d1611b --- /dev/null +++ b/src/pages/dash/mod.rs @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 Aravinth Manivannan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +use actix_web::*; + +pub use super::{context, Footer, TemplateFile, PAGES, PAYLOAD_KEY, TEMPLATES}; + +mod home; + +pub fn register_templates(t: &mut tera::Tera) { + home::DASH_HOME.register(t).expect(home::DASH_HOME.name); +} + +pub fn services(cfg: &mut web::ServiceConfig) { + home::services(cfg); +} diff --git a/templates/pages/dash/index.html b/templates/pages/dash/index.html new file mode 100644 index 0000000..1f5c17c --- /dev/null +++ b/templates/pages/dash/index.html @@ -0,0 +1,160 @@ + + + + + + + LibrePages + + +
+ +
+
+ +
+ {% include "footer" %} + + + +