mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-14 03:49:19 +01:00
fix: improved panel edit UI, removed some old stuff
This commit is contained in:
parent
d6c2e49843
commit
868a1a4e0a
5 changed files with 63 additions and 151 deletions
|
@ -17,7 +17,7 @@ fn color_square(ui: &mut Ui, color:Color32) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn metric_edit_ui(ui: &mut Ui, metric: &entities::metrics::Model) {
|
||||
pub fn metric_line_ui(ui: &mut Ui, metric: &entities::metrics::Model) {
|
||||
let mut name = metric.name.clone();
|
||||
let mut query = metric.query.clone();
|
||||
ui.horizontal(|ui| {
|
||||
|
|
|
@ -15,7 +15,7 @@ use scaffold::{
|
|||
// confirmation_popup_delete_metric, confirmation_popup_delete_source, footer,
|
||||
header,
|
||||
};
|
||||
use source::source_panel;
|
||||
use source::source_panel_ui;
|
||||
|
||||
use self::scaffold::{footer, EditingModel, popup_edit_ui};
|
||||
|
||||
|
@ -112,7 +112,7 @@ impl eframe::App for App {
|
|||
SidePanel::left("sources-bar")
|
||||
.width_range(280.0..=800.0)
|
||||
.default_width(if self.edit { 450.0 } else { 330.0 })
|
||||
.show(ctx, |ui| source_panel(self, ui));
|
||||
.show(ctx, |ui| source_panel_ui(self, ui));
|
||||
}
|
||||
|
||||
CentralPanel::default().show(ctx, |ui| {
|
||||
|
|
|
@ -25,6 +25,7 @@ pub fn main_content(app: &mut App, ctx: &Context, ui: &mut Ui) {
|
|||
panel_title_ui_edit(ui, &mut panel, &mut app.editing, &app.view.metrics.borrow(), &app.view.panel_metric.borrow());
|
||||
})
|
||||
.body(|ui| panel_body_ui(ui, panel, &metrics, &app.view.points.borrow(), &app.view.panel_metric.borrow()));
|
||||
ui.separator();
|
||||
}
|
||||
} else {
|
||||
for panel in app.view.panels.borrow().iter() {
|
||||
|
@ -34,58 +35,32 @@ pub fn main_content(app: &mut App, ctx: &Context, ui: &mut Ui) {
|
|||
true,
|
||||
)
|
||||
.show_header(ui, |ui| {
|
||||
panel_title_ui(ui, &panel);
|
||||
panel_title_ui(ui, &panel, &mut app.editing, &app.view.metrics.borrow(), &app.view.panel_metric.borrow());
|
||||
})
|
||||
.body(|ui| panel_body_ui(ui, panel, &metrics, &app.view.points.borrow(), &app.view.panel_metric.borrow()));
|
||||
ui.separator();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pub fn _panel_edit_inline_ui(_ui: &mut Ui, _panel: &entities::panels::Model) {
|
||||
// TextEdit::singleline(&mut panel.name)
|
||||
// .hint_text("name")
|
||||
// .desired_width(100.0)
|
||||
// .show(ui);
|
||||
}
|
||||
|
||||
pub fn panel_title_ui(
|
||||
ui: &mut Ui,
|
||||
panel: &entities::panels::Model,
|
||||
editing: &mut Vec<EditingModel>,
|
||||
metrics: &Vec<entities::metrics::Model>,
|
||||
panel_metric: &Vec<entities::panel_metric::Model>,
|
||||
) { // TODO make edit UI in separate func
|
||||
ui.horizontal(|ui| {
|
||||
ui.separator();
|
||||
if ui.small_button("#").clicked() {
|
||||
// TODO don't add duplicates
|
||||
editing.push(
|
||||
EditingModel::make_edit_panel(panel.clone(), metrics, panel_metric)
|
||||
);
|
||||
}
|
||||
ui.separator();
|
||||
ui.heading(panel.name.as_str());
|
||||
ui.with_layout(Layout::right_to_left(eframe::emath::Align::Min), |ui| {
|
||||
ui.horizontal(|_ui| {
|
||||
// TODO just show these, with no editing
|
||||
// ui.toggle_value(&mut panel.view_scroll, "🔒");
|
||||
// ui.separator();
|
||||
// ui.add(
|
||||
// DragValue::new(&mut panel.view_size)
|
||||
// .speed(10)
|
||||
// .suffix(" min")
|
||||
// .clamp_range(0..=2147483647i32),
|
||||
// );
|
||||
// ui.separator();
|
||||
// ui.add(
|
||||
// DragValue::new(&mut panel.view_offset)
|
||||
// .speed(10)
|
||||
// .suffix(" min")
|
||||
// .clamp_range(0..=2147483647i32),
|
||||
// );
|
||||
// ui.separator();
|
||||
// if panel.reduce_view {
|
||||
// ui.add(
|
||||
// DragValue::new(&mut panel.view_chunks)
|
||||
// .speed(1)
|
||||
// .prefix("x")
|
||||
// .clamp_range(1..=1000), // TODO allow to average larger spans maybe?
|
||||
// );
|
||||
// ui.toggle_value(&mut panel.average_view, "avg");
|
||||
// }
|
||||
// ui.toggle_value(&mut panel.reduce_view, "reduce");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -97,7 +72,6 @@ pub fn panel_title_ui_edit(
|
|||
panel_metric: &Vec<entities::panel_metric::Model>,
|
||||
) { // TODO make edit UI in separate func
|
||||
ui.horizontal(|ui| {
|
||||
ui.heading(panel.name.as_str());
|
||||
ui.separator();
|
||||
if ui.small_button("#").clicked() {
|
||||
// TODO don't add duplicates
|
||||
|
@ -106,7 +80,7 @@ pub fn panel_title_ui_edit(
|
|||
);
|
||||
}
|
||||
ui.separator();
|
||||
ui.add(Slider::new(&mut panel.height, 0..=500).text("height"));
|
||||
ui.heading(panel.name.as_str());
|
||||
//ui.separator();
|
||||
//ui.checkbox(&mut panel.timeserie, "timeserie");
|
||||
ui.with_layout(Layout::right_to_left(eframe::emath::Align::Min), |ui| {
|
||||
|
@ -137,6 +111,8 @@ pub fn panel_title_ui_edit(
|
|||
ui.toggle_value(&mut panel.average_view, "avg");
|
||||
}
|
||||
ui.toggle_value(&mut panel.reduce_view, "reduce");
|
||||
ui.separator();
|
||||
ui.add(Slider::new(&mut panel.height, 0..=500).text("height"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -218,7 +194,6 @@ pub fn panel_body_ui(
|
|||
let metric_ids : Vec<i64> = panel_metric.iter().filter(|x| x.panel_id == panel.id).map(|x| x.metric_id).collect();
|
||||
for metric in metrics {
|
||||
if metric_ids.contains(&metric.id) {
|
||||
// let values = metric.values(min_x, max_x, chunk_size, panel.average_view);
|
||||
let mut values : Vec<[f64;2]> = points
|
||||
.iter()
|
||||
.filter(|v| v.metric_id == metric.id)
|
||||
|
@ -233,13 +208,6 @@ pub fn panel_body_ui(
|
|||
if x.len() > 0 { x[x.len()-1] } else { [0.0, 0.0 ]}
|
||||
}).collect();
|
||||
}
|
||||
// if !panel.timeserie && panel.view_scroll && values.len() > 0 {
|
||||
// let l = values.len() - 1;
|
||||
// p = p.include_x(values[0].x)
|
||||
// .include_x(values[l].x)
|
||||
// .include_y(values[0].y)
|
||||
// .include_y(values[l].y);
|
||||
// }
|
||||
lines.push(
|
||||
Line::new(values)
|
||||
.name(metric.name.as_str())
|
||||
|
|
|
@ -205,12 +205,42 @@ pub fn popup_edit_ui(
|
|||
ui.label("position");
|
||||
ui.add(DragValue::new(&mut panel.position).clamp_range(0..=1000));
|
||||
});
|
||||
for (i, metric) in metrics.iter().enumerate() {
|
||||
if i >= opts.len() { // TODO safe but jank: always starts with all off
|
||||
opts.push(false);
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(
|
||||
DragValue::new(&mut panel.view_size)
|
||||
.speed(10)
|
||||
.suffix(" min")
|
||||
.clamp_range(0..=2147483647i32),
|
||||
);
|
||||
ui.separator();
|
||||
ui.add(
|
||||
DragValue::new(&mut panel.view_offset)
|
||||
.speed(10)
|
||||
.suffix(" min")
|
||||
.clamp_range(0..=2147483647i32),
|
||||
);
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.toggle_value(&mut panel.reduce_view, "reduce");
|
||||
if panel.reduce_view {
|
||||
ui.add(
|
||||
DragValue::new(&mut panel.view_chunks)
|
||||
.speed(1)
|
||||
.suffix("×")
|
||||
.clamp_range(1..=1000)
|
||||
);
|
||||
ui.toggle_value(&mut panel.average_view, "avg");
|
||||
}
|
||||
ui.checkbox(&mut opts[i], &metric.name);
|
||||
}
|
||||
});
|
||||
ui.label("metrics:");
|
||||
ui.group(|ui| {
|
||||
for (i, metric) in metrics.iter().enumerate() {
|
||||
if i >= opts.len() { // TODO safe but jank: always starts with all off
|
||||
opts.push(false);
|
||||
}
|
||||
ui.checkbox(&mut opts[i], &metric.name);
|
||||
}
|
||||
});
|
||||
},
|
||||
EditingModelType::EditingSource { source } => {
|
||||
ui.horizontal(|ui| {
|
||||
|
@ -249,9 +279,6 @@ pub fn popup_edit_ui(
|
|||
ui.selectable_value(&mut metric.source_id, s.id, s.name.as_str());
|
||||
}
|
||||
});
|
||||
// TextEdit::singleline(&mut metric.query_x)
|
||||
// .hint_text("x")
|
||||
// .show(ui);
|
||||
TextEdit::singleline(&mut metric.query)
|
||||
.hint_text("query")
|
||||
.show(ui);
|
||||
|
@ -308,18 +335,6 @@ pub fn header(app: &mut App, ui: &mut Ui, frame: &mut Frame) {
|
|||
}
|
||||
}
|
||||
ui.separator();
|
||||
// ui.separator();
|
||||
// ui.checkbox(&mut app.edit, "edit");
|
||||
// if app.edit {
|
||||
// ui.label("+ panel");
|
||||
// panel_edit_inline_ui(ui, &mut app.buffer_panel);
|
||||
// if ui.button("add").clicked() {
|
||||
// // if let Err(e) = app.data.add_panel(&app.input_panel) {
|
||||
// // error!(target: "ui", "Failed to add panel: {:?}", e);
|
||||
// // };
|
||||
// }
|
||||
// ui.separator();
|
||||
// }
|
||||
ui.with_layout(Layout::top_down(Align::RIGHT), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.small_button("×").clicked() {
|
||||
|
|
|
@ -3,11 +3,9 @@ use eframe::egui::{ScrollArea, Ui, DragValue, TextEdit, Checkbox};
|
|||
use crate::gui::App;
|
||||
use crate::data::entities;
|
||||
|
||||
use super::metric::metric_edit_ui;
|
||||
use super::metric::metric_line_ui;
|
||||
|
||||
pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
||||
let source_to_put_metric_on : Option<i64> = None;
|
||||
// let mut to_delete: Option<usize> = None;
|
||||
pub fn source_panel_ui(app: &mut App, ui: &mut Ui) {
|
||||
let panel_width = ui.available_width();
|
||||
let mut orphaned_metrics = app.view.metrics.borrow().clone();
|
||||
ScrollArea::vertical()
|
||||
|
@ -26,12 +24,11 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
|||
if ui.small_button("#").clicked() {
|
||||
app.editing.push(source.clone().into());
|
||||
}
|
||||
// if ui.small_button("−").clicked() { }
|
||||
});
|
||||
ui.vertical(|ui| { // actual sources list container
|
||||
ui.group(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
source_edit_ui(ui, source);
|
||||
source_line_ui(ui, source);
|
||||
});
|
||||
let metrics = app
|
||||
.view
|
||||
|
@ -41,24 +38,7 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
|||
if metric.source_id == source.id {
|
||||
orphaned_metrics.retain(|m| m.id != metric.id);
|
||||
ui.horizontal(|ui| {
|
||||
metric_edit_ui(ui, metric);
|
||||
// if ui.small_button("s").clicked() {
|
||||
// let path = FileDialog::new()
|
||||
// .add_filter("csv", &["csv"])
|
||||
// .set_file_name(format!("{}-{}.csv", source.name, metric.name).as_str())
|
||||
// .save_file();
|
||||
// if let Some(_path) = path {
|
||||
// // serialize_values(
|
||||
// // &*metric
|
||||
// // .data
|
||||
// // .read()
|
||||
// // .expect("Values RwLock poisoned"),
|
||||
// // metric,
|
||||
// // path,
|
||||
// // )
|
||||
// // .expect("Could not serialize data");
|
||||
// }
|
||||
// }
|
||||
metric_line_ui(ui, metric);
|
||||
if ui.small_button("#").clicked() {
|
||||
// TODO don't add duplicates
|
||||
app.editing.push(metric.clone().into());
|
||||
|
@ -81,28 +61,11 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
|||
ui.vertical(|ui| { // actual sources list container
|
||||
ui.group(|ui| {
|
||||
ui.horizontal(|ui| {
|
||||
source_edit_ui(ui, &app.buffer_source);
|
||||
source_line_ui(ui, &app.buffer_source);
|
||||
});
|
||||
for metric in orphaned_metrics.iter() {
|
||||
ui.horizontal(|ui| {
|
||||
metric_edit_ui(ui, metric);
|
||||
// if ui.small_button("s").clicked() {
|
||||
// // let path = FileDialog::new()
|
||||
// // .add_filter("csv", &["csv"])
|
||||
// // .set_file_name(format!("{}-{}.csv", source.name, metric.name).as_str())
|
||||
// // .save_file();
|
||||
// // if let Some(_path) = path {
|
||||
// // // serialize_values(
|
||||
// // // &*metric
|
||||
// // // .data
|
||||
// // // .read()
|
||||
// // // .expect("Values RwLock poisoned"),
|
||||
// // // metric,
|
||||
// // // path,
|
||||
// // // )
|
||||
// // // .expect("Could not serialize data");
|
||||
// // }
|
||||
// }
|
||||
metric_line_ui(ui, metric);
|
||||
if ui.small_button("#").clicked() {
|
||||
// TODO don't add duplicates
|
||||
app.editing.push(metric.clone().into());
|
||||
|
@ -111,7 +74,7 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
|||
}
|
||||
// Add an empty metric to insert new ones
|
||||
ui.horizontal(|ui| {
|
||||
metric_edit_ui(ui, &mut app.buffer_metric);
|
||||
metric_line_ui(ui, &mut app.buffer_metric);
|
||||
if ui.small_button("+").clicked() {
|
||||
app.editing.push(entities::metrics::Model::default().into());
|
||||
}
|
||||
|
@ -121,43 +84,9 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
|||
});
|
||||
}
|
||||
});
|
||||
//if let Some(i) = to_delete {
|
||||
// // TODO can this be done in background? idk
|
||||
// let mut panels = app.data.panels.write().expect("Panels RwLock poisoned");
|
||||
// panels.remove(i);
|
||||
// } else
|
||||
// if let Some(i) = to_swap {
|
||||
// // TODO can this be done in background? idk
|
||||
// let mut sources = app.sources.borrow();
|
||||
// sources.swap(i - 1, i);
|
||||
// }
|
||||
// if to_insert.len() > 0 {
|
||||
// let mut metrics = app.metrics.borrow();
|
||||
// for m in to_insert {
|
||||
// metrics.push(m);
|
||||
// }
|
||||
// }
|
||||
if let Some(s) = source_to_put_metric_on {
|
||||
for source in app.view.sources.borrow().iter() {
|
||||
if source.id == s {
|
||||
// if let Err(e) =
|
||||
// app.data.add_metric(&app.input_metric, &source)
|
||||
// {
|
||||
// error!(target: "ui", "Error adding metric : {:?}", e);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn _source_display_ui(ui: &mut Ui, source: &entities::sources::Model, _width: f32) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.heading(&source.name).on_hover_text(&source.url);
|
||||
// ui.add_enabled(false, Checkbox::new(&mut source.enabled, ""));
|
||||
});
|
||||
}
|
||||
|
||||
pub fn source_edit_ui(ui: &mut Ui, source: &entities::sources::Model) {
|
||||
pub fn source_line_ui(ui: &mut Ui, source: &entities::sources::Model) {
|
||||
let mut interval = source.interval.clone();
|
||||
let mut name = source.name.clone();
|
||||
let mut enabled = source.enabled.clone();
|
||||
|
|
Loading…
Reference in a new issue