add comments

This commit is contained in:
JMARyA 2024-06-07 08:36:34 +02:00
parent 8c6310eb61
commit 7c6efb4755
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 48 additions and 5 deletions

View file

@ -4,6 +4,7 @@ mod project;
mod task;
pub use project::Project;
pub use task::Comment;
pub use task::Task;
use moka::sync::Cache;
@ -349,4 +350,9 @@ impl VikunjaAPI {
let user_id = user.first().unwrap().id;
self.delete_request(&format!("/tasks/{task_id}/assignees/{user_id}"));
}
pub fn get_task_comments(&self, task_id: isize) -> Vec<Comment> {
let resp = self.get_request(&format!("/tasks/{task_id}/comments"));
serde_json::from_str(&resp).unwrap()
}
}

View file

@ -34,3 +34,12 @@ pub struct Task {
pub kanban_position: f64,
pub created_by: Option<User>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Comment {
pub author: User,
pub comment: String,
pub created: String,
pub id: isize,
pub updated: String,
}

View file

@ -68,6 +68,12 @@ pub fn get_args() -> clap::ArgMatches {
.arg(arg!([user] "User").required(true))
.arg(arg!([task_id] "Task ID").required(true)),
)
.subcommand(
command!()
.name("comments")
.about("Show task comments")
.arg(arg!([task_id] "Task ID").required(true)),
)
.subcommand(
command!()
.name("fav")

View file

@ -5,6 +5,10 @@ mod ui;
use api::{ProjectID, VikunjaAPI};
// todo : error handling
// todo : task relations
// todo : task comments
fn main() {
let arg = args::get_args();
let config_path = dirs::home_dir().unwrap().join(".config").join("vk.toml");
@ -86,10 +90,15 @@ fn main() {
api.assign_to_task(user, task_id.parse().unwrap());
}
}
Some(("labels", label_args)) => match label_args.subcommand() {
Some(("ls", _)) => {
ui::print_all_labels(&api);
Some(("comments", c_arg)) => {
let task_id: &String = c_arg.get_one("task_id").unwrap();
let comments = api.get_task_comments(task_id.parse().unwrap());
for comment in comments {
ui::task::print_comment(&comment);
}
}
Some(("labels", label_args)) => match label_args.subcommand() {
Some(("rm", rm_label_arg)) => {
let title: &String = rm_label_arg.get_one("title").unwrap();
@ -106,7 +115,9 @@ fn main() {
color.map(|x| x.as_str()),
);
}
_ => {}
_ => {
ui::print_all_labels(&api);
}
},
Some(("label", label_args)) => {
let label: &String = label_args.get_one("label").unwrap();

View file

@ -1,5 +1,5 @@
use crate::{
api::{Project, ProjectID, Task, VikunjaAPI},
api::{Comment, Project, ProjectID, Task, VikunjaAPI},
ui::{
format_html_to_terminal, hex_to_color, is_in_past, parse_datetime, print_color,
print_label, time_relative,
@ -171,3 +171,14 @@ pub fn print_task_info(task_id: isize, api: &VikunjaAPI) {
// pub percent_done: f64,
}
pub fn print_comment(comment: &Comment) {
print_color(crossterm::style::Color::Blue, &comment.author.username);
print!(
" ({}): ",
time_relative(parse_datetime(&comment.created).unwrap())
);
println!();
print!("{}", format_html_to_terminal(&comment.comment));
println!();
}