♻️ Major code restructuring
This commit is contained in:
parent
a96e203bb3
commit
fa66d628a0
221 changed files with 228 additions and 315 deletions
44
packages/pagetop-node/src/lib.rs
Normal file
44
packages/pagetop-node/src/lib.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
static_locales!(LOCALES_NODE);
|
||||
|
||||
//mod entity;
|
||||
mod migration;
|
||||
|
||||
#[derive(AssignHandle)]
|
||||
pub struct Node;
|
||||
|
||||
impl PackageTrait for Node {
|
||||
fn name(&self) -> L10n {
|
||||
L10n::t("package_name", &LOCALES_NODE)
|
||||
}
|
||||
|
||||
fn description(&self) -> L10n {
|
||||
L10n::t("package_description", &LOCALES_NODE)
|
||||
}
|
||||
|
||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||
scfg.route("/node", service::web::get().to(node));
|
||||
}
|
||||
|
||||
fn actions(&self) -> Vec<Action> {
|
||||
actions![action::page::BeforePrepareBody::new(before_prepare_body).with_weight(-1)]
|
||||
}
|
||||
|
||||
fn migrations(&self) -> Vec<MigrationItem> {
|
||||
migrations![
|
||||
m20220316_000001_create_table_node_type,
|
||||
m20220316_000002_create_table_node,
|
||||
m20220316_000003_create_table_node_access,
|
||||
m20220316_000004_create_table_node_revision,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
async fn node(request: service::HttpRequest) -> ResultPage<Markup, ErrorPage> {
|
||||
Page::new(request).with_title(L10n::n("Nodo")).render()
|
||||
}
|
||||
|
||||
fn before_prepare_body(page: &mut Page) {
|
||||
page.alter_body_classes(ClassesOp::Add, "test-node");
|
||||
}
|
||||
2
packages/pagetop-node/src/locale/en-US/homepage.ftl
Normal file
2
packages/pagetop-node/src/locale/en-US/homepage.ftl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
package_name = Node
|
||||
package_description = Allows content to be submitted to the site and displayed on pages.
|
||||
2
packages/pagetop-node/src/locale/es-ES/homepage.ftl
Normal file
2
packages/pagetop-node/src/locale/es-ES/homepage.ftl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
package_name = Nodo
|
||||
package_description = Permite enviar contenidos al sitio y mostrarlos en páginas.
|
||||
4
packages/pagetop-node/src/migration.rs
Normal file
4
packages/pagetop-node/src/migration.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
pub mod m20220316_000001_create_table_node_type;
|
||||
pub mod m20220316_000002_create_table_node;
|
||||
pub mod m20220316_000003_create_table_node_access;
|
||||
pub mod m20220316_000004_create_table_node_revision;
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[derive(Iden)]
|
||||
enum NodeType {
|
||||
Table, // node_type: Stores information about all defined Node types.
|
||||
|
||||
Type, // The machine-readable name of this type.
|
||||
Name, // The human-readable name of this type.
|
||||
Description, // Descripción breve del tipo.
|
||||
Help, // Help information shown to the user when creating a Node of this type.
|
||||
HasTitle, // Boolean indicating whether this type uses the Node.Title field.
|
||||
TitleLabel, // The label displayed for the title field on the edit form.
|
||||
Custom, // A boolean indicating whether this type is defined by a module (FALSE) or
|
||||
// by a user via Add content type (TRUE).
|
||||
Locked, // A boolean indicating whether the administrator can change the machine
|
||||
// name of this type.
|
||||
Disabled, // A boolean indicating whether the node type is disabled.
|
||||
OrigType, // The original machine-readable name of this node type, this may be
|
||||
// different from the current type name if the locked field is 0.
|
||||
}
|
||||
|
||||
new_migration!(Migration);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(NodeType::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(NodeType::Type)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(NodeType::Name).string().not_null())
|
||||
.col(ColumnDef::new(NodeType::Description).string().not_null())
|
||||
.col(ColumnDef::new(NodeType::Help).string().not_null())
|
||||
.col(ColumnDef::new(NodeType::HasTitle).string().not_null())
|
||||
.col(ColumnDef::new(NodeType::TitleLabel).string().not_null())
|
||||
.col(ColumnDef::new(NodeType::Custom).string().not_null())
|
||||
.col(ColumnDef::new(NodeType::Locked).string().not_null())
|
||||
.col(ColumnDef::new(NodeType::Disabled).string().not_null())
|
||||
.col(ColumnDef::new(NodeType::OrigType).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(NodeType::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[derive(Iden)]
|
||||
enum Node {
|
||||
Table, // node: The base table for nodes.
|
||||
|
||||
Nid, // The primary identifier for a node.
|
||||
Vid, // The current NodeRevision.vid version identifier.
|
||||
Type, // The NodeType.type of this node.
|
||||
Language, // The {languages}.language of this node.
|
||||
Title, // The title of this node, always treated as non-markup plain text.
|
||||
Uid, // The User.uid that owns this node; initially, this is the user that
|
||||
// created it.
|
||||
Status, // Boolean indicating whether the node is published (visible to
|
||||
// non-administrators).
|
||||
Created, // The Unix timestamp when the node was created.
|
||||
Changed, // The Unix timestamp when the node was most recently saved.
|
||||
Comment, // Whether comments are allowed on this node: 0 = no, 1 = closed (read
|
||||
// only), 2 = open (read/write).
|
||||
Promote, // Boolean indicating whether the node should be displayed on the front
|
||||
// page.
|
||||
Sticky, // Boolean indicating whether the node should be displayed at the top of
|
||||
// lists in which it appears.
|
||||
Tnid, // The translation set id for this node, which equals the node id of the
|
||||
// source post in each set.
|
||||
Translate, // A boolean indicating whether this translation page needs to be updated.
|
||||
}
|
||||
|
||||
new_migration!(Migration);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Node::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Node::Nid)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Node::Vid).string().not_null())
|
||||
.col(ColumnDef::new(Node::Type).string().not_null())
|
||||
.col(ColumnDef::new(Node::Language).string().not_null())
|
||||
.col(ColumnDef::new(Node::Title).string().not_null())
|
||||
.col(ColumnDef::new(Node::Uid).string().not_null())
|
||||
.col(ColumnDef::new(Node::Status).string().not_null())
|
||||
.col(ColumnDef::new(Node::Created).string().not_null())
|
||||
.col(ColumnDef::new(Node::Changed).string().not_null())
|
||||
.col(ColumnDef::new(Node::Comment).string().not_null())
|
||||
.col(ColumnDef::new(Node::Promote).string().not_null())
|
||||
.col(ColumnDef::new(Node::Sticky).string().not_null())
|
||||
.col(ColumnDef::new(Node::Tnid).string().not_null())
|
||||
.col(ColumnDef::new(Node::Translate).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Node::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[derive(Iden)]
|
||||
enum NodeAccess {
|
||||
Table, // node_access: Identifies which realm/grant pairs a user must possess in
|
||||
// order to view, update, or delete specific nodes.
|
||||
|
||||
Nid, // The Node.nid this record affects.
|
||||
Gid, // The grant ID a user must possess in the specified realm to gain this
|
||||
// row's privileges on the node.
|
||||
Realm, // The realm in which the user must possess the grant ID. Each node access
|
||||
// node can define one or more realms.
|
||||
GrantView, // Boolean indicating whether a user with the realm/grant pair can view this
|
||||
// node.
|
||||
GrantUpdate, // Boolean indicating whether a user with the realm/grant pair can edit this
|
||||
// node.
|
||||
GrantDelete, // Boolean indicating whether a user with the realm/grant pair can delete
|
||||
// this node.
|
||||
}
|
||||
|
||||
new_migration!(Migration);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(NodeAccess::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(NodeAccess::Nid)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(NodeAccess::Gid).string().not_null())
|
||||
.col(ColumnDef::new(NodeAccess::Realm).string().not_null())
|
||||
.col(ColumnDef::new(NodeAccess::GrantView).string().not_null())
|
||||
.col(ColumnDef::new(NodeAccess::GrantUpdate).string().not_null())
|
||||
.col(ColumnDef::new(NodeAccess::GrantDelete).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(NodeAccess::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
use pagetop::prelude::*;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[derive(Iden)]
|
||||
enum NodeRevision {
|
||||
Table, // node_revision: Stores information about each saved version of a Node.
|
||||
|
||||
Nid, // The Node this version belongs to.
|
||||
Vid, // The primary identifier for this version.
|
||||
Uid, // The User.uid that created this version.
|
||||
Title, // The title of this version.
|
||||
Log, // The log entry explaining the changes in this version.
|
||||
Timestamp, // A Unix timestamp indicating when this version was created.
|
||||
Status, // Boolean indicating whether the node (at the time of this revision) is
|
||||
// published (visible to non-administrators).
|
||||
Comment, // Whether comments are allowed on this node (at the time of this revision):
|
||||
// 0 = no, 1 = closed (read only), 2 = open (read/write).
|
||||
Promote, // Boolean indicating whether the node (at the time of this revision) should
|
||||
// be displayed on the front page.
|
||||
Sticky, // Boolean indicating whether the node (at the time of this revision) should
|
||||
// be displayed at the top of lists in which it appears.
|
||||
}
|
||||
|
||||
new_migration!(Migration);
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(NodeRevision::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(NodeRevision::Nid)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(NodeRevision::Vid).string().not_null())
|
||||
.col(ColumnDef::new(NodeRevision::Uid).string().not_null())
|
||||
.col(ColumnDef::new(NodeRevision::Title).string().not_null())
|
||||
.col(ColumnDef::new(NodeRevision::Log).string().not_null())
|
||||
.col(ColumnDef::new(NodeRevision::Timestamp).string().not_null())
|
||||
.col(ColumnDef::new(NodeRevision::Status).string().not_null())
|
||||
.col(ColumnDef::new(NodeRevision::Comment).string().not_null())
|
||||
.col(ColumnDef::new(NodeRevision::Promote).string().not_null())
|
||||
.col(ColumnDef::new(NodeRevision::Sticky).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(NodeRevision::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue