Replace Store::retrieve_for_module() with own iterator type
This commit is contained in:
parent
007c02c2f1
commit
22fb26dc12
10 changed files with 58 additions and 23 deletions
|
@ -37,8 +37,6 @@ pub fn cont(rt: &Runtime) -> i32 {
|
|||
.get_timetrackings()
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
.filter(|e| has_end_time.filter(&e))
|
||||
.group_by(|elem| match elem.get_end_datetime() { // Now group them by the end time
|
||||
Ok(Some(dt)) => dt,
|
||||
|
|
|
@ -90,8 +90,6 @@ pub fn day(rt: &Runtime) -> i32 {
|
|||
.get_timetrackings()
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
.filter(|e| filter.filter(e))
|
||||
.map(|e| -> Result<_, TTE> {
|
||||
debug!("Processing {:?}", e.get_location());
|
||||
|
|
|
@ -121,8 +121,6 @@ pub fn list_impl(rt: &Runtime,
|
|||
.get_timetrackings()
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
.filter(|e| filter.filter(e))
|
||||
.fold(Ok(table), |acc: Result<_>, e| {
|
||||
acc.and_then(|mut tab: Table| {
|
||||
|
|
|
@ -105,8 +105,6 @@ pub fn month(rt: &Runtime) -> i32 {
|
|||
.get_timetrackings()
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
.filter(|e| filter.filter(e))
|
||||
.map(|e| -> Result<_, TTE> {
|
||||
debug!("Processing {:?}", e.get_location());
|
||||
|
|
|
@ -60,8 +60,6 @@ pub fn stop(rt: &Runtime) -> i32 {
|
|||
.get_timetrackings()
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
.filter_map(|tracking| {
|
||||
let is_none = tracking
|
||||
.get_end_datetime()
|
||||
|
@ -87,8 +85,6 @@ pub fn stop(rt: &Runtime) -> i32 {
|
|||
.map_warn_err_str("Getting timetrackings failed")
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
|
||||
// Filter all timetrackings for the ones that are not yet ended.
|
||||
.filter(|e| filter.filter(e))
|
||||
|
|
|
@ -103,8 +103,6 @@ pub fn week(rt: &Runtime) -> i32 {
|
|||
.get_timetrackings()
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
.filter(|e| filter.filter(e))
|
||||
.map(|e| -> Result<_, TTE> {
|
||||
debug!("Processing {:?}", e.get_location());
|
||||
|
|
|
@ -103,8 +103,6 @@ pub fn year(rt: &Runtime) -> i32 {
|
|||
.get_timetrackings()
|
||||
.map_err_trace_exit_unwrap(1)
|
||||
.trace_unwrap()
|
||||
.filter(Option::is_some)
|
||||
.map(Option::unwrap)
|
||||
.filter(|e| filter.filter(e))
|
||||
.map(|e| -> Result<_, TTE> {
|
||||
debug!("Processing {:?}", e.get_location());
|
||||
|
|
53
lib/domain/libimagtimetrack/src/iter/get.rs
Normal file
53
lib/domain/libimagtimetrack/src/iter/get.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
//
|
||||
// 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 libimagstore::storeid::StoreIdIteratorWithStore;
|
||||
use libimagstore::store::Store;
|
||||
use libimagstore::store::Result as StoreResult;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
|
||||
use constants::*;
|
||||
|
||||
pub struct TimeTrackingsGetIterator<'a>(StoreIdIteratorWithStore<'a>, &'a Store);
|
||||
|
||||
impl<'a> TimeTrackingsGetIterator<'a> {
|
||||
pub fn new(sit: StoreIdIteratorWithStore<'a>, store: &'a Store) -> Self {
|
||||
TimeTrackingsGetIterator(sit, store)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for TimeTrackingsGetIterator<'a> {
|
||||
type Item = StoreResult<FileLockEntry<'a>>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
while let Some(next) = self.0.next() {
|
||||
if next.is_in_collection(&[CRATE_NAME]) {
|
||||
return match self.1.get(next) {
|
||||
Ok(Some(fle)) => Some(Ok(fle)),
|
||||
Ok(None) => continue,
|
||||
Err(e) => Some(Err(e))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
pub mod create;
|
||||
pub mod filter;
|
||||
pub mod get;
|
||||
pub mod setendtime;
|
||||
pub mod storeid;
|
||||
pub mod tag;
|
||||
|
|
|
@ -28,12 +28,11 @@ use toml_query::insert::TomlValueInsertExt;
|
|||
|
||||
use libimagstore::store::Store;
|
||||
use libimagstore::store::FileLockEntry;
|
||||
use libimagstore::iter::get::StoreGetIterator;
|
||||
use libimagstore::iter::get::StoreIdGetIteratorExtension;
|
||||
use libimagentrydatetime::datepath::compiler::DatePathCompiler;
|
||||
|
||||
use error::Result;
|
||||
use constants::*;
|
||||
use iter::get::TimeTrackingsGetIterator;
|
||||
|
||||
use tag::TimeTrackingTag as TTT;
|
||||
|
||||
|
@ -43,7 +42,7 @@ pub trait TimeTrackStore<'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 get_timetrackings(&'a self) -> Result<StoreGetIterator<'a>>;
|
||||
fn get_timetrackings(&'a self) -> Result<TimeTrackingsGetIterator<'a>>;
|
||||
}
|
||||
|
||||
fn now() -> NDT {
|
||||
|
@ -103,10 +102,8 @@ impl<'a> TimeTrackStore<'a> for Store {
|
|||
})
|
||||
}
|
||||
|
||||
fn get_timetrackings(&'a self) -> Result<StoreGetIterator<'a>> {
|
||||
self.retrieve_for_module(CRATE_NAME)
|
||||
.map_err(From::from)
|
||||
.map(|iter| iter.into_get_iter(self))
|
||||
fn get_timetrackings(&'a self) -> Result<TimeTrackingsGetIterator<'a>> {
|
||||
Ok(TimeTrackingsGetIterator::new(self.entries()?, self))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue