-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathbackups.rs
More file actions
83 lines (76 loc) · 2.8 KB
/
backups.rs
File metadata and controls
83 lines (76 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use crate::{
common::RelativeDateTime,
interpreter::{ContextArc, options::ChDigViews},
view::{self, TextLogView, ViewProvider},
};
use cursive::{
Cursive,
view::Resizable,
views::{Dialog, DummyView, LinearLayout, NamedView, TextView},
};
use std::collections::HashMap;
pub struct BackupsViewProvider;
impl ViewProvider for BackupsViewProvider {
fn name(&self) -> &'static str {
"Backups"
}
fn view_type(&self) -> ChDigViews {
ChDigViews::Backups
}
fn show(&self, siv: &mut Cursive, context: ContextArc) {
let columns = vec![
"name",
"status::String status",
"error",
"start_time",
"end_time",
"total_size",
"query_id _query_id",
];
let backups_logs_callback =
move |siv: &mut Cursive, columns: Vec<&'static str>, row: view::QueryResultRow| {
let mut map = HashMap::new();
columns.iter().zip(row.0.iter()).for_each(|(c, r)| {
map.insert(c.to_string(), r);
});
let context = siv.user_data::<ContextArc>().unwrap().clone();
siv.add_layer(Dialog::around(
LinearLayout::vertical()
.child(TextView::new("Logs:").center())
.child(DummyView.fixed_height(1))
.child(NamedView::new(
"backups_logs",
TextLogView::new(
"backups_logs",
context,
crate::interpreter::TextLogArguments {
query_ids: Some(vec![map["_query_id"].to_string()]),
logger_names: None,
message_filter: None,
max_level: None,
start: map["start_time"].as_datetime().unwrap(),
end: RelativeDateTime::from(map["end_time"].as_datetime()),
},
),
)),
));
siv.focus_name("backups_logs").unwrap();
};
// TODO:
// - order by elapsed time
super::render_from_clickhouse_query(
siv,
super::RenderFromClickHouseQueryArguments {
context,
table: "backups",
join: None,
filter: None,
sort_by: "total_size",
columns,
columns_to_compare: vec!["name"],
on_submit: Some(backups_logs_callback),
settings: HashMap::<&str, i32>::new(),
},
);
}
}