Remove "get" iterator, store provides this now
This commit is contained in:
parent
f33768abbf
commit
77be32d80f
10 changed files with 199 additions and 261 deletions
|
@ -33,18 +33,14 @@ use libimagtimetrack::iter::filter::*;
|
||||||
use libimagrt::runtime::Runtime;
|
use libimagrt::runtime::Runtime;
|
||||||
|
|
||||||
pub fn cont(rt: &Runtime) -> i32 {
|
pub fn cont(rt: &Runtime) -> i32 {
|
||||||
rt.store()
|
let groups = rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.and_then(|iter| {
|
.map_err_trace_exit_unwrap(1)
|
||||||
let groups = iter
|
|
||||||
// unwrap everything, trace errors
|
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
|
.filter(Option::is_some)
|
||||||
// I want all entries with an end time
|
.map(Option::unwrap)
|
||||||
.filter(|e| has_end_time.filter(&e))
|
.filter(|e| has_end_time.filter(&e))
|
||||||
|
.group_by(|elem| match elem.get_end_datetime() { // Now group them by the end time
|
||||||
// Now group them by the end time
|
|
||||||
.group_by(|elem| match elem.get_end_datetime() {
|
|
||||||
Ok(Some(dt)) => dt,
|
Ok(Some(dt)) => dt,
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
// error. We expect all of them having an end-time.
|
// error. We expect all of them having an end-time.
|
||||||
|
@ -100,10 +96,6 @@ pub fn cont(rt: &Runtime) -> i32 {
|
||||||
info!("No trackings to continue");
|
info!("No trackings to continue");
|
||||||
Ok(1)
|
Ok(1)
|
||||||
},
|
},
|
||||||
}
|
}.map_err_trace_exit_unwrap(1)
|
||||||
})
|
|
||||||
.map(|_| 0)
|
|
||||||
.map_err_trace()
|
|
||||||
.unwrap_or(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,10 +81,12 @@ pub fn day(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.and_then(|iter| {
|
.map_err_trace_exit_unwrap(1)
|
||||||
iter.trace_unwrap()
|
.trace_unwrap()
|
||||||
|
.filter(Option::is_some)
|
||||||
|
.map(Option::unwrap)
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(()), |acc, e| {
|
.fold(Ok(()), |acc: Result<(), ::libimagtimetrack::error::TimeTrackError>, e| {
|
||||||
acc.and_then(|_| {
|
acc.and_then(|_| {
|
||||||
debug!("Processing {:?}", e.get_location());
|
debug!("Processing {:?}", e.get_location());
|
||||||
|
|
||||||
|
@ -106,7 +108,6 @@ pub fn day(rt: &Runtime) -> i32 {
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace()
|
.map_err_trace()
|
||||||
.unwrap_or(1)
|
.unwrap_or(1)
|
||||||
|
|
|
@ -30,6 +30,7 @@ use libimagerror::trace::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
use libimagerror::iter::TraceIterator;
|
use libimagerror::iter::TraceIterator;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagtimetrack::error::TimeTrackError;
|
||||||
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
use libimagtimetrack::timetrackingstore::TimeTrackStore;
|
||||||
use libimagtimetrack::timetracking::TimeTracking;
|
use libimagtimetrack::timetracking::TimeTracking;
|
||||||
use libimagtimetrack::error::Result;
|
use libimagtimetrack::error::Result;
|
||||||
|
@ -120,8 +121,10 @@ pub fn list_impl(rt: &Runtime,
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.and_then(|iter| {
|
.map_err_trace_exit_unwrap(1)
|
||||||
iter.trace_unwrap()
|
.trace_unwrap()
|
||||||
|
.filter(Option::is_some)
|
||||||
|
.map(Option::unwrap)
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(table), |acc: Result<_>, e| {
|
.fold(Ok(table), |acc: Result<_>, e| {
|
||||||
acc.and_then(|mut tab: Table| {
|
acc.and_then(|mut tab: Table| {
|
||||||
|
@ -162,10 +165,10 @@ pub fn list_impl(rt: &Runtime,
|
||||||
|
|
||||||
Ok(tab)
|
Ok(tab)
|
||||||
})
|
})
|
||||||
})?
|
|
||||||
.print(&mut stdout)
|
|
||||||
.map_err(|_| String::from("Failed printing table").into())
|
|
||||||
})
|
})
|
||||||
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
.print(&mut stdout)
|
||||||
|
.map_err(|_| TimeTrackError::from(String::from("Failed printing table")))
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace()
|
.map_err_trace()
|
||||||
.unwrap_or(1)
|
.unwrap_or(1)
|
||||||
|
|
|
@ -96,10 +96,12 @@ pub fn month(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.and_then(|iter| {
|
.map_err_trace_exit_unwrap(1)
|
||||||
iter.trace_unwrap()
|
.trace_unwrap()
|
||||||
|
.filter(Option::is_some)
|
||||||
|
.map(Option::unwrap)
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(()), |acc, e| {
|
.fold(Ok(()), |acc: Result<(), ::libimagtimetrack::error::TimeTrackError>, e| {
|
||||||
acc.and_then(|_| {
|
acc.and_then(|_| {
|
||||||
debug!("Processing {:?}", e.get_location());
|
debug!("Processing {:?}", e.get_location());
|
||||||
|
|
||||||
|
@ -121,7 +123,6 @@ pub fn month(rt: &Runtime) -> i32 {
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace()
|
.map_err_trace()
|
||||||
.unwrap_or(1)
|
.unwrap_or(1)
|
||||||
|
|
|
@ -57,8 +57,10 @@ pub fn stop(rt: &Runtime) -> i32 {
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
.trace_unwrap()
|
||||||
|
.filter(Option::is_some)
|
||||||
|
.map(Option::unwrap)
|
||||||
.filter_map(|tracking| {
|
.filter_map(|tracking| {
|
||||||
let tracking = tracking.map_err_trace_exit_unwrap(1);
|
|
||||||
let is_none = tracking
|
let is_none = tracking
|
||||||
.get_end_datetime()
|
.get_end_datetime()
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
|
@ -83,6 +85,8 @@ pub fn stop(rt: &Runtime) -> i32 {
|
||||||
.map_warn_err_str("Getting timetrackings failed")
|
.map_warn_err_str("Getting timetrackings failed")
|
||||||
.map_err_trace_exit_unwrap(1)
|
.map_err_trace_exit_unwrap(1)
|
||||||
.trace_unwrap()
|
.trace_unwrap()
|
||||||
|
.filter(Option::is_some)
|
||||||
|
.map(Option::unwrap)
|
||||||
|
|
||||||
// Filter all timetrackings for the ones that are not yet ended.
|
// Filter all timetrackings for the ones that are not yet ended.
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
|
|
|
@ -88,10 +88,12 @@ pub fn week(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.and_then(|iter| {
|
.map_err_trace_exit_unwrap(1)
|
||||||
iter.trace_unwrap()
|
.trace_unwrap()
|
||||||
|
.filter(Option::is_some)
|
||||||
|
.map(Option::unwrap)
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(()), |acc, e| {
|
.fold(Ok(()), |acc: Result<(), ::libimagtimetrack::error::TimeTrackError>, e| {
|
||||||
acc.and_then(|_| {
|
acc.and_then(|_| {
|
||||||
debug!("Processing {:?}", e.get_location());
|
debug!("Processing {:?}", e.get_location());
|
||||||
|
|
||||||
|
@ -113,7 +115,6 @@ pub fn week(rt: &Runtime) -> i32 {
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace()
|
.map_err_trace()
|
||||||
.unwrap_or(1)
|
.unwrap_or(1)
|
||||||
|
|
|
@ -87,10 +87,12 @@ pub fn year(rt: &Runtime) -> i32 {
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.get_timetrackings()
|
.get_timetrackings()
|
||||||
.and_then(|iter| {
|
.map_err_trace_exit_unwrap(1)
|
||||||
iter.trace_unwrap()
|
.trace_unwrap()
|
||||||
|
.filter(Option::is_some)
|
||||||
|
.map(Option::unwrap)
|
||||||
.filter(|e| filter.filter(e))
|
.filter(|e| filter.filter(e))
|
||||||
.fold(Ok(()), |acc, e| {
|
.fold(Ok(()), |acc: Result<(), ::libimagtimetrack::error::TimeTrackError>, e| {
|
||||||
acc.and_then(|_| {
|
acc.and_then(|_| {
|
||||||
debug!("Processing {:?}", e.get_location());
|
debug!("Processing {:?}", e.get_location());
|
||||||
|
|
||||||
|
@ -112,7 +114,6 @@ pub fn year(rt: &Runtime) -> i32 {
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
|
||||||
.map(|_| 0)
|
.map(|_| 0)
|
||||||
.map_err_trace()
|
.map_err_trace()
|
||||||
.unwrap_or(1)
|
.unwrap_or(1)
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
//
|
|
||||||
// imag - the personal information management suite for the commandline
|
|
||||||
// Copyright (C) 2015-2018 Matthias Beyer <mail@beyermatthias.de> and contributors
|
|
||||||
//
|
|
||||||
// This library is free software; you can redistribute it and/or
|
|
||||||
// modify it under the terms of the GNU Lesser General Public
|
|
||||||
// License as published by the Free Software Foundation; version
|
|
||||||
// 2.1 of the License.
|
|
||||||
//
|
|
||||||
// This library is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
// Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public
|
|
||||||
// License along with this library; if not, write to the Free Software
|
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
//
|
|
||||||
|
|
||||||
use error::TimeTrackError as TTE;
|
|
||||||
use error::TimeTrackErrorKind as TTEK;
|
|
||||||
use error::ResultExt;
|
|
||||||
|
|
||||||
use libimagstore::store::FileLockEntry;
|
|
||||||
use libimagstore::store::Store;
|
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
|
||||||
|
|
||||||
pub struct GetTimeTrackIter<'a>{
|
|
||||||
inner: StoreIdIterator,
|
|
||||||
store: &'a Store,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> GetTimeTrackIter<'a> {
|
|
||||||
|
|
||||||
pub fn new(sidit: StoreIdIterator, store: &'a Store) -> GetTimeTrackIter<'a> {
|
|
||||||
GetTimeTrackIter {
|
|
||||||
inner: sidit,
|
|
||||||
store: store
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for GetTimeTrackIter<'a> {
|
|
||||||
type Item = Result<FileLockEntry<'a>, TTE>;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
self.inner.next().map(|sid| {
|
|
||||||
self.store
|
|
||||||
.get(sid)
|
|
||||||
.chain_err(|| TTEK::StoreReadError)?
|
|
||||||
.ok_or(TTE::from_kind(TTEK::StoreReadError))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// impl<'a, I> From<I> for GetTimeTrackIter<'a, I>
|
|
||||||
// where I: Iterator<Item = Result<FileLockEntry<'a>, TTE>>
|
|
||||||
// {
|
|
||||||
// fn from(i: I) -> GetTimeTrackIter<'a, I> {
|
|
||||||
// GetTimeTrackIter(i)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
pub mod create;
|
pub mod create;
|
||||||
pub mod filter;
|
pub mod filter;
|
||||||
pub mod get;
|
|
||||||
pub mod setendtime;
|
pub mod setendtime;
|
||||||
pub mod storeid;
|
pub mod storeid;
|
||||||
pub mod tag;
|
pub mod tag;
|
||||||
|
|
|
@ -28,13 +28,12 @@ use toml_query::insert::TomlValueInsertExt;
|
||||||
|
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagstore::iter::get::StoreGetIterator;
|
||||||
|
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||||
use libimagentrydatetime::datepath::compiler::DatePathCompiler;
|
use libimagentrydatetime::datepath::compiler::DatePathCompiler;
|
||||||
|
|
||||||
use error::Result;
|
use error::Result;
|
||||||
use constants::*;
|
use constants::*;
|
||||||
use error::TimeTrackErrorKind as TTEK;
|
|
||||||
use error::ResultExt;
|
|
||||||
use iter::get::GetTimeTrackIter;
|
|
||||||
|
|
||||||
use tag::TimeTrackingTag as TTT;
|
use tag::TimeTrackingTag as TTT;
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ pub trait TimeTrackStore<'a> {
|
||||||
fn create_timetracking_at(&'a self, start: &NDT, ts: &TTT) -> Result<FileLockEntry<'a>>;
|
fn create_timetracking_at(&'a self, start: &NDT, ts: &TTT) -> Result<FileLockEntry<'a>>;
|
||||||
fn create_timetracking(&'a self, start: &NDT, end: &NDT, ts: &TTT) -> Result<FileLockEntry<'a>>;
|
fn create_timetracking(&'a self, start: &NDT, end: &NDT, ts: &TTT) -> Result<FileLockEntry<'a>>;
|
||||||
|
|
||||||
fn get_timetrackings(&'a self) -> Result<GetTimeTrackIter<'a>>;
|
fn get_timetrackings(&'a self) -> Result<StoreGetIterator<'a>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn now() -> NDT {
|
fn now() -> NDT {
|
||||||
|
@ -99,15 +98,15 @@ impl<'a> TimeTrackStore<'a> for Store {
|
||||||
let v = Value::String(end.format(DATE_TIME_FORMAT).to_string());
|
let v = Value::String(end.format(DATE_TIME_FORMAT).to_string());
|
||||||
fle.get_header_mut()
|
fle.get_header_mut()
|
||||||
.insert(DATE_TIME_END_HEADER_PATH, v)
|
.insert(DATE_TIME_END_HEADER_PATH, v)
|
||||||
.chain_err(|| TTEK::HeaderWriteError)
|
.map_err(From::from)
|
||||||
.map(|_| fle)
|
.map(|_| fle)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_timetrackings(&'a self) -> Result<GetTimeTrackIter<'a>> {
|
fn get_timetrackings(&'a self) -> Result<StoreGetIterator<'a>> {
|
||||||
self.retrieve_for_module(CRATE_NAME)
|
self.retrieve_for_module(CRATE_NAME)
|
||||||
.chain_err(|| TTEK::StoreReadError)
|
.map_err(From::from)
|
||||||
.map(|iter| GetTimeTrackIter::new(iter, self))
|
.map(|iter| iter.into_get_iter(self))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue