From 7b9b25a7cfcdc36d5c951a5c2ab8674f66ca4b34 Mon Sep 17 00:00:00 2001 From: alemidev Date: Sat, 11 Jun 2022 03:04:17 +0200 Subject: [PATCH] feat: limit flag is stored per panel --- src/app/data/mod.rs | 1 + src/app/data/store.rs | 14 +++++++++----- src/app/mod.rs | 28 +++++++++++++--------------- src/app/worker.rs | 3 ++- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/app/data/mod.rs b/src/app/data/mod.rs index fc242ee..873c8f3 100644 --- a/src/app/data/mod.rs +++ b/src/app/data/mod.rs @@ -84,6 +84,7 @@ pub struct Panel { pub timeserie: bool, pub(crate) width: i32, pub(crate) height: i32, + pub limit: bool, } impl Panel { diff --git a/src/app/data/store.rs b/src/app/data/store.rs index dda9ba1..b9f8d88 100644 --- a/src/app/data/store.rs +++ b/src/app/data/store.rs @@ -25,7 +25,8 @@ impl SQLiteDataStore { view_size INT NOT NULL, timeserie BOOL NOT NULL, width INT NOT NULL, - height INT NOT NULL + height INT NOT NULL, + limit_view BOOL NOT NULL );", [], )?; @@ -202,6 +203,7 @@ impl SQLiteDataStore { timeserie: row.get(4)?, width: row.get(5)?, height: row.get(6)?, + limit: row.get(7)?, }) })?; @@ -217,8 +219,8 @@ impl SQLiteDataStore { // jank! TODO make it not jank! pub fn new_panel(&self, name: &str, view_size:i32, width: i32, height: i32) -> rusqlite::Result { self.conn.execute( - "INSERT INTO panels (name, view_scroll, view_size, timeserie, width, height) VALUES (?, ?, ?, ?, ?, ?)", - params![name, true, view_size, true, width, height] + "INSERT INTO panels (name, view_scroll, view_size, timeserie, width, height, limit_view) VALUES (?, ?, ?, ?, ?, ?, ?)", + params![name, true, view_size, true, width, height, false] )?; let mut statement = self.conn.prepare("SELECT * FROM panels WHERE name = ?")?; for panel in statement.query_map(params![name], |row| { @@ -230,6 +232,7 @@ impl SQLiteDataStore { timeserie: row.get(4)?, width: row.get(5)?, height: row.get(6)?, + limit: row.get(7)?, }) })? { if let Ok(p) = panel { @@ -248,10 +251,11 @@ impl SQLiteDataStore { timeserie: bool, width: i32, height: i32, + limit: bool, ) -> rusqlite::Result { self.conn.execute( - "UPDATE panels SET name = ?, view_scroll = ?, view_size = ?, timeserie = ?, width = ?, height = ? WHERE id = ?", - params![name, view_scroll, view_size, timeserie, width, height, id], + "UPDATE panels SET name = ?, view_scroll = ?, view_size = ?, timeserie = ?, width = ?, height = ?, limit_view = ? WHERE id = ?", + params![name, view_scroll, view_size, timeserie, width, height, limit, id], ) } diff --git a/src/app/mod.rs b/src/app/mod.rs index 1b53b1d..50c03b6 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -43,12 +43,11 @@ pub struct App { data: Arc, input: InputBuffer, edit: bool, - filter: bool, } impl App { pub fn new(_cc: &eframe::CreationContext, data: Arc) -> Self { - Self { data, input: InputBuffer::default(), edit: false, filter: false } + Self { data, input: InputBuffer::default(), edit: false } } } @@ -59,12 +58,11 @@ impl eframe::App for App { egui::widgets::global_dark_light_mode_switch(ui); ui.heading("dashboard"); ui.separator(); - ui.checkbox(&mut self.filter, "filter"); - ui.separator(); ui.checkbox(&mut self.edit, "edit"); if self.edit { if ui.button("save").clicked() { native_save(self.data.clone()); + self.edit = false; } ui.separator(); ui.label("+ panel"); @@ -74,10 +72,10 @@ impl eframe::App for App { } ui.separator(); ui.label("+ source"); - eframe::egui::TextEdit::singleline(&mut self.input.name).hint_text("name").desired_width(35.0).show(ui); - eframe::egui::TextEdit::singleline(&mut self.input.url).hint_text("url").desired_width(80.0).show(ui); - eframe::egui::TextEdit::singleline(&mut self.input.query_x).hint_text("x").desired_width(25.0).show(ui); - eframe::egui::TextEdit::singleline(&mut self.input.query_y).hint_text("y").desired_width(25.0).show(ui); + eframe::egui::TextEdit::singleline(&mut self.input.name).hint_text("name").desired_width(50.0).show(ui); + eframe::egui::TextEdit::singleline(&mut self.input.url).hint_text("url").desired_width(160.0).show(ui); + eframe::egui::TextEdit::singleline(&mut self.input.query_x).hint_text("x").desired_width(30.0).show(ui); + eframe::egui::TextEdit::singleline(&mut self.input.query_y).hint_text("y").desired_width(30.0).show(ui); egui::ComboBox::from_id_source("panel") .selected_text(format!("panel [{}]", self.input.panel_id)) .width(70.0) @@ -180,14 +178,14 @@ impl eframe::App for App { ui.separator(); } } - if self.filter { - ui.add(egui::Slider::new(&mut panel.view_size, 1..=1440).text("samples")); - ui.separator(); - } ui.add(egui::Slider::new(&mut panel.height, 0..=500).text("height")); ui.separator(); - ui.checkbox(&mut panel.view_scroll, "autoscroll"); + ui.checkbox(&mut panel.limit, "limit"); + ui.add(egui::DragValue::new(&mut panel.view_size).speed(10).clamp_range(0..=2147483647)); + ui.label("mins"); + ui.separator(); ui.checkbox(&mut panel.timeserie, "timeserie"); + ui.checkbox(&mut panel.view_scroll, "autoscroll"); ui.separator(); }); @@ -197,7 +195,7 @@ impl eframe::App for App { if panel.view_scroll { p = p.include_x(Utc::now().timestamp() as f64); - if self.filter { + if panel.limit { p = p.include_x((Utc::now().timestamp() - (panel.view_size as i64 * 60)) as f64); } } @@ -216,7 +214,7 @@ impl eframe::App for App { p.show(ui, |plot_ui| { for source in &*sources { if source.visible && source.panel_id == panel.id { - let line = if self.filter { + let line = if panel.limit { Line::new(source.values_filter((Utc::now().timestamp() - (panel.view_size as i64 * 60)) as f64)).name(source.name.as_str()) } else { Line::new(source.values()).name(source.name.as_str()) diff --git a/src/app/worker.rs b/src/app/worker.rs index b3e5e7a..017e4ac 100644 --- a/src/app/worker.rs +++ b/src/app/worker.rs @@ -15,7 +15,8 @@ pub fn native_save(state:Arc) { panel.view_size, panel.timeserie, panel.width, - panel.height + panel.height, + panel.limit, ).unwrap(); let sources = state.sources.read().unwrap(); for source in &*sources {