✨ (menu): Añade extensión pagetop-menu
Gestión centralizada y persistente de menús: entidades y migraciones SeaORM, sistema de acciones para declarar menús/ítems por código, caché in-process del árbol y los componentes `MenuBlock`/`MenuBreadcrumb`.
This commit is contained in:
parent
88acc08b5f
commit
043873a954
25 changed files with 1963 additions and 2 deletions
37
extensions/pagetop-menu/src/entity/menu.rs
Normal file
37
extensions/pagetop-menu/src/entity/menu.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
use pagetop_seaorm::db::*;
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
#[derive(Clone, Debug, DeriveEntityModel, PartialEq)]
|
||||
#[sea_orm(table_name = "menus")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
#[sea_orm(unique)]
|
||||
pub machine_name: String,
|
||||
pub locked: bool,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, DeriveRelation, EnumIter)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::menu_translation::Entity")]
|
||||
MenuTranslations,
|
||||
#[sea_orm(has_many = "super::menu_item::Entity")]
|
||||
MenuItems,
|
||||
}
|
||||
|
||||
impl Related<super::menu_translation::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::MenuTranslations.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::menu_item::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::MenuItems.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
47
extensions/pagetop-menu/src/entity/menu_item.rs
Normal file
47
extensions/pagetop-menu/src/entity/menu_item.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
use pagetop_seaorm::db::*;
|
||||
|
||||
use chrono::NaiveDateTime;
|
||||
|
||||
#[derive(Clone, Debug, DeriveEntityModel, PartialEq)]
|
||||
#[sea_orm(table_name = "menu_items")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub menu_id: i32,
|
||||
pub parent_id: Option<i32>,
|
||||
pub url: String,
|
||||
pub weight: i32,
|
||||
pub enabled: bool,
|
||||
pub expanded: bool,
|
||||
pub provider: String,
|
||||
pub external_key: Option<String>,
|
||||
pub created_at: NaiveDateTime,
|
||||
pub updated_at: NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, DeriveRelation, EnumIter)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::menu::Entity",
|
||||
from = "Column::MenuId",
|
||||
to = "super::menu::Column::Id",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Menu,
|
||||
#[sea_orm(has_many = "super::menu_item_translation::Entity")]
|
||||
MenuItemTranslations,
|
||||
}
|
||||
|
||||
impl Related<super::menu::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Menu.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::menu_item_translation::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::MenuItemTranslations.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
30
extensions/pagetop-menu/src/entity/menu_item_translation.rs
Normal file
30
extensions/pagetop-menu/src/entity/menu_item_translation.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
use pagetop_seaorm::db::*;
|
||||
|
||||
#[derive(Clone, Debug, DeriveEntityModel, PartialEq)]
|
||||
#[sea_orm(table_name = "menu_item_translations")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub item_id: i32,
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub lang: String,
|
||||
pub title: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, DeriveRelation, EnumIter)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::menu_item::Entity",
|
||||
from = "Column::ItemId",
|
||||
to = "super::menu_item::Column::Id",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
MenuItem,
|
||||
}
|
||||
|
||||
impl Related<super::menu_item::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::MenuItem.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
31
extensions/pagetop-menu/src/entity/menu_translation.rs
Normal file
31
extensions/pagetop-menu/src/entity/menu_translation.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use pagetop_seaorm::db::*;
|
||||
|
||||
#[derive(Clone, Debug, DeriveEntityModel, PartialEq)]
|
||||
#[sea_orm(table_name = "menu_translations")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub menu_id: i32,
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub lang: String,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, DeriveRelation, EnumIter)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::menu::Entity",
|
||||
from = "Column::MenuId",
|
||||
to = "super::menu::Column::Id",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Menu,
|
||||
}
|
||||
|
||||
impl Related<super::menu::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Menu.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue