add initial crate documentation
This commit is contained in:
parent
420bdbceaf
commit
229a77c88b
@ -5,12 +5,14 @@ use crate::prelude::*;
|
||||
|
||||
use crate::routes::{create_get, create_post, delete, delete_many, edit_get, edit_post, index, list};
|
||||
|
||||
/// Represents a builder entity which helps generating the ActixAdmin configuration
|
||||
pub struct ActixAdminBuilder {
|
||||
pub scopes: HashMap<String, actix_web::Scope>,
|
||||
pub actix_admin: ActixAdmin,
|
||||
pub custom_index: Option<Route>
|
||||
}
|
||||
|
||||
/// The trait to work with ActixAdminBuilder
|
||||
pub trait ActixAdminBuilderTrait {
|
||||
fn new(configuration: ActixAdminConfiguration) -> Self;
|
||||
fn add_entity<T: ActixAdminAppDataTrait + 'static, E: ActixAdminViewModelTrait + 'static>(
|
||||
|
111
src/lib.rs
111
src/lib.rs
@ -1,3 +1,114 @@
|
||||
//! # Actix Admin
|
||||
//!
|
||||
//! The actix-admin crate creates admin interface similar to other admin interfaces (such as flask-admin in python).
|
||||
//!
|
||||
//! ## Getting Started
|
||||
//!
|
||||
//! * See the [example](https://github.com/mgugger/actix-admin/tree/main/example).
|
||||
//! * See the step by [step tutorial](TODO)
|
||||
//!
|
||||
//! ## Features
|
||||
//! 1. Async, builds on [sea-orm](https://crates.io/crates/sea-orm) for the database backend
|
||||
//! 2. Macros, generate the required implementations for models automatically
|
||||
//! 3. Authentication, optionally pass authentication handler to implement authentication for views
|
||||
//! 4. Supports custom validation rules
|
||||
//! 5. Searchable attributes can be specified
|
||||
//! 6. Supports a custom index view
|
||||
//!
|
||||
//! ## Screenshot
|
||||
//!
|
||||
//! ## Quick overview
|
||||
//!
|
||||
//! ### Required dependencies
|
||||
//! ```
|
||||
//! itertools = "0.10.3"
|
||||
//! sea-orm = { version = "^0.9.1", features = [ "sqlx-sqlite", "runtime-actix-native-tls", "macros" ], default-features = true }
|
||||
//! actix_admin = { version = "^0.1.0" }
|
||||
//! ```
|
||||
//!
|
||||
//! ### Derive Macros
|
||||
//! ```
|
||||
//! use sea_orm::entity::prelude::*;
|
||||
//! use serde::{Deserialize, Serialize};
|
||||
//! use actix_admin::prelude::*;
|
||||
//! use super::Post;
|
||||
//!
|
||||
//! // Use DeriveActixAmin* Macros to implement the traits for the model
|
||||
//! #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize,
|
||||
//! DeriveActixAdmin, DeriveActixAdminModel, DeriveActixAdminViewModel
|
||||
//! )]
|
||||
//! #[sea_orm(table_name = "comment")]
|
||||
//! pub struct Model {
|
||||
//! #[sea_orm(primary_key)]
|
||||
//! #[serde(skip_deserializing)]
|
||||
//! #[actix_admin(primary_key)]
|
||||
//! pub id: i32,
|
||||
//! pub comment: String
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! ### Add actix-admin to the AppState
|
||||
//! ```
|
||||
//! pub struct AppState {
|
||||
//! pub db: DatabaseConnection,
|
||||
//! pub actix_admin: ActixAdmin,
|
||||
//! }
|
||||
//!
|
||||
//! impl ActixAdminAppDataTrait for AppState {
|
||||
//! fn get_db(&self) -> &DatabaseConnection {
|
||||
//! &self.db
|
||||
//! }
|
||||
//!
|
||||
//! fn get_actix_admin(&self) -> &ActixAdmin {
|
||||
//! &self.actix_admin
|
||||
//! }
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! ### Actix Admin Builder
|
||||
//! ```
|
||||
//! pub fn create_actix_admin_builder() -> ActixAdminBuilder {
|
||||
//! let comment_view_model = ActixAdminViewModel::from(Comment);
|
||||
//!
|
||||
//! let configuration = ActixAdminConfiguration {
|
||||
//! enable_auth: false,
|
||||
//! user_is_logged_in: None,
|
||||
//! login_link: None,
|
||||
//! logout_link: None,
|
||||
//! };
|
||||
//!
|
||||
//! let mut admin_builder = ActixAdminBuilder::new(configuration);
|
||||
//! admin_builder.add_entity::<AppState, Comment>(&comment_view_model);
|
||||
//!
|
||||
//! admin_builder
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! ### Add to the actix app
|
||||
//! ```
|
||||
//! let actix_admin = create_actix_admin_builder().get_actix_admin();
|
||||
//!
|
||||
//! let app_state = AppState {
|
||||
//! db: conn,
|
||||
//! actix_admin: actix_admin,
|
||||
//! };
|
||||
//!
|
||||
//! HttpServer::new(move || {
|
||||
//! App::new()
|
||||
//! .app_data(web::Data::new(app_state.clone()))
|
||||
//! .wrap(SessionMiddleware::new(CookieSessionStore::default(), cookie_secret_key.clone()))
|
||||
//! .route("/", web::get().to(index))
|
||||
//! .service(azure_auth.clone().create_scope::<AppState>())
|
||||
//! .service(
|
||||
//! create_actix_admin_builder().get_scope::<AppState>()
|
||||
//! )
|
||||
//! .wrap(middleware::Logger::default())
|
||||
//! })
|
||||
//! ```
|
||||
//!
|
||||
//! ### Access
|
||||
//! The admin interface will be available under /admin/.
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use sea_orm::DatabaseConnection;
|
||||
use std::collections::HashMap;
|
||||
|
BIN
static/Screenshot.png
Normal file
BIN
static/Screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 62 KiB |
@ -3,7 +3,9 @@ use serde::{Deserialize, Serialize};
|
||||
use actix_admin::prelude::*;
|
||||
use super::Post;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize, DeriveActixAdmin, DeriveActixAdminModel, DeriveActixAdminViewModel)]
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize,
|
||||
DeriveActixAdmin, DeriveActixAdminModel, DeriveActixAdminViewModel
|
||||
)]
|
||||
#[sea_orm(table_name = "comment")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
|
Loading…
Reference in New Issue
Block a user