Remove dependency on libimagnotes
This commit is contained in:
parent
3ed9c1fcc8
commit
ec855fefc7
4 changed files with 15 additions and 19 deletions
|
@ -17,5 +17,4 @@ error-chain = "0.10"
|
||||||
|
|
||||||
libimagstore = { version = "0.5.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.5.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagerror = { version = "0.5.0", path = "../../../lib/core/libimagerror" }
|
libimagerror = { version = "0.5.0", path = "../../../lib/core/libimagerror" }
|
||||||
libimagnotes = { version = "0.5.0", path = "../../../lib/domain/libimagnotes" }
|
|
||||||
libimagentrylink = { version = "0.5.0", path = "../../../lib/entry/libimagentrylink" }
|
libimagentrylink = { version = "0.5.0", path = "../../../lib/entry/libimagentrylink" }
|
||||||
|
|
|
@ -20,12 +20,9 @@
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagentrylink::internal::InternalLinker;
|
use libimagentrylink::internal::InternalLinker;
|
||||||
use libimagnotes::notestore::NoteStore;
|
|
||||||
use libimagnotes::iter::NoteIterator;
|
|
||||||
use libimagstore::storeid::StoreIdIterator;
|
use libimagstore::storeid::StoreIdIterator;
|
||||||
|
|
||||||
use error::Result;
|
use error::Result;
|
||||||
use error::AnnotationErrorKind as AEK;
|
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
use self::iter::*;
|
use self::iter::*;
|
||||||
|
@ -40,12 +37,10 @@ pub trait AnnotationFetcher<'a> {
|
||||||
|
|
||||||
impl<'a> AnnotationFetcher<'a> for Store {
|
impl<'a> AnnotationFetcher<'a> for Store {
|
||||||
|
|
||||||
/// Wrapper around `Note::all_notes()` of `libimagnotes` which filters out normal notes and
|
|
||||||
/// leaves only annotations in the iterator.
|
|
||||||
fn all_annotations(&'a self) -> Result<AnnotationIter<'a>> {
|
fn all_annotations(&'a self) -> Result<AnnotationIter<'a>> {
|
||||||
NoteStore::all_notes(self)
|
self.retrieve_for_module("annotations")
|
||||||
.map(|iter| AnnotationIter::new(iter, self))
|
.map(|iter| AnnotationIter::new(iter, self))
|
||||||
.chain_err(|| AEK::StoreReadError)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all annotations (in an iterator) for an entry
|
/// Get all annotations (in an iterator) for an entry
|
||||||
|
@ -57,9 +52,8 @@ impl<'a> AnnotationFetcher<'a> for Store {
|
||||||
/// entry, but should normally be not that heavy.
|
/// entry, but should normally be not that heavy.
|
||||||
fn annotations_for_entry(&'a self, entry: &Entry) -> Result<AnnotationIter<'a>> {
|
fn annotations_for_entry(&'a self, entry: &Entry) -> Result<AnnotationIter<'a>> {
|
||||||
entry.get_internal_links()
|
entry.get_internal_links()
|
||||||
.chain_err(|| AEK::StoreReadError)
|
.map_err(Into::into)
|
||||||
.map(|iter| StoreIdIterator::new(Box::new(iter.map(|e| e.get_store_id().clone()))))
|
.map(|iter| StoreIdIterator::new(Box::new(iter.map(|e| e.get_store_id().clone()))))
|
||||||
.map(NoteIterator::new)
|
|
||||||
.map(|i| AnnotationIter::new(i, self))
|
.map(|i| AnnotationIter::new(i, self))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,12 +61,11 @@ impl<'a> AnnotationFetcher<'a> for Store {
|
||||||
|
|
||||||
pub mod iter {
|
pub mod iter {
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
|
|
||||||
use libimagnotes::iter::NoteIterator;
|
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
use libimagstore::storeid::StoreIdIterator;
|
||||||
|
|
||||||
use error::Result;
|
use error::Result;
|
||||||
use error::AnnotationErrorKind as AEK;
|
use error::AnnotationErrorKind as AEK;
|
||||||
|
@ -80,12 +73,12 @@ pub mod iter {
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AnnotationIter<'a>(NoteIterator, &'a Store);
|
pub struct AnnotationIter<'a>(StoreIdIterator, &'a Store);
|
||||||
|
|
||||||
impl<'a> AnnotationIter<'a> {
|
impl<'a> AnnotationIter<'a> {
|
||||||
|
|
||||||
pub fn new(noteiter: NoteIterator, store: &'a Store) -> AnnotationIter<'a> {
|
pub fn new(iter: StoreIdIterator, store: &'a Store) -> AnnotationIter<'a> {
|
||||||
AnnotationIter(noteiter, store)
|
AnnotationIter(iter, store)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -96,10 +89,10 @@ pub mod iter {
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
loop {
|
loop {
|
||||||
match self.0.next().map(|id| self.1.get(id)) {
|
match self.0.next().map(|id| self.1.get(id)) {
|
||||||
Some(Ok(Some(note))) => {
|
Some(Ok(Some(entry))) => {
|
||||||
match note.get_header().read("annotation.is_annotation") {
|
match entry.get_header().read("annotation.is_annotation") {
|
||||||
Ok(None) => continue, // not an annotation
|
Ok(None) => continue, // not an annotation
|
||||||
Ok(Some(&Value::Boolean(true))) => return Some(Ok(note)),
|
Ok(Some(&Value::Boolean(true))) => return Some(Ok(entry)),
|
||||||
Ok(Some(_)) => return Some(Err(AE::from_kind(AEK::HeaderTypeError))),
|
Ok(Some(_)) => return Some(Err(AE::from_kind(AEK::HeaderTypeError))),
|
||||||
Err(e) => return Some(Err(e).chain_err(|| AEK::HeaderReadError)),
|
Err(e) => return Some(Err(e).chain_err(|| AEK::HeaderReadError)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,11 @@ error_chain! {
|
||||||
AnnotationError, AnnotationErrorKind, ResultExt, Result;
|
AnnotationError, AnnotationErrorKind, ResultExt, Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
links {
|
||||||
|
StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind);
|
||||||
|
LinkError(::libimagentrylink::error::LinkError, ::libimagentrylink::error::LinkErrorKind);
|
||||||
|
}
|
||||||
|
|
||||||
errors {
|
errors {
|
||||||
StoreReadError {
|
StoreReadError {
|
||||||
description("Store read error")
|
description("Store read error")
|
||||||
|
|
|
@ -42,7 +42,6 @@ extern crate toml_query;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
extern crate libimagentrylink;
|
extern crate libimagentrylink;
|
||||||
extern crate libimagnotes;
|
|
||||||
|
|
||||||
pub mod annotateable;
|
pub mod annotateable;
|
||||||
pub mod annotation_fetcher;
|
pub mod annotation_fetcher;
|
||||||
|
|
Loading…
Reference in a new issue