summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-07-15 16:59:04 +0200
committerGitHub <noreply@github.com>2017-07-15 16:59:04 +0200
commit3c07f47c4ae6c9a74958200b018646233fce23fe (patch)
tree9d6f2814c222b0e52ecd5426b724a16086d022e1
parent58047d319a0aaa82fd9da7c4cc4857ca65ef53f6 (diff)
parent3429ff5a57c03077dc19906665a21d6cc6d37067 (diff)
downloadimag-3c07f47c4ae6c9a74958200b018646233fce23fe.zip
imag-3c07f47c4ae6c9a74958200b018646233fce23fe.tar.gz
Merge pull request #998 from matthiasbeyer/libimagtimetrack/more-features
Libimagtimetrack/more features
-rw-r--r--libimagentrytimetrack/src/iter/filter.rs141
-rw-r--r--libimagentrytimetrack/src/iter/mod.rs1
-rw-r--r--libimagentrytimetrack/src/iter/storeid.rs2
-rw-r--r--libimagentrytimetrack/src/tag.rs1
-rw-r--r--libimagentrytimetrack/src/timetracking.rs13
-rw-r--r--libimagentrytimetrack/src/timetrackingstore.rs1
6 files changed, 156 insertions, 3 deletions
diff --git a/libimagentrytimetrack/src/iter/filter.rs b/libimagentrytimetrack/src/iter/filter.rs
new file mode 100644
index 0000000..b8299b4
--- /dev/null
+++ b/libimagentrytimetrack/src/iter/filter.rs
@@ -0,0 +1,141 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015, 2016 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 result::Result;
+
+use libimagstore::store::FileLockEntry;
+
+use tag::TimeTrackingTag as TTT;
+use timetracking::TimeTracking;
+
+pub struct WithOneOf<'a, I>
+ where I: Iterator<Item = Result<FileLockEntry<'a>>>
+{
+ iter: I,
+ allowed_tags: &'a Vec<TTT>,
+}
+
+impl<'a, I> WithOneOf<'a, I>
+ where I: Iterator<Item = Result<FileLockEntry<'a>>>
+{
+
+ pub fn new(iter: I, allowed_tags: &'a Vec<TTT>) -> WithOneOf<'a, I> {
+ WithOneOf {
+ iter: iter,
+ allowed_tags: allowed_tags
+ }
+ }
+}
+
+impl<'a, I> Iterator for WithOneOf<'a, I>
+ where I: Iterator<Item = Result<FileLockEntry<'a>>>
+{
+ type Item = Result<FileLockEntry<'a>>;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ loop {
+ match self.iter.next() {
+ Some(Ok(fle)) => {
+ match fle.get_timetrack_tag() {
+ Err(e) => return Some(Err(e)),
+ Ok(t) => if self.allowed_tags.contains(&t) {
+ return Some(Ok(fle))
+ } else {
+ // loop
+ },
+ }
+ },
+ Some(Err(e)) => return Some(Err(e)),
+ None => return None,
+ }
+ }
+ }
+}
+
+pub trait WithOneOfTags<'a> : Sized + Iterator<Item = Result<FileLockEntry<'a>>> {
+ fn with_timetracking_tags(self, tags: &'a Vec<TTT>) -> WithOneOf<'a, Self>;
+}
+
+impl<'a, I> WithOneOfTags<'a> for I
+ where I: Iterator<Item = Result<FileLockEntry<'a>>>,
+ Self: Sized
+{
+ fn with_timetracking_tags(self, tags: &'a Vec<TTT>) -> WithOneOf<'a, Self> {
+ WithOneOf::new(self, tags)
+ }
+}
+
+
+pub struct WithNoneOf<'a, I>
+ where I: Iterator<Item = Result<FileLockEntry<'a>>>
+{
+ iter: I,
+ disallowed_tags: &'a Vec<TTT>,
+}
+
+impl<'a, I> WithNoneOf<'a, I>
+ where I: Iterator<Item = Result<FileLockEntry<'a>>>
+{
+
+ pub fn new(iter: I, disallowed_tags: &'a Vec<TTT>) -> WithNoneOf<'a, I> {
+ WithNoneOf {
+ iter: iter,
+ disallowed_tags: disallowed_tags
+ }
+ }
+}
+
+impl<'a, I> Iterator for WithNoneOf<'a, I>
+ where I: Iterator<Item = Result<FileLockEntry<'a>>>
+{
+ type Item = Result<FileLockEntry<'a>>;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ loop {
+ match self.iter.next() {
+ Some(Ok(fle)) => {
+ match fle.get_timetrack_tag() {
+ Err(e) => return Some(Err(e)),
+ Ok(t) => if !self.disallowed_tags.contains(&t) {
+ return Some(Ok(fle))
+ } else {
+ // loop
+ },
+ }
+ },
+ Some(Err(e)) => return Some(Err(e)),
+ None => return None,
+ }
+ }
+ }
+}
+
+pub trait WithNoneOfTags<'a> : Sized + Iterator<Item = Result<FileLockEntry<'a>>> {
+ fn without_timetracking_tags(self, tags: &'a Vec<TTT>) -> WithNoneOf<'a, Self>;
+}
+
+impl<'a, I> WithNoneOfTags<'a> for I
+ where I: Iterator<Item = Result<FileLockEntry<'a>>>,
+ Self: Sized
+{
+ fn without_timetracking_tags(self, tags: &'a Vec<TTT>) -> WithNoneOf<'a, Self> {
+ WithNoneOf::new(self, tags)
+ }
+}
+
diff --git a/libimagentrytimetrack/src/iter/mod.rs b/libimagentrytimetrack/src/iter/mod.rs
index 22dcea2..d2d78cd 100644
--- a/libimagentrytimetrack/src/iter/mod.rs
+++ b/libimagentrytimetrack/src/iter/mod.rs
@@ -18,6 +18,7 @@
//
pub mod create;
+pub mod filter;
pub mod get;
pub mod setendtime;
pub mod storeid;
diff --git a/libimagentrytimetrack/src/iter/storeid.rs b/libimagentrytimetrack/src/iter/storeid.rs
index ecab55d..ac44c3c 100644
--- a/libimagentrytimetrack/src/iter/storeid.rs
+++ b/libimagentrytimetrack/src/iter/storeid.rs
@@ -17,8 +17,6 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
-use std::path::PathBuf;
-
use chrono::naive::datetime::NaiveDateTime as NDT;
use constants::*;
diff --git a/libimagentrytimetrack/src/tag.rs b/libimagentrytimetrack/src/tag.rs
index c28d19f..ecf9c15 100644
--- a/libimagentrytimetrack/src/tag.rs
+++ b/libimagentrytimetrack/src/tag.rs
@@ -25,6 +25,7 @@ use libimagstore::storeid::StoreId;
/// A tag for time-tracking. This is not a normal `libimagentrytag` tag, because we want the user
/// give the possibility to use the tagging functionality without interfering with this functionality.
+#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TimeTrackingTag(String);
impl TimeTrackingTag {
diff --git a/libimagentrytimetrack/src/timetracking.rs b/libimagentrytimetrack/src/timetracking.rs
index 6ee2c10..a2d21e0 100644
--- a/libimagentrytimetrack/src/timetracking.rs
+++ b/libimagentrytimetrack/src/timetracking.rs
@@ -29,6 +29,7 @@ use chrono::naive::datetime::NaiveDateTime;
use libimagstore::store::Entry;
use libimagerror::into::IntoError;
+use tag::TimeTrackingTag as TTT;
use error::TimeTrackErrorKind as TTEK;
use error::MapErrInto;
use result::Result;
@@ -41,6 +42,8 @@ use toml_query::read::TomlValueReadExt;
pub trait TimeTracking {
+ fn get_timetrack_tag(&self) -> Result<TTT>;
+
fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()>;
fn get_start_datetime(&self) -> Result<Option<NaiveDateTime>>;
@@ -59,6 +62,16 @@ pub trait TimeTracking {
impl TimeTracking for Entry {
+ fn get_timetrack_tag(&self) -> Result<TTT> {
+ self.get_header()
+ .read(DATE_TIME_TAG_HEADER_PATH)
+ .map_err_into(TTEK::HeaderReadError)
+ .map(|value| match value {
+ Some(&Value::String(ref s)) => s.clone().into(),
+ _ => unimplemented!(),
+ })
+ }
+
fn set_start_datetime(&mut self, dt: NaiveDateTime) -> Result<()> {
let s = dt.format(DATE_TIME_FORMAT).to_string();
diff --git a/libimagentrytimetrack/src/timetrackingstore.rs b/libimagentrytimetrack/src/timetrackingstore.rs
index 1ce5d55..1791df8 100644
--- a/libimagentrytimetrack/src/timetrackingstore.rs
+++ b/libimagentrytimetrack/src/timetrackingstore.rs
@@ -28,7 +28,6 @@ use toml_query::insert::TomlValueInsertExt;
use libimagstore::store::Store;
use libimagstore::store::FileLockEntry;
-use libimagstore::storeid::StoreId;
use libimagentrydatetime::datepath::compiler::DatePathCompiler;
use result::Result;