diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2018-04-13 13:41:02 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2018-04-13 13:41:02 +0200 |
commit | ae5c4cf9ba18ea9e63bb78cf517732d5125c2a06 (patch) | |
tree | 2f1cf4f37230afddf567129a80a20af243527aae /lib | |
parent | c27dc79afe2ed2d978515dbcb737b0927783027b (diff) |
Fix: view entries sorted
Diffstat (limited to 'lib')
-rw-r--r-- | lib/domain/libimagdiary/src/viewer.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/domain/libimagdiary/src/viewer.rs b/lib/domain/libimagdiary/src/viewer.rs index 7d804364..17971f5f 100644 --- a/lib/domain/libimagdiary/src/viewer.rs +++ b/lib/domain/libimagdiary/src/viewer.rs @@ -27,7 +27,6 @@ use error::Result; use libimagstore::store::FileLockEntry; use libimagentryview::viewer::Viewer; use libimagentryview::builtin::plain::PlainViewer; -use libimagerror::trace::trace_error; /// This viewer does _not_ implement libimagentryview::viewer::Viewer because we need to be able to /// call some diary-type specific functions on the entries passed to this. @@ -49,11 +48,16 @@ impl DiaryViewer { /// View all entries from the iterator, or stop immediately if an error occurs, returning that /// error. pub fn view_entries<'a, I: Iterator<Item = FileLockEntry<'a>>>(&self, entries: I) -> Result<()> { - for entry in entries { - match entry.diary_id() { - Ok(id) => println!("{} :\n", id), - Err(e) => trace_error(&e), - } + let mut entries = entries + .map(|e| e.diary_id().map(|id| (id, e))) + .collect::<Result<Vec<_>>>()?; + + entries.sort_by_key(|&(ref id, _)| { + [id.year() as u32, id.month(), id.day(), id.hour(), id.minute(), id.second()] + }); + + for (id, entry) in entries.into_iter() { + println!("{} :\n", id); let _ = self.0 .view_entry(&entry) .chain_err(|| DEK::ViewError) |