Record data to the database
This isn't recording real data. It's basically discarding all information from the weight edit field. But it is creating a record.
This commit is contained in:
parent
68c5ab0958
commit
d4dc493297
|
@ -217,7 +217,24 @@ impl AppWindow {
|
||||||
Rc::new(move |date, records| {
|
Rc::new(move |date, records| {
|
||||||
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||||
layout.append(&adw::HeaderBar::new());
|
layout.append(&adw::HeaderBar::new());
|
||||||
layout.append(&DayDetail::new(date, records));
|
layout.append(&DayDetail::new(
|
||||||
|
date,
|
||||||
|
records,
|
||||||
|
{
|
||||||
|
let app_tx = s.app_tx.clone();
|
||||||
|
move |record| {
|
||||||
|
let _ =
|
||||||
|
app_tx.send_blocking(AppInvocation::PutRecord(record));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
let app_tx = s.app_tx.clone();
|
||||||
|
move |record| {
|
||||||
|
let _ = app_tx
|
||||||
|
.send_blocking(AppInvocation::UpdateRecord(record));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
));
|
||||||
let page = &adw::NavigationPage::builder()
|
let page = &adw::NavigationPage::builder()
|
||||||
.title(date.format("%Y-%m-%d").to_string())
|
.title(date.format("%Y-%m-%d").to_string())
|
||||||
.child(&layout)
|
.child(&layout)
|
||||||
|
|
|
@ -133,7 +133,16 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DayDetail {
|
impl DayDetail {
|
||||||
pub fn new(date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>) -> Self {
|
pub fn new<SaveRecordFn, UpdateRecordFn>(
|
||||||
|
date: chrono::NaiveDate,
|
||||||
|
records: Vec<Record<TraxRecord>>,
|
||||||
|
on_save_record: SaveRecordFn,
|
||||||
|
on_update_record: UpdateRecordFn,
|
||||||
|
) -> Self
|
||||||
|
where
|
||||||
|
SaveRecordFn: Fn(TraxRecord) + 'static,
|
||||||
|
UpdateRecordFn: Fn(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);
|
||||||
|
|
||||||
|
@ -159,17 +168,14 @@ impl DayDetail {
|
||||||
});
|
});
|
||||||
|
|
||||||
let weight_view = match weight_record {
|
let weight_view = match weight_record {
|
||||||
Some((id, record)) => WeightView::new(Some(record.clone()), move |weight| {
|
Some((id, data)) => WeightView::new(Some(data.clone()), move |weight| {
|
||||||
println!(
|
on_update_record(Record {
|
||||||
"on_blur on the weight view. Need to record {:?}, {:?}",
|
id: id.clone(),
|
||||||
id, weight
|
data: TraxRecord::Weight(Weight { date, weight }),
|
||||||
);
|
})
|
||||||
}),
|
}),
|
||||||
None => WeightView::new(None, |weight| {
|
None => WeightView::new(None, move |weight| {
|
||||||
println!(
|
on_save_record(TraxRecord::Weight(Weight { date, weight }));
|
||||||
"on_blur on the weight view. Need to create a new record for {:?}",
|
|
||||||
weight
|
|
||||||
);
|
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
s.append(&weight_view);
|
s.append(&weight_view);
|
||||||
|
|
|
@ -155,6 +155,9 @@ impl DayRecords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This isn't feeling quite right. DayRecords is a glib object, but I'm not sure that I want to
|
||||||
|
// really be passing that around. It seems not generic enough. I feel like this whole grouped
|
||||||
|
// records thing can be made more generic.
|
||||||
struct GroupedRecords {
|
struct GroupedRecords {
|
||||||
interval: DayInterval,
|
interval: DayInterval,
|
||||||
data: HashMap<NaiveDate, DayRecords>,
|
data: HashMap<NaiveDate, DayRecords>,
|
||||||
|
@ -184,12 +187,6 @@ impl GroupedRecords {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn items<'a>(&'a self) -> impl Iterator<Item = DayRecords> + 'a {
|
fn items<'a>(&'a self) -> impl Iterator<Item = DayRecords> + 'a {
|
||||||
/*
|
|
||||||
GroupedRecordIterator {
|
|
||||||
interval: self.interval.clone(),
|
|
||||||
data: &self.data,
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
self.interval.days().map(|date| {
|
self.interval.days().map(|date| {
|
||||||
self.data
|
self.data
|
||||||
.get(&date)
|
.get(&date)
|
||||||
|
@ -199,21 +196,9 @@ impl GroupedRecords {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// This interval doesn't feel right, either. The idea that I have a specific interval type for just
|
||||||
struct GroupedRecordIterator<'a> {
|
// NaiveDate is odd. This should be genericized, as should the iterator. Also, it shouldn't live
|
||||||
interval: DayInterval,
|
// here, but in utilities.
|
||||||
data: &'a HashMap<NaiveDate, DayRecords>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl <'a> Iterator for GroupedRecordIterator<'a> {
|
|
||||||
type Item = &'a DayRecords;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<&'a DayRecords> {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
struct DayInterval {
|
struct DayInterval {
|
||||||
start: NaiveDate,
|
start: NaiveDate,
|
||||||
|
|
Loading…
Reference in New Issue