Files
komp_ac/web/src/pages/admin/table_definition/mod.rs
2026-08-15 18:31:51 +02:00

71 lines
2.7 KiB
Rust

//! What can be done to a table once it exists, as one page per decision.
//!
//! Adding columns, presenting columns, dropping the table, copying its profile,
//! generating tables from a template and reading the rename history are six
//! different jobs, and they used to be panels stacked on one `/admin/table-definition`
//! workspace — which meant that after creating a table you landed on a screen
//! where finding the delete form meant scrolling past five other forms.
//!
//! They are now five routes, and the browsing they all needed — which profile,
//! which table — is done in the admin panel, which was already a three-pane
//! browser for exactly that. Every page here is entered with its selection in
//! the query string, and links back to the panel it came from.
//!
//! Creating a table is still elsewhere: it is a form long enough to want its
//! own page, `pages/add_table`.
mod loader;
mod logic;
mod state;
mod ui;
use axum::{
Router,
response::Redirect,
routing::{get, post},
};
use crate::AppState;
pub(crate) fn router() -> Router<AppState> {
Router::new()
// Table-scoped.
.route(
"/admin/tables/columns/add",
get(logic::add_columns_page).post(logic::add_columns),
)
.route(
"/admin/tables/columns/add/builder",
post(logic::update_columns),
)
// Naming a column and ordering the columns are one backend call but two
// forms, because a request that carries both is a request in which a
// stale alias can ride along with an unrelated edit. See
// `state::AliasForm`.
.route("/admin/tables/presentation", get(logic::presentation_page))
.route(
"/admin/tables/presentation/alias",
post(logic::set_column_alias),
)
.route(
"/admin/tables/presentation/order",
post(logic::set_column_order),
)
.route("/admin/tables/delete", get(logic::delete_page))
.route("/admin/tables/delete", post(logic::delete_table))
// Profile-scoped.
.route("/admin/profiles/copy", get(logic::copy_page))
.route("/admin/profiles/copy", post(logic::copy_profile))
.route("/admin/profiles/history", get(logic::history_page))
.route(
"/admin/tables/from-template",
get(logic::template_page).post(logic::create_from_invoice_template),
)
// The workspace these came out of. Anything still pointing at it —
// a bookmark, an old link — lands on the browser instead.
.route(
"/admin/table-definition",
get(|| async { Redirect::permanent("/admin") }),
)
}