web interface for table_definition improved
This commit is contained in:
@@ -5,13 +5,16 @@
|
||||
//! the TUI client applies in-process between keystrokes.
|
||||
|
||||
use axum::{
|
||||
extract::State,
|
||||
extract::{Query, State},
|
||||
http::{HeaderMap, HeaderValue, StatusCode, header},
|
||||
response::{Html, IntoResponse, Redirect, Response},
|
||||
};
|
||||
use axum_extra::extract::Form;
|
||||
|
||||
use crate::{AppState, services::authenticated_request};
|
||||
use crate::{
|
||||
AppState,
|
||||
services::{authenticated_request, reject_cross_site},
|
||||
};
|
||||
|
||||
use super::{
|
||||
draft::TableDraft,
|
||||
@@ -20,9 +23,24 @@ use super::{
|
||||
ui,
|
||||
};
|
||||
|
||||
/// The profile the table-definition workspace hands over when it sends the
|
||||
/// user here to create a table, so the picker opens on the right one.
|
||||
#[derive(Debug, Default, serde::Deserialize)]
|
||||
pub(crate) struct NewTableQuery {
|
||||
#[serde(default)]
|
||||
profile: String,
|
||||
}
|
||||
|
||||
/// GET /admin/tables/new
|
||||
pub(crate) async fn new_table_page(State(state): State<AppState>, headers: HeaderMap) -> Response {
|
||||
match load_page(state, &headers, TableDraft::new(), None, None).await {
|
||||
pub(crate) async fn new_table_page(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
Query(query): Query<NewTableQuery>,
|
||||
) -> Response {
|
||||
let mut draft = TableDraft::new();
|
||||
draft.profile_name = query.profile.trim().to_string();
|
||||
|
||||
match load_page(state, &headers, draft, None, None).await {
|
||||
Ok(page) => Html(ui::render_page(&page)).into_response(),
|
||||
Err(error) => load_error_response(error),
|
||||
}
|
||||
@@ -115,7 +133,7 @@ pub(crate) async fn create_table(
|
||||
fn apply_action(page: &mut AddTablePageState, form: &BuilderForm) {
|
||||
let index = form.index.unwrap_or(0);
|
||||
match form.action.as_str() {
|
||||
"add-column" => match page.draft.add_column_from_inputs() {
|
||||
"add-column" => match page.draft.columns.add_from_inputs() {
|
||||
Ok(status) => page.status = Some(status),
|
||||
Err(message) => page.error = Some(message),
|
||||
},
|
||||
@@ -123,20 +141,13 @@ fn apply_action(page: &mut AddTablePageState, form: &BuilderForm) {
|
||||
Ok(status) => page.status = Some(status),
|
||||
Err(message) => page.error = Some(message),
|
||||
},
|
||||
"toggle-index" => page.draft.toggle_column_indexed(index),
|
||||
"toggle-index" => page.draft.columns.toggle_indexed(index),
|
||||
"cycle-link" => page.draft.cycle_link_mode(index),
|
||||
"toggle-display" => page.draft.toggle_row_display_candidate(index),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn reject_cross_site(headers: &HeaderMap) -> Option<Response> {
|
||||
headers
|
||||
.get("sec-fetch-site")
|
||||
.is_some_and(|value| value == "cross-site")
|
||||
.then(|| (StatusCode::FORBIDDEN, "Cross-site form submission rejected").into_response())
|
||||
}
|
||||
|
||||
fn load_error_response(error: LoadError) -> Response {
|
||||
match error {
|
||||
LoadError::Unauthenticated => Redirect::to("/login").into_response(),
|
||||
|
||||
Reference in New Issue
Block a user