♻️ (admin): Construye piezas del panel con new()
AdminSection, AdminPage, AdminTask y AdminAction pasan a campos privados con constructores y pesos Weight.
This commit is contained in:
parent
8e0c887ba6
commit
71ea609088
11 changed files with 616 additions and 445 deletions
|
|
@ -49,9 +49,9 @@ impl Component for AdminFrame {
|
|||
// Sin título propio, la página declarada aporta el suyo, también al `<head>` (que se
|
||||
// renderiza después del `<body>`).
|
||||
if cx.title().is_none()
|
||||
&& let Some(page) = AdminRegistry::global().pages().get(&path)
|
||||
&& let Some(page) = AdminRegistry::global().page(&path)
|
||||
{
|
||||
cx.alter_title(page.title.clone());
|
||||
cx.alter_title(page.title().clone());
|
||||
}
|
||||
|
||||
let breadcrumbs = breadcrumbs(cx, &path).render(cx).await;
|
||||
|
|
@ -89,26 +89,26 @@ fn breadcrumbs(cx: &Context, path: &str) -> Breadcrumb {
|
|||
admin_path(""),
|
||||
));
|
||||
if let Some(page) = registry.nearest_page(path) {
|
||||
if let Some(section) = registry.sections().get(&page.section) {
|
||||
if let Some(section) = registry.section(page.section()) {
|
||||
bc = bc.with_crumb(breadcrumb::Crumb::new(
|
||||
section.title.clone(),
|
||||
admin_path(§ion.path),
|
||||
section.title().clone(),
|
||||
admin_path(section.path()),
|
||||
));
|
||||
}
|
||||
if page.path == path {
|
||||
bc = bc.with_crumb(breadcrumb::Crumb::current(page.title.clone()));
|
||||
if page.path() == path {
|
||||
bc = bc.with_crumb(breadcrumb::Crumb::current(page.title().clone()));
|
||||
} else {
|
||||
bc = bc.with_crumb(breadcrumb::Crumb::new(
|
||||
page.title.clone(),
|
||||
admin_path(&page.path),
|
||||
page.title().clone(),
|
||||
admin_path(page.path()),
|
||||
));
|
||||
if !cx.title().is_none() {
|
||||
bc = bc.with_crumb(breadcrumb::Crumb::current(cx.title().clone()));
|
||||
}
|
||||
}
|
||||
} else if let Some(section) = registry.sections().values().find(|s| s.path == path) {
|
||||
} else if let Some(section) = registry.section_by_path(path) {
|
||||
// La ruta es la propia sección (su página de aterrizaje), no una página declarada en ella.
|
||||
bc = bc.with_crumb(breadcrumb::Crumb::current(section.title.clone()));
|
||||
bc = bc.with_crumb(breadcrumb::Crumb::current(section.title().clone()));
|
||||
}
|
||||
bc
|
||||
}
|
||||
|
|
@ -117,16 +117,11 @@ fn breadcrumbs(cx: &Context, path: &str) -> Breadcrumb {
|
|||
// permiso que el usuario no tiene no se muestran.
|
||||
fn local_tasks(cx: &Context, path: &str) -> Markup {
|
||||
let registry = AdminRegistry::global();
|
||||
let parent = registry
|
||||
.tasks()
|
||||
.values()
|
||||
.flatten()
|
||||
.find(|task| task.path == path)
|
||||
.map_or(path, |task| task.parent_path.as_str());
|
||||
let parent = registry.task(path).map_or(path, |task| task.parent_path());
|
||||
let tasks: Vec<_> = registry
|
||||
.tasks_for(parent)
|
||||
.into_iter()
|
||||
.filter(|task| is_granted(cx, task.permission))
|
||||
.iter()
|
||||
.filter(|task| is_granted(cx, task.permission()))
|
||||
.collect();
|
||||
if tasks.is_empty() {
|
||||
return html! {};
|
||||
|
|
@ -134,8 +129,8 @@ fn local_tasks(cx: &Context, path: &str) -> Markup {
|
|||
html! {
|
||||
ul class="admin-tasks-list" {
|
||||
@for task in tasks {
|
||||
li class="admin-task" .admin-task-active[task.path == path] {
|
||||
a href=(cx.route(admin_path(&task.path))) { (task.title.using(cx)) }
|
||||
li class="admin-task" .admin-task-active[task.path() == path] {
|
||||
a href=(cx.route(admin_path(task.path()))) { (task.title().using(cx)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -147,8 +142,8 @@ fn local_tasks(cx: &Context, path: &str) -> Markup {
|
|||
fn local_actions(cx: &Context, path: &str) -> Markup {
|
||||
let actions: Vec<_> = AdminRegistry::global()
|
||||
.actions_for(path)
|
||||
.into_iter()
|
||||
.filter(|action| is_granted(cx, action.permission))
|
||||
.iter()
|
||||
.filter(|action| is_granted(cx, action.permission()))
|
||||
.collect();
|
||||
if actions.is_empty() {
|
||||
return html! {};
|
||||
|
|
@ -157,8 +152,8 @@ fn local_actions(cx: &Context, path: &str) -> Markup {
|
|||
ul class="admin-actions-list" {
|
||||
@for action in actions {
|
||||
li class="admin-action" {
|
||||
a class="admin-action-link" href=(cx.route(admin_path(&action.url))) {
|
||||
(action.title.using(cx))
|
||||
a class="admin-action-link" href=(cx.route(admin_path(action.url()))) {
|
||||
(action.title().using(cx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,20 +32,20 @@ impl Component for AdminMenu {
|
|||
|
||||
let mut nav =
|
||||
Nav::new().with_item(nav::Item::link(Lc::l("admin_dashboard"), admin_path("")));
|
||||
for section in registry.ordered_sections() {
|
||||
for section in registry.sections() {
|
||||
let pages: Vec<_> = registry
|
||||
.pages_for_section(§ion.key)
|
||||
.into_iter()
|
||||
.pages_for_section(section.key())
|
||||
.iter()
|
||||
.filter(|p| p.is_accessible(cx))
|
||||
.collect();
|
||||
if pages.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let mut menu = Dropdown::new().with_title(section.title.clone());
|
||||
let mut menu = Dropdown::new().with_title(section.title().clone());
|
||||
for page in pages {
|
||||
menu = menu.with_item(dropdown::Item::link(
|
||||
page.title.clone(),
|
||||
admin_path(&page.path),
|
||||
page.title().clone(),
|
||||
admin_path(page.path()),
|
||||
));
|
||||
}
|
||||
nav = nav.with_item(nav::Item::dropdown(menu));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue