♻️ Migra #[builder_fn] a #[builder_impl]
Sustituye las ~400 anotaciones `#[builder_fn]` método a método por un único `#[builder_impl]` por `impl`/`trait`, en 74 ficheros de pagetop y sus extensiones (admin, bootsier, menu, user).
This commit is contained in:
parent
c34dc02357
commit
1be3d88888
74 changed files with 104 additions and 394 deletions
|
|
@ -68,16 +68,15 @@ impl Component for AdminFrame {
|
|||
}
|
||||
}
|
||||
|
||||
#[builder_impl]
|
||||
impl AdminFrame {
|
||||
/// Establece el título de la página.
|
||||
#[builder_fn]
|
||||
pub fn with_title(mut self, title: Lc) -> Self {
|
||||
self.title = title;
|
||||
self
|
||||
}
|
||||
|
||||
/// Añade un componente hijo al contenido de la página.
|
||||
#[builder_fn]
|
||||
pub fn with_child(mut self, op: impl Into<ChildOp>) -> Self {
|
||||
self.children.alter_child(op.into());
|
||||
self
|
||||
|
|
|
|||
|
|
@ -201,8 +201,10 @@ impl Component for ConfigForm {
|
|||
}
|
||||
}
|
||||
|
||||
#[builder_impl]
|
||||
impl ConfigForm {
|
||||
/// Crea el componente con el [`SettingsSchema`] dado.
|
||||
#[builder_skip]
|
||||
pub fn with_schema(schema: SettingsSchema) -> Self {
|
||||
ConfigForm {
|
||||
schema: Some(schema),
|
||||
|
|
@ -210,7 +212,6 @@ impl ConfigForm {
|
|||
}
|
||||
}
|
||||
|
||||
#[builder_fn]
|
||||
pub fn with_action_path(mut self, v: impl Into<Option<Route>>) -> Self {
|
||||
if let Some(v) = v.into() {
|
||||
self.action_path = Some(v);
|
||||
|
|
@ -218,6 +219,7 @@ impl ConfigForm {
|
|||
self
|
||||
}
|
||||
|
||||
#[builder_skip]
|
||||
pub(crate) fn with_saved(mut self, saved: bool, error: bool) -> Self {
|
||||
self.saved = saved;
|
||||
self.error = error;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
//! Proporciona una API async para leer y escribir valores JSON en la tabla `settings`.
|
||||
|
||||
use pagetop::datetime::Utc;
|
||||
use pagetop::{Getters, builder_fn};
|
||||
use pagetop::{Getters, builder_impl};
|
||||
use pagetop_seaorm::db::{
|
||||
ActiveModelTrait, ActiveValue, ColumnTrait, EntityTrait, QueryFilter, dbconn,
|
||||
};
|
||||
|
|
@ -128,6 +128,7 @@ pub struct SettingField {
|
|||
default_value: Option<String>,
|
||||
}
|
||||
|
||||
#[builder_impl]
|
||||
impl SettingField {
|
||||
/// Crea un campo de texto con nombre y etiqueta.
|
||||
pub fn text(name: impl Into<String>, label: impl Into<String>) -> Self {
|
||||
|
|
@ -185,21 +186,18 @@ impl SettingField {
|
|||
}
|
||||
|
||||
/// Establece si el campo es obligatorio.
|
||||
#[builder_fn]
|
||||
pub fn with_required(mut self, required: bool) -> Self {
|
||||
self.required = required;
|
||||
self
|
||||
}
|
||||
|
||||
/// Añade texto de ayuda bajo el campo.
|
||||
#[builder_fn]
|
||||
pub fn with_help(mut self, text: impl Into<String>) -> Self {
|
||||
self.help_text = Some(text.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Establece el valor por defecto (como valor JSON serializado).
|
||||
#[builder_fn]
|
||||
pub fn with_default<T: Serialize>(mut self, value: &T) -> Self {
|
||||
self.default_value = serde_json::to_string(value).ok();
|
||||
self
|
||||
|
|
@ -215,6 +213,7 @@ pub struct SettingsSchema {
|
|||
fields: Vec<SettingField>,
|
||||
}
|
||||
|
||||
#[builder_impl]
|
||||
impl SettingsSchema {
|
||||
/// Crea un nuevo esquema vacío para el `scope` dado.
|
||||
pub fn new(scope: impl Into<String>) -> Self {
|
||||
|
|
@ -225,7 +224,6 @@ impl SettingsSchema {
|
|||
}
|
||||
|
||||
/// Añade un campo al esquema.
|
||||
#[builder_fn]
|
||||
pub fn with_field(mut self, field: SettingField) -> Self {
|
||||
self.fields.push(field);
|
||||
self
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue