Skip to content

Commit

Permalink
[sea-orm-pro] edit
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Jan 7, 2025
1 parent 5e22183 commit d5530cc
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 264 deletions.
8 changes: 2 additions & 6 deletions sea-orm-pro/docs/01-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@

2. Installation & Configuration

2.1 [Database & Async Runtime](02-install-and-config/01-database.md)
2.1 [Getting Started with Loco](02-install-and-config/01-getting-started-loco.md)

2.2 [Admin Dashboard Frontend](02-install-and-config/02-frontend.md)

2.3 [Getting Started](02-install-and-config/03-getting-started.md)
2.2 [Getting Started with Axum](02-install-and-config/02-getting-started-axum.md)

3. Site Config

Expand Down Expand Up @@ -47,5 +45,3 @@
6. Deployment

6.1 [Nginx](06-deployment/01-nginx.md)

6.2 [User Authentication](06-deployment/02-user-auth.md)
2 changes: 1 addition & 1 deletion sea-orm-pro/docs/01-introduction/01-sea-orm-pro.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# What is SeaORM Pro

SeaORM Pro is an admin dashboard that provides full CRUD interface for your SeaORM entities, includes a GraphQL interface to handles CRUD request.
SeaORM Pro is an admin panel that provides full CRUD interface for your SeaORM entities, includes a GraphQL interface to handles CRUD request.

The source code of the frontend and backend are fully customizable and accessible. The tech stack includes a sleek Ant Design React frontend admin panel, Loco.rs Rust backend server, SeaORM object relational mapper to interact with your relational database and Seaography to extends entity that defines in SeaORM to serve as a GraphQL interface.

Expand Down
60 changes: 0 additions & 60 deletions sea-orm-pro/docs/02-install-and-config/01-database.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Getting Started

## Start with Loco Starter Example
# Getting Started with Loco

We use the [`loco_starter`](https://github.com/SeaQL/sea-orm/tree/master/examples/loco_starter) example as the base, it contains basic REST API to handle basic user management such as user registration, login and user info of current session.

We will extends the SeaORM entities in the example to define a GraphQL schema, handle GraphQL request and serve SeaORM Pro admin dashboard.
## 1. Setup Admin Endpoint

We will extends the SeaORM entities in the example to define a GraphQL schema, handle GraphQL request and serve SeaORM Pro admin panel.

## Download Admin Dashboard Frontend
### 1.1 Download frontend assets

```sh
# Go to the root of `loco_starter` example
Expand All @@ -15,13 +15,13 @@ cd sea-orm/examples/loco_starter
# Create a directory for the static assets
mkdir assets

# Use the `download_frontend.sh` to download SeaORM Pro FREE admin dashboard to `assets/admin` directory
# Use the `download_frontend.sh` to download SeaORM Pro FREE admin panel to `assets/admin` directory
curl "https://raw.githubusercontent.com/SeaQL/sea-orm-pro/refs/heads/main/build_tools/download_frontend.sh" -sSf | sh
```

## Serve Frontend via Static Middleware
### 1.2 Serve frontend via `static` middleware

Open Loco.rs config file, add `static` middlewares. The admin dashboard frontend is located in `/assets/admin` and we want to serve it under `http://localhost:3000/admin`, so we set the path as `assets`. Also, the admin dashboard frontend is a single page application, so we set a fallback route to the index file, `./assets/admin/index.html`.
Open Loco.rs config file, add `static` middlewares. The admin panel frontend is located in `/assets/admin` and we want to serve it under `http://localhost:3000/admin`, so we set the path as `assets`. Also, the admin panel frontend is a single page application, so we set a fallback route to the index file, `./assets/admin/index.html`.

```diff title=loco_starter/config/development.yaml
server:
Expand All @@ -36,7 +36,62 @@ server:
+ fallback: ./assets/admin/index.html
```

## Define GraphQL Schema
### 1.3 Setup admin API endpoint

The admin panel frontend is customizable and it read the configuration from the `api/admin/config` endpoint.

```rust title=loco_starter/src/controllers/admin.rs
use loco_rs::prelude::*;

pub async fn config(State(_ctx): State<AppContext>) -> Result<Response> {
format::json(serde_json::json!({
"site": {
"theme": {
"title": "SeaORM Pro FREE",
"logo": "/admin/favicon.ico",
"login_banner": "/admin/logo.png",
}
},
"raw_tables": {},
"composite_tables": {},
}))
}

pub fn routes() -> Routes {
Routes::new().prefix("admin").add("/config", get(config))
}
```

Use the admin controller and register the `/api/admin` route.

```diff title=loco_starter/src/controllers/mod.rs
+ pub mod admin;
pub mod auth;
pub mod files;
pub mod notes;
pub mod user;
```

```diff title=loco_starter/src/app.rs
pub struct App;

#[async_trait]
impl Hooks for App {
fn routes(_ctx: &AppContext) -> AppRoutes {
AppRoutes::with_default_routes()
.prefix("/api")
.add_route(controllers::notes::routes())
.add_route(controllers::auth::routes())
.add_route(controllers::user::routes())
.add_route(controllers::files::routes())
+ .add_route(controllers::admin::routes())
}
}
```

## 2. Setup GraphQL Endpoint

### 2.1 Define GraphQL schema

Add the dependencies for defining GraphQL schema: `async-graphql`, `seaography` and `lazy_static`.

Expand Down Expand Up @@ -214,7 +269,7 @@ pub mod workers;
+ pub mod graphql;
```

## Setup GraphQL Endpoint
### 2.2 Setup GraphQL playground and query root

Add dependencies for serving GraphQL playground and handling GraphQL request.

Expand Down Expand Up @@ -276,68 +331,12 @@ pub fn routes() -> Routes {
Use the GraphQL controller and register the `/api/graphql` route.

```diff title=loco_starter/src/controllers/mod.rs
pub mod admin;
pub mod auth;
pub mod files;
pub mod notes;
pub mod user;
+ pub mod graphql;
```

```diff title=loco_starter/src/app.rs
pub struct App;

#[async_trait]
impl Hooks for App {
fn routes(_ctx: &AppContext) -> AppRoutes {
AppRoutes::with_default_routes()
.prefix("/api")
.add_route(controllers::notes::routes())
.add_route(controllers::auth::routes())
.add_route(controllers::user::routes())
.add_route(controllers::files::routes())
+ .add_route(controllers::graphql::routes())
}
}
```

## Setup Library Endpoint

The admin dashboard frontend is customizable and it read the configuration from the `api/library/config` endpoint.

```rust title=loco_starter/src/controllers/library.rs
use loco_rs::prelude::*;

pub async fn config(State(_ctx): State<AppContext>) -> Result<Response> {
format::json(serde_json::json!({
"site": {
"theme": {
"title": "SeaORM Pro FREE",
"logo": "/admin/favicon.ico",
"login_banner": "/admin/logo.png",
"copyright": "Powered by SeaORM Pro",
}
},
"raw_tables": {},
"composite_tables": {},
}))
}

pub fn routes() -> Routes {
Routes::new()
.prefix("library")
.add("/config", get(config))
}
```

Use the library controller and register the `/api/library` route.

```diff title=loco_starter/src/controllers/mod.rs
pub mod auth;
pub mod files;
pub mod notes;
pub mod user;
pub mod graphql;
+ pub mod library;
```

```diff title=loco_starter/src/app.rs
Expand All @@ -352,13 +351,13 @@ impl Hooks for App {
.add_route(controllers::auth::routes())
.add_route(controllers::user::routes())
.add_route(controllers::files::routes())
.add_route(controllers::graphql::routes())
+ .add_route(controllers::library::routes())
.add_route(controllers::admin::routes())
+ .add_route(controllers::graphql::routes())
}
}
```

## Compile and Run
## 3. Launch!

```sh
$ cargo run start
Expand Down Expand Up @@ -386,7 +385,7 @@ $ cargo run start
2025-01-03T08:48:32.471041Z INFO app: loco_rs::controller::app_routes: [POST] /api/files/upload/:notes_id environment=development
2025-01-03T08:48:32.471090Z INFO app: loco_rs::controller::app_routes: [GET] /api/files/list/:notes_id environment=development
2025-01-03T08:48:32.471144Z INFO app: loco_rs::controller::app_routes: [GET] /api/files/view/:files_id environment=development
2025-01-03T08:48:32.471195Z INFO app: loco_rs::controller::app_routes: [GET] /api/library/config environment=development
2025-01-03T08:48:32.471195Z INFO app: loco_rs::controller::app_routes: [GET] /api/admin/config environment=development
2025-01-03T08:48:32.471239Z INFO app: loco_rs::controller::app_routes: [GET] /api/graphql environment=development
2025-01-03T08:48:32.471319Z INFO app: loco_rs::controller::app_routes: [POST] /api/graphql environment=development
2025-01-03T08:48:32.472125Z INFO app: loco_rs::controller::app_routes: [Middleware] Adding static environment=development
Expand Down
29 changes: 0 additions & 29 deletions sea-orm-pro/docs/02-install-and-config/02-frontend.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Getting Started with Axum

8 changes: 4 additions & 4 deletions sea-orm-pro/docs/03-site-config/01-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
```toml
[site.theme]

# Title of admin dashboard
# Title of admin panel
title = "SeaORM Pro FREE"

# File path of admin dashboard logo
# File path of admin panel logo
logo = "/admin/favicon.ico"

# File path of admin dashboard login banner
# File path of admin panel login banner
login_banner = "/admin/logo.png"

# Copyright of admin dashboard
# Copyright of admin panel
copyright = "Powered by SeaORM Pro"
```
2 changes: 1 addition & 1 deletion sea-orm-pro/docs/04-raw-table-config/01-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The TOML config file should be named the same as the corresponding name of the d

## Overall Structure of TOML File

The TOML config file of raw table is not compulsory. All database tables and all its columns will be shown on the admin dashboard by default. However, if you wish to customize the display of raw table, a TOML config file is required.
The TOML config file of raw table is not compulsory. All database tables and all its columns will be shown on the admin panel by default. However, if you wish to customize the display of raw table, a TOML config file is required.

The TOML config consists of 5 sections, each section will be explained separately in the following.

Expand Down
2 changes: 1 addition & 1 deletion sea-orm-pro/docs/04-raw-table-config/02-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ page_size = 20

By default, the `all_columns` is turned on, meaning all columns will be shown, you can override this in the config.

The sequence of item in which the `columns` array is the same as the table displayed in the admin dashboard.
The sequence of item in which the `columns` array is the same as the table displayed in the admin panel.

The `title` is optional, if it's not set it will use the title case of the `field` as the title.

Expand Down
2 changes: 1 addition & 1 deletion sea-orm-pro/docs/06-deployment/01-nginx.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nginx

You can serve the admin dashboard through Nginx.
You can serve the admin panel through Nginx.

First build the frontend artifact.

Expand Down
Loading

0 comments on commit d5530cc

Please sign in to comment.