♻️ Major code restructuring

This commit is contained in:
Manuel Cillero 2024-02-09 14:05:38 +01:00
parent a96e203bb3
commit fa66d628a0
221 changed files with 228 additions and 315 deletions

View file

@ -0,0 +1,18 @@
[package]
name = "pagetop-admin"
version = "0.0.16"
edition = "2021"
authors = [
"Manuel Cillero <manuel@cillero.es>"
]
description = """\
Module for PageTop that provides a common place for other modules to handle general site \
settings for administrators.\
"""
homepage = "https://pagetop.cillero.es"
repository = "https://github.com/manuelcillero/pagetop"
license = "MIT OR Apache-2.0"
[dependencies]
pagetop = { version = "0.0", path = "../../" }

View file

@ -0,0 +1,27 @@
Módulo para **PageTop** que proporciona a otros módulos un lugar común donde presentar a los
administradores sus opciones de configuración.
[PageTop](https://github.com/manuelcillero/pagetop/tree/main/pagetop), es un entorno de desarrollo
basado en algunos de los *crates* más estables y populares del ecosistema Rust para proporcionar
APIs, patrones de desarrollo y buenas prácticas para la creación de soluciones web SSR (*Server-Side
Rendering*).
# 🚧 Advertencia
**PageTop** sólo libera actualmente versiones de desarrollo. La API no es estable y los cambios son
constantes. No puede considerarse preparado hasta que se libere la versión **0.1.0**.
# 📜 Licencia
Este proyecto tiene licencia, de hecho tiene dos, puedes aplicar cualquiera de las siguientes a tu
elección:
* Licencia Apache versión 2.0
([LICENSE-APACHE](https://github.com/manuelcillero/pagetop/blob/main/LICENSE-APACHE) o
[http://www.apache.org/licenses/LICENSE-2.0]).
* Licencia MIT
([LICENSE-MIT](https://github.com/manuelcillero/pagetop/blob/main/LICENSE-MIT) o
[http://opensource.org/licenses/MIT]).

View file

@ -0,0 +1,40 @@
use pagetop::prelude::*;
static_locales!(LOCALES_ADMIN);
mod summary;
#[derive(AssignHandle)]
pub struct Admin;
impl PackageTrait for Admin {
fn name(&self) -> L10n {
L10n::t("package_name", &LOCALES_ADMIN)
}
fn description(&self) -> L10n {
L10n::t("package_description", &LOCALES_ADMIN)
}
fn actions(&self) -> Vec<Action> {
actions![
action::page::BeforePrepareBody::new(before_prepare_body),
action::component::BeforePrepareComponent::<Menu>::new(before_prepare_menu)
.filter_by_referer_id("admin-menu-test"),
]
}
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
scfg.service(
service::web::scope("/admin").route("", service::web::get().to(summary::summary)),
);
}
}
fn before_prepare_body(page: &mut Page) {
page.alter_body_classes(ClassesOp::Add, "test-admin");
}
fn before_prepare_menu(component: &mut Menu, _cx: &mut Context) {
component.alter_id("admin-menu-test-altered");
}

View file

@ -0,0 +1,2 @@
package_name = Admin module
package_description = Administration module.

View file

@ -0,0 +1,2 @@
package_name = Admin module
package_description = Módulo de administración.

View file

@ -0,0 +1,170 @@
use crate::LOCALES_ADMIN;
use pagetop::prelude::*;
pub async fn summary(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
let top_menu = Menu::new()
.with_id("admin-menu-test")
.add_item(menu::Item::label(L10n::t("package_name", &LOCALES_ADMIN)))
.add_item(menu::Item::label(L10n::n("Ejemplo \"Label\"")))
.add_item(menu::Item::link(L10n::n("Ejemplo \"Link\""), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(
L10n::n("Ejemplo \"LinkBlank\""),
|_| "https://www.google.es",
))
.add_item(menu::Item::submenu(
L10n::n("Ejemplo Submenú"),
menu::Submenu::new()
.with_title(L10n::n("Título submenú"))
.add_item(menu::Item::link(L10n::n("Opción \"Link\""), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(
L10n::n("Opción \"LinkBlank\""),
|_| "https://www.google.es",
))
.add_item(menu::Item::submenu(
L10n::n("Otro submenú con un texto muy, pero que muy largo"),
menu::Submenu::new()
.add_item(menu::Item::label(L10n::n("Opción \"Label\"")))
.add_item(menu::Item::link(L10n::n("Opción \"Link\""), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(
L10n::n("Opción \"LinkBlank\""),
|_| "https://www.google.es",
))
.add_item(menu::Item::label(L10n::n("Opción \"Label\""))),
))
.add_item(menu::Item::label(L10n::n("Opción \"Label\""))),
))
.add_item(menu::Item::megamenu(
L10n::n("Ejemplo Megamenú 1"),
menu::Megamenu::new()
.add_group(
menu::Group::new()
.add_element(menu::Element::submenu(
menu::Submenu::new()
.with_title(L10n::n("Título submenú"))
.add_item(menu::Item::label(L10n::n("Opción \"Label\"")))
.add_item(menu::Item::link(L10n::n("Opción \"Link\""), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(
L10n::n("Opción \"LinkBlank\""),
|_| "https://www.google.es",
)),
))
.add_element(menu::Element::submenu(
menu::Submenu::new()
.with_title(L10n::n("Título submenú"))
.add_item(menu::Item::label(L10n::n("Opción \"Label\"")))
.add_item(menu::Item::link(L10n::n("Opción \"Link\""), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(
L10n::n("Opción \"LinkBlank\""),
|_| "https://www.google.es",
)),
)),
)
.add_group(
menu::Group::new().add_element(menu::Element::submenu(
menu::Submenu::new()
.add_item(menu::Item::label(L10n::n("Opción \"Label\"")))
.add_item(menu::Item::link(L10n::n("Opción \"Link\""), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(
L10n::n("Opción \"LinkBlank\""),
|_| "https://www.google.es",
))
.add_item(menu::Item::label(L10n::n("Opción \"Label\""))),
)),
)
.add_group(
menu::Group::new()
.add_element(menu::Element::submenu(
menu::Submenu::new()
.with_title(L10n::n("Título submenú"))
.add_item(menu::Item::label(L10n::n("Opción \"Label\"")))
.add_item(menu::Item::link(L10n::n("Opción \"Link\""), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(
L10n::n("Opción \"LinkBlank\""),
|_| "https://www.google.es",
)),
))
.add_element(menu::Element::submenu(
menu::Submenu::new()
.with_title(L10n::n("Título submenú"))
.add_item(menu::Item::label(L10n::n("Opción \"Label\"")))
.add_item(menu::Item::link(L10n::n("Opción \"Link\""), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(
L10n::n("Opción \"LinkBlank\""),
|_| "https://www.google.es",
)),
)),
)
.add_group(
menu::Group::new().add_element(menu::Element::submenu(
menu::Submenu::new()
.add_item(menu::Item::label(L10n::n("Opción \"Label\"")))
.add_item(menu::Item::link(L10n::n("Opción \"Link\""), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(
L10n::n("Opción \"LinkBlank\""),
|_| "https://www.google.es",
))
.add_item(menu::Item::label(L10n::n("Opción \"Label\""))),
)),
),
));
let side_menu = Menu::new()
.add_item(menu::Item::label(L10n::n("Opción 1")))
.add_item(menu::Item::link(L10n::n("Opción 2"), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::link_blank(L10n::n("Opción 3"), |_| {
"https://www.google.es"
}))
.add_item(menu::Item::submenu(
L10n::n("Submenú 1"),
menu::Submenu::new()
.add_item(menu::Item::label(L10n::n("Opción 1")))
.add_item(menu::Item::label(L10n::n("Opción 2"))),
)) /*
.add_item(menu::Item::separator()) */
.add_item(menu::Item::submenu(
L10n::n("Submenú 2"),
menu::Submenu::new()
.add_item(menu::Item::label(L10n::n("Opción 1")))
.add_item(menu::Item::label(L10n::n("Opción 2"))),
))
.add_item(menu::Item::label(L10n::n("Opción 4")));
Page::new(request)
//.with_context(ContextOp::Theme("Bootsier"))
.with_title(L10n::n("Admin"))
.with_component_in("top-menu", side_menu)
.with_component_in(
"content",
flex::Container::new()
.add_item(flex::Item::new().add_component(Html::with(html! {
p { "Columna 1"}
})))
.add_item(flex::Item::new().add_component(top_menu))
.add_item(flex::Item::new().add_component(Html::with(html! {
p { "Columna 3"}
}))),
)
.with_template("admin")
.render()
}