export lib crates in prelude to use in macro

This commit is contained in:
Manuel Gugger 2022-10-24 18:42:51 +02:00
parent e48acd015c
commit ac2d1d6ed0
3 changed files with 15 additions and 14 deletions

View File

@ -28,16 +28,17 @@ pub fn derive_actix_admin_model_select_list(input: proc_macro::TokenStream) -> p
pub fn derive_actix_admin(_input: proc_macro::TokenStream) -> proc_macro::TokenStream { pub fn derive_actix_admin(_input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let expanded = quote! { let expanded = quote! {
use std::convert::From; use std::convert::From;
use async_trait::async_trait;
use actix_admin::prelude::*; use actix_admin::prelude::*;
use sea_orm::ActiveValue::Set; use sea_orm::{
use sea_orm::{ConnectOptions, DatabaseConnection}; ActiveValue::Set,
use sea_orm::{entity::*, query::*}; ConnectOptions,
DatabaseConnection,
entity::*,
query::*,
EntityTrait
};
use std::collections::HashMap; use std::collections::HashMap;
use sea_orm::EntityTrait;
use itertools::izip;
use actix_session::{Session}; use actix_session::{Session};
use lazy_static::lazy_static;
}; };
proc_macro::TokenStream::from(expanded) proc_macro::TokenStream::from(expanded)
} }
@ -66,7 +67,7 @@ pub fn derive_actix_admin_view_model(input: proc_macro::TokenStream) -> proc_mac
} }
} }
#[async_trait(?Send)] #[actix_admin::prelude::async_trait(?Send)]
impl ActixAdminViewModelTrait for Entity { impl ActixAdminViewModelTrait for Entity {
async fn list(db: &DatabaseConnection, page: usize, entities_per_page: usize, search: &String) -> Result<(usize, Vec<ActixAdminModel>), ActixAdminError> { async fn list(db: &DatabaseConnection, page: usize, entities_per_page: usize, search: &String) -> Result<(usize, Vec<ActixAdminModel>), ActixAdminError> {
let entities = Entity::list_model(db, page, entities_per_page, search).await; let entities = Entity::list_model(db, page, entities_per_page, search).await;
@ -156,7 +157,7 @@ pub fn derive_actix_admin_model(input: proc_macro::TokenStream) -> proc_macro::T
let fields_textarea = get_actix_admin_fields_textarea(&fields); let fields_textarea = get_actix_admin_fields_textarea(&fields);
let expanded = quote! { let expanded = quote! {
lazy_static! { actix_admin::prelude::lazy_static! {
pub static ref ACTIX_ADMIN_VIEWMODEL_FIELDS: Vec<ActixAdminViewModelField> = { pub static ref ACTIX_ADMIN_VIEWMODEL_FIELDS: Vec<ActixAdminViewModelField> = {
let mut vec = Vec::new(); let mut vec = Vec::new();
@ -187,7 +188,7 @@ pub fn derive_actix_admin_model(input: proc_macro::TokenStream) -> proc_macro::T
#(#fields_textarea),* #(#fields_textarea),*
]; ];
for (field_name, html_input_type, select_list, is_option_list, fields_type_path, is_textarea) in izip!(&field_names, &html_input_types, &field_select_lists, is_option_lists, fields_type_paths, fields_textareas) { for (field_name, html_input_type, select_list, is_option_list, fields_type_path, is_textarea) in actix_admin::prelude::izip!(&field_names, &html_input_types, &field_select_lists, is_option_lists, fields_type_paths, fields_textareas) {
let select_list = select_list.replace('"', "").replace(' ', "").to_string(); let select_list = select_list.replace('"', "").replace(' ', "").to_string();
let field_name = field_name.replace('"', "").replace(' ', "").to_string(); let field_name = field_name.replace('"', "").replace(' ', "").to_string();
@ -229,7 +230,7 @@ pub fn derive_actix_admin_model(input: proc_macro::TokenStream) -> proc_macro::T
} }
} }
#[async_trait] #[actix_admin::prelude::async_trait]
impl ActixAdminModelTrait for Entity { impl ActixAdminModelTrait for Entity {
async fn list_model(db: &DatabaseConnection, page: usize, posts_per_page: usize, search: &String) -> Result<(usize, Vec<ActixAdminModel>), ActixAdminError> { async fn list_model(db: &DatabaseConnection, page: usize, posts_per_page: usize, search: &String) -> Result<(usize, Vec<ActixAdminModel>), ActixAdminError> {
use sea_orm::{ query::* }; use sea_orm::{ query::* };

View File

@ -8,13 +8,10 @@ actix-web = "4.0.1"
actix-rt = "2.7.0" actix-rt = "2.7.0"
actix-session = { version = "0.7.1", features = ["cookie-session"] } actix-session = { version = "0.7.1", features = ["cookie-session"] }
tera = "1.15.0" tera = "1.15.0"
itertools = "0.10.3"
oauth2 = "4.1" oauth2 = "4.1"
async-trait = "0.1.53"
dotenv = "0.15" dotenv = "0.15"
serde = "1.0.136" serde = "1.0.136"
serde_derive = "1.0.136" serde_derive = "1.0.136"
sea-orm = { version = "^0.9.1", features = [ "sqlx-sqlite", "runtime-actix-native-tls", "macros" ], default-features = true } sea-orm = { version = "^0.9.1", features = [ "sqlx-sqlite", "runtime-actix-native-tls", "macros" ], default-features = true }
lazy_static = "1.4.0"
actix-admin = { path = "../" } actix-admin = { path = "../" }
azure_auth = { path = "./azure_auth" } azure_auth = { path = "./azure_auth" }

View File

@ -143,6 +143,9 @@ pub mod prelude {
pub use crate::{ hashmap, ActixAdminSelectListTrait }; pub use crate::{ hashmap, ActixAdminSelectListTrait };
pub use crate::routes::{ create_or_edit_post, get_admin_ctx }; pub use crate::routes::{ create_or_edit_post, get_admin_ctx };
pub use crate::{ TERA }; pub use crate::{ TERA };
pub use itertools::izip;
pub use lazy_static::lazy_static;
pub use async_trait::async_trait;
} }
use crate::prelude::*; use crate::prelude::*;