Merge pull request #1392 from matthiasbeyer/libimagdiary/list-sorted

Fix: view entries sorted
This commit is contained in:
Matthias Beyer 2018-04-13 15:54:25 +02:00 committed by GitHub
commit 633032586d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,7 +27,6 @@ use error::Result;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagentryview::viewer::Viewer; use libimagentryview::viewer::Viewer;
use libimagentryview::builtin::plain::PlainViewer; 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 /// 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. /// 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 /// View all entries from the iterator, or stop immediately if an error occurs, returning that
/// error. /// error.
pub fn view_entries<'a, I: Iterator<Item = FileLockEntry<'a>>>(&self, entries: I) -> Result<()> { pub fn view_entries<'a, I: Iterator<Item = FileLockEntry<'a>>>(&self, entries: I) -> Result<()> {
for entry in entries { let mut entries = entries
match entry.diary_id() { .map(|e| e.diary_id().map(|id| (id, e)))
Ok(id) => println!("{} :\n", id), .collect::<Result<Vec<_>>>()?;
Err(e) => trace_error(&e),
} 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 let _ = self.0
.view_entry(&entry) .view_entry(&entry)
.chain_err(|| DEK::ViewError) .chain_err(|| DEK::ViewError)