Add ID reporting in imag-timetrack

This commit is contained in:
Matthias Beyer 2018-11-02 11:23:48 +01:00
parent be56f9fe75
commit f6483f54db
9 changed files with 57 additions and 19 deletions

View file

@ -81,11 +81,16 @@ pub fn cont(rt: &Runtime) -> i32 {
acc.and_then(|_| { acc.and_then(|_| {
// create a new tracking with the same tag // create a new tracking with the same tag
tracking let val = tracking
.get_timetrack_tag() .get_timetrack_tag()
.and_then(|tag| rt.store().create_timetracking_now(&tag)) .and_then(|tag| rt.store().create_timetracking_now(&tag))
.map(|_| 0) .map(|_| 0)
.map_err_trace() .map_err_trace();
let _ = rt.report_touched(tracking.get_location())
.map_err_trace_exit_unwrap(1);
val
}) })
}) })
}, },

View file

@ -103,6 +103,9 @@ pub fn day(rt: &Runtime) -> i32 {
let end = e.get_end_datetime()?; let end = e.get_end_datetime()?;
debug!(" -> end = {:?}", end); debug!(" -> end = {:?}", end);
let _ = rt.report_touched(e.get_location())
.map_err_trace_exit_unwrap(1);
Ok((tag, start, end)) Ok((tag, start, end))
}) })
.trace_unwrap_exit(1) .trace_unwrap_exit(1)

View file

@ -162,6 +162,9 @@ pub fn list_impl(rt: &Runtime,
.collect(); .collect();
tab.add_row(Row::new(cells)); tab.add_row(Row::new(cells));
let _ = rt.report_touched(e.get_location())
.map_err_trace_exit_unwrap(1);
Ok(tab) Ok(tab)
}) })
}) })

View file

@ -118,6 +118,9 @@ pub fn month(rt: &Runtime) -> i32 {
let end = e.get_end_datetime()?; let end = e.get_end_datetime()?;
debug!(" -> end = {:?}", end); debug!(" -> end = {:?}", end);
let _ = rt.report_touched(e.get_location())
.map_err_trace_exit_unwrap(1);
Ok((tag, start, end)) Ok((tag, start, end))
}) })
.trace_unwrap_exit(1) .trace_unwrap_exit(1)

View file

@ -24,9 +24,9 @@ use failure::Error;
use libimagrt::runtime::Runtime; use libimagrt::runtime::Runtime;
use libimagerror::trace::trace_error; use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace;
use libimagtimetrack::tag::TimeTrackingTag; use libimagtimetrack::tag::TimeTrackingTag;
use libimagtimetrack::timetrackingstore::TimeTrackStore; use libimagtimetrack::timetrackingstore::TimeTrackStore;
use libimagerror::trace::MapErrTrace;
pub fn start(rt: &Runtime) -> i32 { pub fn start(rt: &Runtime) -> i32 {
let (_, cmd) = rt.cli().subcommand(); let (_, cmd) = rt.cli().subcommand();
@ -49,11 +49,18 @@ pub fn start(rt: &Runtime) -> i32 {
.map(String::from) .map(String::from)
.map(TimeTrackingTag::from) .map(TimeTrackingTag::from)
.fold(0, |acc, ttt| { .fold(0, |acc, ttt| {
rt.store() match rt.store().create_timetracking_at(&start, &ttt) {
.create_timetracking_at(&start, &ttt) Err(e) => {
.map_err_trace() trace_error(&e);
.map(|_| acc) 1
.unwrap_or(1) },
Ok(entry) => {
let _ = rt.report_touched(entry.get_location())
.map_err_trace_exit_unwrap(1);
acc
}
}
}) })
} }

View file

@ -34,7 +34,6 @@ use libimagtimetrack::timetrackingstore::*;
use libimagtimetrack::iter::filter::has_end_time; use libimagtimetrack::iter::filter::has_end_time;
use libimagtimetrack::iter::filter::has_one_of_tags; use libimagtimetrack::iter::filter::has_one_of_tags;
use libimagutil::warn_result::*; use libimagutil::warn_result::*;
use libimagutil::debug_result::*;
pub fn stop(rt: &Runtime) -> i32 { pub fn stop(rt: &Runtime) -> i32 {
let (_, cmd) = rt.cli().subcommand(); let (_, cmd) = rt.cli().subcommand();
@ -92,10 +91,18 @@ pub fn stop(rt: &Runtime) -> i32 {
// for each of these timetrackings, end them // for each of these timetrackings, end them
// for each result, print the backtrace (if any) // for each result, print the backtrace (if any)
.fold(0, |acc, mut elem| { .fold(0, |acc, mut elem| {
elem.set_end_datetime(stop_time.clone()) match elem.set_end_datetime(stop_time.clone()) {
.map_dbg(|e| format!("Setting end time worked: {:?}", e)) Err(e) => {
.map(|_| acc) trace_error(&e);
.map_err_trace_exit_unwrap(1) 1
}
Ok(_) => {
format!("Setting end time worked: {:?}", elem);
let _ = rt.report_touched(elem.get_location())
.map_err_trace_exit_unwrap(1);
acc
}
}
}) })
} }

View file

@ -81,12 +81,16 @@ pub fn track(rt: &Runtime) -> i32 {
.unwrap() // enforced by clap .unwrap() // enforced by clap
.map(String::from) .map(String::from)
.map(TimeTrackingTag::from) .map(TimeTrackingTag::from)
.fold(0, |acc, ttt| { .fold(0, |acc, ttt| match rt.store().create_timetracking(&start, &stop, &ttt) {
rt.store() Err(e) => {
.create_timetracking(&start, &stop, &ttt) trace_error(&e);
.map_err_trace() 1
.map(|_| acc) },
.unwrap_or(1) Ok(entry) => {
let _ = rt.report_touched(entry.get_location())
.map_err_trace_exit_unwrap(1);
acc
}
}) })
} }

View file

@ -116,6 +116,9 @@ pub fn week(rt: &Runtime) -> i32 {
let end = e.get_end_datetime()?; let end = e.get_end_datetime()?;
debug!(" -> end = {:?}", end); debug!(" -> end = {:?}", end);
let _ = rt.report_touched(e.get_location())
.map_err_trace_exit_unwrap(1);
Ok((tag, start, end)) Ok((tag, start, end))
}) })
.trace_unwrap_exit(1) .trace_unwrap_exit(1)

View file

@ -116,6 +116,9 @@ pub fn year(rt: &Runtime) -> i32 {
let end = e.get_end_datetime()?; let end = e.get_end_datetime()?;
debug!(" -> end = {:?}", end); debug!(" -> end = {:?}", end);
let _ = rt.report_touched(e.get_location())
.map_err_trace_exit_unwrap(1);
Ok((tag, start, end)) Ok((tag, start, end))
}) })
.trace_unwrap_exit(1) .trace_unwrap_exit(1)