Compare commits
No commits in common. "7bd4885b09bfe6d2cc5b0b147b80fdc970498374" and "d269924827976bfb6fee0d8faeb6b96a603d516c" have entirely different histories.
7bd4885b09
...
d269924827
|
@ -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 id: RecordId,
|
pub(crate) id: RecordId,
|
||||||
pub data: T,
|
pub data: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,38 +2,32 @@
|
||||||
margin: 64px;
|
margin: 64px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome__title {
|
.welcome-title {
|
||||||
font-size: larger;
|
font-size: larger;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome__content {
|
.welcome-content {
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.welcome__footer {
|
.welcome-footer {
|
||||||
}
|
}
|
||||||
|
|
||||||
.historical {
|
.dialog-row {
|
||||||
margin: 32px;
|
margin: 8px 0px 8px 0px;
|
||||||
border-radius: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.day-summary {
|
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.day-summary__date {
|
.daysummary {
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.daysummary-date {
|
||||||
font-size: larger;
|
font-size: larger;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.day-summary__weight {
|
.daysummary-weight {
|
||||||
margin: 4px;
|
margin: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.weight-view {
|
|
||||||
padding: 8px;
|
|
||||||
margin: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,11 @@ 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 crate::types::DayInterval;
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use emseries::{time_range, Record, RecordId, Series, Timestamp};
|
use emseries::{time_range, Record, RecordId, Series, Timestamp};
|
||||||
use ft_core::TraxRecord;
|
use ft_core::TraxRecord;
|
||||||
use std::{
|
use std::{
|
||||||
path::PathBuf,
|
path::{Path, PathBuf},
|
||||||
sync::{Arc, RwLock},
|
sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
|
@ -98,7 +97,7 @@ impl App {
|
||||||
.map_err(|_| AppError::Unhandled)
|
.map_err(|_| AppError::Unhandled)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_record(&self, record: Record<TraxRecord>) -> Result<(), AppError> {
|
pub async fn save_record(&self, record: Record<TraxRecord>) -> Result<(), AppError> {
|
||||||
let db = self.database.clone();
|
let db = self.database.clone();
|
||||||
self.runtime
|
self.runtime
|
||||||
.spawn_blocking(move || {
|
.spawn_blocking(move || {
|
||||||
|
|
|
@ -16,13 +16,10 @@ You should have received a copy of the GNU General Public License along with Fit
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::App,
|
app::App,
|
||||||
components::DayDetail,
|
|
||||||
views::{HistoricalView, PlaceholderView, View, WelcomeView},
|
views::{HistoricalView, PlaceholderView, View, WelcomeView},
|
||||||
};
|
};
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use chrono::{Duration, Local};
|
use chrono::{Duration, Local};
|
||||||
use emseries::Record;
|
|
||||||
use ft_core::TraxRecord;
|
|
||||||
use gio::resources_lookup_data;
|
use gio::resources_lookup_data;
|
||||||
use gtk::STYLE_PROVIDER_PRIORITY_USER;
|
use gtk::STYLE_PROVIDER_PRIORITY_USER;
|
||||||
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
||||||
|
@ -32,6 +29,7 @@ use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AppWindow {
|
pub struct AppWindow {
|
||||||
app: App,
|
app: App,
|
||||||
|
app_id: String,
|
||||||
layout: gtk::Box,
|
layout: gtk::Box,
|
||||||
current_view: Rc<RefCell<View>>,
|
current_view: Rc<RefCell<View>>,
|
||||||
settings: gio::Settings,
|
settings: gio::Settings,
|
||||||
|
@ -83,6 +81,7 @@ impl AppWindow {
|
||||||
|
|
||||||
let initial_view = View::Placeholder(PlaceholderView::new().upcast());
|
let initial_view = View::Placeholder(PlaceholderView::new().upcast());
|
||||||
|
|
||||||
|
// layout.append(&header);
|
||||||
layout.append(&initial_view.widget());
|
layout.append(&initial_view.widget());
|
||||||
|
|
||||||
let nav_layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
let nav_layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||||
|
@ -99,25 +98,24 @@ impl AppWindow {
|
||||||
window.set_content(Some(&navigation));
|
window.set_content(Some(&navigation));
|
||||||
window.present();
|
window.present();
|
||||||
|
|
||||||
let gesture = gtk::GestureClick::new();
|
|
||||||
gesture.connect_released(|_, _, _, _| println!("detected gesture"));
|
|
||||||
layout.add_controller(gesture);
|
|
||||||
|
|
||||||
let s = Self {
|
let s = Self {
|
||||||
app: ft_app,
|
app: ft_app,
|
||||||
|
app_id: app_id.to_owned(),
|
||||||
layout,
|
layout,
|
||||||
current_view: Rc::new(RefCell::new(initial_view)),
|
current_view: Rc::new(RefCell::new(initial_view)),
|
||||||
settings: gio::Settings::new(app_id),
|
settings: gio::Settings::new(app_id),
|
||||||
navigation,
|
navigation,
|
||||||
};
|
};
|
||||||
|
|
||||||
s.load_records();
|
glib::spawn_future_local({
|
||||||
|
|
||||||
s.navigation.connect_popped({
|
|
||||||
let s = s.clone();
|
let s = s.clone();
|
||||||
move |_, _| match *s.current_view.borrow() {
|
async move {
|
||||||
View::Historical(_) => s.load_records(),
|
let end = Local::now().date_naive();
|
||||||
_ => {}
|
let start = end - Duration::days(7);
|
||||||
|
match s.app.records(start, end).await {
|
||||||
|
Ok(_) => s.show_historical_view(),
|
||||||
|
Err(_) => s.show_welcome_view(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -132,48 +130,11 @@ impl AppWindow {
|
||||||
self.swap_main(view);
|
self.swap_main(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn show_historical_view(&self, records: Vec<Record<TraxRecord>>) {
|
fn show_historical_view(&self) {
|
||||||
let view = View::Historical(HistoricalView::new(records, {
|
let view = View::Historical(HistoricalView::new(vec![]));
|
||||||
let s = self.clone();
|
|
||||||
Rc::new(move |date, records| {
|
|
||||||
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
|
||||||
layout.append(&adw::HeaderBar::new());
|
|
||||||
layout.append(&DayDetail::new(
|
|
||||||
date,
|
|
||||||
records,
|
|
||||||
{
|
|
||||||
let s = s.clone();
|
|
||||||
move |record| s.on_put_record(record)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
let s = s.clone();
|
|
||||||
move |record| s.on_update_record(record)
|
|
||||||
},
|
|
||||||
));
|
|
||||||
let page = &adw::NavigationPage::builder()
|
|
||||||
.title(date.format("%Y-%m-%d").to_string())
|
|
||||||
.child(&layout)
|
|
||||||
.build();
|
|
||||||
s.navigation.push(page);
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
self.swap_main(view);
|
self.swap_main(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_records(&self) {
|
|
||||||
glib::spawn_future_local({
|
|
||||||
let s = self.clone();
|
|
||||||
async move {
|
|
||||||
let end = Local::now().date_naive();
|
|
||||||
let start = end - Duration::days(7);
|
|
||||||
match s.app.records(start, end).await {
|
|
||||||
Ok(records) => s.show_historical_view(records),
|
|
||||||
Err(_) => s.show_welcome_view(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Switch views.
|
// Switch views.
|
||||||
//
|
//
|
||||||
// This function only replaces the old view with the one which matches the current view state.
|
// This function only replaces the old view with the one which matches the current view state.
|
||||||
|
@ -192,27 +153,9 @@ impl AppWindow {
|
||||||
async move {
|
async move {
|
||||||
if s.app.open_db(path.clone()).await.is_ok() {
|
if s.app.open_db(path.clone()).await.is_ok() {
|
||||||
let _ = s.settings.set("series-path", path.to_str().unwrap());
|
let _ = s.settings.set("series-path", path.to_str().unwrap());
|
||||||
s.load_records();
|
s.show_historical_view();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_put_record(&self, record: TraxRecord) {
|
|
||||||
glib::spawn_future_local({
|
|
||||||
let s = self.clone();
|
|
||||||
async move {
|
|
||||||
s.app.put_record(record).await;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn on_update_record(&self, record: Record<TraxRecord>) {
|
|
||||||
glib::spawn_future_local({
|
|
||||||
let s = self.clone();
|
|
||||||
async move {
|
|
||||||
s.app.update_record(record).await;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,12 @@ 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 chrono::{Local, NaiveDate};
|
use ft_core::TraxRecord;
|
||||||
use dimensioned::si;
|
|
||||||
use emseries::Record;
|
|
||||||
use ft_core::{RecordType, TimeDistance, TraxRecord, Weight};
|
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct DaySummaryPrivate {
|
pub struct DaySummaryPrivate {
|
||||||
date: gtk::Label,
|
date: gtk::Label,
|
||||||
weight: RefCell<Option<gtk::Label>>,
|
weight: RefCell<Option<gtk::Label>>,
|
||||||
|
@ -37,7 +35,7 @@ impl ObjectSubclass for DaySummaryPrivate {
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let date = gtk::Label::builder()
|
let date = gtk::Label::builder()
|
||||||
.css_classes(["day-summary__date"])
|
.css_classes(["daysummary-date"])
|
||||||
.halign(gtk::Align::Start)
|
.halign(gtk::Align::Start)
|
||||||
.build();
|
.build();
|
||||||
Self {
|
Self {
|
||||||
|
@ -61,14 +59,14 @@ impl DaySummary {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> 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);
|
||||||
s.set_css_classes(&["day-summary"]);
|
s.set_css_classes(&["daysummary"]);
|
||||||
|
|
||||||
s.append(&s.imp().date);
|
s.append(&s.imp().date);
|
||||||
|
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_data(&self, date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>) {
|
pub fn set_data(&self, date: chrono::NaiveDate, records: Vec<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());
|
||||||
|
@ -77,357 +75,16 @@ impl DaySummary {
|
||||||
self.remove(weight_label);
|
self.remove(weight_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(Record {
|
if let Some(TraxRecord::Weight(weight_record)) =
|
||||||
data: TraxRecord::Weight(weight_record),
|
records.iter().filter(|f| f.is_weight()).next()
|
||||||
..
|
|
||||||
}) = 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)
|
||||||
.label(&format!("{}", weight_record.weight))
|
.label(&format!("{}", weight_record.weight))
|
||||||
.css_classes(["day-summary__weight"])
|
.css_classes(["daysummary-weight"])
|
||||||
.build();
|
.build();
|
||||||
self.append(&label);
|
self.append(&label);
|
||||||
*self.imp().weight.borrow_mut() = Some(label);
|
*self.imp().weight.borrow_mut() = Some(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
self.append(
|
|
||||||
>k::Label::builder()
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.label("15km of biking in 60 minutes")
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DayDetailPrivate {
|
|
||||||
date: gtk::Label,
|
|
||||||
weight: RefCell<Option<gtk::Label>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for DayDetailPrivate {
|
|
||||||
const NAME: &'static str = "DayDetail";
|
|
||||||
type Type = DayDetail;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
|
|
||||||
fn new() -> Self {
|
|
||||||
let date = gtk::Label::builder()
|
|
||||||
.css_classes(["daysummary-date"])
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.build();
|
|
||||||
Self {
|
|
||||||
date,
|
|
||||||
weight: RefCell::new(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for DayDetailPrivate {}
|
|
||||||
impl WidgetImpl for DayDetailPrivate {}
|
|
||||||
impl BoxImpl for DayDetailPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct DayDetail(ObjectSubclass<DayDetailPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DayDetail {
|
|
||||||
pub fn new<PutRecordFn, UpdateRecordFn>(
|
|
||||||
date: chrono::NaiveDate,
|
|
||||||
records: Vec<Record<TraxRecord>>,
|
|
||||||
on_put_record: PutRecordFn,
|
|
||||||
on_update_record: UpdateRecordFn,
|
|
||||||
) -> Self
|
|
||||||
where
|
|
||||||
PutRecordFn: Fn(TraxRecord) + 'static,
|
|
||||||
UpdateRecordFn: Fn(Record<TraxRecord>) + 'static,
|
|
||||||
{
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
s.set_orientation(gtk::Orientation::Vertical);
|
|
||||||
|
|
||||||
let click_controller = gtk::GestureClick::new();
|
|
||||||
click_controller.connect_released({
|
|
||||||
let s = s.clone();
|
|
||||||
move |_, _, _, _| {
|
|
||||||
println!("clicked outside of focusable entity");
|
|
||||||
if let Some(widget) = s.focus_child().and_downcast_ref::<WeightView>() {
|
|
||||||
println!("focused child is the weight view");
|
|
||||||
widget.blur();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
s.add_controller(click_controller);
|
|
||||||
|
|
||||||
let weight_record = records.iter().find_map(|record| match record {
|
|
||||||
Record {
|
|
||||||
id,
|
|
||||||
data: TraxRecord::Weight(record),
|
|
||||||
} => Some((id.clone(), record.clone())),
|
|
||||||
_ => None,
|
|
||||||
});
|
|
||||||
|
|
||||||
let weight_view = match weight_record {
|
|
||||||
Some((id, data)) => WeightView::new(date.clone(), Some(data.clone()), move |weight| {
|
|
||||||
on_update_record(Record {
|
|
||||||
id: id.clone(),
|
|
||||||
data: TraxRecord::Weight(Weight { date, weight }),
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
None => WeightView::new(date.clone(), None, move |weight| {
|
|
||||||
on_put_record(TraxRecord::Weight(Weight { date, weight }));
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
s.append(&weight_view);
|
|
||||||
|
|
||||||
records.into_iter().for_each(|record| {
|
|
||||||
let record_view = match record {
|
|
||||||
Record {
|
|
||||||
data: TraxRecord::BikeRide(record),
|
|
||||||
..
|
|
||||||
} => Some(
|
|
||||||
TimeDistanceView::new(RecordType::BikeRide, record).upcast::<gtk::Widget>(),
|
|
||||||
),
|
|
||||||
Record {
|
|
||||||
data: TraxRecord::Row(record),
|
|
||||||
..
|
|
||||||
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
|
||||||
Record {
|
|
||||||
data: TraxRecord::Run(record),
|
|
||||||
..
|
|
||||||
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
|
||||||
Record {
|
|
||||||
data: TraxRecord::Swim(record),
|
|
||||||
..
|
|
||||||
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
|
||||||
Record {
|
|
||||||
data: TraxRecord::Walk(record),
|
|
||||||
..
|
|
||||||
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(record_view) = record_view {
|
|
||||||
record_view.add_css_class("day-detail");
|
|
||||||
record_view.set_halign(gtk::Align::Start);
|
|
||||||
|
|
||||||
s.append(&record_view);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct WeightViewPrivate {
|
|
||||||
date: RefCell<NaiveDate>,
|
|
||||||
record: RefCell<Option<Weight>>,
|
|
||||||
view: RefCell<gtk::Label>,
|
|
||||||
edit: RefCell<gtk::Entry>,
|
|
||||||
current: RefCell<gtk::Widget>,
|
|
||||||
on_edit_finished: RefCell<Box<dyn Fn(si::Kilogram<f64>)>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for WeightViewPrivate {
|
|
||||||
fn default() -> Self {
|
|
||||||
let view = gtk::Label::builder()
|
|
||||||
.css_classes(["card", "weight-view"])
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.can_focus(true)
|
|
||||||
.build();
|
|
||||||
let edit = gtk::Entry::builder().halign(gtk::Align::Start).build();
|
|
||||||
|
|
||||||
let current = view.clone();
|
|
||||||
|
|
||||||
Self {
|
|
||||||
date: RefCell::new(Local::now().date_naive()),
|
|
||||||
record: RefCell::new(None),
|
|
||||||
view: RefCell::new(view),
|
|
||||||
edit: RefCell::new(edit),
|
|
||||||
current: RefCell::new(current.upcast()),
|
|
||||||
on_edit_finished: RefCell::new(Box::new(|_| {})),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for WeightViewPrivate {
|
|
||||||
const NAME: &'static str = "WeightView";
|
|
||||||
type Type = WeightView;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for WeightViewPrivate {}
|
|
||||||
impl WidgetImpl for WeightViewPrivate {}
|
|
||||||
impl BoxImpl for WeightViewPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct WeightView(ObjectSubclass<WeightViewPrivate>) @extends gtk::Box, gtk::Widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WeightView {
|
|
||||||
pub fn new<OnEditFinished>(
|
|
||||||
date: NaiveDate,
|
|
||||||
weight: Option<Weight>,
|
|
||||||
on_edit_finished: OnEditFinished,
|
|
||||||
) -> Self
|
|
||||||
where
|
|
||||||
OnEditFinished: Fn(si::Kilogram<f64>) + 'static,
|
|
||||||
{
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
|
|
||||||
*s.imp().on_edit_finished.borrow_mut() = Box::new(on_edit_finished);
|
|
||||||
*s.imp().date.borrow_mut() = date;
|
|
||||||
|
|
||||||
*s.imp().record.borrow_mut() = weight;
|
|
||||||
s.view();
|
|
||||||
|
|
||||||
let view_click_controller = gtk::GestureClick::new();
|
|
||||||
view_click_controller.connect_released({
|
|
||||||
let s = s.clone();
|
|
||||||
move |_, _, _, _| {
|
|
||||||
s.edit();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
s.imp().view.borrow().add_controller(view_click_controller);
|
|
||||||
s
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self) {
|
|
||||||
let view = self.imp().view.borrow();
|
|
||||||
match *self.imp().record.borrow() {
|
|
||||||
Some(ref record) => {
|
|
||||||
view.remove_css_class("dim_label");
|
|
||||||
view.set_label(&format!("{:?}", record.weight));
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
view.add_css_class("dim_label");
|
|
||||||
view.set_label("No weight recorded");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.swap(view.clone().upcast());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn edit(&self) {
|
|
||||||
let edit = self.imp().edit.borrow();
|
|
||||||
match *self.imp().record.borrow() {
|
|
||||||
Some(ref record) => edit.buffer().set_text(&format!("{:?}", record.weight)),
|
|
||||||
None => edit.buffer().set_text(""),
|
|
||||||
}
|
|
||||||
self.swap(edit.clone().upcast());
|
|
||||||
edit.grab_focus();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn swap(&self, new_view: gtk::Widget) {
|
|
||||||
let mut current = self.imp().current.borrow_mut();
|
|
||||||
self.remove(&*current);
|
|
||||||
self.append(&new_view);
|
|
||||||
*current = new_view;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn blur(&self) {
|
|
||||||
let edit = self.imp().edit.borrow();
|
|
||||||
if *self.imp().current.borrow() == *edit {
|
|
||||||
let w = edit.buffer().text().parse::<f64>().unwrap();
|
|
||||||
self.imp().on_edit_finished.borrow()(w * si::KG);
|
|
||||||
|
|
||||||
let mut record = self.imp().record.borrow_mut();
|
|
||||||
match *record {
|
|
||||||
Some(ref mut record) => record.weight = w * si::KG,
|
|
||||||
None => {
|
|
||||||
*record = Some(Weight {
|
|
||||||
date: self.imp().date.borrow().clone(),
|
|
||||||
weight: w * si::KG,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.view();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct TimeDistanceViewPrivate {
|
|
||||||
record: RefCell<Option<TimeDistance>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
|
||||||
impl ObjectSubclass for TimeDistanceViewPrivate {
|
|
||||||
const NAME: &'static str = "TimeDistanceView";
|
|
||||||
type Type = TimeDistanceView;
|
|
||||||
type ParentType = gtk::Box;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ObjectImpl for TimeDistanceViewPrivate {}
|
|
||||||
impl WidgetImpl for TimeDistanceViewPrivate {}
|
|
||||||
impl BoxImpl for TimeDistanceViewPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct TimeDistanceView(ObjectSubclass<TimeDistanceViewPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TimeDistanceView {
|
|
||||||
pub fn new(type_: RecordType, record: TimeDistance) -> Self {
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
s.set_orientation(gtk::Orientation::Vertical);
|
|
||||||
s.set_hexpand(true);
|
|
||||||
|
|
||||||
let first_row = gtk::Box::builder().homogeneous(true).build();
|
|
||||||
|
|
||||||
first_row.append(
|
|
||||||
>k::Label::builder()
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.label(&record.datetime.format("%H:%M").to_string())
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
first_row.append(
|
|
||||||
>k::Label::builder()
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.label(format!("{:?}", type_))
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
first_row.append(
|
|
||||||
>k::Label::builder()
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.label(
|
|
||||||
record
|
|
||||||
.distance
|
|
||||||
.map(|dist| format!("{}", dist))
|
|
||||||
.unwrap_or("".to_owned()),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
first_row.append(
|
|
||||||
>k::Label::builder()
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.label(
|
|
||||||
record
|
|
||||||
.duration
|
|
||||||
.map(|duration| format!("{}", duration))
|
|
||||||
.unwrap_or("".to_owned()),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
s.append(&first_row);
|
|
||||||
|
|
||||||
s.append(
|
|
||||||
>k::Label::builder()
|
|
||||||
.halign(gtk::Align::Start)
|
|
||||||
.label(
|
|
||||||
record
|
|
||||||
.comments
|
|
||||||
.map(|comments| format!("{}", comments))
|
|
||||||
.unwrap_or("".to_owned()),
|
|
||||||
)
|
|
||||||
.build(),
|
|
||||||
);
|
|
||||||
|
|
||||||
s
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with Fit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mod day;
|
mod day;
|
||||||
pub use day::{DayDetail, DaySummary};
|
|
||||||
|
|
||||||
|
pub use day::DaySummary;
|
||||||
use glib::Object;
|
use glib::Object;
|
||||||
use gtk::{prelude::*, subclass::prelude::*};
|
use gtk::{prelude::*, subclass::prelude::*};
|
||||||
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
||||||
|
|
|
@ -17,13 +17,11 @@ You should have received a copy of the GNU General Public License along with Fit
|
||||||
mod app;
|
mod app;
|
||||||
mod app_window;
|
mod app_window;
|
||||||
mod components;
|
mod components;
|
||||||
mod types;
|
|
||||||
mod views;
|
mod views;
|
||||||
|
|
||||||
use adw::prelude::*;
|
use adw::prelude::*;
|
||||||
use app_window::AppWindow;
|
use app_window::AppWindow;
|
||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
use types::DayInterval;
|
|
||||||
|
|
||||||
const APP_ID_DEV: &str = "com.luminescent-dreams.fitnesstrax.dev";
|
const APP_ID_DEV: &str = "com.luminescent-dreams.fitnesstrax.dev";
|
||||||
const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax";
|
const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax";
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
use chrono::{Duration, Local, NaiveDate};
|
|
||||||
|
|
||||||
// This interval doesn't feel right, either. The idea that I have a specific interval type for just
|
|
||||||
// NaiveDate is odd. This should be genericized, as should the iterator. Also, it shouldn't live
|
|
||||||
// here, but in utilities.
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
||||||
pub struct DayInterval {
|
|
||||||
pub start: NaiveDate,
|
|
||||||
pub end: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for DayInterval {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
start: (Local::now() - Duration::days(7)).date_naive(),
|
|
||||||
end: Local::now().date_naive(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DayInterval {
|
|
||||||
pub fn days(&self) -> impl Iterator<Item = NaiveDate> {
|
|
||||||
DayIterator {
|
|
||||||
current: self.start.clone(),
|
|
||||||
end: self.end.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct DayIterator {
|
|
||||||
current: NaiveDate,
|
|
||||||
end: NaiveDate,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Iterator for DayIterator {
|
|
||||||
type Item = NaiveDate;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
|
||||||
if self.current <= self.end {
|
|
||||||
let val = self.current.clone();
|
|
||||||
self.current += Duration::days(1);
|
|
||||||
Some(val)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -14,21 +14,17 @@ 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 crate::{components::DaySummary, types::DayInterval};
|
use crate::components::DaySummary;
|
||||||
use chrono::{Duration, Local, NaiveDate};
|
use emseries::{Recordable, Timestamp};
|
||||||
use emseries::Record;
|
|
||||||
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, collections::HashMap, rc::Rc};
|
use std::{cell::RefCell, collections::HashMap};
|
||||||
|
|
||||||
/// The historical view will show a window into the main database. It will show some version of
|
/// The historical view will show a window into the main database. It will show some version of
|
||||||
/// daily summaries, daily details, and will provide all functions the user may need for editing
|
/// daily summaries, daily details, and will provide all functions the user may need for editing
|
||||||
/// records.
|
/// records.
|
||||||
pub struct HistoricalViewPrivate {
|
pub struct HistoricalViewPrivate {}
|
||||||
time_window: RefCell<DayInterval>,
|
|
||||||
list_view: gtk::ListView,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
impl ObjectSubclass for HistoricalViewPrivate {
|
impl ObjectSubclass for HistoricalViewPrivate {
|
||||||
|
@ -37,6 +33,28 @@ impl ObjectSubclass for HistoricalViewPrivate {
|
||||||
type ParentType = gtk::Box;
|
type ParentType = gtk::Box;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
|
Self {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ObjectImpl for HistoricalViewPrivate {}
|
||||||
|
impl WidgetImpl for HistoricalViewPrivate {}
|
||||||
|
impl BoxImpl for HistoricalViewPrivate {}
|
||||||
|
|
||||||
|
glib::wrapper! {
|
||||||
|
pub struct HistoricalView(ObjectSubclass<HistoricalViewPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HistoricalView {
|
||||||
|
pub fn new(records: Vec<TraxRecord>) -> Self {
|
||||||
|
let s: Self = Object::builder().build();
|
||||||
|
s.set_orientation(gtk::Orientation::Vertical);
|
||||||
|
|
||||||
|
let day_records: GroupedRecords = GroupedRecords::from(records);
|
||||||
|
|
||||||
|
let model = gio::ListStore::new::<DayRecords>();
|
||||||
|
model.extend_from_slice(&day_records.0);
|
||||||
|
|
||||||
let factory = gtk::SignalListItemFactory::new();
|
let factory = gtk::SignalListItemFactory::new();
|
||||||
factory.connect_setup(move |_, list_item| {
|
factory.connect_setup(move |_, list_item| {
|
||||||
list_item
|
list_item
|
||||||
|
@ -63,79 +81,30 @@ impl ObjectSubclass for HistoricalViewPrivate {
|
||||||
summary.set_data(records.date(), records.records());
|
summary.set_data(records.date(), records.records());
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
let lst = gtk::ListView::builder()
|
||||||
time_window: RefCell::new(DayInterval::default()),
|
.model(>k::NoSelection::new(Some(model)))
|
||||||
list_view: gtk::ListView::builder()
|
.factory(&factory)
|
||||||
.factory(&factory)
|
.single_click_activate(true)
|
||||||
.single_click_activate(true)
|
.build();
|
||||||
.build(),
|
lst.connect_activate(|s, idx| {
|
||||||
}
|
// This gets triggered whenever the user clicks on an item on the list. What we
|
||||||
}
|
// actually want to do here is to open a modal dialog that shows all of the details of
|
||||||
}
|
// the day and which allows the user to edit items within that dialog.
|
||||||
|
let item = s.model().unwrap().item(idx).unwrap();
|
||||||
impl ObjectImpl for HistoricalViewPrivate {}
|
let records = item.downcast_ref::<DayRecords>().unwrap();
|
||||||
impl WidgetImpl for HistoricalViewPrivate {}
|
println!("list item activated: [{:?}] {:?}", idx, records.date());
|
||||||
impl BoxImpl for HistoricalViewPrivate {}
|
|
||||||
|
|
||||||
glib::wrapper! {
|
|
||||||
pub struct HistoricalView(ObjectSubclass<HistoricalViewPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HistoricalView {
|
|
||||||
pub fn new<SelectFn>(records: Vec<Record<TraxRecord>>, on_select_day: Rc<SelectFn>) -> Self
|
|
||||||
where
|
|
||||||
SelectFn: Fn(chrono::NaiveDate, Vec<Record<TraxRecord>>) + 'static,
|
|
||||||
{
|
|
||||||
let s: Self = Object::builder().build();
|
|
||||||
s.set_orientation(gtk::Orientation::Vertical);
|
|
||||||
s.set_css_classes(&["historical"]);
|
|
||||||
|
|
||||||
let grouped_records =
|
|
||||||
GroupedRecords::new((*s.imp().time_window.borrow()).clone()).with_data(records);
|
|
||||||
|
|
||||||
let mut model = gio::ListStore::new::<DayRecords>();
|
|
||||||
model.extend(grouped_records.items());
|
|
||||||
s.imp()
|
|
||||||
.list_view
|
|
||||||
.set_model(Some(>k::NoSelection::new(Some(model))));
|
|
||||||
|
|
||||||
s.imp().list_view.connect_activate({
|
|
||||||
let on_select_day = on_select_day.clone();
|
|
||||||
move |s, idx| {
|
|
||||||
// This gets triggered whenever the user clicks on an item on the list. What we
|
|
||||||
// actually want to do here is to open a modal dialog that shows all of the details of
|
|
||||||
// the day and which allows the user to edit items within that dialog.
|
|
||||||
let item = s.model().unwrap().item(idx).unwrap();
|
|
||||||
let records = item.downcast_ref::<DayRecords>().unwrap();
|
|
||||||
on_select_day(records.date(), records.records());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
s.append(&s.imp().list_view);
|
s.append(&lst);
|
||||||
|
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_records(&self, records: Vec<Record<TraxRecord>>) {
|
|
||||||
println!("set_records: {:?}", records);
|
|
||||||
let grouped_records =
|
|
||||||
GroupedRecords::new((self.imp().time_window.borrow()).clone()).with_data(records);
|
|
||||||
let mut model = gio::ListStore::new::<DayRecords>();
|
|
||||||
model.extend(grouped_records.items());
|
|
||||||
self.imp()
|
|
||||||
.list_view
|
|
||||||
.set_model(Some(>k::NoSelection::new(Some(model))));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn time_window(&self) -> DayInterval {
|
|
||||||
self.imp().time_window.borrow().clone()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct DayRecordsPrivate {
|
pub struct DayRecordsPrivate {
|
||||||
date: RefCell<chrono::NaiveDate>,
|
date: RefCell<chrono::NaiveDate>,
|
||||||
records: RefCell<Vec<Record<TraxRecord>>>,
|
records: RefCell<Vec<TraxRecord>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[glib::object_subclass]
|
#[glib::object_subclass]
|
||||||
|
@ -151,7 +120,7 @@ glib::wrapper! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DayRecords {
|
impl DayRecords {
|
||||||
pub fn new(date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>) -> Self {
|
pub fn new(date: chrono::NaiveDate, records: Vec<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;
|
||||||
|
@ -164,53 +133,36 @@ impl DayRecords {
|
||||||
self.imp().date.borrow().clone()
|
self.imp().date.borrow().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn records(&self) -> Vec<Record<TraxRecord>> {
|
pub fn records(&self) -> Vec<TraxRecord> {
|
||||||
self.imp().records.borrow().clone()
|
self.imp().records.borrow().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_record(&self, record: Record<TraxRecord>) {
|
pub fn add_record(&self, record: TraxRecord) {
|
||||||
self.imp().records.borrow_mut().push(record);
|
self.imp().records.borrow_mut().push(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This isn't feeling quite right. DayRecords is a glib object, but I'm not sure that I want to
|
struct GroupedRecords(Vec<DayRecords>);
|
||||||
// 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 {
|
|
||||||
interval: DayInterval,
|
|
||||||
data: HashMap<NaiveDate, DayRecords>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl GroupedRecords {
|
impl From<Vec<TraxRecord>> for GroupedRecords {
|
||||||
fn new(interval: DayInterval) -> Self {
|
fn from(records: Vec<TraxRecord>) -> GroupedRecords {
|
||||||
let mut s = Self {
|
GroupedRecords(
|
||||||
interval: interval.clone(),
|
records
|
||||||
data: HashMap::new(),
|
.into_iter()
|
||||||
};
|
.fold(HashMap::new(), |mut acc, rec| {
|
||||||
interval.days().for_each(|date| {
|
let date = match rec.timestamp() {
|
||||||
let _ = s.data.insert(date, DayRecords::new(date, vec![]));
|
Timestamp::DateTime(dtz) => dtz.date_naive(),
|
||||||
});
|
Timestamp::Date(date) => date,
|
||||||
s
|
};
|
||||||
}
|
acc.entry(date)
|
||||||
|
.and_modify(|entry: &mut DayRecords| (*entry).add_record(rec.clone()))
|
||||||
fn with_data(mut self, records: Vec<Record<TraxRecord>>) -> Self {
|
.or_insert(DayRecords::new(date, vec![rec]));
|
||||||
records.into_iter().for_each(|record| {
|
acc
|
||||||
self.data
|
})
|
||||||
.entry(record.date())
|
.values()
|
||||||
.and_modify(|entry: &mut DayRecords| (*entry).add_record(record.clone()))
|
.cloned()
|
||||||
.or_insert(DayRecords::new(record.date(), vec![record]));
|
.collect::<Vec<DayRecords>>(),
|
||||||
});
|
)
|
||||||
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn items<'a>(&'a self) -> impl Iterator<Item = DayRecords> + 'a {
|
|
||||||
self.interval.days().map(|date| {
|
|
||||||
self.data
|
|
||||||
.get(&date)
|
|
||||||
.map(|rec| rec.clone())
|
|
||||||
.unwrap_or(DayRecords::new(date, vec![]))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,6 +170,7 @@ impl 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};
|
||||||
|
@ -225,51 +178,36 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn groups_records() {
|
fn groups_records() {
|
||||||
let records = vec![
|
let records = vec![
|
||||||
Record {
|
TraxRecord::Steps(Steps {
|
||||||
id: RecordId::default(),
|
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
||||||
data: TraxRecord::Steps(Steps {
|
count: 1500,
|
||||||
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
}),
|
||||||
count: 1500,
|
TraxRecord::Weight(Weight {
|
||||||
}),
|
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
||||||
},
|
weight: 85. * KG,
|
||||||
Record {
|
}),
|
||||||
id: RecordId::default(),
|
TraxRecord::Weight(Weight {
|
||||||
data: TraxRecord::Weight(Weight {
|
date: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(),
|
||||||
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
|
weight: 86. * KG,
|
||||||
weight: 85. * KG,
|
}),
|
||||||
}),
|
TraxRecord::BikeRide(TimeDistance {
|
||||||
},
|
datetime: FixedOffset::west_opt(10 * 60 * 60)
|
||||||
Record {
|
.unwrap()
|
||||||
id: RecordId::default(),
|
.with_ymd_and_hms(2019, 6, 15, 12, 0, 0)
|
||||||
data: TraxRecord::Weight(Weight {
|
.unwrap(),
|
||||||
date: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(),
|
distance: Some(1000. * M),
|
||||||
weight: 86. * KG,
|
duration: Some(150. * S),
|
||||||
}),
|
comments: Some("Test Comments".to_owned()),
|
||||||
},
|
}),
|
||||||
Record {
|
TraxRecord::BikeRide(TimeDistance {
|
||||||
id: RecordId::default(),
|
datetime: FixedOffset::west_opt(10 * 60 * 60)
|
||||||
data: TraxRecord::BikeRide(TimeDistance {
|
.unwrap()
|
||||||
datetime: FixedOffset::west_opt(10 * 60 * 60)
|
.with_ymd_and_hms(2019, 6, 15, 23, 0, 0)
|
||||||
.unwrap()
|
.unwrap(),
|
||||||
.with_ymd_and_hms(2019, 6, 15, 12, 0, 0)
|
distance: Some(1000. * M),
|
||||||
.unwrap(),
|
duration: Some(150. * S),
|
||||||
distance: Some(1000. * M),
|
comments: Some("Test Comments".to_owned()),
|
||||||
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;
|
||||||
|
|
|
@ -55,10 +55,11 @@ impl WelcomeView {
|
||||||
// branch.
|
// branch.
|
||||||
let title = gtk::Label::builder()
|
let title = gtk::Label::builder()
|
||||||
.label("Welcome to FitnessTrax")
|
.label("Welcome to FitnessTrax")
|
||||||
.css_classes(["welcome__title"])
|
.css_classes(["welcome-title"])
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let content = gtk::Box::builder()
|
let content = gtk::Box::builder()
|
||||||
|
.css_classes(["model-content"])
|
||||||
.orientation(gtk::Orientation::Vertical)
|
.orientation(gtk::Orientation::Vertical)
|
||||||
.vexpand(true)
|
.vexpand(true)
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
mod legacy;
|
mod legacy;
|
||||||
|
|
||||||
mod types;
|
mod types;
|
||||||
pub use types::{RecordType, Steps, TimeDistance, TraxRecord, Weight};
|
pub use types::{Steps, TimeDistance, TraxRecord, Weight};
|
||||||
|
|
|
@ -54,17 +54,6 @@ pub struct Weight {
|
||||||
pub weight: si::Kilogram<f64>,
|
pub weight: si::Kilogram<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
|
||||||
pub enum RecordType {
|
|
||||||
BikeRide,
|
|
||||||
Row,
|
|
||||||
Run,
|
|
||||||
Steps,
|
|
||||||
Swim,
|
|
||||||
Walk,
|
|
||||||
Weight,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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.
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum TraxRecord {
|
pub enum TraxRecord {
|
||||||
|
@ -78,18 +67,6 @@ pub enum TraxRecord {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TraxRecord {
|
impl TraxRecord {
|
||||||
pub fn workout_type(&self) -> RecordType {
|
|
||||||
match self {
|
|
||||||
TraxRecord::BikeRide(_) => RecordType::BikeRide,
|
|
||||||
TraxRecord::Row(_) => RecordType::Row,
|
|
||||||
TraxRecord::Run(_) => RecordType::Run,
|
|
||||||
TraxRecord::Steps(_) => RecordType::Steps,
|
|
||||||
TraxRecord::Swim(_) => RecordType::Swim,
|
|
||||||
TraxRecord::Walk(_) => RecordType::Walk,
|
|
||||||
TraxRecord::Weight(_) => RecordType::Weight,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_weight(&self) -> bool {
|
pub fn is_weight(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
TraxRecord::Weight(_) => true,
|
TraxRecord::Weight(_) => true,
|
||||||
|
|
Loading…
Reference in New Issue