Save real data to the database. Load data on app start.
This commit is contained in:
parent
f422e233a1
commit
0c3ae062c8
|
@ -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;
|
||||
|
|
|
@ -320,8 +320,10 @@ impl WeightView {
|
|||
}
|
||||
|
||||
fn blur(&self) {
|
||||
if *self.imp().current.borrow() == *self.imp().edit.borrow() {
|
||||
self.imp().on_edit_finished.borrow()(0. * si::KG);
|
||||
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);
|
||||
self.view();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,13 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
mod app;
|
||||
mod app_window;
|
||||
mod components;
|
||||
mod types;
|
||||
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";
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
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,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::DaySummary;
|
||||
use crate::{components::DaySummary, types::DayInterval};
|
||||
use chrono::{Duration, Local, NaiveDate};
|
||||
use emseries::Record;
|
||||
use ft_core::TraxRecord;
|
||||
|
@ -196,52 +196,6 @@ impl GroupedRecords {
|
|||
}
|
||||
}
|
||||
|
||||
// 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)]
|
||||
struct DayInterval {
|
||||
start: NaiveDate,
|
||||
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 {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::GroupedRecords;
|
||||
|
|
Loading…
Reference in New Issue