From fa39869f4cdb09bb323dd24fb5ccf2acca46e183 Mon Sep 17 00:00:00 2001 From: gabatxo1312 Date: Mon, 19 Jan 2026 21:05:37 +0100 Subject: [PATCH 1/2] Remove category index template & replace new template by a modal --- src/lib.rs | 1 - src/routes/category.rs | 57 ++++--------------- src/routes/index.rs | 31 +++++++--- templates/categories/dropdown_actions.html | 2 +- templates/categories/form.html | 4 +- templates/categories/index.html | 52 ----------------- .../content_folders/dropdown_actions.html | 6 +- templates/index.html | 19 ++++++- templates/menus/header.html | 15 ----- 9 files changed, 57 insertions(+), 130 deletions(-) delete mode 100644 templates/categories/index.html diff --git a/src/lib.rs b/src/lib.rs index b00a1fb..448f86a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,6 @@ pub fn router(state: state::AppState) -> Router { .route("/", get(routes::index::index)) .route("/upload", get(routes::index::upload)) .route("/progress/{view_request}", get(routes::progress::progress)) - .route("/categories", get(routes::category::index)) .route("/categories", post(routes::category::create)) .route("/categories/new", get(routes::category::new)) .route("/categories/{id}/delete", get(routes::category::delete)) diff --git a/src/routes/category.rs b/src/routes/category.rs index 37f6468..8360b89 100644 --- a/src/routes/category.rs +++ b/src/routes/category.rs @@ -12,7 +12,7 @@ use crate::database::content_folder; use crate::database::{category, category::CategoryOperator}; use crate::extractors::normalized_path::*; use crate::extractors::user::User; -use crate::state::flash_message::{OperationStatus, get_cookie}; +use crate::state::flash_message::OperationStatus; use crate::state::{AppState, AppStateContext, error::*}; #[derive(Clone, Debug, Deserialize, Serialize)] @@ -21,19 +21,6 @@ pub struct CategoryForm { pub path: NormalizedPathAbsolute, } -#[derive(Template, WebTemplate)] -#[template(path = "categories/index.html")] -pub struct CategoriesTemplate { - /// Global application state - pub state: AppStateContext, - /// Categories found in database - pub categories: Vec, - /// Logged-in user. - pub user: Option, - /// Operation status for UI confirmation - pub flash: Option, -} - #[derive(Template, WebTemplate)] #[template(path = "categories/new.html")] pub struct NewCategoryTemplate { @@ -94,7 +81,6 @@ pub async fn create( jar: CookieJar, Form(form): Form, ) -> Result { - let app_state_context = app_state.context().await?; let categories = CategoryOperator::new(app_state.clone(), user.clone()); let created = categories.create(&form, user.clone()).await; @@ -111,40 +97,19 @@ pub async fn create( let jar = operation_status.set_cookie(jar); - Ok((jar, Redirect::to("/categories").into_response())) + Ok((jar, Redirect::to("/").into_response())) } - Err(error) => Ok(( - jar, - NewCategoryTemplate { - state: app_state_context, - user, - category_form: Some(form), - error: Some(error), - } - .into_response(), - )), - } -} - -pub async fn index( - State(app_state): State, - user: Option, - jar: CookieJar, -) -> Result<(CookieJar, CategoriesTemplate), AppStateError> { - let app_state_context = app_state.context().await?; - let categories = CategoryOperator::new(app_state.clone(), user.clone()); + Err(error) => { + let operation_status = OperationStatus { + success: false, + message: format!("{}", error), + }; - let (jar, operation_status) = get_cookie(jar); + let jar = operation_status.set_cookie(jar); - Ok(( - jar, - CategoriesTemplate { - categories: categories.list().await.context(CategorySnafu)?, - state: app_state_context, - user, - flash: operation_status, - }, - )) + Ok((jar, Redirect::to("/").into_response())) + } + } } #[derive(Template, WebTemplate)] diff --git a/src/routes/index.rs b/src/routes/index.rs index 5933813..d20d7e3 100644 --- a/src/routes/index.rs +++ b/src/routes/index.rs @@ -1,11 +1,13 @@ use askama::Template; use askama_web::WebTemplate; use axum::extract::State; +use axum_extra::extract::CookieJar; use snafu::prelude::*; // TUTORIAL: https://github.com/SeaQL/sea-orm/blob/master/examples/axum_example/ use crate::database::category::{self, CategoryOperator}; use crate::extractors::user::User; +use crate::state::flash_message::{OperationStatus, get_cookie}; use crate::state::{AppState, AppStateContext, error::*}; #[derive(Template, WebTemplate)] @@ -17,6 +19,8 @@ pub struct IndexTemplate { pub user: Option, /// Categories pub categories: Vec, + /// Operation status for UI confirmation + pub flash: Option, } #[derive(Template, WebTemplate)] @@ -31,7 +35,11 @@ pub struct UploadTemplate { } impl IndexTemplate { - pub async fn new(app_state: AppState, user: Option) -> Result { + pub async fn new( + app_state: AppState, + user: Option, + jar: CookieJar, + ) -> Result<(CookieJar, Self), AppStateError> { let app_state_context = app_state.context().await?; let categories = CategoryOperator::new(app_state.clone(), user.clone()) @@ -39,11 +47,17 @@ impl IndexTemplate { .await .context(CategorySnafu)?; - Ok(IndexTemplate { - state: app_state_context, - user, - categories, - }) + let (jar, operation_status) = get_cookie(jar); + + Ok(( + jar, + IndexTemplate { + state: app_state_context, + user, + categories, + flash: operation_status, + }, + )) } } @@ -68,8 +82,9 @@ impl UploadTemplate { pub async fn index( State(app_state): State, user: Option, -) -> Result { - IndexTemplate::new(app_state, user).await + jar: CookieJar, +) -> Result<(CookieJar, IndexTemplate), AppStateError> { + IndexTemplate::new(app_state, user, jar).await } pub async fn upload( diff --git a/templates/categories/dropdown_actions.html b/templates/categories/dropdown_actions.html index ce2adc1..56791e2 100644 --- a/templates/categories/dropdown_actions.html +++ b/templates/categories/dropdown_actions.html @@ -3,6 +3,6 @@ Actions diff --git a/templates/categories/form.html b/templates/categories/form.html index 04109fe..ef33d07 100644 --- a/templates/categories/form.html +++ b/templates/categories/form.html @@ -1,5 +1,5 @@
-
+
-
+
-
-

Categories

- New category -
- - {% include "shared/alert_operation_status.html" %} - -
-
- {% if categories.is_empty() %} - {% include "shared/empty_state.html" %} - {% else %} -
- - - - - - - - - {% for category in categories %} - - - - - - {% endfor %} -
NamePathActions
{{ category.name }}{{ category.path }} - -
-
- {% endif %} -
-
-
-
-{% endblock %} diff --git a/templates/content_folders/dropdown_actions.html b/templates/content_folders/dropdown_actions.html index acc76b6..f7db052 100644 --- a/templates/content_folders/dropdown_actions.html +++ b/templates/content_folders/dropdown_actions.html @@ -3,8 +3,8 @@ Actions
diff --git a/templates/index.html b/templates/index.html index c58fe6f..15da385 100755 --- a/templates/index.html +++ b/templates/index.html @@ -12,6 +12,10 @@ All categories {% endblock%} +{% block alert_message %} + {% include "shared/alert_operation_status.html" %} +{% endblock %} + {% block actions_buttons %} {% include "categories/dropdown_actions.html" %} {% endblock actions_buttons %} @@ -38,6 +42,17 @@
{% endfor %} -{% endblock %} - + +{% endblock %} diff --git a/templates/menus/header.html b/templates/menus/header.html index e59b6f0..fb858ff 100755 --- a/templates/menus/header.html +++ b/templates/menus/header.html @@ -13,24 +13,9 @@ - - - - - - - From f790dfa3ce8f6cc6377a180b6fd1002db9971f49 Mon Sep 17 00:00:00 2001 From: amateurforger Date: Mon, 19 Jan 2026 21:53:25 +0100 Subject: [PATCH 2/2] fix: Readd operation status on new category page --- src/routes/category.rs | 25 +++++++++++++++++-------- templates/categories/show.html | 4 ++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/routes/category.rs b/src/routes/category.rs index 8360b89..92f8c12 100644 --- a/src/routes/category.rs +++ b/src/routes/category.rs @@ -12,7 +12,7 @@ use crate::database::content_folder; use crate::database::{category, category::CategoryOperator}; use crate::extractors::normalized_path::*; use crate::extractors::user::User; -use crate::state::flash_message::OperationStatus; +use crate::state::flash_message::{OperationStatus, get_cookie}; use crate::state::{AppState, AppStateContext, error::*}; #[derive(Clone, Debug, Deserialize, Serialize)] @@ -123,13 +123,16 @@ pub struct CategoryShowTemplate { pub user: Option, /// Category category: category::Model, + /// Operation status for UI confirmation (Cookie) + pub flash: Option, } pub async fn show( State(app_state): State, user: Option, Path(category_name): Path, -) -> Result { + jar: CookieJar, +) -> Result { let app_state_context = app_state.context().await?; let category: category::Model = CategoryOperator::new(app_state.clone(), user.clone()) @@ -144,10 +147,16 @@ pub async fn show( .await .context(CategorySnafu)?; - Ok(CategoryShowTemplate { - content_folders, - category, - state: app_state_context, - user, - }) + let (jar, operation_status) = get_cookie(jar); + + Ok(( + jar, + CategoryShowTemplate { + content_folders, + category, + state: app_state_context, + user, + flash: operation_status, + }, + )) } diff --git a/templates/categories/show.html b/templates/categories/show.html index 2ed7800..124bc6c 100644 --- a/templates/categories/show.html +++ b/templates/categories/show.html @@ -57,6 +57,10 @@
{% include "content_folders/dropdown_actions.html" %} {% endblock %} +{% block alert_message %} + {% include "shared/alert_operation_status.html" %} +{% endblock %} + {% block content_folder_form %}