summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-03-22 14:15:54 +0100
committerMatthias Beyer <mail@beyermatthias.de>2018-03-22 21:32:58 +0100
commitb62d7eab856f46ab3138ccc933574020b4d7d0c9 (patch)
treeb25310a57bec04791b035a37f039a3daebf207a7 /lib
parentc857f97287ee2d29e0981ccaa5942ca54fe7978e (diff)
Fix: libimaghabit::habit::HabitTemplate should link created instances to the template
Diffstat (limited to 'lib')
-rw-r--r--lib/domain/libimaghabit/src/habit.rs27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/domain/libimaghabit/src/habit.rs b/lib/domain/libimaghabit/src/habit.rs
index 7119e9d5..e3963b7a 100644
--- a/lib/domain/libimaghabit/src/habit.rs
+++ b/lib/domain/libimaghabit/src/habit.rs
@@ -55,18 +55,19 @@ pub trait HabitTemplate : Sized {
///
/// It uses `Store::retrieve()` underneath. So if there is already an instance for the day
/// passed, this will simply return the instance.
- fn create_instance_with_date<'a>(&self, store: &'a Store, date: &NaiveDate)
+ fn create_instance_with_date<'a>(&mut self, store: &'a Store, date: &NaiveDate)
-> Result<FileLockEntry<'a>>;
/// Shortcut for calling `Self::create_instance_with_date()` with an instance of
/// `::chrono::Local::today().naive_local()`.
- fn create_instance_today<'a>(&self, store: &'a Store) -> Result<FileLockEntry<'a>>;
+ fn create_instance_today<'a>(&mut self, store: &'a Store) -> Result<FileLockEntry<'a>>;
/// Same as `HabitTemplate::create_instance_with_date()` but uses `Store::retrieve` internally.
- fn retrieve_instance_with_date<'a>(&self, store: &'a Store, date: &NaiveDate) -> Result<FileLockEntry<'a>>;
+ fn retrieve_instance_with_date<'a>(&mut self, store: &'a Store, date: &NaiveDate)
+ -> Result<FileLockEntry<'a>>;
/// Same as `HabitTemplate::create_instance_today()` but uses `Store::retrieve` internally.
- fn retrieve_instance_today<'a>(&self, store: &'a Store) -> Result<FileLockEntry<'a>>;
+ fn retrieve_instance_today<'a>(&mut self, store: &'a Store) -> Result<FileLockEntry<'a>>;
/// Get instances for this template
fn linked_instances(&self) -> Result<HabitInstanceStoreIdIterator>;
@@ -96,7 +97,7 @@ provide_kindflag_path!(pub IsHabitTemplate, "habit.template.is_habit_template");
impl HabitTemplate for Entry {
- fn create_instance_with_date<'a>(&self, store: &'a Store, date: &NaiveDate) -> Result<FileLockEntry<'a>> {
+ fn create_instance_with_date<'a>(&mut self, store: &'a Store, date: &NaiveDate) -> Result<FileLockEntry<'a>> {
let name = self.habit_name()?;
let comment = self.habit_comment()?;
let date = date_to_string(date);
@@ -104,14 +105,14 @@ impl HabitTemplate for Entry {
store.create(id)
.map_err(From::from)
- .and_then(|entry| postprocess_instance(entry, name, date, comment))
+ .and_then(|entry| postprocess_instance(entry, name, date, comment, self))
}
- fn create_instance_today<'a>(&self, store: &'a Store) -> Result<FileLockEntry<'a>> {
+ fn create_instance_today<'a>(&mut self, store: &'a Store) -> Result<FileLockEntry<'a>> {
self.create_instance_with_date(store, &Local::today().naive_local())
}
- fn retrieve_instance_with_date<'a>(&self, store: &'a Store, date: &NaiveDate) -> Result<FileLockEntry<'a>> {
+ fn retrieve_instance_with_date<'a>(&mut self, store: &'a Store, date: &NaiveDate) -> Result<FileLockEntry<'a>> {
let name = self.habit_name()?;
let comment = self.habit_comment()?;
let date = date_to_string(date);
@@ -119,10 +120,10 @@ impl HabitTemplate for Entry {
store.create(id)
.map_err(From::from)
- .and_then(|entry| postprocess_instance(entry, name, date, comment))
+ .and_then(|entry| postprocess_instance(entry, name, date, comment, self))
}
- fn retrieve_instance_today<'a>(&self, store: &'a Store) -> Result<FileLockEntry<'a>> {
+ fn retrieve_instance_today<'a>(&mut self, store: &'a Store) -> Result<FileLockEntry<'a>> {
self.retrieve_instance_with_date(store, &Local::today().naive_local())
}
@@ -401,7 +402,8 @@ pub mod builder {
fn postprocess_instance<'a>(mut entry: FileLockEntry<'a>,
name: String,
date: String,
- comment: String)
+ comment: String,
+ template: &mut Entry)
-> Result<FileLockEntry<'a>>
{
{
@@ -411,6 +413,9 @@ fn postprocess_instance<'a>(mut entry: FileLockEntry<'a>,
let _ = hdr.insert("habit.instance.date", Value::String(date))?;
let _ = hdr.insert("habit.instance.comment", Value::String(comment))?;
}
+
+ entry.add_internal_link(template)?;
+
Ok(entry)
}