Add: Duration field in Stamp

main
Óscar M. Lage 2021-11-22 18:48:11 +01:00
parent 56e02021c7
commit 5ce6fb8f60
2 changed files with 24 additions and 10 deletions

View File

@ -112,7 +112,7 @@ fn main() {
match task {
0 => panic!("Need some task number to add the stamp"),
_ => {
let stamp = Stamp::new(&config_file, dstart, dend, description, task);
let stamp = Stamp::new(&config_file, dstart, dend, description, task, "");
let added = stamp.api_post(&config_file, "stamp/add");
match added.status() {
reqwest::StatusCode::OK => println!("OK"),
@ -124,7 +124,7 @@ fn main() {
// gst stamp --stop
else if stop == 1 {
console::info("Stop last stamp");
let stamp = Stamp::new(&config_file, "", "", "", 0);
let stamp = Stamp::new(&config_file, "", "", "", 0, "");
let stopped = stamp.api_post(&config_file, "stamp/stop");
match stopped.status() {
reqwest::StatusCode::OK => println!("OK"),
@ -134,7 +134,7 @@ fn main() {
// gst stamp --update --description "desc" --dstart "20120101" --dend "20120101"
else if update == 1 {
console::info("Update last stamp");
let stamp = Stamp::new(&config_file, dstart, dend, description, task);
let stamp = Stamp::new(&config_file, dstart, dend, description, task, "");
let updated = stamp.api_post(&config_file, "stamp/update");
match updated.status() {
reqwest::StatusCode::OK => println!("OK"),

View File

@ -12,6 +12,7 @@ pub struct Stamp {
pub end: Option<String>,
pub description: Option<String>,
pub task_id: Option<u32>,
pub duration: Option<String>,
}
impl Stamp {
@ -19,7 +20,8 @@ impl Stamp {
dstart: &str,
dend: &str,
description: &str,
task: u32
task: u32,
duration: &str,
) -> Stamp {
// Config
let mut default_config = config::Config::default();
@ -32,6 +34,7 @@ impl Stamp {
end: Some(dend.to_string()),
description: Some(description.to_string()),
task_id: Some(task),
duration: Some(duration.to_string()),
}
}
@ -80,19 +83,30 @@ impl Stamps {
let stamps = parsed.json::<Stamps>().unwrap();
// eprintln!("{:#?}", stamps);
for stamp in stamps.data {
let mut open: String = String::from("");
match stamp.end {
None => open = "⏸️ ".to_string(),
_ => {
let op: String = format_args!("{duration}",
duration=stamp.duration.unwrap().to_string()
).to_string();
open = op;
}
}
let output: String = format_args!("⏳ ({id}) {open} - {description}",
open=open,
id=stamp.id,
description=stamp.description.unwrap()
).to_string();
match project {
0 => {
println!("⏳ ({id}) {description}",
id=stamp.id,
description=stamp.description.unwrap());
println!("{}", output);
if last != 0 { break; }
},
_ => {
if project == stamp.project_id {
println!("⏳ ({id}) {description}",
id=stamp.id,
description=stamp.description.unwrap());
println!("{}", output);
if last != 0 { break; }
}
}