add prelude
This commit is contained in:
parent
6dc1401550
commit
411c8668eb
@ -44,7 +44,7 @@ pub fn derive_crud_fns(input: proc_macro::TokenStream) -> proc_macro::TokenStrea
|
||||
use std::convert::From;
|
||||
use async_trait::async_trait;
|
||||
use actix_web::{web, HttpResponse, HttpRequest, Error};
|
||||
use actix_admin::{ ActixAdminField, ActixAdminModelTrait, ActixAdminViewModelTrait, ActixAdminViewModel, ActixAdminModel, AppDataTrait , hashmap};
|
||||
use actix_admin::prelude::*;
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use sea_orm::{ConnectOptions, DatabaseConnection};
|
||||
use sea_orm::{entity::*, query::*};
|
||||
@ -64,12 +64,8 @@ pub fn derive_crud_fns(input: proc_macro::TokenStream) -> proc_macro::TokenStrea
|
||||
impl From<Model> for ActixAdminModel {
|
||||
fn from(model: Model) -> Self {
|
||||
ActixAdminModel {
|
||||
// TODO: create dynamically
|
||||
values: hashmap![
|
||||
#(#fields_for_from_model),*
|
||||
// "title" => model.title,
|
||||
// "text" => model.text,
|
||||
// "id" => model.id.to_string()
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -4,10 +4,7 @@
|
||||
use actix_web::{web};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::ActixAdmin;
|
||||
use crate::ActixAdminViewModelTrait;
|
||||
use crate::ActixAdminViewModel;
|
||||
use crate::AppDataTrait;
|
||||
use crate::prelude::*;
|
||||
|
||||
use crate::routes::list;
|
||||
use crate::routes::create_get;
|
||||
@ -21,8 +18,8 @@ pub struct ActixAdminBuilder {
|
||||
|
||||
pub trait ActixAdminBuilderTrait {
|
||||
fn new() -> Self;
|
||||
fn add_entity<T: AppDataTrait + 'static, E: ActixAdminViewModelTrait + 'static>(&mut self, view_model: &ActixAdminViewModel);
|
||||
fn get_scope<T: AppDataTrait + 'static>(self) -> actix_web::Scope;
|
||||
fn add_entity<T: ActixAdminAppDataTrait + 'static, E: ActixAdminViewModelTrait + 'static>(&mut self, view_model: &ActixAdminViewModel);
|
||||
fn get_scope<T: ActixAdminAppDataTrait + 'static>(self) -> actix_web::Scope;
|
||||
fn get_actix_admin(&self) -> ActixAdmin;
|
||||
}
|
||||
|
||||
@ -37,7 +34,7 @@ impl ActixAdminBuilderTrait for ActixAdminBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
fn add_entity<T: AppDataTrait + 'static, E: ActixAdminViewModelTrait + 'static>(
|
||||
fn add_entity<T: ActixAdminAppDataTrait + 'static, E: ActixAdminViewModelTrait + 'static>(
|
||||
&mut self,
|
||||
view_model: &ActixAdminViewModel,
|
||||
) {
|
||||
@ -54,7 +51,7 @@ impl ActixAdminBuilderTrait for ActixAdminBuilder {
|
||||
self.actix_admin.view_models.insert(key, view_model.clone());
|
||||
}
|
||||
|
||||
fn get_scope<T: AppDataTrait + 'static>(self) -> actix_web::Scope {
|
||||
fn get_scope<T: ActixAdminAppDataTrait + 'static>(self) -> actix_web::Scope {
|
||||
let mut scope = web::scope("/admin").route("/", web::get().to(index::<T>));
|
||||
for entity_scope in self.scopes {
|
||||
scope = scope.service(entity_scope);
|
||||
|
@ -4,21 +4,22 @@ use serde::{Serialize};
|
||||
use std::collections::HashMap;
|
||||
use tera::{Tera};
|
||||
|
||||
pub use actix_admin_macros::DeriveActixAdminModel;
|
||||
pub mod view_model;
|
||||
pub mod model;
|
||||
pub mod routes;
|
||||
pub mod builder;
|
||||
|
||||
mod view_model;
|
||||
pub use view_model::ActixAdminViewModel;
|
||||
pub use view_model::ActixAdminViewModelTrait;
|
||||
pub mod prelude {
|
||||
pub use crate::builder::{ ActixAdminBuilder, ActixAdminBuilderTrait};
|
||||
pub use crate::model::{ ActixAdminModel, ActixAdminModelTrait};
|
||||
pub use crate::view_model::{ ActixAdminViewModel, ActixAdminViewModelTrait};
|
||||
pub use actix_admin_macros::{ DeriveActixAdminModel };
|
||||
pub use crate::{ ActixAdminAppDataTrait, ActixAdmin};
|
||||
pub use crate::{ hashmap };
|
||||
pub use crate::{ ActixAdminField };
|
||||
}
|
||||
|
||||
mod model;
|
||||
pub use model::ActixAdminModel;
|
||||
pub use model::ActixAdminModelTrait;
|
||||
|
||||
mod builder;
|
||||
pub use builder::ActixAdminBuilder;
|
||||
pub use builder::ActixAdminBuilderTrait;
|
||||
|
||||
mod routes;
|
||||
use crate::prelude::*;
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! hashmap {
|
||||
@ -42,7 +43,7 @@ pub enum ActixAdminField {
|
||||
}
|
||||
|
||||
// AppDataTrait
|
||||
pub trait AppDataTrait {
|
||||
pub trait ActixAdminAppDataTrait {
|
||||
fn get_db(&self) -> &DatabaseConnection;
|
||||
fn get_actix_admin(&self) -> &ActixAdmin;
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
use actix_web::{error, web, Error, HttpRequest, HttpResponse};
|
||||
use tera::{Context};
|
||||
|
||||
use crate::AppDataTrait;
|
||||
use crate::ActixAdminViewModelTrait;
|
||||
use crate::prelude::*;
|
||||
|
||||
use crate::TERA;
|
||||
|
||||
pub async fn create_get<T: AppDataTrait, E: ActixAdminViewModelTrait>(
|
||||
pub async fn create_get<T: ActixAdminAppDataTrait, E: ActixAdminViewModelTrait>(
|
||||
_req: HttpRequest,
|
||||
data: web::Data<T>,
|
||||
_body: web::Payload,
|
||||
|
@ -1,11 +1,9 @@
|
||||
use actix_web::http::header;
|
||||
use actix_web::{web, Error, HttpRequest, HttpResponse};
|
||||
|
||||
use crate::AppDataTrait;
|
||||
use crate::ActixAdminViewModelTrait;
|
||||
use crate::ActixAdminModel;
|
||||
use crate::prelude::*;
|
||||
|
||||
pub async fn create_post<T: AppDataTrait, E: ActixAdminViewModelTrait>(
|
||||
pub async fn create_post<T: ActixAdminAppDataTrait, E: ActixAdminViewModelTrait>(
|
||||
_req: HttpRequest,
|
||||
data: web::Data<T>,
|
||||
text: String,
|
||||
|
@ -1,10 +1,11 @@
|
||||
use actix_web::{error, web, Error, HttpResponse};
|
||||
use tera::{Context};
|
||||
|
||||
use crate::AppDataTrait;
|
||||
use crate::prelude::*;
|
||||
|
||||
use crate::TERA;
|
||||
|
||||
pub async fn index<T: AppDataTrait>(data: web::Data<T>) -> Result<HttpResponse, Error> {
|
||||
pub async fn index<T: ActixAdminAppDataTrait>(data: web::Data<T>) -> Result<HttpResponse, Error> {
|
||||
let entity_names = &data.get_actix_admin().entity_names;
|
||||
let mut ctx = Context::new();
|
||||
ctx.insert("entity_names", &entity_names);
|
||||
|
@ -2,7 +2,8 @@ use actix_web::{error, web, Error, HttpRequest, HttpResponse};
|
||||
use serde::{Deserialize};
|
||||
use tera::{Context};
|
||||
|
||||
use crate::AppDataTrait;
|
||||
use crate::prelude::*;
|
||||
|
||||
use crate::ActixAdminViewModelTrait;
|
||||
use crate::ActixAdminViewModel;
|
||||
use crate::ActixAdminModel;
|
||||
@ -16,7 +17,7 @@ pub struct Params {
|
||||
entities_per_page: Option<usize>,
|
||||
}
|
||||
|
||||
pub async fn list<T: AppDataTrait, E: ActixAdminViewModelTrait>(
|
||||
pub async fn list<T: ActixAdminAppDataTrait, E: ActixAdminViewModelTrait>(
|
||||
req: HttpRequest,
|
||||
data: web::Data<T>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
|
@ -1,7 +1,6 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use actix_admin::{ DeriveActixAdminModel };
|
||||
use actix_admin::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize, DeriveActixAdminModel)]
|
||||
#[sea_orm(table_name = "comment")]
|
||||
|
@ -1,6 +1,6 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use actix_admin::{ DeriveActixAdminModel };
|
||||
use actix_admin::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize, DeriveActixAdminModel)]
|
||||
#[sea_orm(table_name = "post")]
|
||||
|
@ -1,9 +1,6 @@
|
||||
extern crate serde_derive;
|
||||
|
||||
use actix_admin::{
|
||||
ActixAdmin, ActixAdminBuilder, ActixAdminBuilderTrait, ActixAdminViewModel,
|
||||
AppDataTrait as ActixAdminAppDataTrait,
|
||||
};
|
||||
use actix_admin::prelude::*;
|
||||
use actix_session::{CookieSession, Session};
|
||||
use actix_web::{web, App, HttpResponse, HttpServer, middleware};
|
||||
use azure_auth::{AppDataTrait as AzureAuthAppDataTrait, AzureAuth, UserInfo};
|
||||
|
Loading…
Reference in New Issue
Block a user