Compare commits
3 Commits
f8d66bbb69
...
226a4b7171
Author | SHA1 | Date |
---|---|---|
Savanni D'Gerinel | 226a4b7171 | |
Savanni D'Gerinel | 1ba2822ab2 | |
Savanni D'Gerinel | 5c59d97ca0 |
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"rust-analyzer.showUnlinkedFileNotification": false
|
||||
}
|
|
@ -642,7 +642,7 @@ dependencies = [
|
|||
"geo-types",
|
||||
"gio",
|
||||
"glib",
|
||||
"glib-build-tools 0.18.0",
|
||||
"glib-build-tools 0.16.3",
|
||||
"gtk4",
|
||||
"ifc",
|
||||
"lazy_static",
|
||||
|
@ -925,7 +925,7 @@ checksum = "8fcfdc7a0362c9f4444381a9e697c79d435fe65b52a37466fc2c1184cee9edc6"
|
|||
|
||||
[[package]]
|
||||
name = "fitnesstrax"
|
||||
version = "0.3.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"chrono",
|
||||
|
@ -938,7 +938,6 @@ dependencies = [
|
|||
"glib-build-tools 0.18.0",
|
||||
"gtk4",
|
||||
"libadwaita",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
|
|
@ -2138,7 +2138,7 @@ rec {
|
|||
buildDependencies = [
|
||||
{
|
||||
name = "glib-build-tools";
|
||||
packageId = "glib-build-tools 0.18.0";
|
||||
packageId = "glib-build-tools 0.16.3";
|
||||
}
|
||||
];
|
||||
|
||||
|
@ -2953,7 +2953,7 @@ rec {
|
|||
};
|
||||
"fitnesstrax" = rec {
|
||||
crateName = "fitnesstrax";
|
||||
version = "0.3.0";
|
||||
version = "0.2.0";
|
||||
edition = "2021";
|
||||
crateBin = [
|
||||
{
|
||||
|
@ -3013,10 +3013,6 @@ rec {
|
|||
rename = "adw";
|
||||
features = [ "v1_4" ];
|
||||
}
|
||||
{
|
||||
name = "thiserror";
|
||||
packageId = "thiserror";
|
||||
}
|
||||
{
|
||||
name = "tokio";
|
||||
packageId = "tokio";
|
||||
|
|
|
@ -28,5 +28,5 @@ tokio = { version = "1", features = ["full"] }
|
|||
unic-langid = { version = "0.9" }
|
||||
|
||||
[build-dependencies]
|
||||
glib-build-tools = "0.18"
|
||||
glib-build-tools = "0.16"
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
fn main() {
|
||||
glib_build_tools::compile_resources(
|
||||
&["resources"],
|
||||
"gresources.xml",
|
||||
"resources",
|
||||
"resources/gresources.xml",
|
||||
"com.luminescent-dreams.dashboard.gresource",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ where
|
|||
Ok(line_) => {
|
||||
match serde_json::from_str::<RecordOnDisk<T>>(line_.as_ref())
|
||||
.map_err(EmseriesReadError::JSONParseError)
|
||||
.and_then(Record::try_from)
|
||||
.and_then(|record| Record::try_from(record))
|
||||
{
|
||||
Ok(record) => records.insert(record.id.clone(), record.clone()),
|
||||
Err(EmseriesReadError::RecordDeleted(id)) => records.remove(&id),
|
||||
|
|
|
@ -11,6 +11,9 @@ You should have received a copy of the GNU General Public License along with Lum
|
|||
*/
|
||||
|
||||
use chrono::{DateTime, FixedOffset, NaiveDate};
|
||||
use chrono_tz::UTC;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::ser::Serialize;
|
||||
use std::{cmp::Ordering, fmt, io, str};
|
||||
use thiserror::Error;
|
||||
use uuid::Uuid;
|
||||
|
@ -90,9 +93,33 @@ impl str::FromStr for Timestamp {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
impl PartialEq for Timestamp {
|
||||
fn eq(&self, other: &Timestamp) -> bool {
|
||||
match (self, other) {
|
||||
(Timestamp::DateTime(dt1), Timestamp::DateTime(dt2)) => {
|
||||
dt1.with_timezone(&UTC) == dt2.with_timezone(&UTC)
|
||||
}
|
||||
// It's not clear to me what would make sense when I'm comparing a date and a
|
||||
// timestamp. I'm going with a naive date comparison on the idea that what I'm wanting
|
||||
// here is human scale, again.
|
||||
(Timestamp::DateTime(dt1), Timestamp::Date(dt2)) => dt1.date_naive() == *dt2,
|
||||
(Timestamp::Date(dt1), Timestamp::DateTime(dt2)) => *dt1 == dt2.date_naive(),
|
||||
(Timestamp::Date(dt1), Timestamp::Date(dt2)) => *dt1 == *dt2,
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
impl PartialOrd for Timestamp {
|
||||
fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
// Some(self.cmp(other))
|
||||
match (self, other) {
|
||||
(Timestamp::DateTime(dt1), Timestamp::DateTime(dt2)) => dt1.partial_cmp(dt2),
|
||||
(Timestamp::DateTime(dt1), Timestamp::Date(dt2)) => dt1.date_naive().partial_cmp(dt2),
|
||||
(Timestamp::Date(dt1), Timestamp::DateTime(dt2)) => dt1.partial_cmp(&dt2.date_naive()),
|
||||
(Timestamp::Date(dt1), Timestamp::Date(dt2)) => dt1.partial_cmp(dt2),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "fitnesstrax"
|
||||
version = "0.3.0"
|
||||
version = "0.2.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
@ -16,7 +16,6 @@ ft-core = { path = "../core" }
|
|||
gio = { version = "0.18" }
|
||||
glib = { version = "0.18" }
|
||||
gtk = { version = "0.7", package = "gtk4", features = [ "v4_10" ] }
|
||||
thiserror = { version = "1.0" }
|
||||
tokio = { version = "1.34", features = [ "full" ] }
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
fn main() {
|
||||
let resources_path = std::env::var_os("PWD").unwrap().clone();
|
||||
let resources_path = resources_path.to_string_lossy().to_owned();
|
||||
let resources_path = resources_path + "/resources/gresources.xml";
|
||||
eprintln!("resources: {}", resources_path);
|
||||
|
||||
glib_build_tools::compile_resources(
|
||||
&["resources"],
|
||||
"gresources.xml",
|
||||
resources_path.as_ref(),
|
||||
"com.luminescent-dreams.fitnesstrax.gresource",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
padding: 8px;
|
||||
}
|
||||
|
||||
.welcome__footer {}
|
||||
.welcome__footer {
|
||||
}
|
||||
|
||||
.historical {
|
||||
margin: 32px;
|
||||
|
@ -36,7 +37,3 @@
|
|||
margin: 8px;
|
||||
}
|
||||
|
||||
.step-view {
|
||||
padding: 8px;
|
||||
margin: 8px;
|
||||
}
|
|
@ -14,6 +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/>.
|
||||
*/
|
||||
|
||||
use crate::types::DayInterval;
|
||||
use chrono::NaiveDate;
|
||||
use emseries::{time_range, Record, RecordId, Series, Timestamp};
|
||||
use ft_core::TraxRecord;
|
||||
|
@ -21,16 +22,11 @@ use std::{
|
|||
path::PathBuf,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
use thiserror::Error;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum AppError {
|
||||
#[error("no database loaded")]
|
||||
NoDatabase,
|
||||
#[error("failed to open the database")]
|
||||
FailedToOpenDatabase,
|
||||
#[error("unhandled error")]
|
||||
Unhandled,
|
||||
}
|
||||
|
||||
|
@ -51,10 +47,12 @@ impl App {
|
|||
.unwrap(),
|
||||
);
|
||||
|
||||
Self {
|
||||
let s = Self {
|
||||
runtime,
|
||||
database: Arc::new(RwLock::new(database)),
|
||||
}
|
||||
};
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
pub async fn records(
|
||||
|
@ -73,7 +71,7 @@ impl App {
|
|||
Timestamp::Date(end),
|
||||
true,
|
||||
))
|
||||
.cloned()
|
||||
.map(|record| record.clone())
|
||||
.collect::<Vec<Record<TraxRecord>>>();
|
||||
Ok(records)
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2023-2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of FitnessTrax.
|
||||
|
||||
|
@ -16,8 +16,8 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
|
||||
use crate::{
|
||||
app::App,
|
||||
view_models::DayDetailViewModel,
|
||||
views::{DayDetailView, HistoricalView, PlaceholderView, View, WelcomeView},
|
||||
components::DayDetail,
|
||||
views::{HistoricalView, PlaceholderView, View, WelcomeView},
|
||||
};
|
||||
use adw::prelude::*;
|
||||
use chrono::{Duration, Local};
|
||||
|
@ -81,7 +81,7 @@ impl AppWindow {
|
|||
.orientation(gtk::Orientation::Vertical)
|
||||
.build();
|
||||
|
||||
let initial_view = View::Placeholder(PlaceholderView::default().upcast());
|
||||
let initial_view = View::Placeholder(PlaceholderView::new().upcast());
|
||||
|
||||
layout.append(&initial_view.widget());
|
||||
|
||||
|
@ -115,10 +115,9 @@ impl AppWindow {
|
|||
|
||||
s.navigation.connect_popped({
|
||||
let s = s.clone();
|
||||
move |_, _| {
|
||||
if let View::Historical(_) = *s.current_view.borrow() {
|
||||
s.load_records();
|
||||
}
|
||||
move |_, _| match *s.current_view.borrow() {
|
||||
View::Historical(_) => s.load_records(),
|
||||
_ => {}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -134,17 +133,23 @@ impl AppWindow {
|
|||
}
|
||||
|
||||
fn show_historical_view(&self, records: Vec<Record<TraxRecord>>) {
|
||||
let view = View::Historical(HistoricalView::new(self.app.clone(), records, {
|
||||
let view = View::Historical(HistoricalView::new(records, {
|
||||
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(&DayDetailView::new(date, records, s.app.clone()));
|
||||
layout.append(&DayDetailView::new(DayDetailViewModel::new(
|
||||
layout.append(&DayDetail::new(
|
||||
date,
|
||||
records,
|
||||
s.app.clone(),
|
||||
)));
|
||||
{
|
||||
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)
|
||||
|
@ -192,4 +197,22 @@ impl AppWindow {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
/*
|
||||
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of FitnessTrax.
|
||||
|
||||
FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
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/>.
|
||||
*/
|
||||
|
||||
//! ActionGroup and related structures
|
||||
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ActionGroupPrivate;
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for ActionGroupPrivate {
|
||||
const NAME: &'static str = "ActionGroup";
|
||||
type Type = ActionGroup;
|
||||
type ParentType = gtk::Box;
|
||||
}
|
||||
|
||||
impl ObjectImpl for ActionGroupPrivate {}
|
||||
impl WidgetImpl for ActionGroupPrivate {}
|
||||
impl BoxImpl for ActionGroupPrivate {}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct ActionGroup(ObjectSubclass<ActionGroupPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||||
}
|
||||
|
||||
impl ActionGroup {
|
||||
fn new(builder: ActionGroupBuilder) -> Self {
|
||||
let s: Self = Object::builder().build();
|
||||
s.set_orientation(builder.orientation);
|
||||
|
||||
let primary_button = builder.primary_action.button();
|
||||
let secondary_button = builder.secondary_action.map(|action| action.button());
|
||||
let tertiary_button = builder.tertiary_action.map(|action| action.button());
|
||||
|
||||
if let Some(button) = tertiary_button {
|
||||
s.append(&button);
|
||||
}
|
||||
|
||||
s.set_halign(gtk::Align::End);
|
||||
if let Some(button) = secondary_button {
|
||||
s.append(&button);
|
||||
}
|
||||
s.append(&primary_button);
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
pub fn builder() -> ActionGroupBuilder {
|
||||
ActionGroupBuilder {
|
||||
orientation: gtk::Orientation::Horizontal,
|
||||
primary_action: Action {
|
||||
label: "Ok".to_owned(),
|
||||
action: Box::new(|| {}),
|
||||
},
|
||||
secondary_action: None,
|
||||
tertiary_action: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Action {
|
||||
label: String,
|
||||
action: Box<dyn Fn()>,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
fn button(self) -> gtk::Button {
|
||||
let button = gtk::Button::builder().label(self.label).build();
|
||||
button.connect_clicked(move |_| (self.action)());
|
||||
button
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ActionGroupBuilder {
|
||||
orientation: gtk::Orientation,
|
||||
primary_action: Action,
|
||||
secondary_action: Option<Action>,
|
||||
tertiary_action: Option<Action>,
|
||||
}
|
||||
|
||||
impl ActionGroupBuilder {
|
||||
pub fn orientation(mut self, orientation: gtk::Orientation) -> Self {
|
||||
self.orientation = orientation;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn primary_action<A>(mut self, label: &str, action: A) -> Self
|
||||
where
|
||||
A: Fn() + 'static,
|
||||
{
|
||||
self.primary_action = Action {
|
||||
label: label.to_owned(),
|
||||
action: Box::new(action),
|
||||
};
|
||||
self
|
||||
}
|
||||
|
||||
pub fn secondary_action<A>(mut self, label: &str, action: A) -> Self
|
||||
where
|
||||
A: Fn() + 'static,
|
||||
{
|
||||
self.secondary_action = Some(Action {
|
||||
label: label.to_owned(),
|
||||
action: Box::new(action),
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
pub fn tertiary_action<A>(mut self, label: &str, action: A) -> Self
|
||||
where
|
||||
A: Fn() + 'static,
|
||||
{
|
||||
self.tertiary_action = Some(Action {
|
||||
label: label.to_owned(),
|
||||
action: Box::new(action),
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> ActionGroup {
|
||||
ActionGroup::new(self)
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2023-2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of FitnessTrax.
|
||||
|
||||
|
@ -16,16 +16,16 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
|
||||
// use chrono::NaiveDate;
|
||||
// use ft_core::TraxRecord;
|
||||
use crate::{
|
||||
components::{steps_editor, weight_editor, ActionGroup, Steps, Weight},
|
||||
view_models::DayDetailViewModel,
|
||||
};
|
||||
use crate::components::{TimeDistanceView, WeightView};
|
||||
use emseries::Record;
|
||||
use ft_core::{RecordType, TraxRecord, Weight};
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub struct DaySummaryPrivate {
|
||||
date: gtk::Label,
|
||||
weight: RefCell<Option<gtk::Label>>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
|
@ -39,7 +39,10 @@ impl ObjectSubclass for DaySummaryPrivate {
|
|||
.css_classes(["day-summary__date"])
|
||||
.halign(gtk::Align::Start)
|
||||
.build();
|
||||
Self { date }
|
||||
Self {
|
||||
date,
|
||||
weight: RefCell::new(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +56,8 @@ glib::wrapper! {
|
|||
pub struct DaySummary(ObjectSubclass<DaySummaryPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||||
}
|
||||
|
||||
impl Default for DaySummary {
|
||||
fn default() -> Self {
|
||||
impl DaySummary {
|
||||
pub fn new() -> Self {
|
||||
let s: Self = Object::builder().build();
|
||||
s.set_orientation(gtk::Orientation::Vertical);
|
||||
s.set_css_classes(&["day-summary"]);
|
||||
|
@ -63,52 +66,62 @@ impl Default for DaySummary {
|
|||
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
impl DaySummary {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn set_data(&self, view_model: DayDetailViewModel) {
|
||||
pub fn set_data(&self, date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>) {
|
||||
self.imp()
|
||||
.date
|
||||
.set_text(&view_model.date.format("%Y-%m-%d").to_string());
|
||||
.set_text(&date.format("%Y-%m-%d").to_string());
|
||||
|
||||
let row = gtk::Box::builder().build();
|
||||
|
||||
let label = gtk::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.css_classes(["day-summary__weight"])
|
||||
.build();
|
||||
if let Some(w) = view_model.weight() {
|
||||
label.set_label(&w.to_string())
|
||||
if let Some(ref weight_label) = *self.imp().weight.borrow() {
|
||||
self.remove(weight_label);
|
||||
}
|
||||
row.append(&label);
|
||||
|
||||
self.append(&label);
|
||||
|
||||
let label = gtk::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.css_classes(["day-summary__weight"])
|
||||
.build();
|
||||
if let Some(s) = view_model.steps() {
|
||||
label.set_label(&format!("{} steps", s.to_string()));
|
||||
if let Some(Record {
|
||||
data: TraxRecord::Weight(weight_record),
|
||||
..
|
||||
}) = records.iter().filter(|f| f.data.is_weight()).next()
|
||||
{
|
||||
let label = gtk::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(&format!("{}", weight_record.weight))
|
||||
.css_classes(["day-summary__weight"])
|
||||
.build();
|
||||
self.append(&label);
|
||||
*self.imp().weight.borrow_mut() = Some(label);
|
||||
}
|
||||
row.append(&label);
|
||||
|
||||
self.append(&row);
|
||||
/*
|
||||
self.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label("15km of biking in 60 minutes")
|
||||
.build(),
|
||||
);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DayDetailPrivate {}
|
||||
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 {}
|
||||
|
@ -120,21 +133,19 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
impl DayDetail {
|
||||
pub fn new<OnEdit>(view_model: DayDetailViewModel, on_edit: OnEdit) -> Self
|
||||
pub fn new<PutRecordFn, UpdateRecordFn>(
|
||||
date: chrono::NaiveDate,
|
||||
records: Vec<Record<TraxRecord>>,
|
||||
on_put_record: PutRecordFn,
|
||||
on_update_record: UpdateRecordFn,
|
||||
) -> Self
|
||||
where
|
||||
OnEdit: Fn() + 'static,
|
||||
PutRecordFn: Fn(TraxRecord) + 'static,
|
||||
UpdateRecordFn: Fn(Record<TraxRecord>) + 'static,
|
||||
{
|
||||
let s: Self = Object::builder().build();
|
||||
s.set_orientation(gtk::Orientation::Vertical);
|
||||
s.set_hexpand(true);
|
||||
|
||||
s.append(
|
||||
&ActionGroup::builder()
|
||||
.primary_action("Edit", Box::new(on_edit))
|
||||
.build(),
|
||||
);
|
||||
|
||||
/*
|
||||
let click_controller = gtk::GestureClick::new();
|
||||
click_controller.connect_released({
|
||||
let s = s.clone();
|
||||
|
@ -147,63 +158,52 @@ impl DayDetail {
|
|||
}
|
||||
});
|
||||
s.add_controller(click_controller);
|
||||
*/
|
||||
|
||||
/*
|
||||
let weight_record = records.iter().find_map(|record| match record {
|
||||
Record {
|
||||
id,
|
||||
data: ft_core::TraxRecord::Weight(record),
|
||||
data: TraxRecord::Weight(record),
|
||||
} => Some((id.clone(), record.clone())),
|
||||
_ => None,
|
||||
});
|
||||
*/
|
||||
|
||||
let top_row = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.build();
|
||||
let weight_view = Weight::new(view_model.weight());
|
||||
top_row.append(&weight_view.widget());
|
||||
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);
|
||||
|
||||
let steps_view = Steps::new(view_model.steps());
|
||||
top_row.append(&steps_view.widget());
|
||||
|
||||
s.append(&top_row);
|
||||
|
||||
/*
|
||||
records.into_iter().for_each(|record| {
|
||||
let record_view = match record {
|
||||
Record {
|
||||
data: ft_core::TraxRecord::BikeRide(record),
|
||||
data: TraxRecord::BikeRide(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::BikeRide, record)
|
||||
.upcast::<gtk::Widget>(),
|
||||
TimeDistanceView::new(RecordType::BikeRide, record).upcast::<gtk::Widget>(),
|
||||
),
|
||||
Record {
|
||||
data: ft_core::TraxRecord::Row(record),
|
||||
data: TraxRecord::Row(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
||||
),
|
||||
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||
Record {
|
||||
data: ft_core::TraxRecord::Run(record),
|
||||
data: TraxRecord::Run(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
||||
),
|
||||
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||
Record {
|
||||
data: ft_core::TraxRecord::Swim(record),
|
||||
data: TraxRecord::Swim(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
||||
),
|
||||
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||
Record {
|
||||
data: ft_core::TraxRecord::Walk(record),
|
||||
data: TraxRecord::Walk(record),
|
||||
..
|
||||
} => Some(
|
||||
TimeDistanceView::new(ft_core::RecordType::Row, record).upcast::<gtk::Widget>(),
|
||||
),
|
||||
} => Some(TimeDistanceView::new(RecordType::Row, record).upcast::<gtk::Widget>()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
@ -214,97 +214,7 @@ impl DayDetail {
|
|||
s.append(&record_view);
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DayEditPrivate {
|
||||
on_finished: RefCell<Box<dyn Fn()>>,
|
||||
}
|
||||
|
||||
impl Default for DayEditPrivate {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
on_finished: RefCell::new(Box::new(|| {})),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for DayEditPrivate {
|
||||
const NAME: &'static str = "DayEdit";
|
||||
type Type = DayEdit;
|
||||
type ParentType = gtk::Box;
|
||||
}
|
||||
|
||||
impl ObjectImpl for DayEditPrivate {}
|
||||
impl WidgetImpl for DayEditPrivate {}
|
||||
impl BoxImpl for DayEditPrivate {}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct DayEdit(ObjectSubclass<DayEditPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
|
||||
}
|
||||
|
||||
impl DayEdit {
|
||||
pub fn new<OnFinished>(view_model: DayDetailViewModel, on_finished: OnFinished) -> Self
|
||||
where
|
||||
OnFinished: Fn() + 'static,
|
||||
{
|
||||
let s: Self = Object::builder().build();
|
||||
s.set_orientation(gtk::Orientation::Vertical);
|
||||
s.set_hexpand(true);
|
||||
|
||||
*s.imp().on_finished.borrow_mut() = Box::new(on_finished);
|
||||
|
||||
s.append(
|
||||
&ActionGroup::builder()
|
||||
.primary_action("Save", {
|
||||
let s = s.clone();
|
||||
let view_model = view_model.clone();
|
||||
move || {
|
||||
view_model.save();
|
||||
s.finish();
|
||||
}
|
||||
})
|
||||
.secondary_action("Cancel", {
|
||||
let s = s.clone();
|
||||
let view_model = view_model.clone();
|
||||
move || {
|
||||
view_model.revert();
|
||||
s.finish();
|
||||
}
|
||||
})
|
||||
.build(),
|
||||
);
|
||||
|
||||
let top_row = gtk::Box::builder()
|
||||
.orientation(gtk::Orientation::Horizontal)
|
||||
.build();
|
||||
top_row.append(
|
||||
&weight_editor(view_model.weight(), {
|
||||
let view_model = view_model.clone();
|
||||
move |w| {
|
||||
view_model.set_weight(w);
|
||||
}
|
||||
})
|
||||
.widget(),
|
||||
);
|
||||
|
||||
top_row.append(
|
||||
&steps_editor(view_model.steps(), {
|
||||
let view_model = view_model.clone();
|
||||
move |s| view_model.set_steps(s)
|
||||
})
|
||||
.widget(),
|
||||
);
|
||||
s.append(&top_row);
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
fn finish(&self) {
|
||||
(self.imp().on_finished.borrow())()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of FitnessTrax.
|
||||
|
||||
|
@ -14,5 +14,9 @@ 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/>.
|
||||
*/
|
||||
|
||||
mod day_detail;
|
||||
pub use day_detail::DayDetailViewModel;
|
||||
#[derive(Clone)]
|
||||
pub enum EditView<View, Edit> {
|
||||
Unconfigured,
|
||||
View(View),
|
||||
Edit(Edit),
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2023-2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
Copyright 2023, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of FitnessTrax.
|
||||
|
||||
|
@ -14,17 +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/>.
|
||||
*/
|
||||
|
||||
mod action_group;
|
||||
pub use action_group::ActionGroup;
|
||||
|
||||
mod day;
|
||||
pub use day::{DayDetail, DayEdit, DaySummary};
|
||||
pub use day::{DayDetail, DaySummary};
|
||||
|
||||
mod singleton;
|
||||
pub use singleton::{Singleton, SingletonImpl};
|
||||
|
||||
mod steps;
|
||||
pub use steps::{steps_editor, Steps};
|
||||
mod edit_view;
|
||||
pub use edit_view::EditView;
|
||||
|
||||
mod text_entry;
|
||||
pub use text_entry::{ParseError, TextEntry};
|
||||
|
@ -33,7 +27,7 @@ mod time_distance;
|
|||
pub use time_distance::TimeDistanceView;
|
||||
|
||||
mod weight;
|
||||
pub use weight::{weight_editor, Weight};
|
||||
pub use weight::WeightView;
|
||||
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of FitnessTrax.
|
||||
|
||||
FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
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/>.
|
||||
*/
|
||||
|
||||
//! A Widget container for a single components
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub struct SingletonPrivate {
|
||||
widget: RefCell<gtk::Widget>,
|
||||
}
|
||||
|
||||
impl Default for SingletonPrivate {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
widget: RefCell::new(gtk::Label::new(None).upcast()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for SingletonPrivate {
|
||||
const NAME: &'static str = "Singleton";
|
||||
type Type = Singleton;
|
||||
type ParentType = gtk::Box;
|
||||
}
|
||||
|
||||
impl ObjectImpl for SingletonPrivate {}
|
||||
impl WidgetImpl for SingletonPrivate {}
|
||||
impl BoxImpl for SingletonPrivate {}
|
||||
|
||||
glib::wrapper! {
|
||||
/// The Singleton component contains exactly one child widget. The swap function makes it easy
|
||||
/// to handle the job of swapping that child out for a different one.
|
||||
pub struct Singleton(ObjectSubclass<SingletonPrivate>) @extends gtk::Box, gtk::Widget;
|
||||
}
|
||||
|
||||
impl Default for Singleton {
|
||||
fn default() -> Self {
|
||||
let s: Self = Object::builder().build();
|
||||
|
||||
s.append(&*s.imp().widget.borrow());
|
||||
|
||||
s
|
||||
}
|
||||
}
|
||||
|
||||
impl Singleton {
|
||||
pub fn swap(&self, new_widget: &impl IsA<gtk::Widget>) {
|
||||
let new_widget = new_widget.clone().upcast();
|
||||
self.remove(&*self.imp().widget.borrow());
|
||||
self.append(&new_widget);
|
||||
*self.imp().widget.borrow_mut() = new_widget;
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SingletonImpl: WidgetImpl + BoxImpl {}
|
||||
unsafe impl<T: SingletonImpl> IsSubclassable<T> for Singleton {}
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of FitnessTrax.
|
||||
|
||||
FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
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/>.
|
||||
*/
|
||||
|
||||
use crate::components::{ParseError, TextEntry};
|
||||
use gtk::prelude::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Steps {
|
||||
label: gtk::Label,
|
||||
}
|
||||
|
||||
impl Steps {
|
||||
pub fn new(steps: Option<u32>) -> Self {
|
||||
let label = gtk::Label::builder()
|
||||
.css_classes(["card", "step-view"])
|
||||
.can_focus(true)
|
||||
.build();
|
||||
|
||||
match steps {
|
||||
Some(s) => label.set_text(&format!("{}", s)),
|
||||
None => label.set_text("No steps recorded"),
|
||||
}
|
||||
|
||||
Self { label }
|
||||
}
|
||||
|
||||
pub fn widget(&self) -> gtk::Widget {
|
||||
self.label.clone().upcast()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn steps_editor<OnUpdate>(value: Option<u32>, on_update: OnUpdate) -> TextEntry<u32>
|
||||
where
|
||||
OnUpdate: Fn(u32) + 'static,
|
||||
{
|
||||
TextEntry::new(
|
||||
"0",
|
||||
value,
|
||||
|v| format!("{}", v),
|
||||
move |v| match v.parse::<u32>() {
|
||||
Ok(val) => {
|
||||
on_update(val);
|
||||
Ok(val)
|
||||
}
|
||||
Err(_) => Err(ParseError),
|
||||
},
|
||||
)
|
||||
}
|
|
@ -17,48 +17,34 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
use gtk::prelude::*;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ParseError;
|
||||
|
||||
type Renderer<T> = dyn Fn(&T) -> String;
|
||||
type Parser<T> = dyn Fn(&str) -> Result<T, ParseError>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TextEntry<T: Clone + std::fmt::Debug> {
|
||||
pub struct TextEntry<T: Clone> {
|
||||
value: Rc<RefCell<Option<T>>>,
|
||||
widget: gtk::Entry,
|
||||
#[allow(unused)]
|
||||
renderer: Rc<Renderer<T>>,
|
||||
parser: Rc<Parser<T>>,
|
||||
}
|
||||
|
||||
impl<T: Clone + std::fmt::Debug> std::fmt::Debug for TextEntry<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
write!(
|
||||
f,
|
||||
"{{ value: {:?}, widget: {:?} }}",
|
||||
self.value, self.widget
|
||||
)
|
||||
}
|
||||
renderer: Rc<Box<dyn Fn(&T) -> String>>,
|
||||
validator: Rc<Box<dyn Fn(&str) -> Result<T, ParseError>>>,
|
||||
}
|
||||
|
||||
// I do not understand why the data should be 'static.
|
||||
impl<T: Clone + std::fmt::Debug + 'static> TextEntry<T> {
|
||||
pub fn new<R, V>(placeholder: &str, value: Option<T>, renderer: R, parser: V) -> Self
|
||||
impl<T: Clone + 'static> TextEntry<T> {
|
||||
pub fn new<R, V>(placeholder: &str, value: Option<T>, renderer: R, validator: V) -> Self
|
||||
where
|
||||
R: Fn(&T) -> String + 'static,
|
||||
V: Fn(&str) -> Result<T, ParseError> + 'static,
|
||||
{
|
||||
let widget = gtk::Entry::builder().placeholder_text(placeholder).build();
|
||||
if let Some(ref v) = value {
|
||||
widget.set_text(&renderer(v))
|
||||
match value {
|
||||
Some(ref v) => widget.set_text(&renderer(&v)),
|
||||
None => {}
|
||||
}
|
||||
|
||||
let s = Self {
|
||||
value: Rc::new(RefCell::new(value)),
|
||||
widget,
|
||||
renderer: Rc::new(renderer),
|
||||
parser: Rc::new(parser),
|
||||
renderer: Rc::new(Box::new(renderer)),
|
||||
validator: Rc::new(Box::new(validator)),
|
||||
};
|
||||
|
||||
s.widget.buffer().connect_text_notify({
|
||||
|
@ -75,7 +61,7 @@ impl<T: Clone + std::fmt::Debug + 'static> TextEntry<T> {
|
|||
self.widget.remove_css_class("error");
|
||||
return;
|
||||
}
|
||||
match (self.parser)(buffer.text().as_str()) {
|
||||
match (self.validator)(buffer.text().as_str()) {
|
||||
Ok(v) => {
|
||||
*self.value.borrow_mut() = Some(v);
|
||||
self.widget.remove_css_class("error");
|
||||
|
@ -87,20 +73,18 @@ impl<T: Clone + std::fmt::Debug + 'static> TextEntry<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn value(&self) -> Option<T> {
|
||||
let v = self.value.borrow().clone();
|
||||
self.value.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn set_value(&self, value: Option<T>) {
|
||||
if let Some(ref v) = value {
|
||||
self.widget.set_text(&(self.renderer)(v))
|
||||
match value {
|
||||
Some(ref v) => self.widget.set_text(&(self.renderer)(&v)),
|
||||
None => {}
|
||||
}
|
||||
*self.value.borrow_mut() = value;
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn grab_focus(&self) {
|
||||
self.widget.grab_focus();
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ use std::cell::RefCell;
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct TimeDistanceViewPrivate {
|
||||
#[allow(unused)]
|
||||
record: RefCell<Option<TimeDistance>>,
|
||||
}
|
||||
|
||||
|
@ -54,7 +53,7 @@ impl TimeDistanceView {
|
|||
first_row.append(
|
||||
>k::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(record.datetime.format("%H:%M").to_string())
|
||||
.label(&record.datetime.format("%H:%M").to_string())
|
||||
.build(),
|
||||
);
|
||||
|
||||
|
@ -97,7 +96,7 @@ impl TimeDistanceView {
|
|||
.label(
|
||||
record
|
||||
.comments
|
||||
.map(|comments| comments.to_string())
|
||||
.map(|comments| format!("{}", comments))
|
||||
.unwrap_or("".to_owned()),
|
||||
)
|
||||
.build(),
|
||||
|
|
|
@ -14,54 +14,173 @@ 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/>.
|
||||
*/
|
||||
|
||||
use crate::components::{ParseError, TextEntry};
|
||||
use crate::components::{EditView, ParseError, TextEntry};
|
||||
use chrono::{Local, NaiveDate};
|
||||
use dimensioned::si;
|
||||
use gtk::prelude::*;
|
||||
use ft_core::Weight;
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub struct Weight {
|
||||
label: gtk::Label,
|
||||
pub struct WeightViewPrivate {
|
||||
date: RefCell<NaiveDate>,
|
||||
record: RefCell<Option<Weight>>,
|
||||
|
||||
widget: RefCell<EditView<gtk::Label, TextEntry<si::Kilogram<f64>>>>,
|
||||
|
||||
on_edit_finished: RefCell<Box<dyn Fn(si::Kilogram<f64>)>>,
|
||||
}
|
||||
|
||||
impl Weight {
|
||||
pub fn new(weight: Option<si::Kilogram<f64>>) -> Self {
|
||||
let label = gtk::Label::builder()
|
||||
impl Default for WeightViewPrivate {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
date: RefCell::new(Local::now().date_naive()),
|
||||
record: RefCell::new(None),
|
||||
widget: RefCell::new(EditView::Unconfigured),
|
||||
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();
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
fn view(&self) {
|
||||
let view = gtk::Label::builder()
|
||||
.css_classes(["card", "weight-view"])
|
||||
.halign(gtk::Align::Start)
|
||||
.can_focus(true)
|
||||
.build();
|
||||
|
||||
match weight {
|
||||
Some(w) => label.set_text(&format!("{:?}", w)),
|
||||
None => label.set_text("No weight recorded"),
|
||||
let view_click_controller = gtk::GestureClick::new();
|
||||
view_click_controller.connect_released({
|
||||
let s = self.clone();
|
||||
move |_, _, _, _| {
|
||||
s.edit();
|
||||
}
|
||||
});
|
||||
|
||||
view.add_controller(view_click_controller);
|
||||
|
||||
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 { label }
|
||||
self.swap(EditView::View(view));
|
||||
}
|
||||
|
||||
pub fn widget(&self) -> gtk::Widget {
|
||||
self.label.clone().upcast()
|
||||
}
|
||||
}
|
||||
fn edit(&self) {
|
||||
let edit = TextEntry::<si::Kilogram<f64>>::new(
|
||||
"weight",
|
||||
None,
|
||||
|val: &si::Kilogram<f64>| val.to_string(),
|
||||
|v: &str| v.parse::<f64>().map(|w| w * si::KG).map_err(|_| ParseError),
|
||||
);
|
||||
|
||||
pub fn weight_editor<OnUpdate>(
|
||||
weight: Option<si::Kilogram<f64>>,
|
||||
on_update: OnUpdate,
|
||||
) -> TextEntry<si::Kilogram<f64>>
|
||||
where
|
||||
OnUpdate: Fn(si::Kilogram<f64>) + 'static,
|
||||
{
|
||||
TextEntry::new(
|
||||
"0 kg",
|
||||
weight,
|
||||
|val: &si::Kilogram<f64>| val.to_string(),
|
||||
move |v: &str| {
|
||||
let new_weight = v.parse::<f64>().map(|w| w * si::KG).map_err(|_| ParseError);
|
||||
match new_weight {
|
||||
Ok(w) => {
|
||||
on_update(w);
|
||||
Ok(w)
|
||||
match *self.imp().record.borrow() {
|
||||
Some(ref record) => edit.set_value(Some(record.weight)),
|
||||
None => edit.set_value(None),
|
||||
}
|
||||
|
||||
self.swap(EditView::Edit(edit.clone()));
|
||||
edit.grab_focus();
|
||||
}
|
||||
|
||||
fn swap(&self, new_view: EditView<gtk::Label, TextEntry<si::Kilogram<f64>>>) {
|
||||
let mut widget = self.imp().widget.borrow_mut();
|
||||
match *widget {
|
||||
EditView::Unconfigured => {}
|
||||
EditView::View(ref view) => self.remove(view),
|
||||
EditView::Edit(ref editor) => self.remove(&editor.widget()),
|
||||
}
|
||||
|
||||
match new_view {
|
||||
EditView::Unconfigured => {}
|
||||
EditView::View(ref view) => self.append(view),
|
||||
EditView::Edit(ref editor) => self.append(&editor.widget()),
|
||||
}
|
||||
*widget = new_view;
|
||||
}
|
||||
|
||||
pub fn blur(&self) {
|
||||
match *self.imp().widget.borrow() {
|
||||
EditView::Unconfigured => {}
|
||||
EditView::View(_) => {}
|
||||
EditView::Edit(ref editor) => {
|
||||
let weight = editor.value();
|
||||
// This has really turned into rubbish
|
||||
// on_edit_finished needs to accept a full record now.
|
||||
// needs to be possible to delete a record if the value is None
|
||||
// it's hard to be sure whether I need the full record object or if I need to update
|
||||
// it. I probably don't. I think I need to borrow it and call on_edit_finished with an
|
||||
// updated version of it.
|
||||
// on_edit_finished still doesn't have a way to support a delete operation
|
||||
let record = match (self.imp().record.borrow().clone(), weight) {
|
||||
// update an existing record
|
||||
(Some(record), Some(weight)) => Some(Weight {
|
||||
date: record.date,
|
||||
weight,
|
||||
}),
|
||||
|
||||
// create a new record
|
||||
(None, Some(weight)) => Some(Weight {
|
||||
date: self.imp().date.borrow().clone(),
|
||||
weight,
|
||||
}),
|
||||
|
||||
// do nothing or delete an existing record
|
||||
(_, None) => None,
|
||||
};
|
||||
|
||||
match record {
|
||||
Some(record) => {
|
||||
self.imp().on_edit_finished.borrow()(record.weight);
|
||||
*self.imp().record.borrow_mut() = Some(record);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
self.view();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@ mod app;
|
|||
mod app_window;
|
||||
mod components;
|
||||
mod types;
|
||||
mod view_models;
|
||||
mod views;
|
||||
|
||||
use adw::prelude::*;
|
||||
use app_window::AppWindow;
|
||||
use std::{env, path::PathBuf};
|
||||
use types::DayInterval;
|
||||
|
||||
const APP_ID_DEV: &str = "com.luminescent-dreams.fitnesstrax.dev";
|
||||
const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax";
|
||||
|
|
|
@ -21,8 +21,8 @@ impl Default for DayInterval {
|
|||
impl DayInterval {
|
||||
pub fn days(&self) -> impl Iterator<Item = NaiveDate> {
|
||||
DayIterator {
|
||||
current: self.start,
|
||||
end: self.end,
|
||||
current: self.start.clone(),
|
||||
end: self.end.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ impl Iterator for DayIterator {
|
|||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.current <= self.end {
|
||||
let val = self.current;
|
||||
let val = self.current.clone();
|
||||
self.current += Duration::days(1);
|
||||
Some(val)
|
||||
} else {
|
||||
|
|
|
@ -1,235 +0,0 @@
|
|||
/*
|
||||
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of FitnessTrax.
|
||||
|
||||
FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
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/>.
|
||||
*/
|
||||
|
||||
use crate::app::App;
|
||||
use dimensioned::si;
|
||||
use emseries::{Record, RecordId, Recordable};
|
||||
use ft_core::TraxRecord;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ops::Deref,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
enum RecordState<T: Clone + Recordable> {
|
||||
Original(Record<T>),
|
||||
New(T),
|
||||
Updated(Record<T>),
|
||||
#[allow(unused)]
|
||||
Deleted(Record<T>),
|
||||
}
|
||||
|
||||
impl<T: Clone + emseries::Recordable> RecordState<T> {
|
||||
#[allow(unused)]
|
||||
fn id(&self) -> Option<&RecordId> {
|
||||
match self {
|
||||
RecordState::Original(ref r) => Some(&r.id),
|
||||
RecordState::New(ref r) => None,
|
||||
RecordState::Updated(ref r) => Some(&r.id),
|
||||
RecordState::Deleted(ref r) => Some(&r.id),
|
||||
}
|
||||
}
|
||||
|
||||
fn with_value(self, value: T) -> RecordState<T> {
|
||||
match self {
|
||||
RecordState::Original(r) => RecordState::Updated(Record { data: value, ..r }),
|
||||
RecordState::New(_) => RecordState::New(value),
|
||||
RecordState::Updated(r) => RecordState::Updated(Record { data: value, ..r }),
|
||||
RecordState::Deleted(r) => RecordState::Updated(Record { data: value, ..r }),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn with_delete(self) -> Option<RecordState<T>> {
|
||||
match self {
|
||||
RecordState::Original(r) => Some(RecordState::Deleted(r)),
|
||||
RecordState::New(r) => None,
|
||||
RecordState::Updated(r) => Some(RecordState::Deleted(r)),
|
||||
RecordState::Deleted(r) => Some(RecordState::Deleted(r)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone + emseries::Recordable> Deref for RecordState<T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match self {
|
||||
RecordState::Original(ref r) => &r.data,
|
||||
RecordState::New(ref r) => r,
|
||||
RecordState::Updated(ref r) => &r.data,
|
||||
RecordState::Deleted(ref r) => &r.data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct DayDetailViewModelInner {}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct DayDetailViewModel {
|
||||
app: Option<App>,
|
||||
pub date: chrono::NaiveDate,
|
||||
weight: Arc<RwLock<Option<RecordState<ft_core::Weight>>>>,
|
||||
steps: Arc<RwLock<Option<RecordState<ft_core::Steps>>>>,
|
||||
records: Arc<RwLock<HashMap<RecordId, RecordState<TraxRecord>>>>,
|
||||
}
|
||||
|
||||
impl DayDetailViewModel {
|
||||
pub fn new(date: chrono::NaiveDate, records: Vec<Record<TraxRecord>>, app: App) -> Self {
|
||||
let (weight_records, records): (Vec<Record<TraxRecord>>, Vec<Record<TraxRecord>>) =
|
||||
records.into_iter().partition(|r| r.data.is_weight());
|
||||
let (step_records, records): (Vec<Record<TraxRecord>>, Vec<Record<TraxRecord>>) =
|
||||
records.into_iter().partition(|r| r.data.is_steps());
|
||||
Self {
|
||||
app: Some(app),
|
||||
date,
|
||||
weight: Arc::new(RwLock::new(
|
||||
weight_records
|
||||
.first()
|
||||
.and_then(|r| match r.data {
|
||||
TraxRecord::Weight(ref w) => Some((r.id.clone(), w.clone())),
|
||||
_ => None,
|
||||
})
|
||||
.map(|(id, w)| RecordState::Original(Record { id, data: w })),
|
||||
)),
|
||||
steps: Arc::new(RwLock::new(
|
||||
step_records
|
||||
.first()
|
||||
.and_then(|r| match r.data {
|
||||
TraxRecord::Steps(ref w) => Some((r.id.clone(), w.clone())),
|
||||
_ => None,
|
||||
})
|
||||
.map(|(id, w)| RecordState::Original(Record { id, data: w })),
|
||||
)),
|
||||
|
||||
records: Arc::new(RwLock::new(
|
||||
records
|
||||
.into_iter()
|
||||
.map(|r| (r.id.clone(), RecordState::Original(r)))
|
||||
.collect::<HashMap<RecordId, RecordState<TraxRecord>>>(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn weight(&self) -> Option<si::Kilogram<f64>> {
|
||||
(*self.weight.read().unwrap()).as_ref().map(|w| w.weight)
|
||||
}
|
||||
|
||||
pub fn set_weight(&self, new_weight: si::Kilogram<f64>) {
|
||||
let mut record = self.weight.write().unwrap();
|
||||
let new_record = match *record {
|
||||
Some(ref rstate) => rstate.clone().with_value(ft_core::Weight {
|
||||
date: self.date,
|
||||
weight: new_weight,
|
||||
}),
|
||||
None => RecordState::New(ft_core::Weight {
|
||||
date: self.date,
|
||||
weight: new_weight,
|
||||
}),
|
||||
};
|
||||
*record = Some(new_record);
|
||||
}
|
||||
|
||||
pub fn steps(&self) -> Option<u32> {
|
||||
(*self.steps.read().unwrap()).as_ref().map(|w| w.count)
|
||||
}
|
||||
|
||||
pub fn set_steps(&self, new_count: u32) {
|
||||
let mut record = self.steps.write().unwrap();
|
||||
let new_record = match *record {
|
||||
Some(ref rstate) => rstate.clone().with_value(ft_core::Steps {
|
||||
date: self.date,
|
||||
count: new_count,
|
||||
}),
|
||||
None => RecordState::New(ft_core::Steps {
|
||||
date: self.date,
|
||||
count: new_count,
|
||||
}),
|
||||
};
|
||||
*record = Some(new_record);
|
||||
}
|
||||
|
||||
pub fn save(&self) {
|
||||
glib::spawn_future({
|
||||
let s = self.clone();
|
||||
async move {
|
||||
if let Some(app) = s.app {
|
||||
let weight_record = s.weight.read().unwrap().clone();
|
||||
match weight_record {
|
||||
Some(RecordState::New(weight)) => {
|
||||
let _ = app.put_record(TraxRecord::Weight(weight)).await;
|
||||
}
|
||||
Some(RecordState::Original(_)) => {}
|
||||
Some(RecordState::Updated(weight)) => {
|
||||
let _ = app
|
||||
.update_record(Record {
|
||||
id: weight.id,
|
||||
data: TraxRecord::Weight(weight.data),
|
||||
})
|
||||
.await;
|
||||
}
|
||||
Some(RecordState::Deleted(_)) => {}
|
||||
None => {}
|
||||
}
|
||||
|
||||
let steps_record = s.steps.read().unwrap().clone();
|
||||
match steps_record {
|
||||
Some(RecordState::New(steps)) => {
|
||||
let _ = app.put_record(TraxRecord::Steps(steps)).await;
|
||||
}
|
||||
Some(RecordState::Original(_)) => {}
|
||||
Some(RecordState::Updated(steps)) => {
|
||||
let _ = app
|
||||
.update_record(Record {
|
||||
id: steps.id,
|
||||
data: TraxRecord::Steps(steps.data),
|
||||
})
|
||||
.await;
|
||||
}
|
||||
Some(RecordState::Deleted(_)) => {}
|
||||
None => {}
|
||||
}
|
||||
|
||||
let records = s
|
||||
.records
|
||||
.write()
|
||||
.unwrap()
|
||||
.drain()
|
||||
.map(|(_, record)| record)
|
||||
.collect::<Vec<RecordState<TraxRecord>>>();
|
||||
|
||||
for record in records {
|
||||
match record {
|
||||
RecordState::New(data) => {
|
||||
let _ = app.put_record(data).await;
|
||||
}
|
||||
RecordState::Original(_) => {}
|
||||
RecordState::Updated(r) => {
|
||||
let _ = app.update_record(r.clone()).await;
|
||||
}
|
||||
RecordState::Deleted(_) => unimplemented!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn revert(&self) {
|
||||
unimplemented!();
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
Copyright 2024, Savanni D'Gerinel <savanni@luminescent-dreams.com>
|
||||
|
||||
This file is part of FitnessTrax.
|
||||
|
||||
FitnessTrax is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||
General Public License as published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
FitnessTrax is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
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/>.
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
components::{DayDetail, DayEdit, Singleton, SingletonImpl},
|
||||
view_models::DayDetailViewModel,
|
||||
};
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DayDetailViewPrivate {
|
||||
container: Singleton,
|
||||
view_model: RefCell<DayDetailViewModel>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for DayDetailViewPrivate {
|
||||
const NAME: &'static str = "DayDetailView";
|
||||
type Type = DayDetailView;
|
||||
type ParentType = gtk::Box;
|
||||
}
|
||||
|
||||
impl ObjectImpl for DayDetailViewPrivate {}
|
||||
impl WidgetImpl for DayDetailViewPrivate {}
|
||||
impl BoxImpl for DayDetailViewPrivate {}
|
||||
impl SingletonImpl for DayDetailViewPrivate {}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct DayDetailView(ObjectSubclass<DayDetailViewPrivate>) @extends gtk::Box, gtk::Widget;
|
||||
}
|
||||
|
||||
impl DayDetailView {
|
||||
pub fn new(view_model: DayDetailViewModel) -> Self {
|
||||
let s: Self = Object::builder().build();
|
||||
*s.imp().view_model.borrow_mut() = view_model;
|
||||
|
||||
s.append(&s.imp().container);
|
||||
|
||||
s.view();
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
fn view(&self) {
|
||||
self.imp()
|
||||
.container
|
||||
.swap(&DayDetail::new(self.imp().view_model.borrow().clone(), {
|
||||
let s = self.clone();
|
||||
move || s.edit()
|
||||
}));
|
||||
}
|
||||
|
||||
fn edit(&self) {
|
||||
self.imp()
|
||||
.container
|
||||
.swap(&DayEdit::new(self.imp().view_model.borrow().clone(), {
|
||||
let s = self.clone();
|
||||
move || s.view()
|
||||
}));
|
||||
}
|
||||
}
|
|
@ -14,10 +14,8 @@ 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/>.
|
||||
*/
|
||||
|
||||
use crate::{
|
||||
app::App, components::DaySummary, types::DayInterval, view_models::DayDetailViewModel,
|
||||
};
|
||||
use chrono::NaiveDate;
|
||||
use crate::{components::DaySummary, types::DayInterval};
|
||||
use chrono::{Duration, Local, NaiveDate};
|
||||
use emseries::Record;
|
||||
use ft_core::TraxRecord;
|
||||
use glib::Object;
|
||||
|
@ -28,8 +26,7 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
|||
/// daily summaries, daily details, and will provide all functions the user may need for editing
|
||||
/// records.
|
||||
pub struct HistoricalViewPrivate {
|
||||
app: Rc<RefCell<Option<App>>>,
|
||||
time_window: Rc<RefCell<DayInterval>>,
|
||||
time_window: RefCell<DayInterval>,
|
||||
list_view: gtk::ListView,
|
||||
}
|
||||
|
||||
|
@ -48,42 +45,31 @@ impl ObjectSubclass for HistoricalViewPrivate {
|
|||
.set_child(Some(&DaySummary::new()));
|
||||
});
|
||||
|
||||
let s = Self {
|
||||
app: Rc::new(RefCell::new(None)),
|
||||
time_window: Rc::new(RefCell::new(DayInterval::default())),
|
||||
factory.connect_bind(move |_, list_item| {
|
||||
let records = list_item
|
||||
.downcast_ref::<gtk::ListItem>()
|
||||
.expect("should be a ListItem")
|
||||
.item()
|
||||
.and_downcast::<DayRecords>()
|
||||
.expect("should be a DaySummary");
|
||||
|
||||
let summary = list_item
|
||||
.downcast_ref::<gtk::ListItem>()
|
||||
.expect("should be a ListItem")
|
||||
.child()
|
||||
.and_downcast::<DaySummary>()
|
||||
.expect("should be a DaySummary");
|
||||
|
||||
summary.set_data(records.date(), records.records());
|
||||
});
|
||||
|
||||
Self {
|
||||
time_window: RefCell::new(DayInterval::default()),
|
||||
list_view: gtk::ListView::builder()
|
||||
.factory(&factory)
|
||||
.single_click_activate(true)
|
||||
.build(),
|
||||
};
|
||||
factory.connect_bind({
|
||||
let app = s.app.clone();
|
||||
move |_, list_item| {
|
||||
let records = list_item
|
||||
.downcast_ref::<gtk::ListItem>()
|
||||
.expect("should be a ListItem")
|
||||
.item()
|
||||
.and_downcast::<DayRecords>()
|
||||
.expect("should be a DaySummary");
|
||||
|
||||
let summary = list_item
|
||||
.downcast_ref::<gtk::ListItem>()
|
||||
.expect("should be a ListItem")
|
||||
.child()
|
||||
.and_downcast::<DaySummary>()
|
||||
.expect("should be a DaySummary");
|
||||
|
||||
if let Some(app) = app.borrow().clone() {
|
||||
summary.set_data(DayDetailViewModel::new(
|
||||
records.date(),
|
||||
records.records(),
|
||||
app.clone(),
|
||||
));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,11 +82,7 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
impl HistoricalView {
|
||||
pub fn new<SelectFn>(
|
||||
app: App,
|
||||
records: Vec<Record<TraxRecord>>,
|
||||
on_select_day: Rc<SelectFn>,
|
||||
) -> Self
|
||||
pub fn new<SelectFn>(records: Vec<Record<TraxRecord>>, on_select_day: Rc<SelectFn>) -> Self
|
||||
where
|
||||
SelectFn: Fn(chrono::NaiveDate, Vec<Record<TraxRecord>>) + 'static,
|
||||
{
|
||||
|
@ -108,8 +90,6 @@ impl HistoricalView {
|
|||
s.set_orientation(gtk::Orientation::Vertical);
|
||||
s.set_css_classes(&["historical"]);
|
||||
|
||||
*s.imp().app.borrow_mut() = Some(app);
|
||||
|
||||
let grouped_records =
|
||||
GroupedRecords::new((*s.imp().time_window.borrow()).clone()).with_data(records);
|
||||
|
||||
|
@ -181,7 +161,7 @@ impl DayRecords {
|
|||
}
|
||||
|
||||
pub fn date(&self) -> chrono::NaiveDate {
|
||||
*self.imp().date.borrow()
|
||||
self.imp().date.borrow().clone()
|
||||
}
|
||||
|
||||
pub fn records(&self) -> Vec<Record<TraxRecord>> {
|
||||
|
@ -224,11 +204,11 @@ impl GroupedRecords {
|
|||
self
|
||||
}
|
||||
|
||||
fn items(&self) -> impl Iterator<Item = DayRecords> + '_ {
|
||||
fn items<'a>(&'a self) -> impl Iterator<Item = DayRecords> + 'a {
|
||||
self.interval.days().map(|date| {
|
||||
self.data
|
||||
.get(&date)
|
||||
.cloned()
|
||||
.map(|rec| rec.clone())
|
||||
.unwrap_or(DayRecords::new(date, vec![]))
|
||||
})
|
||||
}
|
||||
|
@ -237,7 +217,6 @@ impl GroupedRecords {
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::GroupedRecords;
|
||||
use crate::types::DayInterval;
|
||||
use chrono::{FixedOffset, NaiveDate, TimeZone};
|
||||
use dimensioned::si::{KG, M, S};
|
||||
use emseries::{Record, RecordId};
|
||||
|
@ -293,12 +272,7 @@ mod test {
|
|||
},
|
||||
];
|
||||
|
||||
let groups = GroupedRecords::new(DayInterval {
|
||||
start: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(),
|
||||
end: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(),
|
||||
})
|
||||
.with_data(records)
|
||||
.data;
|
||||
let groups = GroupedRecords::from(records).0;
|
||||
assert_eq!(groups.len(), 3);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
|
||||
use gtk::prelude::*;
|
||||
|
||||
mod day_detail_view;
|
||||
pub use day_detail_view::DayDetailView;
|
||||
|
||||
mod historical_view;
|
||||
pub use historical_view::HistoricalView;
|
||||
|
||||
|
|
|
@ -38,8 +38,8 @@ glib::wrapper! {
|
|||
pub struct PlaceholderView(ObjectSubclass<PlaceholderViewPrivate>) @extends gtk::Box, gtk::Widget;
|
||||
}
|
||||
|
||||
impl Default for PlaceholderView {
|
||||
fn default() -> Self {
|
||||
impl PlaceholderView {
|
||||
pub fn new() -> Self {
|
||||
let s: Self = Object::builder().build();
|
||||
s
|
||||
}
|
||||
|
|
|
@ -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/>.
|
||||
*/
|
||||
|
||||
use crate::components::FileChooserRow;
|
||||
use crate::{app::App, components::FileChooserRow};
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
use std::path::PathBuf;
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
use crate::types;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn read_a_legacy_set_rep_record() {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn read_a_legacy_steps_record() {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn read_a_legacy_time_distance_record() {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn read_a_legacy_weight_record() {
|
||||
unimplemented!()
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
/// SetRep represents workouts like pushups or situps, which involve doing a "set" of a number of
|
||||
/// actions, resting, and then doing another set.
|
||||
#[allow(dead_code)]
|
||||
pub struct SetRep {
|
||||
/// I assume that a set/rep workout is only done once in a day.
|
||||
date: NaiveDate,
|
||||
|
@ -23,16 +22,6 @@ pub struct Steps {
|
|||
pub count: u32,
|
||||
}
|
||||
|
||||
impl Recordable for Steps {
|
||||
fn timestamp(&self) -> Timestamp {
|
||||
Timestamp::Date(self.date)
|
||||
}
|
||||
|
||||
fn tags(&self) -> Vec<String> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
/// TimeDistance represents workouts characterized by a duration and a distance travelled. These
|
||||
/// sorts of workouts can occur many times a day, depending on how one records things. I might
|
||||
/// record a single 30-km workout if I go on a long-distanec ride. Or I might record multiple 5km
|
||||
|
@ -65,16 +54,6 @@ pub struct Weight {
|
|||
pub weight: si::Kilogram<f64>,
|
||||
}
|
||||
|
||||
impl Recordable for Weight {
|
||||
fn timestamp(&self) -> Timestamp {
|
||||
Timestamp::Date(self.date)
|
||||
}
|
||||
|
||||
fn tags(&self) -> Vec<String> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum RecordType {
|
||||
BikeRide,
|
||||
|
@ -112,24 +91,23 @@ impl TraxRecord {
|
|||
}
|
||||
|
||||
pub fn is_weight(&self) -> bool {
|
||||
matches!(self, TraxRecord::Weight(_))
|
||||
}
|
||||
|
||||
pub fn is_steps(&self) -> bool {
|
||||
matches!(self, TraxRecord::Steps(_))
|
||||
match self {
|
||||
TraxRecord::Weight(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Recordable for TraxRecord {
|
||||
fn timestamp(&self) -> Timestamp {
|
||||
match self {
|
||||
TraxRecord::BikeRide(rec) => Timestamp::DateTime(rec.datetime),
|
||||
TraxRecord::Row(rec) => Timestamp::DateTime(rec.datetime),
|
||||
TraxRecord::Run(rec) => Timestamp::DateTime(rec.datetime),
|
||||
TraxRecord::Steps(rec) => rec.timestamp(),
|
||||
TraxRecord::Swim(rec) => Timestamp::DateTime(rec.datetime),
|
||||
TraxRecord::Walk(rec) => Timestamp::DateTime(rec.datetime),
|
||||
TraxRecord::Weight(rec) => rec.timestamp(),
|
||||
TraxRecord::BikeRide(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Row(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Run(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Steps(rec) => Timestamp::Date(rec.date),
|
||||
TraxRecord::Swim(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Walk(rec) => Timestamp::DateTime(rec.datetime.clone()),
|
||||
TraxRecord::Weight(rec) => Timestamp::Date(rec.date),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,6 +135,6 @@ mod test {
|
|||
let id = series.put(record.clone()).unwrap();
|
||||
|
||||
let record_ = series.get(&id).unwrap();
|
||||
assert_eq!(record_.data, record);
|
||||
assert_eq!(record_, record);
|
||||
}
|
||||
}
|
||||
|
|
26
flake.nix
26
flake.nix
|
@ -65,9 +65,14 @@
|
|||
gio-sys = attrs: { nativeBuildInputs = gtkNativeInputs; };
|
||||
gdk-pixbuf-sys = attrs: { nativeBuildInputs = gtkNativeInputs; };
|
||||
libadwaita-sys = attrs: { nativeBuildInputs = gtkNativeInputs; };
|
||||
|
||||
dashboard = attrs: { nativeBuildInputs = gtkNativeInputs; };
|
||||
fitnesstrax = attrs: { nativeBuildInputs = gtkNativeInputs; };
|
||||
# fitnesstrax = attrs: {
|
||||
# buildInputs = [
|
||||
# pkgs.pkg-config
|
||||
# pkgs.glib
|
||||
# pkgs.gtk4
|
||||
# pkgs.libadwaita
|
||||
# ];
|
||||
# };
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -75,24 +80,11 @@
|
|||
nixpkgs = nixpkgs;
|
||||
buildRustCrateForPkgs = cargoOverrides;
|
||||
};
|
||||
|
||||
in rec {
|
||||
in {
|
||||
cyberpunk-splash = cargo_nix.workspaceMembers.cyberpunk-splash.build;
|
||||
dashboard = cargo_nix.workspaceMembers.dashboard.build;
|
||||
file-service = cargo_nix.workspaceMembers.file-service.build;
|
||||
fitnesstrax = cargo_nix.workspaceMembers.fitnesstrax.build;
|
||||
|
||||
all = pkgs.symlinkJoin {
|
||||
name = "all";
|
||||
paths = [
|
||||
cyberpunk-splash
|
||||
dashboard
|
||||
file-service
|
||||
fitnesstrax
|
||||
];
|
||||
};
|
||||
|
||||
default = all;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue