Skip to main content

Module admin_generator

Module admin_generator 

Source
Expand description

Config-driven admin model generator.

AdminModelConfig holds the same metadata a hand-written AdminUiModel impl exposes (slug, table, fields, search / status / ensure-table SQL). GeneratedAdminModel then wraps one of these configs and implements AdminUiModel by simply delegating to the stored config — no per-model code path.

The result is that registering a new admin section becomes a single declarative call:

register_generated(
    &mut registry,
    AdminModelConfig::new("orders", "Order")
        .table("admin_new_demo_orders")
        .primary_key("id")
        .fields(vec![
            AdminUiField::text("order_number", "Order #")
                .required(true).filterable(true).sortable(true),
            …
        ])
        .searchable(vec!["order_number", "customer_email"])
        .status_field("is_paid")
        .ensure_sql("CREATE TABLE IF NOT EXISTS …"),
);

All routes (/admin-new/<slug>, search, filters, sort, pagination, bulk actions, row delete, edit drawer) keep working unchanged — they consume &dyn AdminUiModel, and a GeneratedAdminModel satisfies that contract just like any unit-struct impl.

Structs§

AdminModelConfig
Declarative description of an admin section. Cheap to clone — the registry’s factory closure clones one of these on every lookup so each request gets a fresh boxed model.
GeneratedAdminModel
Adapter that turns an AdminModelConfig into an AdminUiModel. Holds the config by value so the registry’s closure can construct one per request without lifetime gymnastics.

Functions§

from_config
Convenience factory matching the registry’s Fn() -> Box<dyn AdminUiModel> shape.