Creating issues
This commit is contained in:
parent
768d91c5e9
commit
e0a88d78fa
43
src/task.rs
43
src/task.rs
|
@ -20,38 +20,23 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Request {
|
||||
r#move: String,
|
||||
pub r#move: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Create {
|
||||
pub title: String,
|
||||
pub status: String,
|
||||
pub assignee: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Task {
|
||||
title: String,
|
||||
date: String,
|
||||
status: String,
|
||||
assignee: String,
|
||||
description: String,
|
||||
pub title: String,
|
||||
pub date: String,
|
||||
pub status: String,
|
||||
pub assignee: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
impl Task {
|
||||
pub fn new(
|
||||
title: String,
|
||||
date: String,
|
||||
status: String,
|
||||
assignee: String,
|
||||
description: String,
|
||||
) -> Task {
|
||||
Task {
|
||||
title,
|
||||
date,
|
||||
status,
|
||||
assignee,
|
||||
description,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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"))
|
||||
}
|
||||
|
|
54
src/web.rs
54
src/web.rs
|
@ -26,6 +26,7 @@ use tokio::sync::broadcast;
|
|||
use tracing::info;
|
||||
use warp::Filter;
|
||||
use warp_sessions::{CookieOptions, SameSiteCookieOption, SessionWithStore};
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::{task, Config, Database};
|
||||
|
||||
|
@ -134,26 +135,43 @@ impl App {
|
|||
move || {
|
||||
let mut ctx = Context::new();
|
||||
let mut tasks = Vec::new();
|
||||
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(),
|
||||
);
|
||||
for _ in 0..10 {
|
||||
let task_ctx = task::Task {
|
||||
date: "TODO".to_string(),
|
||||
assignee: "TODO".to_string(),
|
||||
description: "TODO".to_string(),
|
||||
status: "TODO".to_string(),
|
||||
title: "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::path("task")
|
||||
.and(warp::path("create"))
|
||||
.map({
|
||||
let tera = self.tera.clone();
|
||||
move || {
|
||||
let ctx = Context::new();
|
||||
warp::reply::html(tera.render("create_task.html", &ctx).unwrap())
|
||||
}
|
||||
}))
|
||||
.or(warp::post()
|
||||
.and(warp::path("api"))
|
||||
.and(warp::path("issues"))
|
||||
.and(warp::path("task"))
|
||||
.and(warp::path("move"))
|
||||
.and(warp::body::form::<task::Request>())
|
||||
.then(task::handle_post));
|
||||
.then(handle_post)
|
||||
)
|
||||
.or(warp::post()
|
||||
.and(warp::path("api"))
|
||||
.and(warp::path("task"))
|
||||
.and(warp::path("create"))
|
||||
.and(warp::body::form::<task::Create>())
|
||||
.then(handle_post_create)
|
||||
);
|
||||
|
||||
let (_, server) =
|
||||
warp::serve(route).bind_with_graceful_shutdown(self.config.listen_addr, async move {
|
||||
|
@ -163,3 +181,17 @@ impl App {
|
|||
info!("Web app has been shut down");
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_post(form: task::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)
|
||||
tracing::debug!("Got POST on /api/task/move: {}", form.r#move);
|
||||
warp::redirect(warp::http::Uri::from_static("/"))
|
||||
}
|
||||
|
||||
pub async fn handle_post_create(form: task::Create)-> impl warp::Reply {
|
||||
let date = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap();
|
||||
tracing::debug!("Got POST on /api/task/create: {:?}, date: {:?}", form, date);
|
||||
warp::redirect(warp::http::Uri::from_static("/"))
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,33 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>tmtd</title>
|
||||
<style>
|
||||
form {
|
||||
margin-left: 2%;
|
||||
margin-right: 2%;
|
||||
}
|
||||
input[type=text] {
|
||||
width: 100%;
|
||||
padding: 2px 2px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
input[type=submit] {
|
||||
padding: 2px 2px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
select {
|
||||
width: 100%;
|
||||
padding: 2px 2px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
textarea {
|
||||
width: 100%;
|
||||
padding: 2px 2px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
{% block content %} {% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
35
templates/create_task.html
Normal file
35
templates/create_task.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
logo or something<br>
|
||||
navbar<br>
|
||||
|
||||
<a href="/tasks">tasks</a> |
|
||||
<a href="/users">users</a> |
|
||||
(<a href="/admin">admin panel</a>)
|
||||
|
||||
<hr>
|
||||
<form action="/api/task/create" method="post">
|
||||
<label for="title">Title</label><br>
|
||||
<input type="text" id="title" name="title" style="width:fit-content"><br>
|
||||
|
||||
<label for="status">Status</label><br>
|
||||
<select name="status" id="status">
|
||||
<option value="ideas">ideas</option>
|
||||
<option value="assigned">assigned</option>
|
||||
<option value="in-progress">in progreess</option>
|
||||
<option value="done">done</option>
|
||||
</select><br>
|
||||
|
||||
<label for="assignee">Assignee</label><br>
|
||||
<input type="text" id="assignee" name="assignee"><br>
|
||||
|
||||
<label for="description">Description</label><br>
|
||||
<textarea rows="3" cols="30" name="description" id="description"></textarea><br>
|
||||
|
||||
<input type="submit" value="create"><br>
|
||||
</form>
|
||||
|
||||
|
||||
{% endblock content %}
|
1
templates/form.css
Normal file
1
templates/form.css
Normal file
|
@ -0,0 +1 @@
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
{{task.description}}
|
||||
<hr>
|
||||
|
||||
<form action="/api/issues" method="post">
|
||||
<label for="move">Move to:</label>
|
||||
<select name="move" id="move">
|
||||
<form action="/api/task/move" method="post">
|
||||
<label for="move_task">Move to:</label>
|
||||
<select name="move_task" id="move_task" style="width:auto">
|
||||
<option value="Ideas">ideas</option>
|
||||
<option value="Assigned">assigned</option>
|
||||
<option value="InProgress">in progreess</option>
|
||||
|
|
|
@ -10,8 +10,10 @@ navbar<br>
|
|||
(<a href="/admin">admin panel</a>)
|
||||
|
||||
<hr>
|
||||
<a href="api/task/create">Create issue</a><br><br>
|
||||
|
||||
<label for="group">Task group</label>
|
||||
<select name="group" id="group">
|
||||
<select name="group" id="group" style="width:auo">
|
||||
<option value="ideas">ideas</option>
|
||||
<option value="assigned">assigned</option>
|
||||
<option value="in-progress">in progreess</option>
|
||||
|
|
Loading…
Reference in a new issue