2022-04-06 16:03:00 +00:00
|
|
|
use actix::Addr;
|
2022-04-06 15:18:06 +00:00
|
|
|
use actix_web::{HttpResponse, Responder, web};
|
|
|
|
use askama::Template;
|
|
|
|
|
2022-04-06 16:03:00 +00:00
|
|
|
use crate::actors::users_actor;
|
|
|
|
use crate::actors::users_actor::UsersActor;
|
2022-04-06 15:18:06 +00:00
|
|
|
use crate::controllers::settings_controller::BaseSettingsPage;
|
|
|
|
use crate::data::client::{Client, ClientManager};
|
|
|
|
use crate::data::current_user::CurrentUser;
|
2022-04-06 16:03:00 +00:00
|
|
|
use crate::data::user::User;
|
2022-04-06 15:18:06 +00:00
|
|
|
|
|
|
|
#[derive(Template)]
|
|
|
|
#[template(path = "settings/clients_list.html")]
|
|
|
|
struct ClientsListTemplate {
|
|
|
|
_parent: BaseSettingsPage,
|
|
|
|
clients: Vec<Client>,
|
|
|
|
}
|
|
|
|
|
2022-04-06 16:03:00 +00:00
|
|
|
#[derive(Template)]
|
|
|
|
#[template(path = "settings/users_list.html")]
|
|
|
|
struct UsersListTemplate {
|
|
|
|
_parent: BaseSettingsPage,
|
|
|
|
users: Vec<User>,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-06 15:18:06 +00:00
|
|
|
pub async fn clients_route(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder {
|
|
|
|
HttpResponse::Ok().body(ClientsListTemplate {
|
|
|
|
_parent: BaseSettingsPage::get(
|
|
|
|
"Clients list",
|
|
|
|
&user,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
clients: clients.cloned(),
|
|
|
|
}.render().unwrap())
|
2022-04-06 16:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn users_route(user: CurrentUser, users: web::Data<Addr<UsersActor>>) -> impl Responder {
|
|
|
|
let users = users.send(users_actor::GetAllUsersRequest).await.unwrap().0;
|
|
|
|
|
|
|
|
HttpResponse::Ok().body(UsersListTemplate {
|
|
|
|
_parent: BaseSettingsPage::get(
|
|
|
|
"Users list",
|
|
|
|
&user,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
),
|
|
|
|
users,
|
|
|
|
}.render().unwrap())
|
2022-04-06 15:18:06 +00:00
|
|
|
}
|