hidden columns from clients
This commit is contained in:
@@ -59,6 +59,7 @@ column-flag-half-up = zaokrouhleno nahoru
|
||||
column-flag-read-only = pouze pro čtení
|
||||
column-flag-generated = generovaný
|
||||
column-flag-generated-from = generováno z { $source }
|
||||
column-flag-hidden-from-forms = skrytý ve formulářích
|
||||
|
||||
# --- Přihlášení / registrace / změna hesla -----------------------------------
|
||||
login-title = Přihlášení
|
||||
@@ -189,6 +190,9 @@ td-columns-now = Současné sloupce
|
||||
td-col-column = Sloupec
|
||||
td-col-type = Typ
|
||||
td-col-notes = Poznámky
|
||||
td-form-visibility = Viditelnost ve formuláři
|
||||
td-hide-from-forms = Skrýt
|
||||
td-show-in-forms = Zobrazit
|
||||
td-scripts = Skripty
|
||||
td-col-target-column = Cílový sloupec
|
||||
td-col-description = Popis
|
||||
|
||||
@@ -64,6 +64,7 @@ column-flag-half-up = half-up
|
||||
column-flag-read-only = read only
|
||||
column-flag-generated = generated
|
||||
column-flag-generated-from = generated from { $source }
|
||||
column-flag-hidden-from-forms = hidden from forms
|
||||
|
||||
# --- Login / register / change password ------------------------------------
|
||||
login-title = Sign in
|
||||
@@ -193,6 +194,9 @@ td-columns-now = Columns it has now
|
||||
td-col-column = Column
|
||||
td-col-type = Type
|
||||
td-col-notes = Notes
|
||||
td-form-visibility = Form visibility
|
||||
td-hide-from-forms = Hide
|
||||
td-show-in-forms = Show
|
||||
td-scripts = Scripts
|
||||
td-col-target-column = Target column
|
||||
td-col-description = Description
|
||||
|
||||
@@ -59,6 +59,7 @@ column-flag-half-up = zaokrúhlené nahor
|
||||
column-flag-read-only = len na čítanie
|
||||
column-flag-generated = generovaný
|
||||
column-flag-generated-from = generovaný z { $source }
|
||||
column-flag-hidden-from-forms = skrytý vo formulároch
|
||||
|
||||
# --- Prihlásenie / registrácia / zmena hesla -------------------------------
|
||||
login-title = Prihlásenie
|
||||
@@ -189,6 +190,9 @@ td-columns-now = Súčasné stĺpce
|
||||
td-col-column = Stĺpec
|
||||
td-col-type = Typ
|
||||
td-col-notes = Poznámky
|
||||
td-form-visibility = Viditeľnosť vo formulári
|
||||
td-hide-from-forms = Skryť
|
||||
td-show-in-forms = Zobraziť
|
||||
td-scripts = Skripty
|
||||
td-col-target-column = Cieľový stĺpec
|
||||
td-col-description = Popis
|
||||
|
||||
@@ -344,6 +344,7 @@ mod tests {
|
||||
"/admin/tables/columns/add/builder",
|
||||
"/admin/tables/presentation/alias",
|
||||
"/admin/tables/presentation/order",
|
||||
"/admin/tables/presentation/visibility",
|
||||
"/admin/tables/delete",
|
||||
"/admin/profiles/copy",
|
||||
"/admin/tables/from-template",
|
||||
@@ -481,6 +482,10 @@ mod tests {
|
||||
"/admin/tables/presentation/order",
|
||||
"profile=billing&table=invoice&column_ids=1&column_ids=2",
|
||||
),
|
||||
(
|
||||
"/admin/tables/presentation/visibility",
|
||||
"profile=billing&table=invoice&column_id=1&hidden_from_forms=true",
|
||||
),
|
||||
("/admin/tables/columns/add", "profile=billing&table=invoice"),
|
||||
("/admin/tables/builder", ""),
|
||||
("/admin/tables", ""),
|
||||
|
||||
@@ -225,6 +225,8 @@ pub(crate) async fn load_page(
|
||||
// incomplete server capability response does
|
||||
// not grant permission by omission.
|
||||
renameable: behavior.is_some_and(|behavior| behavior.renameable),
|
||||
hidden_from_forms: behavior
|
||||
.is_some_and(|behavior| behavior.hidden_from_forms),
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
|
||||
@@ -23,8 +23,8 @@ use crate::{
|
||||
AppState,
|
||||
definitions::table_definition::{
|
||||
AddTableColumnsRequest, CopyProfileRequest, CreateInvoiceTemplateTableRequest,
|
||||
ColumnPresentation, DeleteTableRequest, SetColumnPresentationRequest,
|
||||
PutTableDefinitionRequest,
|
||||
ColumnPresentation, DeleteTableRequest, PutTableDefinitionRequest,
|
||||
SetColumnFormVisibilityRequest, SetColumnPresentationRequest,
|
||||
},
|
||||
{i18n::Locale, tr},
|
||||
schema::{ColumnForm, proto_columns, validate_column_alias, validate_table_name},
|
||||
@@ -35,7 +35,7 @@ use super::{
|
||||
loader::{self, load_page},
|
||||
state::{
|
||||
AliasForm, CopyForm, DeleteForm, DetailColumn, GeneratedTableView, InvoiceTemplateForm,
|
||||
LoadError, OrderForm, PageInputs, Selection, TableDefinitionPageState,
|
||||
LoadError, OrderForm, PageInputs, Selection, TableDefinitionPageState, VisibilityForm,
|
||||
},
|
||||
ui,
|
||||
};
|
||||
@@ -551,6 +551,49 @@ pub(crate) async fn set_column_order(
|
||||
.await
|
||||
}
|
||||
|
||||
/// POST /admin/tables/presentation/visibility — show or hide one column in
|
||||
/// bundled data-entry forms without changing its data-plane behavior.
|
||||
pub(crate) async fn set_column_visibility(
|
||||
State(state): State<AppState>,
|
||||
headers: HeaderMap,
|
||||
Form(form): Form<VisibilityForm>,
|
||||
) -> Response {
|
||||
if let Some(rejection) = reject_cross_site(&headers) {
|
||||
return rejection;
|
||||
}
|
||||
|
||||
let inputs = PageInputs::for_selection(Selection {
|
||||
profile: form.profile.clone(),
|
||||
table: form.table.clone(),
|
||||
});
|
||||
let request = SetColumnFormVisibilityRequest {
|
||||
profile_name: form.profile,
|
||||
table_name: form.table,
|
||||
column_id: form.column_id,
|
||||
hidden_from_forms: form.hidden_from_forms,
|
||||
expected_row_version: form.expected_row_version,
|
||||
};
|
||||
let Ok(request) = authenticated_request(&headers, request) else {
|
||||
return Redirect::to("/login").into_response();
|
||||
};
|
||||
|
||||
let mut definitions = state.definitions.clone();
|
||||
match definitions.set_column_form_visibility(request).await {
|
||||
Ok(response) if response.get_ref().success => {
|
||||
let mut inputs = inputs;
|
||||
inputs.status = Some(response.into_inner().message);
|
||||
respond(state, headers, inputs, Page::Presentation, StatusCode::OK).await
|
||||
}
|
||||
Ok(response) => {
|
||||
let message = response.into_inner().message;
|
||||
refuse(state, headers, inputs, Page::Presentation, message).await
|
||||
}
|
||||
Err(error) => {
|
||||
refuse(state, headers, inputs, Page::Presentation, error.message().to_string()).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The table's columns as the backend has them now, in their current order.
|
||||
///
|
||||
/// Both presentation writes have to send every column, and the ones they are
|
||||
|
||||
@@ -50,6 +50,10 @@ pub(crate) fn router() -> Router<AppState> {
|
||||
"/admin/tables/presentation/order",
|
||||
post(logic::set_column_order),
|
||||
)
|
||||
.route(
|
||||
"/admin/tables/presentation/visibility",
|
||||
post(logic::set_column_visibility),
|
||||
)
|
||||
.route("/admin/tables/delete", get(logic::delete_page))
|
||||
.route("/admin/tables/delete", post(logic::delete_table))
|
||||
// Profile-scoped.
|
||||
|
||||
@@ -159,6 +159,7 @@ pub(crate) struct DetailColumn {
|
||||
pub read_only: bool,
|
||||
pub generated_from: String,
|
||||
pub renameable: bool,
|
||||
pub hidden_from_forms: bool,
|
||||
}
|
||||
|
||||
impl DetailColumn {
|
||||
@@ -186,6 +187,9 @@ impl DetailColumn {
|
||||
if self.read_only {
|
||||
flags.push(crate::tr!(*locale, "column-flag-read-only"));
|
||||
}
|
||||
if self.hidden_from_forms {
|
||||
flags.push(crate::tr!(*locale, "column-flag-hidden-from-forms"));
|
||||
}
|
||||
if !self.generated_from.is_empty() {
|
||||
flags.push(crate::tr!(
|
||||
*locale,
|
||||
@@ -266,6 +270,20 @@ pub(crate) struct OrderForm {
|
||||
pub column_ids: Vec<i64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
||||
pub(crate) struct VisibilityForm {
|
||||
#[serde(default)]
|
||||
pub profile: String,
|
||||
#[serde(default)]
|
||||
pub table: String,
|
||||
#[serde(default)]
|
||||
pub expected_row_version: i64,
|
||||
#[serde(default)]
|
||||
pub column_id: i64,
|
||||
#[serde(default)]
|
||||
pub hidden_from_forms: bool,
|
||||
}
|
||||
|
||||
/// The copy-profile panel. An empty `table_names` copies the whole profile,
|
||||
/// which is what the backend takes an empty list to mean.
|
||||
#[derive(Clone, Debug, Default, serde::Deserialize)]
|
||||
@@ -515,6 +533,7 @@ mod tests {
|
||||
read_only: false,
|
||||
generated_from: String::new(),
|
||||
renameable: true,
|
||||
hidden_from_forms: false,
|
||||
},
|
||||
DetailColumn {
|
||||
column_id: 2,
|
||||
@@ -528,6 +547,7 @@ mod tests {
|
||||
read_only: true,
|
||||
generated_from: "work_phone".to_string(),
|
||||
renameable: false,
|
||||
hidden_from_forms: false,
|
||||
},
|
||||
DetailColumn {
|
||||
column_id: 3,
|
||||
@@ -541,6 +561,7 @@ mod tests {
|
||||
read_only: false,
|
||||
generated_from: "accounting".to_string(),
|
||||
renameable: true,
|
||||
hidden_from_forms: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -288,6 +288,7 @@ mod tests {
|
||||
read_only: false,
|
||||
generated_from: String::new(),
|
||||
renameable: true,
|
||||
hidden_from_forms: false,
|
||||
}],
|
||||
}),
|
||||
history: Vec::new(),
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<section class="panel">
|
||||
<h2>{{ nav.tr("td-columns-now") }} <span class="count">{{ detail.columns.len() }}</span></h2>
|
||||
<table class="builder-table">
|
||||
<thead><tr><th>{{ nav.tr("td-col-column") }}</th><th>{{ nav.tr("td-col-type") }}</th><th>{{ nav.tr("td-col-notes") }}</th></tr></thead>
|
||||
<thead><tr><th>{{ nav.tr("td-col-column") }}</th><th>{{ nav.tr("td-col-type") }}</th><th>{{ nav.tr("td-col-notes") }}</th><th>{{ nav.tr("td-form-visibility") }}</th></tr></thead>
|
||||
<tbody>
|
||||
{% for column in detail.columns %}
|
||||
<tr>
|
||||
@@ -91,6 +91,21 @@
|
||||
<td>
|
||||
{%- for flag in column.flags(nav.locale) %}<span class="tag">{{ flag }}</span>{% endfor -%}
|
||||
</td>
|
||||
<td>
|
||||
{% if page.table_is_writable() %}
|
||||
<form hx-post="/admin/tables/presentation/visibility"
|
||||
hx-target="#table-panel" hx-swap="innerHTML">
|
||||
<input type="hidden" name="profile" value="{{ page.selection.profile }}">
|
||||
<input type="hidden" name="table" value="{{ page.selection.table }}">
|
||||
<input type="hidden" name="expected_row_version" value="{{ detail.row_version }}">
|
||||
<input type="hidden" name="column_id" value="{{ column.column_id }}">
|
||||
<input type="hidden" name="hidden_from_forms" value="{% if column.hidden_from_forms %}false{% else %}true{% endif %}">
|
||||
<button class="secondary" type="submit">
|
||||
{% if column.hidden_from_forms %}{{ nav.tr("td-show-in-forms") }}{% else %}{{ nav.tr("td-hide-from-forms") }}{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user