Move logs view from dev_panel page to a logs page
This commit is contained in:
parent
1bb0f05fc0
commit
b0f0633338
7 changed files with 110 additions and 42 deletions
|
|
@ -60,6 +60,13 @@ pub struct HomeTemplate {
|
|||
pub struct DevPanelTemplate {
|
||||
pub context: Context,
|
||||
pub recipes: Recipes,
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
#[template(path = "logs.html")]
|
||||
pub struct LogsTemplate {
|
||||
pub context: Context,
|
||||
pub recipes: Recipes,
|
||||
pub log: Log,
|
||||
pub current_log_file: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -281,6 +281,7 @@ async fn main() {
|
|||
let html_routes = Router::new()
|
||||
.route("/", get(services::home_page))
|
||||
.route("/dev_panel", get(services::dev_panel))
|
||||
.route("/logs", get(services::logs))
|
||||
.route("/signup", get(services::user::sign_up_get))
|
||||
.route("/validation", get(services::user::sign_up_validation))
|
||||
.route("/revalidation", get(services::user::email_revalidation))
|
||||
|
|
|
|||
|
|
@ -68,18 +68,10 @@ pub async fn home_page(
|
|||
|
||||
///// DEV_PANEL /////
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct LogFile {
|
||||
#[serde(default)]
|
||||
pub log_file: String,
|
||||
}
|
||||
|
||||
#[debug_handler(state = AppState)]
|
||||
pub async fn dev_panel(
|
||||
State(connection): State<db::Connection>,
|
||||
State(log): State<Log>,
|
||||
Extension(context): Extension<Context>,
|
||||
log_file: Query<LogFile>,
|
||||
) -> Result<Response> {
|
||||
if context.user.is_some() && context.user.as_ref().unwrap().is_admin {
|
||||
Ok(Html(
|
||||
|
|
@ -92,8 +84,60 @@ pub async fn dev_panel(
|
|||
)
|
||||
.await?,
|
||||
context,
|
||||
}
|
||||
.render()?,
|
||||
)
|
||||
.into_response())
|
||||
} else {
|
||||
Ok((
|
||||
StatusCode::UNAUTHORIZED,
|
||||
Html(
|
||||
MessageTemplate::new_with_user(
|
||||
consts::NOT_AUTHORIZED_MESSAGE,
|
||||
context.tr,
|
||||
context.user,
|
||||
)
|
||||
.render()?,
|
||||
),
|
||||
)
|
||||
.into_response())
|
||||
}
|
||||
}
|
||||
|
||||
///// DEV_PANEL /////
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct LogFile {
|
||||
#[serde(default)]
|
||||
pub log_file: String,
|
||||
}
|
||||
|
||||
#[debug_handler(state = AppState)]
|
||||
pub async fn logs(
|
||||
State(connection): State<db::Connection>,
|
||||
State(log): State<Log>,
|
||||
Extension(context): Extension<Context>,
|
||||
log_file: Query<LogFile>,
|
||||
) -> Result<Response> {
|
||||
if context.user.is_some() && context.user.as_ref().unwrap().is_admin {
|
||||
Ok(Html(
|
||||
LogsTemplate {
|
||||
recipes: Recipes::new(
|
||||
connection,
|
||||
&context.user,
|
||||
context.tr.current_lang_code(),
|
||||
None,
|
||||
)
|
||||
.await?,
|
||||
context,
|
||||
current_log_file: match (
|
||||
log_file.log_file.is_empty(),
|
||||
log.file_names().unwrap_or_default(),
|
||||
) {
|
||||
(true, file_names) if !file_names.is_empty() => file_names[0].clone(),
|
||||
_ => log_file.log_file.clone(),
|
||||
},
|
||||
log,
|
||||
current_log_file: log_file.log_file.clone(),
|
||||
}
|
||||
.render()?,
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue