diff --git a/backend/scss/main.scss b/backend/scss/main.scss index 78f3661..c04f049 100644 --- a/backend/scss/main.scss +++ b/backend/scss/main.scss @@ -187,7 +187,11 @@ body { } } - #dev-panel { + #logs { + .current { + font-weight: bold; + } + .line { padding: 3px; @@ -237,6 +241,9 @@ body { } } + // #dev-panel { + // } + form { display: grid; grid-template-columns: auto 1fr; diff --git a/backend/src/html_templates.rs b/backend/src/html_templates.rs index 58baac7..a0e6d93 100644 --- a/backend/src/html_templates.rs +++ b/backend/src/html_templates.rs @@ -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, } diff --git a/backend/src/main.rs b/backend/src/main.rs index 6cf9d2e..f94689b 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -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)) diff --git a/backend/src/services/mod.rs b/backend/src/services/mod.rs index f44e0a9..6d3980e 100644 --- a/backend/src/services/mod.rs +++ b/backend/src/services/mod.rs @@ -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, - State(log): State, Extension(context): Extension, - log_file: Query, ) -> Result { 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, + State(log): State, + Extension(context): Extension, + log_file: Query, +) -> Result { + 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()?, ) diff --git a/backend/templates/base_with_header.html b/backend/templates/base_with_header.html index b764123..d27fc15 100644 --- a/backend/templates/base_with_header.html +++ b/backend/templates/base_with_header.html @@ -10,7 +10,7 @@ {% when Some with (user) %} {{ context.tr.t(Sentence::CreateNewRecipe) }} {% if user.is_admin %} - Dev panel + LogsDev panel {% endif %} {% if user.name == "" %} diff --git a/backend/templates/dev_panel.html b/backend/templates/dev_panel.html index 26489bb..e76a146 100644 --- a/backend/templates/dev_panel.html +++ b/backend/templates/dev_panel.html @@ -5,37 +5,6 @@
- -
- -
- {% match log.read_content(current_log_file) %} - {% when Ok(lines) %} - {% for l in lines %} -
- {% let l_info = Log::split_line(l) %} - {{ l_info.date_time }} - {{ l_info.level }} - {{ l_info.thread_name }} - {{ l_info.thread_id }} - {{ l_info.message | linebreaksbr }} -
- {% endfor %} - {% when Err(err) %} - Error reading log: {{ err }} - {% endmatch %} -
-
diff --git a/backend/templates/logs.html b/backend/templates/logs.html new file mode 100644 index 0000000..f0357fa --- /dev/null +++ b/backend/templates/logs.html @@ -0,0 +1,40 @@ +{% extends "base_with_list.html" %} + +{% block content %} + +
+
    + {% for f in log.file_names().unwrap() %} +
  • {{ f }}
  • + {% endfor %} +
+
+ {% match log.read_content(current_log_file) %} + {% when Ok(lines) %} + {% for l in lines %} +
+ {% let l_info = Log::split_line(l) %} + {{ l_info.date_time }} + {{ l_info.level }} + {{ l_info.thread_name }} + {{ l_info.thread_id }} + {{ l_info.message | linebreaksbr }} +
+ {% endfor %} + {% when Err(err) %} + Error reading log: {{ err }} + {% endmatch %} +
+
+ +{% endblock %} \ No newline at end of file