feat: add layout to all pages
This commit is contained in:
parent
02639175f4
commit
de3defefa6
12 changed files with 155 additions and 66 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -971,9 +971,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "minijinja"
|
||||
version = "1.0.21"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55e877d961d4f96ce13615862322df7c0b6d169d40cab71a7ef3f9b9e594451e"
|
||||
checksum = "45f7e8e35b6c7b169bf40b0176d2c79291ab8ee53290b84e0668ab21d841aa9d"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
|
|
@ -13,7 +13,7 @@ anyhow = "1.0.75"
|
|||
clap = "4.5.4"
|
||||
tokio = { version = "1.37.0", features = ["full"] }
|
||||
axum = { version = "0.7.5", features = ["json"] }
|
||||
minijinja = { version = "1.0.20", features = ["builtins"] }
|
||||
minijinja = { version = "2.1", features = ["builtins"] }
|
||||
uuid = { version = "1.8.0", features = ["serde", "v4"] }
|
||||
fully_pub = "0.1.4"
|
||||
log = "0.4.22"
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
table {
|
||||
width: 100%;
|
||||
}
|
||||
table tbody tr td:first-child {
|
||||
padding-right: 3rem !important;
|
||||
}
|
|
@ -74,7 +74,7 @@ body {
|
|||
font-size: 1.15rem;
|
||||
line-height: 1.5;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr min(45rem, 90%) 1fr;
|
||||
grid-template-columns: 1fr min(50rem, 90%) 1fr;
|
||||
margin: 0;
|
||||
}
|
||||
body > * {
|
||||
|
|
|
@ -19,7 +19,7 @@ tasks:
|
|||
- ls
|
||||
- /etc/fstab
|
||||
schedule:
|
||||
seconds: 15
|
||||
hours: 1
|
||||
|
||||
clean_up:
|
||||
name: Clean up things
|
||||
|
@ -27,6 +27,6 @@ tasks:
|
|||
command:
|
||||
- cat
|
||||
- /etc/environment
|
||||
schedule:
|
||||
"0 * * * * *"
|
||||
# schedule:
|
||||
# "0 * * * * *"
|
||||
|
||||
|
|
|
@ -19,11 +19,14 @@ pub async fn home(
|
|||
)
|
||||
}
|
||||
|
||||
pub async fn list_tasks(State(app_state): State<AppState>) -> Html<String> {
|
||||
Html(render!(
|
||||
include_str!("./templates/pages/list_tasks.html"),
|
||||
tasks => Vec::from_iter(app_state.config.tasks.iter())
|
||||
))
|
||||
pub async fn list_tasks(State(app_state): State<AppState>) -> impl IntoResponse {
|
||||
Html(
|
||||
app_state.templating_env.get_template("pages/list_tasks.html").unwrap()
|
||||
.render(context!(
|
||||
tasks => Vec::from_iter(app_state.config.tasks.iter())
|
||||
))
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn trigger_task(
|
||||
|
@ -50,10 +53,13 @@ pub async fn trigger_task(
|
|||
|
||||
(
|
||||
StatusCode::OK,
|
||||
Html(render!(
|
||||
include_str!("./templates/pages/run_task.html"),
|
||||
task => task
|
||||
)),
|
||||
Html(
|
||||
app_state.templating_env.get_template("pages/run_task.html").unwrap()
|
||||
.render(context!(
|
||||
task => task
|
||||
))
|
||||
.unwrap()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -70,7 +76,7 @@ pub async fn list_task_runs(
|
|||
State(app_state): State<AppState>,
|
||||
ExtractPath(task_id): ExtractPath<String>,
|
||||
) -> Html<String> {
|
||||
let runs = sqlx::query_as::<_, TaskRunSummary>("SELECT id,status,trigger_mode,submitted_at,started_at,ended_at FROM task_runs WHERE task_id = $1 LIMIT 100")
|
||||
let runs = sqlx::query_as::<_, TaskRunSummary>("SELECT id,status,trigger_mode,submitted_at,started_at,ended_at FROM task_runs WHERE task_id = $1")
|
||||
.bind(&task_id)
|
||||
.fetch_all(&app_state.db)
|
||||
.await
|
||||
|
@ -81,11 +87,15 @@ pub async fn list_task_runs(
|
|||
return Html("<h1>Task not found</h1>".to_string());
|
||||
}
|
||||
};
|
||||
Html(render!(
|
||||
include_str!("./templates/pages/list_task_runs.html"),
|
||||
task => task,
|
||||
runs => runs,
|
||||
))
|
||||
Html(
|
||||
app_state.templating_env.get_template("pages/list_task_runs.html").unwrap()
|
||||
.render(context!(
|
||||
task_id => task_id,
|
||||
task => task,
|
||||
runs => runs
|
||||
))
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn get_task_run(
|
||||
|
@ -102,8 +112,12 @@ pub async fn get_task_run(
|
|||
}
|
||||
};
|
||||
|
||||
Html(render!(
|
||||
include_str!("./templates/pages/task_run_details.html"),
|
||||
run => run_details
|
||||
))
|
||||
Html(
|
||||
app_state.templating_env.get_template("pages/task_run_details.html").unwrap()
|
||||
.render(context!(
|
||||
run => run_details
|
||||
))
|
||||
.unwrap()
|
||||
)
|
||||
}
|
||||
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -48,12 +48,19 @@ async fn main() -> Result<()> {
|
|||
|
||||
let config: Config = get_config().expect("Cannot get config");
|
||||
let mut templating_env = Environment::new();
|
||||
|
||||
templating_env
|
||||
.add_template("layouts/base.html", include_str!("./templates/layouts/base.html"))
|
||||
.unwrap();
|
||||
templating_env
|
||||
.add_template("pages/home.html", include_str!("./templates/pages/home.html"))
|
||||
.unwrap();
|
||||
for path in fs::read_dir("./src/templates/pages").unwrap() {
|
||||
let file_name = path.unwrap().file_name().into_string().unwrap();
|
||||
let path = format!("./src/templates/pages/{}", file_name);
|
||||
let content: &'static str = Box::leak(fs::read_to_string(&path).unwrap().into_boxed_str());
|
||||
let path: &'static str = Box::leak(format!("pages/{}", file_name).into_boxed_str());
|
||||
templating_env
|
||||
.add_template(&path, &content)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let state = AppState {
|
||||
config,
|
||||
|
|
|
@ -8,8 +8,18 @@
|
|||
<link href="/assets/styles/app.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<header>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><a href="/tasks">Tasks</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</header>
|
||||
<main class="container">
|
||||
{% block body %}{% endblock %}
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
Autotasker
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,6 +1,32 @@
|
|||
<h1>List of task runs for "{{ task.name }}"</h1>
|
||||
<ul>
|
||||
{% for task_run in runs %}
|
||||
<li><a href="/tasks/{{ task.id }}/runs/{{ task_run.id }}">{{ task_run.id }}</a> {{ task_run.status }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% extends "layouts/base.html" %}
|
||||
{% block body %}
|
||||
<h1>List of task runs for "{{ task.name }}"</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Date</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for task_run in runs %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ task_run.id | split("-") | first }}
|
||||
</td>
|
||||
<td>
|
||||
{{ task_run.started_at }}
|
||||
</td>
|
||||
<td>
|
||||
{{ task_run.status }}
|
||||
</td>
|
||||
<td>
|
||||
<a href="/tasks/{{ task_id }}/runs/{{ task_run.id }}">Details</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,13 +1,34 @@
|
|||
<h1>Tasks</h1>
|
||||
{% if tasks | length == 0 %}
|
||||
No tasks were configured.
|
||||
{% endif %}
|
||||
<ul>
|
||||
{% for (id, task) in tasks %}
|
||||
<li>
|
||||
{{ task.name }}
|
||||
<a href="/tasks/{{ id }}/trigger">Trigger task</a>
|
||||
<a href="/tasks/{{ id }}/runs">See runs</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% extends "layouts/base.html" %}
|
||||
{% block body %}
|
||||
<h1>Tasks</h1>
|
||||
{% if tasks | length == 0 %}
|
||||
<p>
|
||||
No tasks were configured.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Trigger</th>
|
||||
<th>See runs</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for (id, task) in tasks %}
|
||||
<tr>
|
||||
<td>
|
||||
{{ task.name }}
|
||||
</td>
|
||||
<td>
|
||||
<a href="/tasks/{{ id }}/trigger">Trigger task</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/tasks/{{ id }}/runs">See runs</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1 +1,6 @@
|
|||
Task "{{ task.name }}" triggered!
|
||||
{% extends "layouts/base.html" %}
|
||||
{% block body %}
|
||||
<p>
|
||||
Task "{{ task.name }}" triggered!
|
||||
</p>
|
||||
{% endblock %}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
<h1>Task run {{ run.id }}</h1>
|
||||
{% extends "layouts/base.html" %}
|
||||
{% block body %}
|
||||
<h1>Task run details</h1>
|
||||
<ul>
|
||||
<li>Id: {{ run.id }}</li>
|
||||
<li>State: {{ run.status }}</li>
|
||||
<li>Submitted at: {{ run.submitted_at }}</li>
|
||||
<li>Started at: {{ run.started_at }}</li>
|
||||
<li>Ended at: {{ run.ended_at }}</li>
|
||||
<li>Trigger Mode: {{ run.trigger_mode }}</li>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li>Id: {{ run.id }}</li>
|
||||
<li>State: {{ run.status }}</li>
|
||||
<li>Submitted at: {{ run.submitted_at }}</li>
|
||||
<li>Started at: {{ run.started_at }}</li>
|
||||
<li>Ended at: {{ run.ended_at }}</li>
|
||||
<li>Trigger Mode: {{ run.trigger_mode }}</li>
|
||||
</ul>
|
||||
|
||||
<h3>Logs</h3>
|
||||
<p>Exit code is {{ run.exit_code }}</p>
|
||||
<pre>
|
||||
{{ run.logs }}
|
||||
</pre>
|
||||
<h3>Logs</h3>
|
||||
<p>Exit code is {{ run.exit_code }}</p>
|
||||
<pre>{{ run.logs }}</pre>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue