Handler for all pages defined in the navbar

This commit is contained in:
famfo 2022-05-13 17:11:56 +02:00
parent 163fa89e05
commit 0f0cb303fc
6 changed files with 67 additions and 8 deletions

View file

@ -54,14 +54,14 @@ impl Database {
// Async might become a problem here
pub fn get_tasks(&self) -> templates::Tasks {
// TODO: actually get the issues from the db
// TODO: actually get the issues from the db based on the category cookies
let vec = vec![templates::Task {
title: "TODO".to_string(),
date: "TODO".to_string(), // Convert from unix timestamps to
title: "finish tmtd".to_string(),
date: "yesterday".to_string(), // Convert from unix timestamps to
// the actual date, also timezone info?
status: "TODO".to_string(),
assignee: "TODO".to_string(),
description: "TODO".to_string(),
status: "assigned".to_string(),
assignee: "tmtd contributers".to_string(),
description: "DO SOMETHING AAAAAAA".to_string(),
id: 1,
}];

View file

@ -18,6 +18,18 @@
use askama::Template;
#[derive(Template)]
#[template(path = "index.html")]
pub struct Index();
#[derive(Template)]
#[template(path = "users.html")]
pub struct Users();
#[derive(Template)]
#[template(path = "admin.html")]
pub struct AdminPanel();
#[derive(Template)]
#[template(path = "task/task_page.html")]
pub struct Tasks {

View file

@ -31,9 +31,12 @@ impl App {
let db = db.clone();
let server = HttpServer::new(move || {
actix_web::App::new().service((
web::resource("/").route(web::get().to(index)),
web::resource("/users").route(web::get().to(users)),
web::resource("/task")
.app_data(web::Data::new(db.clone()))
.route(web::get().to(task)),
.route(web::get().to(tasks)),
web::resource("/admin").route(web::get().to(admin)),
web::resource("/create").route(web::get().to(create)),
web::resource("/login").route(web::get().to(login)),
web::resource("/register").route(web::get().to(register)),
@ -58,12 +61,30 @@ impl App {
}
}
async fn task(db: web::Data<Arc<Database>>) -> impl Responder {
async fn index() -> impl Responder {
let index = templates::Index {};
let html = index.render().unwrap();
HttpResponseBuilder::new(StatusCode::OK).body(html)
}
async fn tasks(db: web::Data<Arc<Database>>) -> impl Responder {
let tasks = db.get_tasks();
let html = tasks.render().unwrap();
HttpResponseBuilder::new(StatusCode::OK).body(html)
}
async fn users() -> impl Responder {
let users = templates::Users {};
let html = users.render().unwrap();
HttpResponseBuilder::new(StatusCode::OK).body(html)
}
async fn admin() -> impl Responder {
let admin_panel = templates::AdminPanel {};
let html = admin_panel.render().unwrap();
HttpResponseBuilder::new(StatusCode::OK).body(html)
}
async fn create() -> impl Responder {
let create = templates::CreateTask {};
let html = create.render().unwrap();

8
templates/admin.html Normal file
View file

@ -0,0 +1,8 @@
{% extends "base.html" %}
{% block content %}
{% include "navbar.html" %}
{% endblock content %}

10
templates/index.html Normal file
View file

@ -0,0 +1,10 @@
{% extends "base.html" %}
{% block content %}
{% include "navbar.html" %}
Dashboard or something?
{% endblock content %}

8
templates/users.html Normal file
View file

@ -0,0 +1,8 @@
{% extends "base.html" %}
{% block content %}
{% include "navbar.html" %}
{% endblock content %}