Finished dev [unoptimized + debuginfo] target(s) in 59.76s

This commit is contained in:
famfo 2022-04-10 14:53:00 +02:00
parent 6ecb5dd41f
commit 768d91c5e9
3 changed files with 44 additions and 31 deletions

View file

@ -16,14 +16,11 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
use serde::Serialize;
use serde::{Deserialize, Serialize};
#[derive(Serialize)]
pub enum Status {
Ideas(),
Assigned(String),
InProgress(),
Done(),
#[derive(Deserialize)]
pub struct Request {
r#move: String,
}
#[derive(Debug, Serialize)]
@ -36,13 +33,13 @@ pub struct Task {
}
impl Task {
pub fn new(title: String, date: String, status: Status, assignee: String, description: String) -> Task {
let status = match status {
Status::Ideas() => "Ideas".to_string(),
Status::Assigned(u) => format!("Assiged to {}", u),
Status::InProgress() => "In prograss".to_string(),
Status::Done() => "Done".to_string(),
};
pub fn new(
title: String,
date: String,
status: String,
assignee: String,
description: String,
) -> Task {
Task {
title,
date,
@ -52,3 +49,9 @@ impl Task {
}
}
}
pub async fn handle_post(form: Request) -> impl warp::Reply {
// TODO: intelligent SQL code here (or maybe in another function idk, it's up to the reader to
// decide whats more intelligent)
warp::redirect(warp::http::Uri::from_static("/tmtd"))
}

View file

@ -27,7 +27,7 @@ use tracing::info;
use warp::Filter;
use warp_sessions::{CookieOptions, SameSiteCookieOption, SessionWithStore};
use crate::{Config, Database};
use crate::{task, Config, Database};
macro_rules! warp_try {
($expr:expr) => {
@ -129,24 +129,31 @@ impl App {
warp::reply::html(tera.render("hello.html", &ctx).unwrap())
}
}))
.or(warp::path!("tmtd" / String).map({
.or(warp::path("tmtd").map({
let tera = self.tera.clone();
move |_| {
move || {
let mut ctx = Context::new();
let mut tasks = Vec::new();
for _ in 0..3 {
let task_ctx = crate::task::Task::new("TODO".to_string(),
"TODO".to_string(),
crate::task::Status::Ideas(),
"TODO".to_string(),
"TODO".to_string());
for _ in 0..3 {
let task_ctx = task::Task::new(
"TODO".to_string(),
"TODO".to_string(),
"TODO".to_string(),
"TODO".to_string(),
"TODO".to_string(),
);
tasks.push(task_ctx);
}
ctx.insert("tasks", &tasks);
tracing::debug!("{:?}", tasks);
warp::reply::html(tera.render("task_page.html", &ctx).unwrap())
}
}));
}))
.or(warp::post()
.and(warp::path("api"))
.and(warp::path("issues"))
.and(warp::body::form::<task::Request>())
.then(task::handle_post));
let (_, server) =
warp::serve(route).bind_with_graceful_shutdown(self.config.listen_addr, async move {

View file

@ -10,11 +10,14 @@
{{task.description}}
<hr>
<label for="move">Move to:</label>
<select name="move" id="move">
<option value="ideas">ideas</option>
<option value="assigned">assigned</option>
<option value="in-progress">in progreess</option>
<option value="done">done</option>
<select>
<form action="/api/issues" method="post">
<label for="move">Move to:</label>
<select name="move" id="move">
<option value="Ideas">ideas</option>
<option value="Assigned">assigned</option>
<option value="InProgress">in progreess</option>
<option value="Done">done</option>
<input type="submit" value="Move">
</select>
</form>