mirror of
https://git.alemi.dev/dashboard.git
synced 2024-11-22 15:34:54 +01:00
feat: improved sources side panel UI
This commit is contained in:
parent
e7af410edf
commit
9a7b29c8f8
2 changed files with 65 additions and 104 deletions
|
@ -1,4 +1,4 @@
|
||||||
use eframe::{egui::{Ui, Layout, Sense, color_picker::show_color_at, ComboBox, TextEdit}, emath::Align, epaint::Color32};
|
use eframe::{egui::{Ui, Layout, Sense, color_picker::show_color_at, TextEdit}, emath::Align, epaint::Color32};
|
||||||
|
|
||||||
use crate::{data::entities, util::unpack_color};
|
use crate::{data::entities, util::unpack_color};
|
||||||
|
|
||||||
|
@ -33,43 +33,29 @@ pub fn _metric_display_ui(ui: &mut Ui, metric: &entities::metrics::Model, _width
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn metric_edit_ui(ui: &mut Ui, metric: &entities::metrics::Model, panels: Option<&Vec<entities::panels::Model>>, width: f32) {
|
pub fn metric_edit_ui(ui: &mut Ui, metric: &entities::metrics::Model) {
|
||||||
let text_width = width - 195.0;
|
|
||||||
let mut name = metric.name.clone();
|
let mut name = metric.name.clone();
|
||||||
let mut query_x = metric.query_x.clone();
|
let mut query_x = metric.query_x.clone();
|
||||||
let mut query_y = metric.query_y.clone();
|
let mut query_y = metric.query_y.clone();
|
||||||
let mut panel_id = 0;
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
// ui.color_edit_button_srgba(&mut unpack_color(metric.color));
|
// ui.color_edit_button_srgba(&mut unpack_color(metric.color));
|
||||||
color_square(ui, unpack_color(metric.color));
|
color_square(ui, unpack_color(metric.color));
|
||||||
|
let available = ui.available_width() - 79.0;
|
||||||
TextEdit::singleline(&mut name)
|
TextEdit::singleline(&mut name)
|
||||||
|
.desired_width(available / 2.0)
|
||||||
.interactive(false)
|
.interactive(false)
|
||||||
.desired_width(text_width / 2.0)
|
|
||||||
.hint_text("name")
|
.hint_text("name")
|
||||||
.show(ui);
|
.show(ui);
|
||||||
ui.separator();
|
ui.separator();
|
||||||
if query_x.len() > 0 {
|
|
||||||
TextEdit::singleline(&mut query_x)
|
TextEdit::singleline(&mut query_x)
|
||||||
|
.desired_width(available / 4.0)
|
||||||
.interactive(false)
|
.interactive(false)
|
||||||
.desired_width(text_width / 4.0)
|
|
||||||
.hint_text("x")
|
.hint_text("x")
|
||||||
.show(ui);
|
.show(ui);
|
||||||
}
|
|
||||||
TextEdit::singleline(&mut query_y)
|
TextEdit::singleline(&mut query_y)
|
||||||
|
.desired_width(available / 4.0)
|
||||||
.interactive(false)
|
.interactive(false)
|
||||||
.desired_width(if query_x.len() > 0 { 0.0 } else { 15.0 } + (text_width / if query_x.len() > 0 { 4.0 } else { 2.0 }))
|
|
||||||
.hint_text("y")
|
.hint_text("y")
|
||||||
.show(ui);
|
.show(ui);
|
||||||
if let Some(panels) = panels {
|
|
||||||
ComboBox::from_id_source(format!("panel-selector-{}", metric.id))
|
|
||||||
.width(60.0)
|
|
||||||
.selected_text("panel: ???")
|
|
||||||
.show_ui(ui, |ui| {
|
|
||||||
ui.selectable_value(&mut panel_id, -1, "None");
|
|
||||||
for p in panels {
|
|
||||||
ui.selectable_value(&mut panel_id, p.id, p.name.as_str());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use eframe::{
|
use eframe::{
|
||||||
egui::{Layout, ScrollArea, Ui, DragValue, TextEdit, Checkbox},
|
egui::{Layout, ScrollArea, Ui, DragValue, TextEdit, Checkbox, Button},
|
||||||
emath::Align,
|
emath::Align,
|
||||||
};
|
};
|
||||||
use rfd::FileDialog;
|
|
||||||
|
|
||||||
use crate::gui::App;
|
use crate::gui::App;
|
||||||
use crate::data::entities;
|
use crate::data::entities;
|
||||||
|
@ -12,7 +11,6 @@ use super::metric::metric_edit_ui;
|
||||||
pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
||||||
let source_to_put_metric_on : Option<i64> = None;
|
let source_to_put_metric_on : Option<i64> = None;
|
||||||
// let mut to_delete: Option<usize> = None;
|
// let mut to_delete: Option<usize> = None;
|
||||||
let panels = &app.panels;
|
|
||||||
let panel_width = ui.available_width();
|
let panel_width = ui.available_width();
|
||||||
let mut orphaned_metrics = app.view.metrics.borrow().clone();
|
let mut orphaned_metrics = app.view.metrics.borrow().clone();
|
||||||
ScrollArea::vertical()
|
ScrollArea::vertical()
|
||||||
|
@ -24,21 +22,19 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
||||||
ui.heading("Sources");
|
ui.heading("Sources");
|
||||||
ui.separator();
|
ui.separator();
|
||||||
for source in sources.iter() {
|
for source in sources.iter() {
|
||||||
|
ui.add_space(5.0);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.add_space(10.0);
|
ui.add_space(8.0);
|
||||||
if ui.small_button("+").clicked() { }
|
if ui.small_button("#").clicked() {
|
||||||
if ui.small_button("−").clicked() { }
|
|
||||||
});
|
|
||||||
ui.vertical(|ui| { // actual sources list container
|
|
||||||
let remaining_width = ui.available_width();
|
|
||||||
ui.group(|ui| {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
source_edit_ui(ui, source, remaining_width - 34.0);
|
|
||||||
if ui.small_button("×").clicked() {
|
|
||||||
// TODO don't add duplicates
|
|
||||||
app.editing.push(source.clone().into());
|
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);
|
||||||
});
|
});
|
||||||
let metrics = app
|
let metrics = app
|
||||||
.view
|
.view
|
||||||
|
@ -48,64 +44,8 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
||||||
if metric.source_id == source.id {
|
if metric.source_id == source.id {
|
||||||
orphaned_metrics.retain(|m| m.id != metric.id);
|
orphaned_metrics.retain(|m| m.id != metric.id);
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
metric_edit_ui(
|
metric_edit_ui(ui, metric);
|
||||||
ui,
|
// if ui.small_button("s").clicked() {
|
||||||
metric,
|
|
||||||
Some(&panels),
|
|
||||||
remaining_width - 53.0,
|
|
||||||
);
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ui.small_button("×").clicked() {
|
|
||||||
// TODO don't add duplicates
|
|
||||||
app.editing.push(metric.clone().into());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
ui.horizontal(|ui| { // 1 more for uncategorized sources
|
|
||||||
ui.vertical(|ui| {
|
|
||||||
ui.add_space(10.0);
|
|
||||||
if ui.small_button("+").clicked() { }
|
|
||||||
if ui.small_button("−").clicked() { }
|
|
||||||
});
|
|
||||||
ui.vertical(|ui| { // actual sources list container
|
|
||||||
let remaining_width = ui.available_width();
|
|
||||||
ui.group(|ui| {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
source_edit_ui(ui, &app.buffer_source, remaining_width - 34.0);
|
|
||||||
if ui.small_button("×").clicked() {
|
|
||||||
app.buffer_source = entities::sources::Model::default();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
for metric in orphaned_metrics.iter() {
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
metric_edit_ui(
|
|
||||||
ui,
|
|
||||||
metric,
|
|
||||||
Some(&panels),
|
|
||||||
remaining_width - 53.0,
|
|
||||||
);
|
|
||||||
if ui.small_button("s").clicked() {
|
|
||||||
// let path = FileDialog::new()
|
// let path = FileDialog::new()
|
||||||
// .add_filter("csv", &["csv"])
|
// .add_filter("csv", &["csv"])
|
||||||
// .set_file_name(format!("{}-{}.csv", source.name, metric.name).as_str())
|
// .set_file_name(format!("{}-{}.csv", source.name, metric.name).as_str())
|
||||||
|
@ -121,8 +61,50 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
||||||
// // )
|
// // )
|
||||||
// // .expect("Could not serialize data");
|
// // .expect("Could not serialize data");
|
||||||
// }
|
// }
|
||||||
|
// }
|
||||||
|
if ui.small_button("#").clicked() {
|
||||||
|
// TODO don't add duplicates
|
||||||
|
app.editing.push(metric.clone().into());
|
||||||
}
|
}
|
||||||
if ui.small_button("×").clicked() {
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ui.add_space(5.0);
|
||||||
|
ui.horizontal(|ui| { // 1 more for uncategorized sources
|
||||||
|
ui.vertical(|ui| {
|
||||||
|
ui.add_space(8.0);
|
||||||
|
ui.add_enabled(false, Button::new("#").small());
|
||||||
|
});
|
||||||
|
ui.vertical(|ui| { // actual sources list container
|
||||||
|
ui.group(|ui| {
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
source_edit_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");
|
||||||
|
// // }
|
||||||
|
// }
|
||||||
|
if ui.small_button("#").clicked() {
|
||||||
// TODO don't add duplicates
|
// TODO don't add duplicates
|
||||||
app.editing.push(metric.clone().into());
|
app.editing.push(metric.clone().into());
|
||||||
}
|
}
|
||||||
|
@ -149,7 +131,7 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
source_edit_ui(ui, &mut app.buffer_source, panel_width - 10.0);
|
source_edit_ui(ui, &mut app.buffer_source);
|
||||||
ui.add_space(5.0);
|
ui.add_space(5.0);
|
||||||
if app.padding {
|
if app.padding {
|
||||||
ui.add_space(300.0);
|
ui.add_space(300.0);
|
||||||
|
@ -192,24 +174,17 @@ pub fn _source_display_ui(ui: &mut Ui, source: &entities::sources::Model, _width
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn source_edit_ui(ui: &mut Ui, source: &entities::sources::Model, width: f32) {
|
pub fn source_edit_ui(ui: &mut Ui, source: &entities::sources::Model) {
|
||||||
let mut interval = source.interval.clone();
|
let mut interval = source.interval.clone();
|
||||||
let mut name = source.name.clone();
|
let mut name = source.name.clone();
|
||||||
let mut url = source.url.clone();
|
|
||||||
let mut enabled = source.enabled.clone();
|
let mut enabled = source.enabled.clone();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
let text_width = width - 100.0;
|
|
||||||
ui.add_enabled(false, Checkbox::new(&mut enabled, ""));
|
ui.add_enabled(false, Checkbox::new(&mut enabled, ""));
|
||||||
ui.add_enabled(false, DragValue::new(&mut interval).clamp_range(1..=3600));
|
|
||||||
TextEdit::singleline(&mut name)
|
TextEdit::singleline(&mut name)
|
||||||
|
.desired_width(ui.available_width() - 58.0)
|
||||||
.interactive(false)
|
.interactive(false)
|
||||||
.desired_width(text_width / 4.0)
|
|
||||||
.hint_text("name")
|
.hint_text("name")
|
||||||
.show(ui);
|
.show(ui);
|
||||||
TextEdit::singleline(&mut url)
|
ui.add_enabled(false, DragValue::new(&mut interval).clamp_range(1..=3600));
|
||||||
.interactive(false)
|
|
||||||
.desired_width(text_width * 3.0 / 4.0)
|
|
||||||
.hint_text("url")
|
|
||||||
.show(ui);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue