feat: add block layout for home page with CSS

This commit is contained in:
Matthieu Bessat 2024-07-22 12:07:02 +02:00
parent 282b719e61
commit c2a2721ec6
13 changed files with 842 additions and 351 deletions

View file

@ -2,23 +2,28 @@ use crate::models::{Task, TaskRun, TaskRunSummary};
use axum::extract::{Path as ExtractPath, State};
use axum::http::StatusCode;
use axum::Json;
use axum::response::Html;
use minijinja::render;
use axum::response::{Html, IntoResponse, Response};
use axum_template::RenderHtml;
use minijinja::{context, render};
use uuid::Uuid;
use crate::models::ExecutorOrder;
use crate::AppState;
use crate::{AppState};
pub async fn home() -> Html<String> {
Html(render!(
include_str!("./templates/home.html"),
))
pub async fn home(
State(app_state): State<AppState>
) -> impl IntoResponse {
Html(
app_state.template_engine.get_template("pages/home.html").unwrap()
.render(context!())
.unwrap()
)
}
pub async fn list_tasks(State(app_state): State<AppState>) -> Html<String> {
let tasks: Vec<Task> = app_state.config.tasks;
Html(render!(
include_str!("./templates/list_tasks.html"),
include_str!("./templates/pages/list_tasks.html"),
tasks => tasks
))
}
@ -49,7 +54,7 @@ pub async fn trigger_task(
(
StatusCode::OK,
Html(render!(
include_str!("./templates/run_task.html"),
include_str!("./templates/pages/run_task.html"),
tasks => tasks
)),
)
@ -80,7 +85,7 @@ pub async fn list_task_runs(
}
};
Html(render!(
include_str!("./templates/list_task_runs.html"),
include_str!("./templates/pages/list_task_runs.html"),
task => task,
runs => runs,
))
@ -102,7 +107,7 @@ pub async fn get_task_run(
};
Html(render!(
include_str!("./templates/task_run_details.html"),
include_str!("./templates/pages/task_run_details.html"),
run => run_details
))
}

View file

@ -2,12 +2,15 @@ mod controllers;
mod models;
mod executor;
use axum_template::engine::Engine;
use log::info;
use anyhow::{anyhow, Context, Result};
use axum::routing::get;
use axum::Router;
use minijinja::Environment;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::{ConnectOptions, Pool, Sqlite};
use tower_http::services::ServeDir;
use std::fs;
use std::str::FromStr;
use std::sync::Arc;
@ -20,6 +23,7 @@ pub struct AppState {
config: Config,
db: Pool<Sqlite>,
executor_tx: Arc<Sender<ExecutorOrder>>,
template_engine: Environment<'static>
}
fn get_config() -> Result<Config> {
@ -42,10 +46,17 @@ async fn main() -> Result<()> {
let (tx, rx) = mpsc::channel::<ExecutorOrder>(32);
let config: Config = get_config().expect("Cannot get config");
let mut jinja = Environment::new();
jinja
.add_template("layouts/base.html", include_str!("./templates/layouts/base.html"))
.unwrap();
jinja.add_template("pages/home.html", include_str!("./templates/pages/home.html")).unwrap();
let state = AppState {
config,
db: pool,
executor_tx: Arc::new(tx),
template_engine: jinja
};
// start executor daemon
@ -65,6 +76,7 @@ async fn main() -> Result<()> {
get(controllers::get_task_run),
)
.route("/webhooks/:token", get(controllers::handle_webhook))
.nest_service("/assets", ServeDir::new("./assets"))
.with_state(state);
let listen_addr = "0.0.0.0:8085";

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Autotasker</title>
<link href="/assets/styles/simple.css" rel="stylesheet">
<link href="/assets/styles/app.css" rel="stylesheet">
</head>
<body>
<div class="container">
{% block body %}{% endblock %}
</div>
</body>
</html>

View file

@ -1,3 +1,5 @@
{% extends "layouts/base.html" %}
{% block body %}
<h1>Hello welcome on autotasker</h1>
You main want to start in here.
@ -10,3 +12,4 @@ Autotasker is free software under <a href="https://www.gnu.org/licenses/gpl-3.0.
You can find source code on a <a href="https://forge.lefuturiste.fr/mbess/autotasker">self-hosted forge repository</a>.
</p>
{% endblock %}