aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-07-23 08:37:35 +0100
committerAkshay <[email protected]>2020-07-23 08:37:35 +0100
commit537e4f5ebe7404031f240233cbe9807df0d580d9 (patch)
tree7de9e379217180ccee20f6c74681df36071a893c /src/app
parent59b40932d4602fc7bf84f123930f9a0eb187f4a1 (diff)
parenta0c57162b2026e37220e31a39d821c2a2e31cc51 (diff)
Merge branch 'master' of https://github.com/yoms/dijo into fix/duplicate-habits
Diffstat (limited to 'src/app')
-rw-r--r--src/app/impl_self.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs
index 1ed19e6..1dfe268 100644
--- a/src/app/impl_self.rs
+++ b/src/app/impl_self.rs
@@ -33,8 +33,25 @@ impl App {
33 }; 33 };
34 } 34 }
35 35
36 pub fn list_habit(&self) -> Vec<String> {
37 let habits_names = self.habits.iter().map(|x| x.name()).collect::<Vec<_>>();
38 return habits_names;
39 }
40
36 pub fn add_habit(&mut self, h: Box<dyn HabitWrapper>) { 41 pub fn add_habit(&mut self, h: Box<dyn HabitWrapper>) {
37 self.habits.push(h); 42 if self
43 .habits
44 .iter()
45 .filter(|hab| hab.name() == h.name())
46 .count()
47 > 0
48 {
49 self.message.set_kind(MessageKind::Error);
50 self.message
51 .set_message(format!("Habit `{}` allready exist", h.name()))
52 } else {
53 self.habits.push(h);
54 }
38 } 55 }
39 56
40 pub fn list_habits(&self) -> Vec<String> { 57 pub fn list_habits(&self) -> Vec<String> {