From 13ce89d27ec77fcd34121081d1bcd77622949f45 Mon Sep 17 00:00:00 2001 From: Zack Fu Zi Xiang Date: Thu, 14 Mar 2024 09:55:42 +0800 Subject: [PATCH] feat: layout for workspace usage --- Cargo.lock | 7 ++++++ admin_frontend/Cargo.toml | 1 + admin_frontend/src/templates.rs | 23 ++++++++----------- admin_frontend/src/web_app.rs | 10 +++++++- .../templates/components/workspace_usage.html | 8 ++++--- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2fc8e46a..282d1431 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -325,6 +325,7 @@ dependencies = [ "dotenvy", "gotrue", "gotrue-entity", + "human_bytes", "jwt", "redis 0.24.0", "reqwest", @@ -2556,6 +2557,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "human_bytes" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91f255a4535024abf7640cb288260811fc14794f62b063652ed349f9a6c2348e" + [[package]] name = "humansize" version = "2.1.3" diff --git a/admin_frontend/Cargo.toml b/admin_frontend/Cargo.toml index b237d1b9..997b5b6c 100644 --- a/admin_frontend/Cargo.toml +++ b/admin_frontend/Cargo.toml @@ -28,3 +28,4 @@ tower = "0.4" tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] } jwt = "0.16" +human_bytes = "0.4.3" diff --git a/admin_frontend/src/templates.rs b/admin_frontend/src/templates.rs index c4045d54..e5dc45c9 100644 --- a/admin_frontend/src/templates.rs +++ b/admin_frontend/src/templates.rs @@ -8,15 +8,16 @@ pub struct UserUsage { pub workspace_limit: u32, } -// #[derive(Template)] -// #[template(path = "components/workspace_usage.html")] -// pub struct WorkspaceUsage { -// pub name: String, -// pub member_count: u32, -// pub member_limit: u32, -// pub total_object_size: u64, -// pub total_object_limit: u64, -// } +#[derive(Template)] +#[template(path = "components/workspace_usage.html")] +pub struct WorkspaceUsage<'a> { + pub name: &'a str, + pub member_count: u32, + pub member_limit: u32, + pub total_doc_size: &'a str, + pub total_blob_size: &'a str, + pub total_blob_limit: &'a str, +} #[derive(Template)] #[template(path = "components/admin_sso_detail.html")] @@ -45,10 +46,6 @@ pub struct Login<'a> { pub oauth_providers: Vec<&'a str>, } -// #[derive(Template)] -// #[template(path = "login.html")] -// pub struct Login; - #[derive(Template)] #[template(path = "pages/home.html")] pub struct Home<'a> { diff --git a/admin_frontend/src/web_app.rs b/admin_frontend/src/web_app.rs index 38a42c16..5d5806a6 100644 --- a/admin_frontend/src/web_app.rs +++ b/admin_frontend/src/web_app.rs @@ -6,6 +6,7 @@ use axum::extract::{Path, State}; use axum::response::Result; use axum::{response::Html, routing::get, Router}; use gotrue_entity::dto::User; +use human_bytes::human_bytes; use crate::{templates, AppState}; @@ -122,7 +123,14 @@ pub async fn user_usage_handler( } pub async fn workspace_usage_handler(session: UserSession) -> Result, WebAppError> { - todo!() + render_template(templates::WorkspaceUsage { + name: "test", + member_count: 6, + member_limit: 7, + total_doc_size: &human_bytes(987654), + total_blob_size: &human_bytes(9876543), + total_blob_limit: &human_bytes(98765432), + }) } pub async fn admin_users_create_handler() -> Result, WebAppError> { diff --git a/admin_frontend/templates/components/workspace_usage.html b/admin_frontend/templates/components/workspace_usage.html index 464e63ed..f555dd24 100644 --- a/admin_frontend/templates/components/workspace_usage.html +++ b/admin_frontend/templates/components/workspace_usage.html @@ -5,16 +5,18 @@ Workspace Name Members Members Limit - Storage Space - Storage Space Limit + Document Storage + Object Storage + Object Storage Limit {{ name|escape }} {{ member_count|escape }} {{ member_limit|escape }} + {{ total_doc_size|escape }} {{ total_blob_size|escape }} - {{ total_blob_size_limit|escape }} + {{ total_blob_limit|escape }}