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
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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()?,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
{% when Some with (user) %}
|
||||
<a class="button" href="/recipe/new" >{{ context.tr.t(Sentence::CreateNewRecipe) }}</a>
|
||||
{% if user.is_admin %}
|
||||
<a class="button" href="/dev_panel">Dev panel</a>
|
||||
<a class="button" href="/logs">Logs</a><a class="button" href="/dev_panel">Dev panel</a>
|
||||
{% endif %}
|
||||
<a href="/{{ context.tr.current_lang_code() }}/user/edit">
|
||||
{% if user.name == "" %}
|
||||
|
|
|
|||
|
|
@ -5,37 +5,6 @@
|
|||
<div class="content" id="dev-panel">
|
||||
<input type="button" class="button" id="test-toast" value="Test toast">
|
||||
<input type="button" class="button" id="test-modal-dialog" value="Test modal">
|
||||
|
||||
<div type="log">
|
||||
<ul class="log-files">
|
||||
{% for f in log.file_names().unwrap() %}
|
||||
<li class="log-file"><a href="/dev_panel?log_file={{ f }}">{{ f }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="current-log-file">
|
||||
{% match log.read_content(current_log_file) %}
|
||||
{% when Ok(lines) %}
|
||||
{% for l in lines %}
|
||||
<div class="line
|
||||
{%~ if loop.index0 % 2 == 0 %}
|
||||
even
|
||||
{% else %}
|
||||
odd
|
||||
{% endif %}
|
||||
" >
|
||||
{% let l_info = Log::split_line(l) %}
|
||||
<span class="date-time">{{ l_info.date_time }}</span>
|
||||
<span class="level {{~ l_info.level }}">{{ l_info.level }}</span>
|
||||
<span class="thread-name">{{ l_info.thread_name }}</span>
|
||||
<span class="thread-id">{{ l_info.thread_id }}</span>
|
||||
<span class="message">{{ l_info.message | linebreaksbr }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% when Err(err) %}
|
||||
Error reading log: {{ err }}
|
||||
{% endmatch %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="hidden-templates">
|
||||
|
|
|
|||
40
backend/templates/logs.html
Normal file
40
backend/templates/logs.html
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{% extends "base_with_list.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="content" id="logs">
|
||||
<ul class="log-files">
|
||||
{% for f in log.file_names().unwrap() %}
|
||||
<li class="log-file
|
||||
{%~ if current_log_file == f %}
|
||||
current
|
||||
{% endif %}
|
||||
"><a href="/logs?log_file={{ f }}">{{ f }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="current-log-file">
|
||||
{% match log.read_content(current_log_file) %}
|
||||
{% when Ok(lines) %}
|
||||
{% for l in lines %}
|
||||
<div class="line
|
||||
{%~ if loop.index0 % 2 == 0 %}
|
||||
even
|
||||
{% else %}
|
||||
odd
|
||||
{% endif %}
|
||||
" >
|
||||
{% let l_info = Log::split_line(l) %}
|
||||
<span class="date-time">{{ l_info.date_time }}</span>
|
||||
<span class="level {{~ l_info.level }}">{{ l_info.level }}</span>
|
||||
<span class="thread-name">{{ l_info.thread_name }}</span>
|
||||
<span class="thread-id">{{ l_info.thread_id }}</span>
|
||||
<span class="message">{{ l_info.message | linebreaksbr }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% when Err(err) %}
|
||||
Error reading log: {{ err }}
|
||||
{% endmatch %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue