Completed initial implementation of logs, events, and tasks
This commit is contained in:
+11
-7
@@ -303,6 +303,7 @@ fn draw_table<'a, B, T, F>(
|
||||
table_props: TableProps<'a, T>,
|
||||
row_mapper: F,
|
||||
is_loading: bool,
|
||||
highlight: bool,
|
||||
) where
|
||||
B: Backend,
|
||||
F: Fn(&T) -> Row<'a>,
|
||||
@@ -316,7 +317,7 @@ fn draw_table<'a, B, T, F>(
|
||||
|
||||
let content_area = if let Some(help_string) = help {
|
||||
let chunks = vertical_chunks(
|
||||
vec![Constraint::Min(0), Constraint::Length(3)],
|
||||
vec![Constraint::Min(0), Constraint::Length(2)],
|
||||
content_area,
|
||||
);
|
||||
let mut help_text = Text::from(format!(" {}", help_string));
|
||||
@@ -339,12 +340,15 @@ fn draw_table<'a, B, T, F>(
|
||||
.style(style_default_bold())
|
||||
.bottom_margin(0);
|
||||
|
||||
let table = Table::new(rows)
|
||||
.header(headers)
|
||||
.block(block)
|
||||
.highlight_style(style_highlight())
|
||||
.highlight_symbol(HIGHLIGHT_SYMBOL)
|
||||
.widths(&constraints);
|
||||
let mut table = Table::new(rows).header(headers).block(block);
|
||||
|
||||
if highlight {
|
||||
table = table
|
||||
.highlight_style(style_highlight())
|
||||
.highlight_symbol(HIGHLIGHT_SYMBOL);
|
||||
}
|
||||
|
||||
table = table.widths(&constraints);
|
||||
|
||||
f.render_stateful_widget(table, content_area, &mut content.state);
|
||||
} else {
|
||||
|
||||
@@ -202,12 +202,12 @@ fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, ar
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
let imdb_rating = if imdb_rating == 0.0 {
|
||||
String::default()
|
||||
String::new()
|
||||
} else {
|
||||
format!("{:.1}", imdb_rating)
|
||||
};
|
||||
let rotten_tomatoes_rating = if rotten_tomatoes_rating == 0 {
|
||||
String::default()
|
||||
String::new()
|
||||
} else {
|
||||
format!("{}%", rotten_tomatoes_rating)
|
||||
};
|
||||
@@ -242,6 +242,7 @@ fn draw_add_movie_search<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, ar
|
||||
.style(style_primary())
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
_ => (),
|
||||
|
||||
@@ -200,12 +200,12 @@ pub(super) fn draw_collection_details<B: Backend>(
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
let imdb_rating = if imdb_rating == 0.0 {
|
||||
String::default()
|
||||
String::new()
|
||||
} else {
|
||||
format!("{:.1}", imdb_rating)
|
||||
};
|
||||
let rotten_tomatoes_rating = if rotten_tomatoes_rating == 0 {
|
||||
String::default()
|
||||
String::new()
|
||||
} else {
|
||||
format!("{}%", rotten_tomatoes_rating)
|
||||
};
|
||||
@@ -222,6 +222,7 @@ pub(super) fn draw_collection_details<B: Backend>(
|
||||
.style(style_primary())
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,7 @@ pub(super) fn draw_collections<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'
|
||||
.style(style_primary())
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,7 @@ fn draw_downloads<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rec
|
||||
.style(style_primary())
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,7 @@ pub(super) fn draw_library<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>,
|
||||
.style(determine_row_style(downloads_vec, movie))
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -304,6 +304,7 @@ fn draw_movie_history<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, conte
|
||||
.style(style_success())
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -337,6 +338,7 @@ fn draw_movie_cast<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, content_
|
||||
.style(style_success())
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -371,6 +373,7 @@ fn draw_movie_crew<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, content_
|
||||
.style(style_success())
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -475,7 +478,7 @@ fn draw_movie_releases<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, cont
|
||||
let language = if languages.is_some() {
|
||||
languages.clone().unwrap()[0].name.clone()
|
||||
} else {
|
||||
String::default()
|
||||
String::new()
|
||||
};
|
||||
let quality = quality.quality.name.clone();
|
||||
|
||||
@@ -493,6 +496,7 @@ fn draw_movie_releases<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, cont
|
||||
.style(style_primary())
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ fn draw_root_folders<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area:
|
||||
.style(style_primary())
|
||||
},
|
||||
app.is_loading,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+132
-22
@@ -1,4 +1,4 @@
|
||||
use crate::ui::utils::{style_primary, style_secondary};
|
||||
use crate::ui::utils::{layout_block_top_border, style_help, style_primary, style_secondary};
|
||||
use crate::ui::{draw_table, TableProps};
|
||||
use crate::{
|
||||
app::{radarr::ActiveRadarrBlock, App},
|
||||
@@ -9,11 +9,12 @@ use crate::{
|
||||
DrawUi,
|
||||
},
|
||||
};
|
||||
use chrono::DateTime;
|
||||
use chrono::Utc;
|
||||
use std::ops::Sub;
|
||||
use tui::layout::Alignment;
|
||||
use tui::style::Modifier;
|
||||
use tui::text::{Span, Text};
|
||||
use tui::widgets::{Cell, Row};
|
||||
use tui::widgets::{Cell, Paragraph, Row};
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
layout::{Constraint, Rect},
|
||||
@@ -22,6 +23,10 @@ use tui::{
|
||||
Frame,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "system_ui_tests.rs"]
|
||||
mod system_ui_tests;
|
||||
|
||||
pub(super) struct SystemUi {}
|
||||
|
||||
impl DrawUi for SystemUi {
|
||||
@@ -36,8 +41,14 @@ impl DrawUi for SystemUi {
|
||||
}
|
||||
|
||||
fn draw_system_ui_layout<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
let vertical_chunks =
|
||||
vertical_chunks(vec![Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)], area);
|
||||
let vertical_chunks = vertical_chunks(
|
||||
vec![
|
||||
Constraint::Ratio(1, 2),
|
||||
Constraint::Ratio(1, 2),
|
||||
Constraint::Min(2),
|
||||
],
|
||||
area,
|
||||
);
|
||||
|
||||
let horizontal_chunks = horizontal_chunks(
|
||||
vec![Constraint::Ratio(1, 2), Constraint::Ratio(1, 2)],
|
||||
@@ -45,8 +56,9 @@ fn draw_system_ui_layout<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, ar
|
||||
);
|
||||
|
||||
draw_tasks(f, app, horizontal_chunks[0]);
|
||||
f.render_widget(title_block("Queue"), horizontal_chunks[1]);
|
||||
draw_events(f, app, horizontal_chunks[1]);
|
||||
draw_logs(f, app, vertical_chunks[1]);
|
||||
draw_help(f, app, vertical_chunks[2]);
|
||||
}
|
||||
|
||||
fn draw_tasks<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
@@ -62,31 +74,28 @@ fn draw_tasks<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
"Interval",
|
||||
"Last Execution",
|
||||
"Last Duration",
|
||||
"Next Duration",
|
||||
"Next Execution",
|
||||
],
|
||||
constraints: vec![
|
||||
Constraint::Percentage(30),
|
||||
Constraint::Percentage(12),
|
||||
Constraint::Percentage(16),
|
||||
Constraint::Percentage(16),
|
||||
Constraint::Percentage(16),
|
||||
Constraint::Percentage(18),
|
||||
Constraint::Percentage(18),
|
||||
Constraint::Percentage(22),
|
||||
],
|
||||
help: None,
|
||||
},
|
||||
|task| {
|
||||
let interval = format!("{} hours", task.interval.as_u64().as_ref().unwrap() / 60);
|
||||
let interval = convert_to_minutes_hours_days(*task.interval.as_i64().as_ref().unwrap());
|
||||
let last_duration = &task.last_duration[..8];
|
||||
let next_execution = task.next_execution.sub(DateTime::default()).num_minutes();
|
||||
let next_execution_string = if next_execution > 60 {
|
||||
format!("{} hours", next_execution / 60)
|
||||
let next_execution =
|
||||
convert_to_minutes_hours_days(task.next_execution.sub(Utc::now()).num_minutes());
|
||||
let last_execution =
|
||||
convert_to_minutes_hours_days(Utc::now().sub(task.last_execution).num_minutes());
|
||||
let last_execution_string = if last_execution != "now" {
|
||||
format!("{} ago", last_execution)
|
||||
} else {
|
||||
format!("{} minutes", next_execution)
|
||||
};
|
||||
let last_execution = task.last_execution.sub(DateTime::default()).num_minutes();
|
||||
let last_execution_string = if last_execution > 60 {
|
||||
format!("{} hours", last_execution / 60)
|
||||
} else {
|
||||
format!("{} minutes", last_execution)
|
||||
last_execution
|
||||
};
|
||||
|
||||
Row::new(vec![
|
||||
@@ -94,11 +103,68 @@ fn draw_tasks<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
Cell::from(interval),
|
||||
Cell::from(last_execution_string),
|
||||
Cell::from(last_duration.to_owned()),
|
||||
Cell::from(next_execution_string),
|
||||
Cell::from(next_execution),
|
||||
])
|
||||
.style(style_primary())
|
||||
},
|
||||
app.is_loading,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_events<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
let block = title_block("Events");
|
||||
draw_table(
|
||||
f,
|
||||
area,
|
||||
block,
|
||||
TableProps {
|
||||
content: &mut app.data.radarr_data.events,
|
||||
table_headers: vec!["Trigger", "Status", "Name", "Queued", "Started", "Duration"],
|
||||
constraints: vec![
|
||||
Constraint::Percentage(13),
|
||||
Constraint::Percentage(13),
|
||||
Constraint::Percentage(30),
|
||||
Constraint::Percentage(16),
|
||||
Constraint::Percentage(14),
|
||||
Constraint::Percentage(14),
|
||||
],
|
||||
help: None,
|
||||
},
|
||||
|event| {
|
||||
let queued = convert_to_minutes_hours_days(Utc::now().sub(event.queued).num_minutes());
|
||||
let queued_string = if queued != "now" {
|
||||
format!("{} ago", queued)
|
||||
} else {
|
||||
queued
|
||||
};
|
||||
let started_string = if event.started.is_some() {
|
||||
let started =
|
||||
convert_to_minutes_hours_days(Utc::now().sub(event.started.unwrap()).num_minutes());
|
||||
|
||||
if started != "now" {
|
||||
format!("{} ago", started)
|
||||
} else {
|
||||
started
|
||||
}
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
let duration = &event.duration[..8];
|
||||
|
||||
Row::new(vec![
|
||||
Cell::from(event.trigger.clone()),
|
||||
Cell::from(event.status.clone()),
|
||||
Cell::from(event.command_name.clone()),
|
||||
Cell::from(queued_string),
|
||||
Cell::from(started_string),
|
||||
Cell::from(duration.to_owned()),
|
||||
])
|
||||
.style(style_primary())
|
||||
},
|
||||
app.is_loading,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -134,6 +200,24 @@ fn draw_logs<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_help<B: Backend>(f: &mut Frame<'_, B>, app: &mut App<'_>, area: Rect) {
|
||||
let mut help_text = Text::from(format!(
|
||||
" {}",
|
||||
app
|
||||
.data
|
||||
.radarr_data
|
||||
.main_tabs
|
||||
.get_active_tab_contextual_help()
|
||||
.unwrap()
|
||||
));
|
||||
help_text.patch_style(style_help());
|
||||
let help_paragraph = Paragraph::new(help_text)
|
||||
.block(layout_block_top_border())
|
||||
.alignment(Alignment::Left);
|
||||
|
||||
f.render_widget(help_paragraph, area);
|
||||
}
|
||||
|
||||
fn determine_log_style_by_level(level: &str) -> Style {
|
||||
match level.to_lowercase().as_str() {
|
||||
"trace" => Style::default().fg(Color::Gray),
|
||||
@@ -145,3 +229,29 @@ fn determine_log_style_by_level(level: &str) -> Style {
|
||||
_ => style_default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_to_minutes_hours_days(time: i64) -> String {
|
||||
if time < 60 {
|
||||
if time == 0 {
|
||||
"now".to_owned()
|
||||
} else if time == 1 {
|
||||
format!("{} minute", time)
|
||||
} else {
|
||||
format!("{} minutes", time)
|
||||
}
|
||||
} else if time / 60 < 24 {
|
||||
let hours = time / 60;
|
||||
if hours == 1 {
|
||||
format!("{} hour", hours)
|
||||
} else {
|
||||
format!("{} hours", hours)
|
||||
}
|
||||
} else {
|
||||
let days = time / (60 * 24);
|
||||
if days == 1 {
|
||||
format!("{} day", days)
|
||||
} else {
|
||||
format!("{} days", days)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::*;
|
||||
use pretty_assertions::assert_str_eq;
|
||||
|
||||
#[test]
|
||||
fn test_determine_log_style_by_level() {
|
||||
assert_eq!(
|
||||
determine_log_style_by_level("trace"),
|
||||
Style::default().fg(Color::Gray)
|
||||
);
|
||||
assert_eq!(
|
||||
determine_log_style_by_level("debug"),
|
||||
Style::default().fg(Color::Blue)
|
||||
);
|
||||
assert_eq!(determine_log_style_by_level("info"), style_default());
|
||||
assert_eq!(determine_log_style_by_level("warn"), style_secondary());
|
||||
assert_eq!(determine_log_style_by_level("error"), style_failure());
|
||||
assert_eq!(
|
||||
determine_log_style_by_level("fatal"),
|
||||
style_failure().add_modifier(Modifier::BOLD)
|
||||
);
|
||||
assert_eq!(determine_log_style_by_level(""), style_default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_determine_log_style_by_level_case_insensitive() {
|
||||
assert_eq!(
|
||||
determine_log_style_by_level("TrAcE"),
|
||||
Style::default().fg(Color::Gray)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_convert_to_minutes_hours_days_minutes() {
|
||||
assert_str_eq!(convert_to_minutes_hours_days(0), "now");
|
||||
assert_str_eq!(convert_to_minutes_hours_days(1), "1 minute");
|
||||
assert_str_eq!(convert_to_minutes_hours_days(2), "2 minutes");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_convert_to_minutes_hours_days_hours() {
|
||||
assert_str_eq!(convert_to_minutes_hours_days(60), "1 hour");
|
||||
assert_str_eq!(convert_to_minutes_hours_days(120), "2 hours");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_convert_to_minutes_hours_days_days() {
|
||||
assert_str_eq!(convert_to_minutes_hours_days(1440), "1 day");
|
||||
assert_str_eq!(convert_to_minutes_hours_days(2880), "2 days");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user