Merge pull request #1302 from matthiasbeyer/libimagdiary/fix-set-isflag
libimagdiary: Add "isflag" support
This commit is contained in:
commit
461bebe60a
5 changed files with 25 additions and 2 deletions
|
@ -32,3 +32,5 @@ libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror"
|
||||||
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
||||||
libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" }
|
libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" }
|
||||||
libimagentryview = { version = "0.7.0", path = "../../../lib/entry/libimagentryview" }
|
libimagentryview = { version = "0.7.0", path = "../../../lib/entry/libimagentryview" }
|
||||||
|
libimagentryutil = { version = "0.7.0", path = "../../../lib/entry/libimagentryutil" }
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ use std::cmp::Ordering;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagerror::trace::trace_error;
|
use libimagerror::trace::trace_error;
|
||||||
|
use libimagentryutil::isa::Is;
|
||||||
|
|
||||||
use chrono::offset::Local;
|
use chrono::offset::Local;
|
||||||
use chrono::Datelike;
|
use chrono::Datelike;
|
||||||
|
@ -29,6 +30,7 @@ use itertools::Itertools;
|
||||||
use chrono::naive::NaiveDateTime;
|
use chrono::naive::NaiveDateTime;
|
||||||
use chrono::Timelike;
|
use chrono::Timelike;
|
||||||
|
|
||||||
|
use entry::IsDiaryEntry;
|
||||||
use entry::DiaryEntry;
|
use entry::DiaryEntry;
|
||||||
use diaryid::DiaryId;
|
use diaryid::DiaryId;
|
||||||
use error::DiaryErrorKind as DEK;
|
use error::DiaryErrorKind as DEK;
|
||||||
|
@ -63,7 +65,9 @@ impl Diary for Store {
|
||||||
let ndt = dt.naive_local();
|
let ndt = dt.naive_local();
|
||||||
let id = DiaryId::new(String::from(diary_name), ndt.year(), ndt.month(), ndt.day(), 0, 0, 0);
|
let id = DiaryId::new(String::from(diary_name), ndt.year(), ndt.month(), ndt.day(), 0, 0, 0);
|
||||||
|
|
||||||
self.retrieve(id).chain_err(|| DEK::StoreReadError)
|
let mut entry = self.retrieve(id).chain_err(|| DEK::StoreReadError)?;
|
||||||
|
let _ = entry.set_isflag::<IsDiaryEntry>()?;
|
||||||
|
Ok(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_entry_now(&self, diary_name: &str) -> Result<FileLockEntry> {
|
fn new_entry_now(&self, diary_name: &str) -> Result<FileLockEntry> {
|
||||||
|
@ -77,7 +81,9 @@ impl Diary for Store {
|
||||||
ndt.minute(),
|
ndt.minute(),
|
||||||
ndt.second());
|
ndt.second());
|
||||||
|
|
||||||
self.retrieve(id).chain_err(|| DEK::StoreReadError)
|
let mut entry = self.retrieve(id).chain_err(|| DEK::StoreReadError)?;
|
||||||
|
let _ = entry.set_isflag::<IsDiaryEntry>()?;
|
||||||
|
Ok(entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get an iterator for iterating over all entries
|
// Get an iterator for iterating over all entries
|
||||||
|
|
|
@ -18,17 +18,27 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
|
use libimagentryutil::isa::Is;
|
||||||
|
use libimagentryutil::isa::IsKindHeaderPathProvider;
|
||||||
|
|
||||||
use diaryid::DiaryId;
|
use diaryid::DiaryId;
|
||||||
use diaryid::FromStoreId;
|
use diaryid::FromStoreId;
|
||||||
use error::Result;
|
use error::Result;
|
||||||
|
|
||||||
|
provide_kindflag_path!(pub IsDiaryEntry, "diary.is_diary_entry");
|
||||||
|
|
||||||
pub trait DiaryEntry {
|
pub trait DiaryEntry {
|
||||||
|
fn is_diary_entry(&self) -> Result<bool>;
|
||||||
fn diary_id(&self) -> Result<DiaryId>;
|
fn diary_id(&self) -> Result<DiaryId>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DiaryEntry for Entry {
|
impl DiaryEntry for Entry {
|
||||||
|
|
||||||
|
/// Check whether the entry is a diary entry by checking its headers
|
||||||
|
fn is_diary_entry(&self) -> Result<bool> {
|
||||||
|
self.is::<IsDiaryEntry>().map_err(From::from)
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the diary id for this entry.
|
/// Get the diary id for this entry.
|
||||||
///
|
///
|
||||||
/// TODO: calls Option::unwrap() as it assumes that an existing Entry has an ID that is parsable
|
/// TODO: calls Option::unwrap() as it assumes that an existing Entry has an ID that is parsable
|
||||||
|
|
|
@ -22,6 +22,10 @@ error_chain! {
|
||||||
DiaryError, DiaryErrorKind, ResultExt, Result;
|
DiaryError, DiaryErrorKind, ResultExt, Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
links {
|
||||||
|
EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind);
|
||||||
|
}
|
||||||
|
|
||||||
errors {
|
errors {
|
||||||
StoreWriteError {
|
StoreWriteError {
|
||||||
description("Error writing store")
|
description("Error writing store")
|
||||||
|
|
|
@ -43,6 +43,7 @@ extern crate itertools;
|
||||||
#[macro_use] extern crate error_chain;
|
#[macro_use] extern crate error_chain;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
|
#[macro_use] extern crate libimagentryutil;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagentryedit;
|
extern crate libimagentryedit;
|
||||||
extern crate libimagentryview;
|
extern crate libimagentryview;
|
||||||
|
|
Loading…
Reference in a new issue