aboutsummaryrefslogtreecommitdiff
path: root/src/gui/form/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/form/mod.rs')
-rw-r--r--src/gui/form/mod.rs245
1 files changed, 136 insertions, 109 deletions
diff --git a/src/gui/form/mod.rs b/src/gui/form/mod.rs
index 0b63dea..dbaf879 100644
--- a/src/gui/form/mod.rs
+++ b/src/gui/form/mod.rs
@@ -39,10 +39,16 @@ pub async fn repetition_dialog(app: &App, date: NaiveDate, event: &Event) {
.build();
lines.append(&button);
let tx = app.tx.clone();
- button.connect_clicked(glib::clone!(@weak dialog, @strong event => move |_| {
- update::send(tx.clone(), Msg::ShowUpdateRepetitionForm { date, event_id: event.id });
- dialog.close()
- }));
+ button.connect_clicked(
+ glib::clone!(
+ #[weak] dialog,
+ #[strong] event,
+ move |_| {
+ update::send(tx.clone(), Msg::ShowUpdateRepetitionForm { date, event_id: event.id });
+ dialog.close()
+ }
+ )
+ );
let button = gtk::Button::builder()
.label("Toutes les occurences")
@@ -50,20 +56,32 @@ pub async fn repetition_dialog(app: &App, date: NaiveDate, event: &Event) {
.build();
lines.append(&button);
let tx = app.tx.clone();
- button.connect_clicked(glib::clone!(@weak dialog, @strong event => move |_| {
- update::send(tx.clone(), Msg::ShowUpdateForm { event_id: event.id });
- dialog.close()
- }));
+ button.connect_clicked(
+ glib::clone!(
+ #[weak] dialog,
+ #[strong] event,
+ move |_| {
+ update::send(tx.clone(), Msg::ShowUpdateForm { event_id: event.id });
+ dialog.close()
+ }
+ )
+ );
let button = gtk::Button::builder()
.label("À partir de cette occurence")
.build();
lines.append(&button);
let tx = app.tx.clone();
- button.connect_clicked(glib::clone!(@weak dialog, @strong event => move |_| {
- update::send(tx.clone(), Msg::ShowUpdateFromOccurence { date, event_id: event.id });
- dialog.close()
- }));
+ button.connect_clicked(
+ glib::clone!(
+ #[weak] dialog,
+ #[strong] event,
+ move |_| {
+ update::send(tx.clone(), Msg::ShowUpdateFromOccurence { date, event_id: event.id });
+ dialog.close()
+ }
+ )
+ );
dialog.run_future().await;
}
@@ -193,90 +211,97 @@ pub async fn show(app: &App, target: Target) {
let conn = app.conn.clone();
let tx = app.tx.clone();
let categories = app.categories.clone();
- button.connect_clicked(glib::clone!(@weak dialog, @strong target, @strong event, @strong categories => move |_| {
- let removed_occurences = match &target {
- Target::Update { event, .. } => {
- event.repetition.as_ref().map(|r| r.removed_occurences.clone()).unwrap_or_default()
- },
- _ => HashSet::new(),
- };
- match repetition::validate(&repetition_model, removed_occurences) {
- Ok(repetition) => {
- let id = match &target {
- Target::Update {event} => event.id,
- _ => Uuid::new_v4(),
+ button.connect_clicked(
+ glib::clone!(
+ #[weak] dialog,
+ #[strong] target,
+ #[strong] categories,
+ move |_| {
+ let removed_occurences = match &target {
+ Target::Update { event, .. } => {
+ event.repetition.as_ref().map(|r| r.removed_occurences.clone()).unwrap_or_default()
+ },
+ _ => HashSet::new(),
};
-
- // Find category id from selected id
- let category = categories.iter().find(|c| c.name == dropdown_categories[category_dropdown.selected() as usize]).map(|c| c.id);
-
- match event::validate(id, date.buffer().text(), name.buffer().text(), start.buffer().text(), end.buffer().text(), repetition, category) {
- Some(new) => {
- match &target {
- Target::New {..} => {
- match db::events::insert(&conn, &new) {
- Ok(_) => {
- update::send(tx.clone(), Msg::AddEvent { new });
- dialog.close()
- },
- Err(err) => eprintln!("Error when inserting event: {}", err)
- }
- }
- Target::Update {event} => {
- match db::events::update(&conn, &new) {
- Ok(_) => {
- update::send(tx.clone(), Msg::UpdateEvent { old: event.clone(), new });
- dialog.close()
- },
- Err(err) => eprintln!("Error when updating event: {}", err)
- }
- }
- Target::UpdateRepetition { event, date } => {
- // TODO: improve intermediate error state
- match delete_repetition_occurence(&conn, event, *date) {
- Ok(occurence) => {
- match db::events::insert(&conn, &new) {
- Ok(_) => {
- update::send(tx.clone(), Msg::UpdateEventOccurence {
- event: event.clone(),
- occurence,
- date: *date,
- new
- })
- }
- Err(err) => eprintln!("Error when updating repetition: {}", err)
- };
- dialog.close()
- },
- Err(err) => eprintln!("Error when updating repetition: {}", err)
- }
- }
- Target::UpdateFromOccurence { date, event } => {
- match update_repetition_until(&conn, *date - Duration::days(1), event) {
- Ok(updated) => {
+ match repetition::validate(&repetition_model, removed_occurences) {
+ Ok(repetition) => {
+ let id = match &target {
+ Target::Update {event} => event.id,
+ _ => Uuid::new_v4(),
+ };
+
+ // Find category id from selected id
+ let category = categories.iter().find(|c| c.name == dropdown_categories[category_dropdown.selected() as usize]).map(|c| c.id);
+
+ match event::validate(id, date.buffer().text().to_string(), name.buffer().text().to_string(), start.buffer().text().to_string(), end.buffer().text().to_string(), repetition, category) {
+ Some(new) => {
+ match &target {
+ Target::New {..} => {
match db::events::insert(&conn, &new) {
Ok(_) => {
- update::send(tx.clone(), Msg::UpdateRepeatedFrom {
- old: event.clone(),
- updated,
- new
- });
+ update::send(tx.clone(), Msg::AddEvent { new });
dialog.close()
},
Err(err) => eprintln!("Error when inserting event: {}", err)
}
- },
- Err(err) => eprintln!("Error when updating event: {}", err)
+ }
+ Target::Update {event} => {
+ match db::events::update(&conn, &new) {
+ Ok(_) => {
+ update::send(tx.clone(), Msg::UpdateEvent { old: event.clone(), new });
+ dialog.close()
+ },
+ Err(err) => eprintln!("Error when updating event: {}", err)
+ }
+ }
+ Target::UpdateRepetition { event, date } => {
+ // TODO: improve intermediate error state
+ match delete_repetition_occurence(&conn, event, *date) {
+ Ok(occurence) => {
+ match db::events::insert(&conn, &new) {
+ Ok(_) => {
+ update::send(tx.clone(), Msg::UpdateEventOccurence {
+ event: event.clone(),
+ occurence,
+ date: *date,
+ new
+ })
+ }
+ Err(err) => eprintln!("Error when updating repetition: {}", err)
+ };
+ dialog.close()
+ },
+ Err(err) => eprintln!("Error when updating repetition: {}", err)
+ }
+ }
+ Target::UpdateFromOccurence { date, event } => {
+ match update_repetition_until(&conn, *date - Duration::days(1), event) {
+ Ok(updated) => {
+ match db::events::insert(&conn, &new) {
+ Ok(_) => {
+ update::send(tx.clone(), Msg::UpdateRepeatedFrom {
+ old: event.clone(),
+ updated,
+ new
+ });
+ dialog.close()
+ },
+ Err(err) => eprintln!("Error when inserting event: {}", err)
+ }
+ },
+ Err(err) => eprintln!("Error when updating event: {}", err)
+ }
+ }
}
}
+ None => eprintln!("Event is not valid.")
}
- }
- None => eprintln!("Event is not valid.")
+ },
+ Err(message) => eprintln!("{}", message)
}
- },
- Err(message) => eprintln!("{}", message)
- }
- }));
+ }
+ )
+ );
if let Some(event) = event {
let label = match target {
@@ -288,37 +313,39 @@ pub async fn show(app: &App, target: Target) {
lines.append(&button);
let conn = app.conn.clone();
let tx = app.tx.clone();
- button.connect_clicked(glib::clone!(@weak dialog => move |_| {
- match target {
- Target::UpdateRepetition { date, .. } => {
- match delete_repetition_occurence(&conn, &event, date) {
- Ok(occurence) => {
- update::send(tx.clone(), Msg::DeleteOccurence { event: event.clone(), date, occurence });
- dialog.close()
+ button.connect_clicked(
+ glib::clone!(#[weak] dialog, move |_| {
+ match target {
+ Target::UpdateRepetition { date, .. } => {
+ match delete_repetition_occurence(&conn, &event, date) {
+ Ok(occurence) => {
+ update::send(tx.clone(), Msg::DeleteOccurence { event: event.clone(), date, occurence });
+ dialog.close()
+ }
+ Err(err) => {
+ eprintln!("{:?}", err);
+ }
}
- Err(err) => {
- eprintln!("{:?}", err);
+ }
+ Target::UpdateFromOccurence { date, .. } => {
+ match update_repetition_until(&conn, date - Duration::days(1), &event) {
+ Ok(updated) => {
+ update::send(tx.clone(), Msg::UpdateEvent { old: event.clone(), new: updated });
+ dialog.close()
+ },
+ Err(err) => eprintln!("Error when updating event: {}", err)
}
}
- }
- Target::UpdateFromOccurence { date, .. } => {
- match update_repetition_until(&conn, date - Duration::days(1), &event) {
- Ok(updated) => {
- update::send(tx.clone(), Msg::UpdateEvent { old: event.clone(), new: updated });
+ _ => {
+ let operation = db::events::delete(&conn, &event.id);
+ if operation.is_ok() {
+ update::send(tx.clone(), Msg::DeleteEvent { event: event.clone() });
dialog.close()
- },
- Err(err) => eprintln!("Error when updating event: {}", err)
- }
- }
- _ => {
- let operation = db::events::delete(&conn, &event.id);
- if operation.is_ok() {
- update::send(tx.clone(), Msg::DeleteEvent { event: event.clone() });
- dialog.close()
+ }
}
}
}
- }));
+ ));
}
dialog.run_future().await;