✨ (user): Recuerda el estado de usuarios y roles
Los listados de usuarios y roles se montan con `remember_query()` y dejan de arrastrar el estado en los enlaces. La renovación de la sesión "Recuérdame" ya no se pierde cuando la respuesta fija otra cookie.
This commit is contained in:
parent
030ac92e2f
commit
84eef9ec4f
24 changed files with 251 additions and 201 deletions
|
|
@ -11,8 +11,6 @@ use crate::component::{PasswordConfirm, error_banner, form_actions};
|
|||
pub(crate) struct AdminPasswordForm {
|
||||
user_id: i32,
|
||||
error: Option<Lc>,
|
||||
/// Listado de origen al que volver tras guardar (orden, búsqueda, página).
|
||||
waypoint: Waypoint,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
@ -23,7 +21,7 @@ impl Component for AdminPasswordForm {
|
|||
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let action = user_path(self.user_id(), "password");
|
||||
let action = self.waypoint().append_to(cx.route(action));
|
||||
let action = cx.route(action);
|
||||
|
||||
let mut form = Form::new()
|
||||
.with_id("user-admin-password-form")
|
||||
|
|
@ -36,8 +34,7 @@ impl Component for AdminPasswordForm {
|
|||
)
|
||||
.with_child(form_actions(
|
||||
Lc::t("btn-save", &LOCALES_USER),
|
||||
self.waypoint()
|
||||
.append_to(cx.route(user_path(self.user_id(), "edit"))),
|
||||
cx.route(user_path(self.user_id(), "edit")),
|
||||
));
|
||||
|
||||
Ok(form.render(cx).await)
|
||||
|
|
@ -57,9 +54,4 @@ impl AdminPasswordForm {
|
|||
self.error = error.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_waypoint(mut self, waypoint: impl Into<Waypoint>) -> Self {
|
||||
self.waypoint = waypoint.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,6 @@ pub(crate) struct RoleForm {
|
|||
mode: RoleFormMode,
|
||||
error: Option<Lc>,
|
||||
role_id: Option<i32>,
|
||||
/// Listado de origen al que volver tras guardar (orden).
|
||||
waypoint: Waypoint,
|
||||
machine_name: String,
|
||||
label: String,
|
||||
description: String,
|
||||
|
|
@ -40,7 +38,7 @@ impl Component for RoleForm {
|
|||
RoleFormMode::New => util::join!(ADMIN_ROLES_PATH.as_str(), "/new"),
|
||||
RoleFormMode::Edit => role_path(self.role_id().copied().unwrap_or_default(), "edit"),
|
||||
};
|
||||
let action = self.waypoint().append_to(cx.route(action));
|
||||
let action = cx.route(action);
|
||||
|
||||
let machine_name_field = match self.mode() {
|
||||
RoleFormMode::New => form::input::Field::text()
|
||||
|
|
@ -88,7 +86,7 @@ impl Component for RoleForm {
|
|||
|
||||
form = form.with_child(form_actions(
|
||||
Lc::t("btn-save", &LOCALES_USER),
|
||||
self.waypoint().or(cx.route(ADMIN_ROLES_PATH.as_str())),
|
||||
cx.route(ADMIN_ROLES_PATH.as_str()),
|
||||
));
|
||||
|
||||
Ok(form.render(cx).await)
|
||||
|
|
@ -114,11 +112,6 @@ impl RoleForm {
|
|||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_waypoint(mut self, waypoint: impl Into<Waypoint>) -> Self {
|
||||
self.waypoint = waypoint.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_machine_name(mut self, machine_name: impl Into<String>) -> Self {
|
||||
self.machine_name = machine_name.into();
|
||||
self
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ pub(crate) struct RolePermissionsForm {
|
|||
role_id: i32,
|
||||
error: Option<Lc>,
|
||||
groups: PermissionGroups,
|
||||
/// Listado de origen al que volver tras guardar (orden).
|
||||
waypoint: Waypoint,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
|
@ -29,7 +27,7 @@ impl Component for RolePermissionsForm {
|
|||
|
||||
async fn prepare(&self, cx: &mut Context) -> Result<Markup, ComponentError> {
|
||||
let action = role_path(self.role_id(), "permissions");
|
||||
let action = self.waypoint().append_to(cx.route(action));
|
||||
let action = cx.route(action);
|
||||
|
||||
let mut form = Form::new()
|
||||
.with_id("role-permissions-form")
|
||||
|
|
@ -56,7 +54,7 @@ impl Component for RolePermissionsForm {
|
|||
|
||||
form = form.with_child(form_actions(
|
||||
Lc::t("btn-save", &LOCALES_USER),
|
||||
self.waypoint().or(cx.route(ADMIN_ROLES_PATH.as_str())),
|
||||
cx.route(ADMIN_ROLES_PATH.as_str()),
|
||||
));
|
||||
|
||||
Ok(form.render(cx).await)
|
||||
|
|
@ -81,9 +79,4 @@ impl RolePermissionsForm {
|
|||
self.groups = groups;
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_waypoint(mut self, waypoint: impl Into<Waypoint>) -> Self {
|
||||
self.waypoint = waypoint.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,6 @@ impl Component for RoleTable {
|
|||
.with_column(Lc::t("col-actions", &LOCALES_USER))
|
||||
.with_empty(Lc::t("empty-roles-list", &LOCALES_USER));
|
||||
|
||||
let waypoint = Waypoint::from(self.list_href(cx));
|
||||
|
||||
for role in self.items() {
|
||||
let system_badge = if role.locked {
|
||||
Some(
|
||||
|
|
@ -71,7 +69,7 @@ impl Component for RoleTable {
|
|||
table.alter_row(
|
||||
table::Row::new()
|
||||
.with_cell(role.machine_name.as_str())
|
||||
.with_cell(label_cell(role, &waypoint))
|
||||
.with_cell(label_cell(role))
|
||||
.with_cell(Html::with(move |_cx| {
|
||||
html! {
|
||||
@if let Some(badge) = &system_badge { (badge) }
|
||||
|
|
@ -80,13 +78,12 @@ impl Component for RoleTable {
|
|||
}))
|
||||
.with_cell(role.user_count.to_string())
|
||||
.with_cell(
|
||||
actions_cell(role, &waypoint, *self.sort(), *self.dir(), self.page(), cx)
|
||||
.await,
|
||||
actions_cell(role, *self.sort(), *self.dir(), self.page(), cx).await,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
let new_href = waypoint.append_to(cx.route(util::join!(ADMIN_ROLES_PATH.as_str(), "/new")));
|
||||
let new_href = cx.route(util::join!(ADMIN_ROLES_PATH.as_str(), "/new"));
|
||||
|
||||
if let Some(message) = self.message() {
|
||||
cx.push_message(MessageLevel::Error, message.clone());
|
||||
|
|
@ -160,17 +157,6 @@ impl RoleTable {
|
|||
self
|
||||
}
|
||||
|
||||
// URL del listado con el estado actual (orden, página): es el valor que viaja como `waypoint`
|
||||
// en los enlaces de ver/editar/permisos, para poder volver exactamente a este mismo estado. Se
|
||||
// construye con `cx.route()` para que preserve el parámetro `lang` cuando corresponda.
|
||||
fn list_href(&self, cx: &Context) -> String {
|
||||
cx.route(ADMIN_ROLES_PATH.as_str())
|
||||
.alter_param("sort", self.sort().as_str())
|
||||
.alter_param("dir", *self.dir())
|
||||
.alter_param("page", self.page().to_string())
|
||||
.to_string()
|
||||
}
|
||||
|
||||
// Construye la cabecera ordenable de una columna: el enlace ya funciona sin HTMX (navega con
|
||||
// una petición normal); `pagetop_htmx::hx_table::sort_link()` añade aparte los atributos `hx-*`
|
||||
// para que la tabla se actualice sin recargar la página cuando la extensión esté disponible.
|
||||
|
|
@ -199,12 +185,11 @@ impl RoleTable {
|
|||
// Construye la celda de etiqueta: enlaza a la pantalla de sólo lectura con todos los permisos del
|
||||
// rol. Devuelve un componente `Html` para que el marcado se genere cuando `Table` renderice la
|
||||
// celda, no al construir la fila.
|
||||
fn label_cell(role: &RoleListItem, waypoint: &Waypoint) -> Html {
|
||||
fn label_cell(role: &RoleListItem) -> Html {
|
||||
let label = crate::role_label(role.id, &role.label);
|
||||
let id = role.id;
|
||||
let waypoint = waypoint.clone();
|
||||
Html::with(move |cx| {
|
||||
let view_href = waypoint.append_to(cx.route(role_path(id, "view")));
|
||||
let view_href = cx.route(role_path(id, "view"));
|
||||
html! {
|
||||
a href=(view_href) { (label.using(cx)) }
|
||||
}
|
||||
|
|
@ -216,7 +201,6 @@ fn label_cell(role: &RoleListItem, waypoint: &Waypoint) -> Html {
|
|||
// que el marcado se genere cuando `Table` renderice la celda, no al construir la fila.
|
||||
async fn actions_cell(
|
||||
role: &RoleListItem,
|
||||
waypoint: &Waypoint,
|
||||
sort: RoleSortField,
|
||||
dir: SortDir,
|
||||
page: u64,
|
||||
|
|
@ -224,7 +208,6 @@ async fn actions_cell(
|
|||
) -> Html {
|
||||
let id = role.id;
|
||||
let locked = role.locked;
|
||||
let waypoint = waypoint.clone();
|
||||
|
||||
let can_manage_permissions = cx
|
||||
.request()
|
||||
|
|
@ -235,7 +218,7 @@ async fn actions_cell(
|
|||
// (ver `pagetop-bootsier::theme::bs::button`), incluida la traducción de `data-dialog-*` que
|
||||
// usa el botón de borrado.
|
||||
let permissions_button = if can_manage_permissions {
|
||||
let permissions_href = waypoint.append_to(cx.route(role_path(id, "permissions")));
|
||||
let permissions_href = cx.route(role_path(id, "permissions"));
|
||||
Some(
|
||||
Button::anchor(
|
||||
Lc::t("btn-manage-permissions", &LOCALES_USER),
|
||||
|
|
@ -253,7 +236,7 @@ async fn actions_cell(
|
|||
let (edit_button, delete_button) = if locked {
|
||||
(None, None)
|
||||
} else {
|
||||
let edit_href = waypoint.append_to(cx.route(role_path(id, "edit")));
|
||||
let edit_href = cx.route(role_path(id, "edit"));
|
||||
let edit_button = Button::anchor(Lc::t("btn-edit", &LOCALES_USER), edit_href)
|
||||
.with_style(button::Style::Solid(Intent::Primary))
|
||||
.with_size(button::Size::Small)
|
||||
|
|
|
|||
|
|
@ -27,8 +27,6 @@ pub(crate) struct UserForm {
|
|||
mode: UserFormMode,
|
||||
error: Option<Lc>,
|
||||
user_id: Option<i32>,
|
||||
/// Listado de origen al que volver tras guardar (orden, búsqueda, página).
|
||||
waypoint: Waypoint,
|
||||
username: String,
|
||||
email: String,
|
||||
display_name: String,
|
||||
|
|
@ -63,7 +61,7 @@ impl Component for UserForm {
|
|||
// El propio usuario cambia su email en otra pantalla, que pide su contraseña y confirma la
|
||||
// nueva dirección antes de aplicarla.
|
||||
let email_readonly = *self.mode() == UserFormMode::Profile;
|
||||
let action = self.waypoint().append_to(cx.route(action));
|
||||
let action = cx.route(action);
|
||||
|
||||
let mut form = Form::new()
|
||||
.with_id(USER_ADMIN_FORM_ID)
|
||||
|
|
@ -168,7 +166,7 @@ impl Component for UserForm {
|
|||
form = form.with_child(profile_form_actions(save, cx));
|
||||
}
|
||||
UserFormMode::New => {
|
||||
let cancel = self.waypoint().or(cx.route(ADMIN_USERS_PATH.as_str()));
|
||||
let cancel = cx.route(ADMIN_USERS_PATH.as_str());
|
||||
form = form.with_child(form_actions(save, cancel));
|
||||
}
|
||||
}
|
||||
|
|
@ -196,11 +194,6 @@ impl UserForm {
|
|||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_waypoint(mut self, waypoint: impl Into<Waypoint>) -> Self {
|
||||
self.waypoint = waypoint.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn with_username(mut self, username: impl Into<String>) -> Self {
|
||||
self.username = username.into();
|
||||
self
|
||||
|
|
|
|||
|
|
@ -47,7 +47,6 @@ impl Component for UserTable {
|
|||
.with_column(Lc::t("col-actions", &LOCALES_USER))
|
||||
.with_empty(Lc::t("empty-users-list", &LOCALES_USER));
|
||||
|
||||
let waypoint = Waypoint::from(self.list_href(cx));
|
||||
let viewer_is_admin = cx
|
||||
.request()
|
||||
.and_then(|r| r.extension::<Account>())
|
||||
|
|
@ -58,16 +57,16 @@ impl Component for UserTable {
|
|||
|
||||
table.alter_row(
|
||||
table::Row::new()
|
||||
.with_cell(username_cell(user, &waypoint))
|
||||
.with_cell(username_cell(user))
|
||||
.with_cell(user.email.as_str())
|
||||
.with_cell(user.display_name.as_deref().unwrap_or("-"))
|
||||
.with_cell(roles_cell(user, cx).await)
|
||||
.with_cell(Lc::t(status_key(status), &LOCALES_USER))
|
||||
.with_cell(actions_cell(user, &waypoint, viewer_is_admin, cx).await),
|
||||
.with_cell(actions_cell(user, viewer_is_admin, cx).await),
|
||||
);
|
||||
}
|
||||
|
||||
let new_href = waypoint.append_to(cx.route(util::join!(ADMIN_USERS_PATH.as_str(), "/new")));
|
||||
let new_href = cx.route(util::join!(ADMIN_USERS_PATH.as_str(), "/new"));
|
||||
|
||||
let mut list = ListView::new()
|
||||
.with_id("user-table-wrapper")
|
||||
|
|
@ -120,21 +119,6 @@ impl UserTable {
|
|||
self
|
||||
}
|
||||
|
||||
// URL del listado con el estado actual (búsqueda, orden, página): es el valor que viaja como
|
||||
// `waypoint` en los enlaces de ver/editar, para poder volver exactamente a este mismo estado.
|
||||
// Se construye con `cx.route()` para que preserve el parámetro `lang` cuando corresponda.
|
||||
fn list_href(&self, cx: &Context) -> String {
|
||||
let mut route = cx.route(ADMIN_USERS_PATH.as_str());
|
||||
if let Some(q) = self.query().filter(|q| !q.is_empty()) {
|
||||
route.alter_param("q", q);
|
||||
}
|
||||
route
|
||||
.alter_param("sort", self.sort().as_str())
|
||||
.alter_param("dir", *self.dir())
|
||||
.alter_param("page", self.page().to_string())
|
||||
.to_string()
|
||||
}
|
||||
|
||||
// Construye la cabecera ordenable de una columna: el enlace ya funciona sin HTMX (navega con
|
||||
// una petición normal); `pagetop_htmx::hx_table::sort_link()` añade aparte los atributos `hx-*`
|
||||
// para que la tabla se actualice sin recargar la página cuando la extensión esté disponible.
|
||||
|
|
@ -167,12 +151,11 @@ impl UserTable {
|
|||
// Construye la celda de usuario: el nombre enlaza a la pantalla de sólo lectura con todos sus
|
||||
// datos y roles. Devuelve un componente `Html` para que el marcado se genere cuando `Table`
|
||||
// renderice la celda, no al construir la fila.
|
||||
fn username_cell(user: &UserListItem, waypoint: &Waypoint) -> Html {
|
||||
fn username_cell(user: &UserListItem) -> Html {
|
||||
let username = user.username.clone();
|
||||
let id = user.id;
|
||||
let waypoint = waypoint.clone();
|
||||
Html::with(move |cx| {
|
||||
let view_href = waypoint.append_to(cx.route(user_path(id, "view")));
|
||||
let view_href = cx.route(user_path(id, "view"));
|
||||
html! {
|
||||
a href=(view_href) { (username.as_str()) }
|
||||
}
|
||||
|
|
@ -183,16 +166,11 @@ fn username_cell(user: &UserListItem, waypoint: &Waypoint) -> Html {
|
|||
// si quien mira no lo es (no puede gestionarla, ver `handlers::admin::users::require_manageable`).
|
||||
// Devuelve un componente `Html` para que el marcado se genere cuando `Table` renderice la celda, no
|
||||
// al construir la fila.
|
||||
async fn actions_cell(
|
||||
user: &UserListItem,
|
||||
waypoint: &Waypoint,
|
||||
viewer_is_admin: bool,
|
||||
cx: &mut Context,
|
||||
) -> Html {
|
||||
async fn actions_cell(user: &UserListItem, viewer_is_admin: bool, cx: &mut Context) -> Html {
|
||||
if user.is_admin && !viewer_is_admin {
|
||||
return Html::default();
|
||||
}
|
||||
let edit_href = waypoint.append_to(cx.route(user_path(user.id, "edit")));
|
||||
let edit_href = cx.route(user_path(user.id, "edit"));
|
||||
|
||||
// El botón se renderiza aquí, no dentro del `Html::with()` de abajo: necesita pasar por su
|
||||
// propio ciclo de renderizado (`.render().await`) para que el tema activo lo estilice igual
|
||||
|
|
|
|||
|
|
@ -59,9 +59,13 @@ impl Component for LoginForm {
|
|||
.with_child(
|
||||
form::Checkbox::check()
|
||||
.with_name("remember")
|
||||
.with_label(Lc::t("field-remember-me", &LOCALES_USER)),
|
||||
.with_label(Lc::t("field-remember-me", &LOCALES_USER))
|
||||
.with_help_text(Lc::t("help-remember-me", &LOCALES_USER)),
|
||||
)
|
||||
.with_child(
|
||||
Button::submit(Lc::t("btn-login", &LOCALES_USER))
|
||||
.with_style(button::Style::Solid(Intent::Primary)),
|
||||
)
|
||||
.with_child(Button::submit(Lc::t("btn-login", &LOCALES_USER)))
|
||||
.with_child(links(SETTINGS.allow_registration));
|
||||
|
||||
if strict {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,10 @@ impl Component for PasswordResetConfirmForm {
|
|||
PasswordConfirm::new()
|
||||
.with_password_label(Lc::t("field-new-password", &LOCALES_USER)),
|
||||
)
|
||||
.with_child(Button::submit(Lc::t("btn-set-password", &LOCALES_USER)));
|
||||
.with_child(
|
||||
Button::submit(Lc::t("btn-set-password", &LOCALES_USER))
|
||||
.with_style(button::Style::Solid(Intent::Primary)),
|
||||
);
|
||||
|
||||
Ok(form.render(cx).await)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,10 @@ impl Component for PasswordResetForm {
|
|||
.with_autofocus(true)
|
||||
.with_required(true),
|
||||
)
|
||||
.with_child(Button::submit(Lc::t("btn-send-reset-link", &LOCALES_USER)))
|
||||
.with_child(
|
||||
Button::submit(Lc::t("btn-send-reset-link", &LOCALES_USER))
|
||||
.with_style(button::Style::Solid(Intent::Primary)),
|
||||
)
|
||||
.with_child(back_to_login());
|
||||
|
||||
Ok(form.render(cx).await)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,10 @@ impl Component for RegisterForm {
|
|||
.with_required(true),
|
||||
)
|
||||
.with_child(PasswordConfirm::new())
|
||||
.with_child(Button::submit(Lc::t("btn-register", &LOCALES_USER)));
|
||||
.with_child(
|
||||
Button::submit(Lc::t("btn-register", &LOCALES_USER))
|
||||
.with_style(button::Style::Solid(Intent::Primary)),
|
||||
);
|
||||
|
||||
Ok(form.render(cx).await)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue