Skip to content

Commit 9550b23

Browse files
committed
Improve UI of logs index
1 parent efcaf8b commit 9550b23

File tree

10 files changed

+138
-25
lines changed

10 files changed

+138
-25
lines changed

assets/css/main.css

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
--bs-green: #00A46A;
44
--black: #000;
55
--white: #fff;
6+
--terminal-background: #0d0d0d;
7+
--terminal-border: #ccc;
8+
--terminal-box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
9+
--terminal-red: #f44336;
10+
--terminal-yellow: #ffeb3b;
11+
--terminal-info: #9cdcfe;
12+
--terminal-dark-grey: #555;
613
}
714

815
.filters .filter-item {
@@ -33,10 +40,64 @@ a {
3340
width: auto;
3441
}
3542

43+
/* Terminal style */
44+
45+
.log-container {
46+
background: var(--terminal-background);
47+
font-family: "Fira Code", monospace;
48+
border: 1px solid var(--terminal-color);
49+
padding: 35px;
50+
border-radius: 6px;
51+
overflow-y: auto;
52+
box-shadow: var(--terminal-box-shadow);
53+
color: var(--terminal-color);
54+
border: 1px solid var(--terminal-color);
55+
line-height: 1.4;
56+
}
57+
58+
.log-line {
59+
position: relative;
60+
color: var(--white);
61+
padding-left: 20px;
62+
margin-bottom: 20px;
63+
}
64+
65+
.log-line::before {
66+
content: "$ ";
67+
color: var(--terminal-dark-grey);
68+
position: absolute;
69+
left: -3px;
70+
top: -1;
71+
}
72+
73+
.log-line:last-child {
74+
margin-bottom: 0px;
75+
}
76+
77+
.log-line .log-red {
78+
color: var(--terminal-red);
79+
}
80+
81+
.log-line .log-green {
82+
color: var(--bs-success);
83+
}
84+
85+
.log-line .log-yellow {
86+
color: var(--terminal-yellow);
87+
}
88+
89+
.log-user {
90+
color: var(--terminal-info);
91+
}
92+
93+
.log-object {
94+
color: var(--terminal-border);
95+
}
3696

3797
/* Waiting for bootstrap SASS */
3898

3999
.btn-success {
40100
border-color: var(--bs-success);
41101
background-color: var(--bs-success);
42102
}
103+

src/database/category.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,34 @@ impl CategoryOperator {
7272
}
7373

7474
/// Delete a category
75-
pub async fn delete(&self, id: i32) -> Result<String, CategoryError> {
75+
pub async fn delete(&self, id: i32, user: Option<User>) -> Result<String, CategoryError> {
7676
let db = &self.state.database;
7777
let category: Option<Model> = Entity::find_by_id(id).one(db).await.context(DBSnafu)?;
7878

7979
match category {
8080
Some(category) => {
81-
let category_name: String = category.clone().name;
81+
let category_clone: Model = category.clone();
8282
category.delete(db).await.context(DBSnafu)?;
8383

84-
Ok(category_name)
84+
let operation_log = OperationLog {
85+
user,
86+
date: Utc::now(),
87+
table: Table::Category,
88+
operation: OperationType::Delete,
89+
operation_id: OperationId {
90+
object_id: category_clone.id,
91+
name: category_clone.name.to_owned(),
92+
},
93+
operation_form: None,
94+
};
95+
96+
self.state
97+
.logger
98+
.write(operation_log)
99+
.await
100+
.context(LoggerSnafu)?;
101+
102+
Ok(category_clone.name)
85103
}
86104
None => Err(CategoryError::NotFound { id }),
87105
}
@@ -142,7 +160,7 @@ impl CategoryOperator {
142160
object_id: model.id.to_owned(),
143161
name: f.name.to_string(),
144162
},
145-
operation_form: Operation::Category(f.clone()),
163+
operation_form: Some(Operation::Category(f.clone())),
146164
};
147165

148166
self.state

src/database/operation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ pub struct OperationLog {
4747
pub operation: OperationType,
4848
pub operation_id: OperationId,
4949
// Raw operation parameters
50-
pub operation_form: Operation,
50+
pub operation_form: Option<Operation>,
5151
}

src/routes/category.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub async fn delete(
7272
let app_state_context = app_state.context().await?;
7373
let categories = CategoryOperator::new(app_state.clone(), user.clone());
7474

75-
let deleted = categories.delete(id).await;
75+
let deleted = categories.delete(id, user.clone()).await;
7676

7777
match deleted {
7878
Ok(name) => Ok(CategoriesTemplate {

src/routes/logs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use axum::extract::State;
44
use snafu::prelude::*;
55

66
use crate::database::operation::OperationLog;
7+
use crate::database::operation::OperationType;
78
use crate::extractors::user::User;
89
use crate::state::{AppState, AppStateContext, error::*};
910

1011
#[derive(Template, WebTemplate)]
11-
#[template(path = "logs.html")]
12+
#[template(path = "logs/index.html")]
1213
pub struct LogTemplate {
1314
pub state: AppStateContext,
1415
pub logs: Vec<OperationLog>,

src/state/logger.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ mod tests {
151151
name: "object".to_string(),
152152
object_id: 1,
153153
},
154-
operation_form: Operation::Category(CategoryForm {
154+
operation_form: Some(Operation::Category(CategoryForm {
155155
name: "object".to_string(),
156156
path: "path".to_string(),
157-
}),
157+
})),
158158
};
159159

160160
for _i in 0..100 {
@@ -191,10 +191,10 @@ mod tests {
191191
name: "object".to_string(),
192192
object_id: 1,
193193
},
194-
operation_form: Operation::Category(CategoryForm {
194+
operation_form: Some(Operation::Category(CategoryForm {
195195
name: "object".to_string(),
196196
path: "path".to_string(),
197-
}),
197+
})),
198198
};
199199

200200
for i in 0..200 {

templates/logs.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

templates/logs/index.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{% extends "base.html" %}
2+
3+
{% block main %}
4+
<div class="container">
5+
<h1>Logs</h1>
6+
7+
<div class="log-container mt-4">
8+
{% for log in logs %}
9+
<div class="log-line">
10+
<code class="text-white">
11+
{% match log.operation_form %}
12+
{% when Some(operation_form) %}
13+
<details>
14+
<summary>
15+
{% include "logs/log_line.html" %}
16+
</summary>
17+
<p class="mt-2 mb-3">{{ operation_form }}</p>
18+
</details>
19+
{% when None %}
20+
<p class="mb-0">
21+
{% include "logs/log_line.html" %}
22+
</p>
23+
{% endmatch %}
24+
</code>
25+
</div>
26+
{% endfor %}
27+
<!-- Exemple de lignes de log -->
28+
</div>
29+
</div>
30+
{% endblock %}

templates/logs/log_line.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{ log.date.format("%Y-%m-%d %H:%M:%S").to_string() }} {% if let Some(log_user) = log.user %}{{ log_user }}{% endif %}
2+
<span class="
3+
{% match log.operation %}
4+
{% when OperationType::Create %}
5+
log-green
6+
{% when OperationType::Update %}
7+
log-yellow
8+
{% when OperationType::Delete %}
9+
log-red
10+
{% else %}
11+
{% endmatch %}
12+
"> {{ log.operation }}
13+
</span> on table <span class="log-table fw-bold">{{ log.table }}</span>: <span class="log-object">{{ log.operation_id.name }} ({{ log.operation_id.object_id }})</span>
14+

templates/menus/header.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<li><a class="dropdown-item" href="/categories/new">new</a></li>
2323
</ul>
2424
</li>
25+
<li class="nav-item">
26+
<a class="nav-link" href="/logs">Logs</a>
27+
</li>
2528
<!-- <li class="nav-item"> -->
2629
<!-- <a class="nav-link" href="/collection">Collections</a> -->
2730
<!-- </li> -->

0 commit comments

Comments
 (0)