fix cargo macro version

This commit is contained in:
Manuel Gugger 2023-01-17 12:08:24 +01:00
parent fd8b456733
commit 089670b619
12 changed files with 27 additions and 136 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "docs/themes/hugo-book"]
path = docs/themes/hugo-book
url = https://github.com/alex-shpak/hugo-book

View File

@ -1,24 +0,0 @@
---
layout: default
---
<style type="text/css" media="screen">
.container {
margin: 10px auto;
max-width: 600px;
text-align: center;
}
h1 {
margin: 30px 0;
font-size: 4em;
line-height: 1;
letter-spacing: -1px;
}
</style>
<div class="container">
<h1>404</h1>
<p><strong>Page not found :(</strong></p>
<p>The requested page could not be found.</p>
</div>

View File

@ -1,4 +0,0 @@
title: "Actix-Admin"
remote_theme: just-the-docs/just-the-docs
color_scheme: "dark"
search_enabled: false

View File

@ -0,0 +1,6 @@
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---

4
docs/config.toml Normal file
View File

@ -0,0 +1,4 @@
baseURL = 'https://mgugger.github.io/actix-admin/'
languageCode = 'en-us'
title = 'Actix-Admin'
theme = "hugo-book"

View File

@ -0,0 +1,7 @@
---
title: "Getting Started"
date: 2023-01-17T11:44:56+01:00
draft: false
---
# Getting Started

View File

@ -1,101 +0,0 @@
---
layout: default
---
## Getting Started
* See the [basic example](https://github.com/mgugger/actix-admin/tree/main/examples/basic) and run with ```cargo run```.
## Quick overview
### Required dependencies in Cargo.toml
```
sea-orm = { version = "^0.9.1", features = [ "sqlx-sqlite", "runtime-actix-native-tls", "macros" ], default-features = true }
actix_admin = { version = "^0.2.0" }
```
### Steps
1. Import ActixAdmin in the main.rs and your database models:
```rust
use actix_admin::prelude::*;
```
2. Use the DeriveActixAdminMacros on the Database models to implement required traits:
```rust
#[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
}
```
3. Add ActixAdmin to the actix admin app state
```rust
#[derive(Clone)]
pub struct AppState {
pub db: DatabaseConnection,
pub actix_admin: ActixAdmin,
}
```
4. Implement the ActixAdminAppDataTrait for the AppState
```rust
impl ActixAdminAppDataTrait for AppState {
fn get_db(&self) -> &DatabaseConnection {
&self.db
}
fn get_actix_admin(&self) -> &ActixAdmin {
&self.actix_admin
}
}
```
5. Setup the actix admin configuration and add database models to it in main.rs
```rust
pub fn create_actix_admin_builder() -> ActixAdminBuilder {
let comment_view_model = ActixAdminViewModel::from(Entity);
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, Entity>(&comment_view_model);
admin_builder
}
```
6. Add to the actix app in main.rs
```rust
let opt = ConnectOptions::new("sqlite::memory:".to_owned());
let conn = sea_orm::Database::connect(opt).unwrap();
HttpServer::new(move || {
let actix_admin_builder = create_actix_admin_builder();
let app_state = AppState {
db: conn.clone(),
actix_admin: actix_admin_builder.get_actix_admin(),
};
App::new()
.app_data(web::Data::new(app_state.clone()))
.service(
actix_admin_builder.get_scope::<AppState>()
)
});
```
## Access
The admin interface will be available under /admin/.

View File

@ -1,6 +1,7 @@
---
layout: default
list_title: ' '
title: ""
date: 2023-01-17T11:44:56+01:00
draft: false
---
The actix-admin crate aims at creating a web admin interface similar to other admin interfaces (such as [flask-admin](https://github.com/flask-admin/flask-admin) in python).
@ -15,8 +16,4 @@ The actix-admin crate aims at creating a web admin interface similar to other ad
## Example
Check the [examples](https://github.com/mgugger/actix-admin/tree/main/examples) and run with ```cargo run```. The admin interface is accessible under ```localhost:5000/admin/```.
## Screenshot
<img src="https://raw.githubusercontent.com/mgugger/actix-admin/main/static/Screenshot.png"/>
Check the [examples](https://github.com/mgugger/actix-admin/tree/main/examples) and run ```cargo run --example basic``` from the root folder for a basic in-memory sqlite version. The admin interface is accessible under ```localhost:5000/admin/```.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
{"Target":"book.min.c58292d36b18b675680ab9baea2029204537b839ea72f258746ec0f32ce8d6c8.css","MediaType":"text/css","Data":{"Integrity":"sha256-xYKS02sYtnVoCrm66iApIEU3uDnqcvJYdG7A8yzo1sg="}}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

1
docs/themes/hugo-book vendored Submodule

@ -0,0 +1 @@
Subproject commit d5b75f4fb3aaa5c2f0209db4933a55aa634d5dfd