Refactored tables and loading blocks to use the new dedicated widgets for Tables and Loading blocks

This commit is contained in:
2024-02-10 19:23:19 -07:00
parent 68de986c48
commit 51b789fd0f
19 changed files with 1174 additions and 1150 deletions
+72 -80
View File
@@ -11,13 +11,14 @@ use ratatui::{
};
use crate::app::App;
use crate::models::radarr_models::Task;
use crate::models::radarr_models::{QueueEvent, Task};
use crate::models::servarr_data::radarr::radarr_data::ActiveRadarrBlock;
use crate::ui::radarr_ui::radarr_ui_utils::{convert_to_minutes_hours_days, style_log_list_item};
use crate::ui::radarr_ui::system::system_details_ui::SystemDetailsUi;
use crate::ui::styles::ManagarrStyle;
use crate::ui::utils::layout_block_top_border;
use crate::ui::{draw_table, ListProps, TableProps};
use crate::ui::widgets::managarr_table::ManagarrTable;
use crate::ui::ListProps;
use crate::{
models::Route,
ui::{draw_list_box, utils::title_block, DrawUi},
@@ -87,92 +88,83 @@ pub(super) fn draw_system_ui_layout(f: &mut Frame<'_>, app: &mut App<'_>, area:
}
fn draw_tasks(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
draw_table(
f,
area,
title_block("Tasks"),
TableProps {
content: Some(&mut app.data.radarr_data.tasks),
wrapped_content: None,
table_headers: TASK_TABLE_HEADERS.to_vec(),
constraints: TASK_TABLE_CONSTRAINTS.to_vec(),
help: None,
},
|task| {
let task_props = extract_task_props(task);
let tasks_row_mapping = |task: &Task| {
let task_props = extract_task_props(task);
Row::new(vec![
Cell::from(task_props.name),
Cell::from(task_props.interval),
Cell::from(task_props.last_execution),
Cell::from(task_props.last_duration),
Cell::from(task_props.next_execution),
])
.primary()
},
app.is_loading,
false,
);
Row::new(vec![
Cell::from(task_props.name),
Cell::from(task_props.interval),
Cell::from(task_props.last_execution),
Cell::from(task_props.last_duration),
Cell::from(task_props.next_execution),
])
.primary()
};
let tasks_table = ManagarrTable::new(Some(&mut app.data.radarr_data.tasks), tasks_row_mapping)
.block(title_block("Tasks"))
.loading(app.is_loading)
.highlight_rows(false)
.headers(TASK_TABLE_HEADERS)
.constraints(TASK_TABLE_CONSTRAINTS);
f.render_widget(tasks_table, area);
}
pub(super) fn draw_queued_events(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
draw_table(
f,
area,
title_block("Queued Events"),
TableProps {
content: Some(&mut app.data.radarr_data.queued_events),
wrapped_content: None,
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!("{queued} ago")
} 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());
let events_row_mapping = |event: &QueueEvent| {
let queued = convert_to_minutes_hours_days(Utc::now().sub(event.queued).num_minutes());
let queued_string = if queued != "now" {
format!("{queued} ago")
} 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!("{started} ago")
} else {
started
}
if started != "now" {
format!("{started} ago")
} else {
String::new()
};
started
}
} else {
String::new()
};
let duration = if event.duration.is_some() {
&event.duration.as_ref().unwrap()[..8]
} else {
""
};
let duration = if event.duration.is_some() {
&event.duration.as_ref().unwrap()[..8]
} else {
""
};
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()),
])
.primary()
},
app.is_loading,
false,
);
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()),
])
.primary()
};
let events_table = ManagarrTable::new(
Some(&mut app.data.radarr_data.queued_events),
events_row_mapping,
)
.block(title_block("Queued Events"))
.loading(app.is_loading)
.highlight_rows(false)
.headers(["Trigger", "Status", "Name", "Queued", "Started", "Duration"])
.constraints([
Constraint::Percentage(13),
Constraint::Percentage(13),
Constraint::Percentage(30),
Constraint::Percentage(16),
Constraint::Percentage(14),
Constraint::Percentage(14),
]);
f.render_widget(events_table, area);
}
fn draw_logs(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
+34 -37
View File
@@ -1,4 +1,4 @@
use ratatui::layout::Rect;
use ratatui::layout::{Alignment, Rect};
use ratatui::text::{Span, Text};
use ratatui::widgets::{Cell, ListItem, Paragraph, Row};
use ratatui::Frame;
@@ -6,6 +6,7 @@ use ratatui::Frame;
use crate::app::context_clues::{build_context_clue_string, BARE_POPUP_CONTEXT_CLUES};
use crate::app::radarr::radarr_context_clues::SYSTEM_TASKS_CONTEXT_CLUES;
use crate::app::App;
use crate::models::radarr_models::Task;
use crate::models::servarr_data::radarr::radarr_data::{ActiveRadarrBlock, SYSTEM_DETAILS_BLOCKS};
use crate::models::Route;
use crate::ui::radarr_ui::radarr_ui_utils::style_log_list_item;
@@ -15,10 +16,11 @@ use crate::ui::radarr_ui::system::{
};
use crate::ui::styles::ManagarrStyle;
use crate::ui::utils::{borderless_block, title_block};
use crate::ui::widgets::loading_block::LoadingBlock;
use crate::ui::widgets::managarr_table::ManagarrTable;
use crate::ui::{
draw_help_footer_and_get_content_area, draw_large_popup_over, draw_list_box,
draw_medium_popup_over, draw_prompt_box, draw_prompt_popup_over, draw_table, loading, DrawUi,
ListProps, TableProps,
draw_medium_popup_over, draw_prompt_box, draw_prompt_popup_over, DrawUi, ListProps,
};
#[cfg(test)]
@@ -82,40 +84,35 @@ fn draw_logs_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
fn draw_tasks_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
let tasks_popup_table = |f: &mut Frame<'_>, app: &mut App<'_>, area: Rect| {
let help_footer = Some(build_context_clue_string(&SYSTEM_TASKS_CONTEXT_CLUES));
// let context_area = draw_help_footer_and_get_content_area(
// f,
// area,
// help_footer,
// );
let tasks_row_mapping = |task: &Task| {
let task_props = extract_task_props(task);
Row::new(vec![
Cell::from(task_props.name),
Cell::from(task_props.interval),
Cell::from(task_props.last_execution),
Cell::from(task_props.last_duration),
Cell::from(task_props.next_execution),
])
.primary()
};
let tasks_table = ManagarrTable::new(Some(&mut app.data.radarr_data.tasks), tasks_row_mapping)
.block(borderless_block())
.loading(app.is_loading)
.margin(1)
.footer(help_footer)
.footer_alignment(Alignment::Center)
.headers(TASK_TABLE_HEADERS)
.constraints(TASK_TABLE_CONSTRAINTS);
f.render_widget(title_block("Tasks"), area);
let context_area = draw_help_footer_and_get_content_area(
f,
area,
Some(build_context_clue_string(&SYSTEM_TASKS_CONTEXT_CLUES)),
);
draw_table(
f,
context_area,
borderless_block(),
TableProps {
content: Some(&mut app.data.radarr_data.tasks),
wrapped_content: None,
table_headers: TASK_TABLE_HEADERS.to_vec(),
constraints: TASK_TABLE_CONSTRAINTS.to_vec(),
help: None,
},
|task| {
let task_props = extract_task_props(task);
Row::new(vec![
Cell::from(task_props.name),
Cell::from(task_props.interval),
Cell::from(task_props.last_execution),
Cell::from(task_props.last_duration),
Cell::from(task_props.next_execution),
])
.primary()
},
app.is_loading,
true,
)
f.render_widget(tasks_table, area);
};
if matches!(
@@ -163,6 +160,6 @@ fn draw_updates_popup(f: &mut Frame<'_>, app: &mut App<'_>, area: Rect) {
f.render_widget(updates_paragraph, content_area);
} else {
loading(f, block, content_area, app.is_loading);
f.render_widget(LoadingBlock::new(app.is_loading, block), content_area);
}
}