✨ (base) Añade ListView y ListFilter para listados
- ListView: botones, mensajes, tabla y paginador en orden fijo; anuncia el número de resultados a los lectores de pantalla. - ListFilter: filtros en fila con "Filtrar" y "Limpiar", envío automático opcional y marcas de cambios sin aplicar. - pagetop-htmx: hx_pager::boost() y hx_filter::boost(); cancelan las peticiones solapadas y atenúan el listado mientras carga, con estilos sólo en las páginas con listado. - Usuarios y roles migrados al nuevo patrón.
This commit is contained in:
parent
0f71eba7ab
commit
d8493291e4
28 changed files with 1264 additions and 144 deletions
|
|
@ -12,7 +12,7 @@ mod user_table;
|
|||
pub(crate) use admin_password_form::AdminPasswordForm;
|
||||
pub(crate) use role_form::{RoleForm, RoleFormMode};
|
||||
pub(crate) use role_permissions_form::RolePermissionsForm;
|
||||
pub(crate) use role_table::RoleTable;
|
||||
pub(crate) use role_table::{RoleTable, delete_dialog};
|
||||
pub(crate) use user_form::{UserForm, UserFormMode};
|
||||
pub(crate) use user_table::{UserTable, status_key};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
//! Tabla de roles: cabeceras ordenables y filas con acciones.
|
||||
//! Listado de roles: cabeceras ordenables y filas con acciones, en un `ListView`.
|
||||
|
||||
use pagetop::prelude::*;
|
||||
use pagetop_htmx::hx;
|
||||
use pagetop_htmx::hx_table::sort_link;
|
||||
use pagetop_htmx::{hx, hx_pager};
|
||||
|
||||
use crate::ADMIN_ROLES_PATH;
|
||||
use crate::LOCALES_USER;
|
||||
|
|
@ -12,7 +12,6 @@ use crate::service::role_admin::{RoleListItem, RoleSortField};
|
|||
|
||||
#[derive(AutoDefault, Clone, Debug, Getters)]
|
||||
pub(crate) struct RoleTable {
|
||||
props: Props,
|
||||
items: Vec<RoleListItem>,
|
||||
sort: RoleSortField,
|
||||
dir: SortDir,
|
||||
|
|
@ -29,15 +28,6 @@ impl Component for RoleTable {
|
|||
Self::default()
|
||||
}
|
||||
|
||||
fn id(&self) -> Option<String> {
|
||||
self.props.get_id()
|
||||
}
|
||||
|
||||
fn setup(&mut self, _cx: &mut Context) {
|
||||
self.alter_prop(PropsOp::set_id("role-table-wrapper"));
|
||||
self.alter_prop(PropsOp::prepend_classes("user-admin-table-wrapper"));
|
||||
}
|
||||
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let pager = Pager::new()
|
||||
.with_base_path(ADMIN_ROLES_PATH.as_str())
|
||||
|
|
@ -45,13 +35,7 @@ impl Component for RoleTable {
|
|||
.with_extra_query("dir", *self.dir())
|
||||
.with_current_page(self.page())
|
||||
.with_items_per_page(self.per_page())
|
||||
.with_total_items(self.total())
|
||||
.with_prop(PropsOp::set(hx::BOOST, "true"))
|
||||
.with_prop(PropsOp::set(hx::TARGET, "#role-table-wrapper"))
|
||||
.with_prop(PropsOp::set(hx::SWAP, hx::swap::OUTER_HTML_SCROLL_TOP))
|
||||
.with_prop(PropsOp::set(hx::PUSH_URL, "true"))
|
||||
.render(cx)
|
||||
.await;
|
||||
.with_total_items(self.total());
|
||||
|
||||
let mut table = Table::new()
|
||||
.with_prop(PropsOp::add_classes("user-admin-table"))
|
||||
|
|
@ -62,21 +46,6 @@ impl Component for RoleTable {
|
|||
.with_column(Lc::t("col-actions", &LOCALES_USER))
|
||||
.with_empty(Lc::t("empty-roles-list", &LOCALES_USER));
|
||||
|
||||
let confirm_dialog = Dialog::new()
|
||||
.with_id("confirm-delete-role")
|
||||
.with_child(Html::with(|cx| {
|
||||
html! { p { (Lc::t("confirm-delete-role", &LOCALES_USER).using(cx)) } }
|
||||
}))
|
||||
.with_footer(
|
||||
Button::plain(Lc::t("btn-cancel", &LOCALES_USER))
|
||||
.with_prop(PropsOp::set("data-dialog-dismiss", "modal")),
|
||||
)
|
||||
.with_footer(Html::with(
|
||||
|_cx| html! { span id="role-delete-confirm-action" {} },
|
||||
))
|
||||
.render(cx)
|
||||
.await;
|
||||
|
||||
let waypoint = Waypoint::from(self.list_href(cx));
|
||||
|
||||
for role in self.items() {
|
||||
|
|
@ -119,32 +88,43 @@ impl Component for RoleTable {
|
|||
|
||||
let new_href = waypoint.append_to(cx.route(util::join!(ADMIN_ROLES_PATH.as_str(), "/new")));
|
||||
|
||||
Ok(html! {
|
||||
div (self.props().unpack(cx)) {
|
||||
(Button::anchor(Lc::t("btn-create-role", &LOCALES_USER), new_href)
|
||||
.with_style(button::Style::Solid(Intent::Primary))
|
||||
.render(cx)
|
||||
.await)
|
||||
@if let Some(message) = self.message() {
|
||||
div class="user-form-error" role="alert" { (message.clone().using(cx)) }
|
||||
}
|
||||
(table.render(cx).await)
|
||||
(pager)
|
||||
(confirm_dialog)
|
||||
}
|
||||
})
|
||||
if let Some(message) = self.message() {
|
||||
cx.push_message(MessageLevel::Error, message.clone());
|
||||
}
|
||||
let mut list = ListView::new()
|
||||
.with_id("role-table-wrapper")
|
||||
.with_action(
|
||||
Button::anchor(Lc::t("btn-create-role", &LOCALES_USER), new_href)
|
||||
.with_style(button::Style::Solid(Intent::Primary)),
|
||||
)
|
||||
.with_table(table)
|
||||
.with_pager(hx_pager::boost(pager, "#role-table-wrapper"));
|
||||
Ok(list.render(cx).await)
|
||||
}
|
||||
}
|
||||
|
||||
// Diálogo de confirmación de borrado, compartido por todas las filas: el botón de borrar de cada
|
||||
// una lo abre y carga en él su botón de confirmación (ver `delete_confirm_get` en los *handlers* de
|
||||
// roles). Va en la página, fuera del listado, para que HTMX no lo reemplace al actualizarlo.
|
||||
pub(crate) fn delete_dialog() -> Dialog {
|
||||
Dialog::new()
|
||||
.with_id("confirm-delete-role")
|
||||
.with_child(Html::with(|cx| {
|
||||
html! { p { (Lc::t("confirm-delete-role", &LOCALES_USER).using(cx)) } }
|
||||
}))
|
||||
.with_footer(
|
||||
Button::plain(Lc::t("btn-cancel", &LOCALES_USER))
|
||||
.with_prop(PropsOp::set("data-dialog-dismiss", "modal")),
|
||||
)
|
||||
.with_footer(Html::with(
|
||||
|_cx| html! { span id="role-delete-confirm-action" {} },
|
||||
))
|
||||
}
|
||||
|
||||
#[builder_impl]
|
||||
impl RoleTable {
|
||||
// **< RoleTable BUILDER >**********************************************************************
|
||||
|
||||
pub(crate) fn with_prop(mut self, op: impl Into<PropsOp>) -> Self {
|
||||
self.props.alter_prop(op);
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_items(mut self, items: Vec<RoleListItem>) -> Self {
|
||||
self.items = items;
|
||||
self
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
//! Tabla de usuarios: cabeceras ordenables, filas y paginación embebida.
|
||||
//! Listado de usuarios: cabeceras ordenables, filas y paginación, en un `ListView`.
|
||||
|
||||
use pagetop::prelude::*;
|
||||
use pagetop_htmx::hx;
|
||||
use pagetop_htmx::hx_pager;
|
||||
use pagetop_htmx::hx_table::sort_link;
|
||||
|
||||
use crate::ADMIN_USERS_PATH;
|
||||
|
|
@ -12,7 +12,6 @@ use crate::user_path;
|
|||
|
||||
#[derive(AutoDefault, Clone, Debug, Getters)]
|
||||
pub(crate) struct UserTable {
|
||||
props: Props,
|
||||
items: Vec<UserListItem>,
|
||||
sort: UserSortField,
|
||||
dir: SortDir,
|
||||
|
|
@ -28,15 +27,6 @@ impl Component for UserTable {
|
|||
Self::default()
|
||||
}
|
||||
|
||||
fn id(&self) -> Option<String> {
|
||||
self.props.get_id()
|
||||
}
|
||||
|
||||
fn setup(&mut self, _cx: &mut Context) {
|
||||
self.alter_prop(PropsOp::set_id("user-table-wrapper"));
|
||||
self.alter_prop(PropsOp::prepend_classes("user-admin-table-wrapper"));
|
||||
}
|
||||
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let pager = Pager::new()
|
||||
.with_base_path(ADMIN_USERS_PATH.as_str())
|
||||
|
|
@ -45,13 +35,7 @@ impl Component for UserTable {
|
|||
.with_extra_query("dir", *self.dir())
|
||||
.with_current_page(self.page())
|
||||
.with_items_per_page(self.per_page())
|
||||
.with_total_items(self.total())
|
||||
.with_prop(PropsOp::set(hx::BOOST, "true"))
|
||||
.with_prop(PropsOp::set(hx::TARGET, "#user-table-wrapper"))
|
||||
.with_prop(PropsOp::set(hx::SWAP, hx::swap::OUTER_HTML_SCROLL_TOP))
|
||||
.with_prop(PropsOp::set(hx::PUSH_URL, "true"))
|
||||
.render(cx)
|
||||
.await;
|
||||
.with_total_items(self.total());
|
||||
|
||||
let mut table = Table::new()
|
||||
.with_prop(PropsOp::add_classes("user-admin-table"))
|
||||
|
|
@ -85,16 +69,15 @@ impl Component for UserTable {
|
|||
|
||||
let new_href = waypoint.append_to(cx.route(util::join!(ADMIN_USERS_PATH.as_str(), "/new")));
|
||||
|
||||
Ok(html! {
|
||||
div (self.props().unpack(cx)) {
|
||||
(Button::anchor(Lc::t("btn-create-user", &LOCALES_USER), new_href)
|
||||
.with_style(button::Style::Solid(Intent::Primary))
|
||||
.render(cx)
|
||||
.await)
|
||||
(table.render(cx).await)
|
||||
(pager)
|
||||
}
|
||||
})
|
||||
let mut list = ListView::new()
|
||||
.with_id("user-table-wrapper")
|
||||
.with_action(
|
||||
Button::anchor(Lc::t("btn-create-user", &LOCALES_USER), new_href)
|
||||
.with_style(button::Style::Solid(Intent::Primary)),
|
||||
)
|
||||
.with_table(table)
|
||||
.with_pager(hx_pager::boost(pager, "#user-table-wrapper"));
|
||||
Ok(list.render(cx).await)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -102,11 +85,6 @@ impl Component for UserTable {
|
|||
impl UserTable {
|
||||
// **< UserTable BUILDER >**********************************************************************
|
||||
|
||||
pub(crate) fn with_prop(mut self, op: impl Into<PropsOp>) -> Self {
|
||||
self.props.alter_prop(op);
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_items(mut self, items: Vec<UserListItem>) -> Self {
|
||||
self.items = items;
|
||||
self
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use pagetop_htmx::prelude::*;
|
|||
use crate::ADMIN_ROLES_PATH;
|
||||
use crate::LOCALES_USER;
|
||||
use crate::component::admin::{
|
||||
PermissionGroups, RoleForm, RoleFormMode, RolePermissionsForm, RoleTable,
|
||||
PermissionGroups, RoleForm, RoleFormMode, RolePermissionsForm, RoleTable, delete_dialog,
|
||||
};
|
||||
use crate::config::SETTINGS;
|
||||
use crate::entity::role;
|
||||
|
|
@ -62,6 +62,7 @@ pub(crate) async fn list_get(
|
|||
Ok(Page::admin(request)
|
||||
.with_title(title)
|
||||
.with_child(table)
|
||||
.with_child(delete_dialog())
|
||||
.render()
|
||||
.await
|
||||
.into_response())
|
||||
|
|
@ -403,7 +404,7 @@ pub(crate) async fn delete_post(
|
|||
|
||||
/// GET /admin/user/roles/{id}/delete/confirm - Botón de confirmación de borrado para esta fila,
|
||||
/// insertado vía htmx en el diálogo de confirmación compartido por toda la tabla (ver
|
||||
/// `RoleTable`), con la URL de borrado de este rol ya incrustada.
|
||||
/// `delete_dialog()`), con la URL de borrado de este rol ya incrustada.
|
||||
///
|
||||
/// Propaga `sort`/`dir`/`page` (recibidos como query string desde la propia fila) hacia la URL de
|
||||
/// borrado, para que `delete_post` pueda volver a mostrar la misma página tras el borrado, en vez
|
||||
|
|
|
|||
|
|
@ -70,11 +70,9 @@ pub(crate) async fn list_get(
|
|||
Ok(HtmxResponse::new(table.render(&mut cx).await).into_response())
|
||||
} else {
|
||||
let title = Lc::t("title-admin-users", &LOCALES_USER);
|
||||
let page = Page::admin(request);
|
||||
let search = search_bar(page.route(ADMIN_USERS_PATH.as_str()), query.q);
|
||||
Ok(page
|
||||
Ok(Page::admin(request)
|
||||
.with_title(title)
|
||||
.with_child(search)
|
||||
.with_child(search_filter(query.q))
|
||||
.with_child(table)
|
||||
.render()
|
||||
.await
|
||||
|
|
@ -82,26 +80,21 @@ pub(crate) async fn list_get(
|
|||
}
|
||||
}
|
||||
|
||||
// **< search_bar >*********************************************************************************
|
||||
// **< search_filter >******************************************************************************
|
||||
|
||||
// Los atributos HTMX van en el formulario porque `with_prop()` de un campo los pondría en su
|
||||
// contenedor, que no enviaría el valor. `input` cubre también vaciar con la "x" del navegador.
|
||||
fn search_bar(route: RoutePath, current_query: Option<String>) -> Form {
|
||||
Form::new()
|
||||
.with_action(route.clone())
|
||||
.with_method(form::Method::Get)
|
||||
.with_prop(PropsOp::set(hx::GET, route.to_string()))
|
||||
.with_prop(PropsOp::set(hx::TRIGGER, "input delay:400ms, submit"))
|
||||
.with_prop(PropsOp::set(hx::TARGET, "#user-table-wrapper"))
|
||||
.with_prop(PropsOp::set(hx::SWAP, hx::swap::OUTER_HTML_SCROLL_TOP))
|
||||
.with_prop(PropsOp::set(hx::PUSH_URL, "true"))
|
||||
.with_child(
|
||||
form::input::Field::search()
|
||||
.with_id("user-admin-search")
|
||||
.with_name("q")
|
||||
.with_value(current_query.unwrap_or_default())
|
||||
.with_placeholder(Lc::t("field-search-users", &LOCALES_USER)),
|
||||
)
|
||||
fn search_filter(current_query: Option<String>) -> ListFilter {
|
||||
hx_filter::boost(
|
||||
ListFilter::new()
|
||||
.with_filter_action(ADMIN_USERS_PATH.as_str())
|
||||
.with_field(
|
||||
form::input::Field::search()
|
||||
.with_id("user-admin-search")
|
||||
.with_name("q")
|
||||
.with_value(current_query.unwrap_or_default())
|
||||
.with_placeholder(Lc::t("field-search-users", &LOCALES_USER)),
|
||||
),
|
||||
"#user-table-wrapper",
|
||||
)
|
||||
}
|
||||
|
||||
// **< available_roles >****************************************************************************
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue