Switch to the updated emseries record type
This commit is contained in:
parent
819078c15b
commit
00994d51c0
|
@ -14,7 +14,7 @@ General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
|
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use emseries::Series;
|
use emseries::{Record, RecordId, Series};
|
||||||
use ft_core::TraxRecord;
|
use ft_core::TraxRecord;
|
||||||
use std::{
|
use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
@ -30,6 +30,12 @@ pub enum AppInvocation {
|
||||||
/// Request a set of records from the core.
|
/// Request a set of records from the core.
|
||||||
// Note: this will require a time range, but doesn't yet.
|
// Note: this will require a time range, but doesn't yet.
|
||||||
RequestRecords,
|
RequestRecords,
|
||||||
|
|
||||||
|
UpdateRecord(Record<TraxRecord>),
|
||||||
|
|
||||||
|
PutRecord(TraxRecord),
|
||||||
|
|
||||||
|
DeleteRecord(RecordId),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Responses are messages that the core sends to the UI. Though they are called responses, the
|
/// Responses are messages that the core sends to the UI. Though they are called responses, the
|
||||||
|
@ -83,6 +89,27 @@ impl App {
|
||||||
AppResponse::Records
|
AppResponse::Records
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
AppInvocation::UpdateRecord(record) => match *self.database.write().unwrap() {
|
||||||
|
Some(ref mut database) => {
|
||||||
|
database.update(record).unwrap();
|
||||||
|
AppResponse::Records
|
||||||
|
}
|
||||||
|
None => AppResponse::NoDatabase,
|
||||||
|
},
|
||||||
|
AppInvocation::PutRecord(record) => match *self.database.write().unwrap() {
|
||||||
|
Some(ref mut database) => {
|
||||||
|
database.put(record).unwrap();
|
||||||
|
AppResponse::Records
|
||||||
|
}
|
||||||
|
None => AppResponse::NoDatabase,
|
||||||
|
},
|
||||||
|
AppInvocation::DeleteRecord(record_id) => match *self.database.write().unwrap() {
|
||||||
|
Some(ref mut database) => {
|
||||||
|
database.delete(&record_id).unwrap();
|
||||||
|
AppResponse::Records
|
||||||
|
}
|
||||||
|
None => AppResponse::NoDatabase,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,10 +157,10 @@ impl DayDetail {
|
||||||
});
|
});
|
||||||
|
|
||||||
let weight_view = match weight_record {
|
let weight_view = match weight_record {
|
||||||
Some((unique_id, record)) => WeightView::new(Some(record), move |weight| {
|
Some((id, record)) => WeightView::new(Some(record.clone()), move |weight| {
|
||||||
println!(
|
println!(
|
||||||
"on_blur on the weight view. Need to record {:?}, {:?}",
|
"on_blur on the weight view. Need to record {:?}, {:?}",
|
||||||
unique_id, weight
|
id, weight
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
None => WeightView::new(None, |weight| {
|
None => WeightView::new(None, |weight| {
|
||||||
|
|
|
@ -173,7 +173,6 @@ impl From<Vec<Record<TraxRecord>>> for GroupedRecords {
|
||||||
mod test {
|
mod test {
|
||||||
use super::GroupedRecords;
|
use super::GroupedRecords;
|
||||||
use chrono::{FixedOffset, NaiveDate, TimeZone};
|
use chrono::{FixedOffset, NaiveDate, TimeZone};
|
||||||
use chrono_tz::America::Anchorage;
|
|
||||||
use dimensioned::si::{KG, M, S};
|
use dimensioned::si::{KG, M, S};
|
||||||
use emseries::{Record, RecordId};
|
use emseries::{Record, RecordId};
|
||||||
use ft_core::{Steps, TimeDistance, TraxRecord, Weight};
|
use ft_core::{Steps, TimeDistance, TraxRecord, Weight};
|
||||||
|
@ -181,36 +180,51 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn groups_records() {
|
fn groups_records() {
|
||||||
let records = vec![
|
let records = vec![
|
||||||
TraxRecord::Steps(Steps {
|
Record {
|
||||||
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
id: RecordId::default(),
|
||||||
count: 1500,
|
data: TraxRecord::Steps(Steps {
|
||||||
}),
|
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
||||||
TraxRecord::Weight(Weight {
|
count: 1500,
|
||||||
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
}),
|
||||||
weight: 85. * KG,
|
},
|
||||||
}),
|
Record {
|
||||||
TraxRecord::Weight(Weight {
|
id: RecordId::default(),
|
||||||
date: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(),
|
data: TraxRecord::Weight(Weight {
|
||||||
weight: 86. * KG,
|
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
||||||
}),
|
weight: 85. * KG,
|
||||||
TraxRecord::BikeRide(TimeDistance {
|
}),
|
||||||
datetime: FixedOffset::west_opt(10 * 60 * 60)
|
},
|
||||||
.unwrap()
|
Record {
|
||||||
.with_ymd_and_hms(2019, 6, 15, 12, 0, 0)
|
id: RecordId::default(),
|
||||||
.unwrap(),
|
data: TraxRecord::Weight(Weight {
|
||||||
distance: Some(1000. * M),
|
date: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(),
|
||||||
duration: Some(150. * S),
|
weight: 86. * KG,
|
||||||
comments: Some("Test Comments".to_owned()),
|
}),
|
||||||
}),
|
},
|
||||||
TraxRecord::BikeRide(TimeDistance {
|
Record {
|
||||||
datetime: FixedOffset::west_opt(10 * 60 * 60)
|
id: RecordId::default(),
|
||||||
.unwrap()
|
data: TraxRecord::BikeRide(TimeDistance {
|
||||||
.with_ymd_and_hms(2019, 6, 15, 23, 0, 0)
|
datetime: FixedOffset::west_opt(10 * 60 * 60)
|
||||||
.unwrap(),
|
.unwrap()
|
||||||
distance: Some(1000. * M),
|
.with_ymd_and_hms(2019, 6, 15, 12, 0, 0)
|
||||||
duration: Some(150. * S),
|
.unwrap(),
|
||||||
comments: Some("Test Comments".to_owned()),
|
distance: Some(1000. * M),
|
||||||
}),
|
duration: Some(150. * S),
|
||||||
|
comments: Some("Test Comments".to_owned()),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
Record {
|
||||||
|
id: RecordId::default(),
|
||||||
|
data: 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 groups = GroupedRecords::from(records).0;
|
let groups = GroupedRecords::from(records).0;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
mod legacy;
|
mod legacy;
|
||||||
|
|
||||||
mod types;
|
mod types;
|
||||||
pub use types::{RecordType, Steps, TimeDistance, TraxRecord, Weight};
|
pub use types::{RecordType, Steps, TimeDistance, TraxRecord, Weight};
|
||||||
|
|
Loading…
Reference in New Issue