Render a weight record
This commit is contained in:
parent
43cd408e2c
commit
3dc8be0d26
|
@ -1022,6 +1022,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-channel",
|
"async-channel",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"dimensioned 0.8.0",
|
||||||
"emseries",
|
"emseries",
|
||||||
"ft-core",
|
"ft-core",
|
||||||
"gio",
|
"gio",
|
||||||
|
|
|
@ -9,6 +9,7 @@ edition = "2021"
|
||||||
adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] }
|
adw = { version = "0.5", package = "libadwaita", features = [ "v1_2" ] }
|
||||||
async-channel = { version = "2.1" }
|
async-channel = { version = "2.1" }
|
||||||
chrono = { version = "0.4" }
|
chrono = { version = "0.4" }
|
||||||
|
dimensioned = { version = "0.8", features = [ "serde" ] }
|
||||||
emseries = { path = "../../emseries" }
|
emseries = { path = "../../emseries" }
|
||||||
ft-core = { path = "../core" }
|
ft-core = { path = "../core" }
|
||||||
gio = { version = "0.18" }
|
gio = { version = "0.18" }
|
||||||
|
|
|
@ -16,12 +16,15 @@ 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 ft_core::TraxRecord;
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
|
use std::cell::RefCell;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct DaySummaryPrivate {
|
pub struct DaySummaryPrivate {
|
||||||
date: gtk::Label,
|
date: gtk::Label,
|
||||||
|
weight: RefCell<Option<gtk::Label>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -33,6 +36,7 @@ impl ObjectSubclass for DaySummaryPrivate {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
date: gtk::Label::new(None),
|
date: gtk::Label::new(None),
|
||||||
|
weight: RefCell::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,4 +64,18 @@ impl DaySummary {
|
||||||
.date
|
.date
|
||||||
.set_text(&date.format("%y-%m-%d").to_string());
|
.set_text(&date.format("%y-%m-%d").to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_records(&self, records: Vec<TraxRecord>) {
|
||||||
|
if let Some(ref weight_label) = *self.imp().weight.borrow() {
|
||||||
|
self.remove(weight_label);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(TraxRecord::Weight(weight_record)) =
|
||||||
|
records.iter().filter(|f| f.is_weight()).next()
|
||||||
|
{
|
||||||
|
let label = gtk::Label::new(Some(&format!("{}", weight_record.weight)));
|
||||||
|
self.append(&label);
|
||||||
|
*self.imp().weight.borrow_mut() = Some(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ You should have received a copy of the GNU General Public License along with Fit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use crate::components::DaySummary;
|
use crate::components::DaySummary;
|
||||||
use ft_core::TraxRecord;
|
use dimensioned::si::KG;
|
||||||
|
use ft_core::{TraxRecord, Weight};
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -56,7 +57,10 @@ impl HistoricalView {
|
||||||
|
|
||||||
let day_records: Vec<DayRecords> = vec![DayRecords::new(
|
let day_records: Vec<DayRecords> = vec![DayRecords::new(
|
||||||
chrono::NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
chrono::NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
||||||
vec![],
|
vec![TraxRecord::Weight(Weight {
|
||||||
|
date: chrono::NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
||||||
|
weight: 100. * KG,
|
||||||
|
})],
|
||||||
)];
|
)];
|
||||||
|
|
||||||
let model = gio::ListStore::new::<DayRecords>();
|
let model = gio::ListStore::new::<DayRecords>();
|
||||||
|
@ -86,6 +90,7 @@ impl HistoricalView {
|
||||||
.expect("should be a DaySummary");
|
.expect("should be a DaySummary");
|
||||||
|
|
||||||
summary.set_date(records.date());
|
summary.set_date(records.date());
|
||||||
|
summary.set_records(records.records());
|
||||||
});
|
});
|
||||||
|
|
||||||
let lst = gtk::ListView::builder()
|
let lst = gtk::ListView::builder()
|
||||||
|
|
|
@ -4,4 +4,4 @@ use emseries::DateTimeTz;
|
||||||
|
|
||||||
mod legacy;
|
mod legacy;
|
||||||
mod types;
|
mod types;
|
||||||
pub use types::TraxRecord;
|
pub use types::{TraxRecord, Weight};
|
||||||
|
|
|
@ -48,8 +48,8 @@ pub struct TimeDistance {
|
||||||
/// need to track more than a single weight in a day.
|
/// need to track more than a single weight in a day.
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Weight {
|
pub struct Weight {
|
||||||
date: NaiveDate,
|
pub date: NaiveDate,
|
||||||
weight: si::Kilogram<f64>,
|
pub weight: si::Kilogram<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The unified data structure for all records that are part of the app.
|
/// The unified data structure for all records that are part of the app.
|
||||||
|
@ -64,6 +64,15 @@ pub enum TraxRecord {
|
||||||
Weight(Weight),
|
Weight(Weight),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TraxRecord {
|
||||||
|
pub fn is_weight(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
TraxRecord::Weight(_) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Recordable for TraxRecord {
|
impl Recordable for TraxRecord {
|
||||||
fn timestamp(&self) -> Timestamp {
|
fn timestamp(&self) -> Timestamp {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in New Issue