add comments
This commit is contained in:
parent
8c6310eb61
commit
7c6efb4755
5 changed files with 48 additions and 5 deletions
|
@ -4,6 +4,7 @@ mod project;
|
||||||
mod task;
|
mod task;
|
||||||
|
|
||||||
pub use project::Project;
|
pub use project::Project;
|
||||||
|
pub use task::Comment;
|
||||||
pub use task::Task;
|
pub use task::Task;
|
||||||
|
|
||||||
use moka::sync::Cache;
|
use moka::sync::Cache;
|
||||||
|
@ -349,4 +350,9 @@ impl VikunjaAPI {
|
||||||
let user_id = user.first().unwrap().id;
|
let user_id = user.first().unwrap().id;
|
||||||
self.delete_request(&format!("/tasks/{task_id}/assignees/{user_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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,3 +34,12 @@ pub struct Task {
|
||||||
pub kanban_position: f64,
|
pub kanban_position: f64,
|
||||||
pub created_by: Option<User>,
|
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,
|
||||||
|
}
|
||||||
|
|
|
@ -68,6 +68,12 @@ pub fn get_args() -> clap::ArgMatches {
|
||||||
.arg(arg!([user] "User").required(true))
|
.arg(arg!([user] "User").required(true))
|
||||||
.arg(arg!([task_id] "Task ID").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(
|
.subcommand(
|
||||||
command!()
|
command!()
|
||||||
.name("fav")
|
.name("fav")
|
||||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -5,6 +5,10 @@ mod ui;
|
||||||
|
|
||||||
use api::{ProjectID, VikunjaAPI};
|
use api::{ProjectID, VikunjaAPI};
|
||||||
|
|
||||||
|
// todo : error handling
|
||||||
|
// todo : task relations
|
||||||
|
// todo : task comments
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let arg = args::get_args();
|
let arg = args::get_args();
|
||||||
let config_path = dirs::home_dir().unwrap().join(".config").join("vk.toml");
|
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());
|
api.assign_to_task(user, task_id.parse().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(("labels", label_args)) => match label_args.subcommand() {
|
Some(("comments", c_arg)) => {
|
||||||
Some(("ls", _)) => {
|
let task_id: &String = c_arg.get_one("task_id").unwrap();
|
||||||
ui::print_all_labels(&api);
|
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)) => {
|
Some(("rm", rm_label_arg)) => {
|
||||||
let title: &String = rm_label_arg.get_one("title").unwrap();
|
let title: &String = rm_label_arg.get_one("title").unwrap();
|
||||||
|
|
||||||
|
@ -106,7 +115,9 @@ fn main() {
|
||||||
color.map(|x| x.as_str()),
|
color.map(|x| x.as_str()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {
|
||||||
|
ui::print_all_labels(&api);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Some(("label", label_args)) => {
|
Some(("label", label_args)) => {
|
||||||
let label: &String = label_args.get_one("label").unwrap();
|
let label: &String = label_args.get_one("label").unwrap();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{Project, ProjectID, Task, VikunjaAPI},
|
api::{Comment, Project, ProjectID, Task, VikunjaAPI},
|
||||||
ui::{
|
ui::{
|
||||||
format_html_to_terminal, hex_to_color, is_in_past, parse_datetime, print_color,
|
format_html_to_terminal, hex_to_color, is_in_past, parse_datetime, print_color,
|
||||||
print_label, time_relative,
|
print_label, time_relative,
|
||||||
|
@ -171,3 +171,14 @@ pub fn print_task_info(task_id: isize, api: &VikunjaAPI) {
|
||||||
|
|
||||||
// pub percent_done: f64,
|
// 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!();
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue