This commit is contained in:
JMARyA 2024-06-06 19:55:09 +02:00
parent 71abc0ca74
commit ad97a36c60
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 17 additions and 6 deletions

View file

@ -282,11 +282,12 @@ impl VikunjaAPI {
serde_json::from_str(&resp).unwrap()
}
pub fn done_task(&self, task_id: isize) -> Task {
pub fn done_task(&self, task_id: isize, done: bool) -> Task {
let resp = self.post_request(
&format!("/tasks/{task_id}"),
&serde_json::json!({
"done": true
"done": done,
"done_at": if done { Some(chrono::Utc::now().to_rfc3339()) } else { None }
}),
);
serde_json::from_str(&resp).unwrap()

View file

@ -32,5 +32,5 @@ pub struct Task {
pub bucket_id: usize,
pub position: f64,
pub kanban_position: f64,
pub created_by: User,
pub created_by: Option<User>,
}

View file

@ -104,6 +104,7 @@ pub fn get_args() -> clap::ArgMatches {
.subcommand(
command!()
.name("done")
.arg(arg!(-u --undo "Undo completing the task").required(false))
.about("Mark task as done")
.arg(arg!([task_id] "Task ID").required(true)),
)

View file

@ -128,7 +128,9 @@ fn main() {
}
Some(("done", done_args)) => {
let task_id: &String = done_args.get_one("task_id").unwrap();
api.done_task(task_id.parse().unwrap());
let done = !done_args.get_flag("undo");
api.done_task(task_id.parse().unwrap(), done);
ui::task::print_task_info(task_id.parse().unwrap(), &api);
}
_ => {
let done = arg.get_flag("done");

View file

@ -94,7 +94,11 @@ pub fn print_task_info(task_id: isize, api: &VikunjaAPI) {
crossterm::style::Color::Green,
&format!(
"{} ✓ ",
time_relative(parse_datetime(&task.done_at).unwrap())
if let Some(dt) = parse_datetime(&task.done_at) {
time_relative(dt)
} else {
String::new()
}
),
);
}
@ -110,7 +114,10 @@ pub fn print_task_info(task_id: isize, api: &VikunjaAPI) {
&format!(" [{}]\n", api.get_project_name_from_id(task.project_id)),
);
println!("Created by {}", task.created_by.username);
if let Some(user) = task.created_by {
println!("Created by {}", user.username);
}
println!(
"Created: {} | Updated: {}",
time_relative(parse_datetime(&task.created).unwrap()),