aboutsummaryrefslogtreecommitdiff
path: root/src/app/calendar.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/calendar.rs')
-rw-r--r--src/app/calendar.rs44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/app/calendar.rs b/src/app/calendar.rs
index fa4ebe6..11eb893 100644
--- a/src/app/calendar.rs
+++ b/src/app/calendar.rs
@@ -4,8 +4,9 @@ use async_channel::Sender;
use chrono::{Datelike, NaiveDate};
use gtk::glib;
use gtk::prelude::*;
+use std::collections::HashMap;
-use crate::{app::update, app::update::Msg, app::App, model::event::Event};
+use crate::{app::update, app::update::Msg, app::App, model::event, model::event::Event};
static DAYS: [&str; 7] = ["LUN", "MAR", "MER", "JEU", "VEN", "SAM", "DIM"];
static MONTHES: [&str; 12] = [
@@ -14,9 +15,11 @@ static MONTHES: [&str; 12] = [
pub fn create(
tx: Sender<Msg>,
- today: &NaiveDate,
- start_date: &NaiveDate,
+ today: NaiveDate,
+ start_date: NaiveDate,
+ end_date: NaiveDate,
events: &Vec<Event>,
+ repeated_events: &Vec<Event>,
) -> gtk::Grid {
let grid = gtk::Grid::builder().build();
@@ -24,7 +27,8 @@ pub fn create(
grid.attach(&day_title(col), col, 0, 1, 1);
}
- attach_days(tx, &grid, &start_date, &today, &events);
+ let repetitions = event::repetitions_between(repeated_events, start_date, end_date);
+ attach_days(tx, &grid, start_date, today, events, &repetitions);
grid
}
@@ -32,27 +36,34 @@ pub fn create(
fn attach_days(
tx: Sender<Msg>,
grid: &gtk::Grid,
- start_date: &NaiveDate,
- today: &NaiveDate,
+ start_date: NaiveDate,
+ today: NaiveDate,
events: &Vec<Event>,
+ repetitions: &HashMap<NaiveDate, Vec<Event>>,
) {
- let mut d = *start_date;
+ let mut d = start_date;
for row in 1..5 {
for col in 0..7 {
- grid.attach(&day_entry(tx.clone(), &d, &today, &events), col, row, 1, 1);
+ grid.attach(
+ &day_entry(tx.clone(), d, today, events, repetitions),
+ col,
+ row,
+ 1,
+ 1,
+ );
d = d.succ();
}
}
}
-pub fn refresh_date(app: &App, date: NaiveDate) {
+pub fn refresh_date(app: &App, date: NaiveDate, repetitions: &HashMap<NaiveDate, Vec<Event>>) {
let d = date.signed_duration_since(app.start_date).num_days();
let col = (d % 7) as i32;
let row = 1 + (d / 7) as i32;
app.grid.attach(
- &day_entry(app.tx.clone(), &date, &app.today, &app.events),
+ &day_entry(app.tx.clone(), date, app.today, &app.events, repetitions),
col,
row,
1,
@@ -76,9 +87,10 @@ fn day_title(col: i32) -> gtk::Box {
pub fn day_entry(
tx: Sender<Msg>,
- date: &NaiveDate,
- today: &NaiveDate,
+ date: NaiveDate,
+ today: NaiveDate,
events: &Vec<Event>,
+ repetitions: &HashMap<NaiveDate, Vec<Event>>,
) -> gtk::ScrolledWindow {
let vbox = gtk::Box::builder()
.orientation(gtk::Orientation::Vertical)
@@ -87,7 +99,7 @@ pub fn day_entry(
vbox.add_css_class("g-Calendar__Day");
let gesture = gtk::GestureClick::new();
- gesture.connect_pressed(glib::clone!(@strong date, @strong tx => move |_, n, _, _| {
+ gesture.connect_pressed(glib::clone!(@strong tx => move |_, n, _, _| {
if n == 2 {
update::send(tx.clone(), Msg::ShowAddForm { date });
}
@@ -102,8 +114,10 @@ pub fn day_entry(
let mut events = events
.iter()
- .filter(|e| e.date == *date)
+ .filter(|e| e.date == date)
.collect::<Vec<&Event>>();
+ let repeated_events = repetitions.get(&date).map(|e| e.clone()).unwrap_or(vec![]);
+ events.extend(repeated_events.iter());
events.sort_by_key(|e| e.start);
if !events.is_empty() {
@@ -120,7 +134,7 @@ pub fn day_entry(
scrolled_window
}
-fn day_label(date: &NaiveDate) -> gtk::Label {
+fn day_label(date: NaiveDate) -> gtk::Label {
let label = gtk::Label::builder()
.label(&format!(
"{} {}",