From 798fbff3201ad0d9423be62254f22f56d2def27c Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Sun, 28 Jan 2024 16:28:27 -0500 Subject: [PATCH] Show existing time/distance workout rows in day detail and editor --- fitnesstrax/app/gresources.xml | 4 ++ .../app/resources/cycling-symbolic.svg | 2 + .../app/resources/resources.gresource.xml | 6 --- fitnesstrax/app/src/components/day.rs | 45 ++++++++++++++++++- 4 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 fitnesstrax/app/resources/cycling-symbolic.svg delete mode 100644 fitnesstrax/app/resources/resources.gresource.xml diff --git a/fitnesstrax/app/gresources.xml b/fitnesstrax/app/gresources.xml index 4eafed7..b26eb63 100644 --- a/fitnesstrax/app/gresources.xml +++ b/fitnesstrax/app/gresources.xml @@ -10,4 +10,8 @@ running-symbolic.svg + + + cycling-symbolic.svg + diff --git a/fitnesstrax/app/resources/cycling-symbolic.svg b/fitnesstrax/app/resources/cycling-symbolic.svg new file mode 100644 index 0000000..d1a3f13 --- /dev/null +++ b/fitnesstrax/app/resources/cycling-symbolic.svg @@ -0,0 +1,2 @@ + + diff --git a/fitnesstrax/app/resources/resources.gresource.xml b/fitnesstrax/app/resources/resources.gresource.xml deleted file mode 100644 index 67e604b..0000000 --- a/fitnesstrax/app/resources/resources.gresource.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - start-here-symbolic.svg - - \ No newline at end of file diff --git a/fitnesstrax/app/src/components/day.rs b/fitnesstrax/app/src/components/day.rs index c23bebd..ee6e4f0 100644 --- a/fitnesstrax/app/src/components/day.rs +++ b/fitnesstrax/app/src/components/day.rs @@ -186,6 +186,7 @@ impl DayDetail { } TraxRecord::Row(row) => s.append(&time_distance_detail(RecordType::Row, row)), TraxRecord::Run(run) => s.append(&time_distance_detail(RecordType::Run, run)), + TraxRecord::Swim(walk) => s.append(&time_distance_detail(RecordType::Swim, walk)), TraxRecord::Walk(walk) => s.append(&time_distance_detail(RecordType::Walk, walk)), _ => {} } @@ -247,6 +248,32 @@ impl DayEdit { move |workout| s.add_row(workout) }); + view_model + .records() + .into_iter() + .filter_map({ + let s = s.clone(); + move |record| { + let workout_type = record.data.workout_type(); + match record.data { + TraxRecord::BikeRide(workout) + | TraxRecord::Row(workout) + | TraxRecord::Run(workout) + | TraxRecord::Swim(workout) + | TraxRecord::Walk(workout) => { + Some(TimeDistanceEdit::new(workout_type, workout, { + let s = s.clone(); + move |type_, data| { + s.update_workout(record.id, type_, data); + } + })) + } + _ => None, + } + } + }) + .for_each(|row| s.imp().workout_rows.borrow().append(&row)); + s.append(&control_buttons(&s, &view_model)); s.append(&weight_and_steps_row(&view_model)); s.append(&*s.imp().workout_rows.borrow()); @@ -354,6 +381,7 @@ where AddRow: Fn(Record) + 'static, { let add_row = Rc::new(add_row); + /* let walking_button = gtk::Button::builder() .icon_name("walking2-symbolic") .width_request(64) @@ -380,6 +408,20 @@ where add_row(workout); } }); + */ + + let biking_button = gtk::Button::builder() + .icon_name("cycling-symbolic") + .width_request(64) + .height_request(64) + .build(); + biking_button.connect_clicked({ + let view_model = view_model.clone(); + move |_| { + let workout = view_model.new_record(RecordType::Walk); + add_row(workout); + } + }); let layout = gtk::Box::builder() .orientation(gtk::Orientation::Vertical) @@ -387,8 +429,7 @@ where let row = gtk::Box::builder() .orientation(gtk::Orientation::Horizontal) .build(); - row.append(&walking_button); - row.append(&running_button); + row.append(&biking_button); layout.append(&row); layout