Be able to respond to blur events and potentially be able to record weight
This commit is contained in:
parent
3e681dbffd
commit
eae24ae313
|
@ -178,7 +178,7 @@ impl fmt::Display for RecordId {
|
||||||
/// directly, as the database will create them.
|
/// directly, as the database will create them.
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||||
pub struct Record<T: Clone + Recordable> {
|
pub struct Record<T: Clone + Recordable> {
|
||||||
pub(crate) id: RecordId,
|
pub id: RecordId,
|
||||||
pub data: T,
|
pub data: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,53 +170,19 @@ impl AppWindow {
|
||||||
.upcast(),
|
.upcast(),
|
||||||
),
|
),
|
||||||
ViewName::Historical => View::Historical(
|
ViewName::Historical => View::Historical(
|
||||||
HistoricalView::new(
|
HistoricalView::new(vec![], {
|
||||||
vec![
|
let s = self.clone();
|
||||||
TraxRecord::Steps(Steps {
|
Rc::new(move |date: chrono::NaiveDate, records| {
|
||||||
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||||
count: 1500,
|
layout.append(&adw::HeaderBar::new());
|
||||||
}),
|
layout.append(&DayDetail::new(date, records));
|
||||||
TraxRecord::Weight(Weight {
|
let page = &adw::NavigationPage::builder()
|
||||||
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
.title(date.format("%Y-%m-%d").to_string())
|
||||||
weight: 85. * KG,
|
.child(&layout)
|
||||||
}),
|
.build();
|
||||||
TraxRecord::Weight(Weight {
|
s.navigation.push(page);
|
||||||
date: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(),
|
})
|
||||||
weight: 86. * KG,
|
})
|
||||||
}),
|
|
||||||
TraxRecord::BikeRide(TimeDistance {
|
|
||||||
datetime: FixedOffset::west_opt(10 * 60 * 60)
|
|
||||||
.unwrap()
|
|
||||||
.with_ymd_and_hms(2019, 6, 15, 12, 0, 0)
|
|
||||||
.unwrap(),
|
|
||||||
distance: Some(1000. * M),
|
|
||||||
duration: Some(150. * S),
|
|
||||||
comments: Some("Test Comments".to_owned()),
|
|
||||||
}),
|
|
||||||
TraxRecord::BikeRide(TimeDistance {
|
|
||||||
datetime: FixedOffset::west_opt(10 * 60 * 60)
|
|
||||||
.unwrap()
|
|
||||||
.with_ymd_and_hms(2019, 6, 15, 23, 0, 0)
|
|
||||||
.unwrap(),
|
|
||||||
distance: Some(1000. * M),
|
|
||||||
duration: Some(150. * S),
|
|
||||||
comments: Some("Test Comments".to_owned()),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
{
|
|
||||||
let s = self.clone();
|
|
||||||
Rc::new(move |date: chrono::NaiveDate, records| {
|
|
||||||
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
|
||||||
layout.append(&adw::HeaderBar::new());
|
|
||||||
layout.append(&DayDetail::new(date, records));
|
|
||||||
let page = &adw::NavigationPage::builder()
|
|
||||||
.title(date.format("%Y-%m-%d").to_string())
|
|
||||||
.child(&layout)
|
|
||||||
.build();
|
|
||||||
s.navigation.push(page);
|
|
||||||
})
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.upcast(),
|
.upcast(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with Fit
|
||||||
// use chrono::NaiveDate;
|
// use chrono::NaiveDate;
|
||||||
// use ft_core::TraxRecord;
|
// use ft_core::TraxRecord;
|
||||||
use dimensioned::si;
|
use dimensioned::si;
|
||||||
|
use emseries::Record;
|
||||||
use ft_core::{RecordType, TimeDistance, TraxRecord, Weight};
|
use ft_core::{RecordType, TimeDistance, TraxRecord, Weight};
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
@ -66,7 +67,7 @@ impl DaySummary {
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_data(&self, date: chrono::NaiveDate, records: Vec<TraxRecord>) {
|
pub fn set_data(&self, date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>) {
|
||||||
self.imp()
|
self.imp()
|
||||||
.date
|
.date
|
||||||
.set_text(&date.format("%Y-%m-%d").to_string());
|
.set_text(&date.format("%Y-%m-%d").to_string());
|
||||||
|
@ -75,8 +76,10 @@ impl DaySummary {
|
||||||
self.remove(weight_label);
|
self.remove(weight_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(TraxRecord::Weight(weight_record)) =
|
if let Some(Record {
|
||||||
records.iter().filter(|f| f.is_weight()).next()
|
data: TraxRecord::Weight(weight_record),
|
||||||
|
..
|
||||||
|
}) = records.iter().filter(|f| f.data.is_weight()).next()
|
||||||
{
|
{
|
||||||
let label = gtk::Label::builder()
|
let label = gtk::Label::builder()
|
||||||
.halign(gtk::Align::Start)
|
.halign(gtk::Align::Start)
|
||||||
|
@ -128,7 +131,7 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DayDetail {
|
impl DayDetail {
|
||||||
pub fn new(date: chrono::NaiveDate, records: Vec<TraxRecord>) -> Self {
|
pub fn new(date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>) -> Self {
|
||||||
let s: Self = Object::builder().build();
|
let s: Self = Object::builder().build();
|
||||||
s.set_orientation(gtk::Orientation::Vertical);
|
s.set_orientation(gtk::Orientation::Vertical);
|
||||||
|
|
||||||
|
@ -146,32 +149,53 @@ impl DayDetail {
|
||||||
s.add_controller(click_controller);
|
s.add_controller(click_controller);
|
||||||
|
|
||||||
let weight_record = records.iter().find_map(|record| match record {
|
let weight_record = records.iter().find_map(|record| match record {
|
||||||
TraxRecord::Weight(record) => Some(record.clone()),
|
Record {
|
||||||
|
id,
|
||||||
|
data: TraxRecord::Weight(record),
|
||||||
|
} => Some((id.clone(), record.clone())),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
|
|
||||||
let weight_view = WeightView::new(weight_record, |weight| {
|
let weight_view = match weight_record {
|
||||||
println!("on_blur on the weight view: {:?}", weight)
|
Some((unique_id, record)) => WeightView::new(Some(record), move |weight| {
|
||||||
});
|
println!(
|
||||||
|
"on_blur on the weight view. Need to record {:?}, {:?}",
|
||||||
|
unique_id, weight
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
None => WeightView::new(None, |weight| {
|
||||||
|
println!(
|
||||||
|
"on_blur on the weight view. Need to create a new record for {:?}",
|
||||||
|
weight
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
};
|
||||||
s.append(&weight_view);
|
s.append(&weight_view);
|
||||||
|
|
||||||
records.into_iter().for_each(|record| {
|
records.into_iter().for_each(|record| {
|
||||||
let record_view = match record {
|
let record_view = match record {
|
||||||
TraxRecord::BikeRide(record) => Some(
|
Record {
|
||||||
|
data: TraxRecord::BikeRide(record),
|
||||||
|
..
|
||||||
|
} => Some(
|
||||||
TimeDistanceView::new(RecordType::BikeRide, record).upcast::<gtk::Widget>(),
|
TimeDistanceView::new(RecordType::BikeRide, record).upcast::<gtk::Widget>(),
|
||||||
),
|
),
|
||||||
TraxRecord::Row(record) => {
|
Record {
|
||||||
Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>())
|
data: TraxRecord::Row(record),
|
||||||
}
|
..
|
||||||
TraxRecord::Run(record) => {
|
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||||
Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>())
|
Record {
|
||||||
}
|
data: TraxRecord::Run(record),
|
||||||
TraxRecord::Swim(record) => {
|
..
|
||||||
Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>())
|
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||||
}
|
Record {
|
||||||
TraxRecord::Walk(record) => {
|
data: TraxRecord::Swim(record),
|
||||||
Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>())
|
..
|
||||||
}
|
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||||
|
Record {
|
||||||
|
data: TraxRecord::Walk(record),
|
||||||
|
..
|
||||||
|
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with Fit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::components::DaySummary;
|
use crate::components::DaySummary;
|
||||||
use emseries::{Recordable, Timestamp};
|
use emseries::{Record, Recordable, Timestamp};
|
||||||
use ft_core::TraxRecord;
|
use ft_core::TraxRecord;
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
@ -46,9 +46,9 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HistoricalView {
|
impl HistoricalView {
|
||||||
pub fn new<SelectFn>(records: Vec<TraxRecord>, on_select_day: Rc<SelectFn>) -> Self
|
pub fn new<SelectFn>(records: Vec<Record<TraxRecord>>, on_select_day: Rc<SelectFn>) -> Self
|
||||||
where
|
where
|
||||||
SelectFn: Fn(chrono::NaiveDate, Vec<TraxRecord>) + 'static,
|
SelectFn: Fn(chrono::NaiveDate, Vec<Record<TraxRecord>>) + 'static,
|
||||||
{
|
{
|
||||||
let s: Self = Object::builder().build();
|
let s: Self = Object::builder().build();
|
||||||
s.set_orientation(gtk::Orientation::Vertical);
|
s.set_orientation(gtk::Orientation::Vertical);
|
||||||
|
@ -111,7 +111,7 @@ impl HistoricalView {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct DayRecordsPrivate {
|
pub struct DayRecordsPrivate {
|
||||||
date: RefCell<chrono::NaiveDate>,
|
date: RefCell<chrono::NaiveDate>,
|
||||||
records: RefCell<Vec<TraxRecord>>,
|
records: RefCell<Vec<Record<TraxRecord>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -127,7 +127,7 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DayRecords {
|
impl DayRecords {
|
||||||
pub fn new(date: chrono::NaiveDate, records: Vec<TraxRecord>) -> Self {
|
pub fn new(date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>) -> Self {
|
||||||
let s: Self = Object::builder().build();
|
let s: Self = Object::builder().build();
|
||||||
|
|
||||||
*s.imp().date.borrow_mut() = date;
|
*s.imp().date.borrow_mut() = date;
|
||||||
|
@ -140,30 +140,26 @@ impl DayRecords {
|
||||||
self.imp().date.borrow().clone()
|
self.imp().date.borrow().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn records(&self) -> Vec<TraxRecord> {
|
pub fn records(&self) -> Vec<Record<TraxRecord>> {
|
||||||
self.imp().records.borrow().clone()
|
self.imp().records.borrow().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_record(&self, record: TraxRecord) {
|
pub fn add_record(&self, record: Record<TraxRecord>) {
|
||||||
self.imp().records.borrow_mut().push(record);
|
self.imp().records.borrow_mut().push(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GroupedRecords(Vec<DayRecords>);
|
struct GroupedRecords(Vec<DayRecords>);
|
||||||
|
|
||||||
impl From<Vec<TraxRecord>> for GroupedRecords {
|
impl From<Vec<Record<TraxRecord>>> for GroupedRecords {
|
||||||
fn from(records: Vec<TraxRecord>) -> GroupedRecords {
|
fn from(records: Vec<Record<TraxRecord>>) -> GroupedRecords {
|
||||||
GroupedRecords(
|
GroupedRecords(
|
||||||
records
|
records
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.fold(HashMap::new(), |mut acc, rec| {
|
.fold(HashMap::new(), |mut acc, rec| {
|
||||||
let date = match rec.timestamp() {
|
acc.entry(rec.date())
|
||||||
Timestamp::DateTime(dtz) => dtz.date_naive(),
|
|
||||||
Timestamp::Date(date) => date,
|
|
||||||
};
|
|
||||||
acc.entry(date)
|
|
||||||
.and_modify(|entry: &mut DayRecords| (*entry).add_record(rec.clone()))
|
.and_modify(|entry: &mut DayRecords| (*entry).add_record(rec.clone()))
|
||||||
.or_insert(DayRecords::new(date, vec![rec]));
|
.or_insert(DayRecords::new(rec.date(), vec![rec]));
|
||||||
acc
|
acc
|
||||||
})
|
})
|
||||||
.values()
|
.values()
|
||||||
|
|
Loading…
Reference in New Issue