♻️ (user): Unifica la tabla de datos del perfil
«Mi cuenta» y la ficha de administración muestran los datos del usuario con la misma función, user_details(), en lugar de dos copias idénticas.
This commit is contained in:
parent
e238db1a1b
commit
31f4c516e4
3 changed files with 90 additions and 164 deletions
|
|
@ -23,6 +23,10 @@ pub use user_name::UserName;
|
|||
use pagetop::prelude::*;
|
||||
|
||||
use crate::LOCALES_USER;
|
||||
use crate::account::UserStatus;
|
||||
use crate::component::admin::status_key;
|
||||
use crate::config::{user_language_applies, user_timezone_applies};
|
||||
use crate::entity::user;
|
||||
|
||||
// Texto libre de varias líneas como contenido seguro: cada salto de línea se convierte en `<br>`,
|
||||
// sin depender del CSS del tema. Se usa para mostrar el "Sobre mí" del usuario.
|
||||
|
|
@ -80,3 +84,82 @@ pub(crate) fn error_banner(error: Option<Lc>) -> Html {
|
|||
None => html! {},
|
||||
})
|
||||
}
|
||||
|
||||
// Bloque de sólo lectura con los datos de perfil de un usuario, para «Mi cuenta» y para la ficha de
|
||||
// administración.
|
||||
pub(crate) async fn user_details(user: &user::Model, cx: &mut Context) -> Block {
|
||||
let status = UserStatus::from_i16(user.status);
|
||||
let mut table = Table::new()
|
||||
.with_prop(PropsOp::add_classes("user-admin-table"))
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-username-admin", &LOCALES_USER))
|
||||
.with_cell(user.username.as_str()),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-email", &LOCALES_USER))
|
||||
.with_cell(user.email.as_str()),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-display-name", &LOCALES_USER))
|
||||
.with_cell(user.display_name.as_deref().unwrap_or("-")),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-about", &LOCALES_USER))
|
||||
.with_cell(multiline_text(
|
||||
user.about.clone().unwrap_or_else(|| "-".into()),
|
||||
)),
|
||||
);
|
||||
// Sólo se muestran si se aplican, igual que en el formulario de edición.
|
||||
if user_language_applies() {
|
||||
table = table.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-language", &LOCALES_USER))
|
||||
.with_cell(language_name(user.language.as_deref())),
|
||||
);
|
||||
}
|
||||
if user_timezone_applies() {
|
||||
table = table.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-timezone", &LOCALES_USER))
|
||||
.with_cell(user.timezone.as_deref().unwrap_or("-")),
|
||||
);
|
||||
}
|
||||
table = table
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-theme", &LOCALES_USER))
|
||||
.with_cell(theme_name(user.theme.as_deref())),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("col-status", &LOCALES_USER))
|
||||
.with_cell(Lc::t(status_key(status), &LOCALES_USER)),
|
||||
)
|
||||
.with_row(
|
||||
table::Row::new()
|
||||
.with_cell(Lc::t("field-member-since", &LOCALES_USER))
|
||||
.with_cell(cx.format_date(
|
||||
user.created_at.with_timezone(&cx.timezone()).date_naive(),
|
||||
DateFormat::Long,
|
||||
)),
|
||||
);
|
||||
|
||||
if user.is_admin {
|
||||
let badge = Badge::severe(Lc::t("badge-admin", &LOCALES_USER))
|
||||
.render(cx)
|
||||
.await;
|
||||
table = table.with_row(
|
||||
table::Row::new()
|
||||
.with_cell("")
|
||||
.with_cell(Html::with(move |_| badge.clone())),
|
||||
);
|
||||
}
|
||||
|
||||
Block::new()
|
||||
.with_title(Lc::t("title-user-details", &LOCALES_USER))
|
||||
.with_child(table)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue