Almost kinda functional description box
This commit is contained in:
+23
-23
@@ -17,29 +17,29 @@ generate_keybindings! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct KeyBinding {
|
pub struct KeyBinding {
|
||||||
pub key: Key,
|
pub key: Key,
|
||||||
pub desc: &'static str
|
pub desc: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const DEFAULT_KEYBINDINGS: KeyBindings = KeyBindings {
|
pub const DEFAULT_KEYBINDINGS: KeyBindings = KeyBindings {
|
||||||
quit: KeyBinding {
|
quit: KeyBinding {
|
||||||
key: Key::Char('q'),
|
key: Key::Char('q'),
|
||||||
desc: "Quit",
|
desc: "Quit",
|
||||||
},
|
},
|
||||||
up: KeyBinding {
|
up: KeyBinding {
|
||||||
key: Key::Up,
|
key: Key::Up,
|
||||||
desc: "Scroll up"
|
desc: "Scroll up",
|
||||||
},
|
},
|
||||||
down: KeyBinding {
|
down: KeyBinding {
|
||||||
key: Key::Down,
|
key: Key::Down,
|
||||||
desc: "Scroll down"
|
desc: "Scroll down",
|
||||||
},
|
},
|
||||||
submit: KeyBinding {
|
submit: KeyBinding {
|
||||||
key: Key::Enter,
|
key: Key::Enter,
|
||||||
desc: "Select"
|
desc: "Select",
|
||||||
},
|
},
|
||||||
esc: KeyBinding {
|
esc: KeyBinding {
|
||||||
key: Key::Esc,
|
key: Key::Esc,
|
||||||
desc: "Exit menu"
|
desc: "Exit current menu",
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+15
-68
@@ -1,21 +1,27 @@
|
|||||||
use log::error;
|
use log::{debug, error};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tokio::sync::mpsc::Sender;
|
use tokio::sync::mpsc::Sender;
|
||||||
use tui::widgets::TableState;
|
|
||||||
|
|
||||||
use crate::app::radarr::{ActiveRadarrBlock, RadarrData};
|
use crate::app::radarr::{ActiveRadarrBlock, RadarrData};
|
||||||
use crate::network::NetworkEvent;
|
|
||||||
use crate::network::radarr_network::RadarrEvent;
|
use crate::network::radarr_network::RadarrEvent;
|
||||||
|
use crate::network::NetworkEvent;
|
||||||
|
|
||||||
pub(crate) mod key_binding;
|
pub(crate) mod key_binding;
|
||||||
|
pub mod models;
|
||||||
pub mod radarr;
|
pub mod radarr;
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
pub enum Route {
|
pub enum Route {
|
||||||
Radarr(ActiveRadarrBlock),
|
Radarr(ActiveRadarrBlock),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ActiveRadarrBlock> for Route {
|
||||||
|
fn from(active_radarr_block: ActiveRadarrBlock) -> Route {
|
||||||
|
Route::Radarr(active_radarr_block)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const DEFAULT_ROUTE: Route = Route::Radarr(ActiveRadarrBlock::Movies);
|
const DEFAULT_ROUTE: Route = Route::Radarr(ActiveRadarrBlock::Movies);
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
@@ -26,6 +32,7 @@ pub struct App {
|
|||||||
pub tick_until_poll: u64,
|
pub tick_until_poll: u64,
|
||||||
pub tick_count: u64,
|
pub tick_count: u64,
|
||||||
pub is_routing: bool,
|
pub is_routing: bool,
|
||||||
|
pub is_loading: bool,
|
||||||
pub config: AppConfig,
|
pub config: AppConfig,
|
||||||
pub data: Data,
|
pub data: Data,
|
||||||
}
|
}
|
||||||
@@ -41,8 +48,10 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn dispatch(&mut self, action: NetworkEvent) {
|
pub async fn dispatch(&mut self, action: NetworkEvent) {
|
||||||
|
self.is_loading = true;
|
||||||
if let Some(network_tx) = &self.network_tx {
|
if let Some(network_tx) = &self.network_tx {
|
||||||
if let Err(e) = network_tx.send(action).await {
|
if let Err(e) = network_tx.send(action).await {
|
||||||
|
self.is_loading = false;
|
||||||
error!("Failed to send event. {:?}", e);
|
error!("Failed to send event. {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +79,6 @@ impl App {
|
|||||||
self.dispatch(RadarrEvent::GetOverview.into()).await;
|
self.dispatch(RadarrEvent::GetOverview.into()).await;
|
||||||
self.dispatch(RadarrEvent::GetStatus.into()).await;
|
self.dispatch(RadarrEvent::GetStatus.into()).await;
|
||||||
|
|
||||||
|
|
||||||
self.dispatch_by_radarr_block(active_block).await;
|
self.dispatch_by_radarr_block(active_block).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,6 +95,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn pop_navigation_stack(&mut self) {
|
pub fn pop_navigation_stack(&mut self) {
|
||||||
|
self.is_routing = true;
|
||||||
if self.navigation_stack.len() > 1 {
|
if self.navigation_stack.len() > 1 {
|
||||||
self.navigation_stack.pop();
|
self.navigation_stack.pop();
|
||||||
}
|
}
|
||||||
@@ -106,6 +115,7 @@ impl Default for App {
|
|||||||
title: "Managarr",
|
title: "Managarr",
|
||||||
tick_until_poll: 0,
|
tick_until_poll: 0,
|
||||||
tick_count: 0,
|
tick_count: 0,
|
||||||
|
is_loading: false,
|
||||||
is_routing: false,
|
is_routing: false,
|
||||||
config: AppConfig::default(),
|
config: AppConfig::default(),
|
||||||
data: Data::default(),
|
data: Data::default(),
|
||||||
@@ -139,66 +149,3 @@ impl Default for RadarrConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StatefulTable<T> {
|
|
||||||
pub state: TableState,
|
|
||||||
pub items: Vec<T>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Default for StatefulTable<T> {
|
|
||||||
fn default() -> StatefulTable<T> {
|
|
||||||
StatefulTable {
|
|
||||||
state: TableState::default(),
|
|
||||||
items: Vec::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> StatefulTable<T> {
|
|
||||||
pub fn set_items(&mut self, items: Vec<T>) {
|
|
||||||
let items_len = items.len();
|
|
||||||
self.items = items;
|
|
||||||
if !self.items.is_empty() {
|
|
||||||
let selected_row = self.state.selected().map_or(0, |i| {
|
|
||||||
if i > 0 && i < items_len {
|
|
||||||
i
|
|
||||||
} else if i >= items_len {
|
|
||||||
items_len - 1
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
});
|
|
||||||
self.state.select(Some(selected_row));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn scroll_down(&mut self) {
|
|
||||||
let selected_row = match self.state.selected() {
|
|
||||||
Some(i) => {
|
|
||||||
if i >= self.items.len() - 1 {
|
|
||||||
0
|
|
||||||
} else {
|
|
||||||
i + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => 0
|
|
||||||
};
|
|
||||||
|
|
||||||
self.state.select(Some(selected_row));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn scroll_up(&mut self) {
|
|
||||||
let selected_row = match self.state.selected() {
|
|
||||||
Some(i) => {
|
|
||||||
if i == 0 {
|
|
||||||
self.items.len() - 1
|
|
||||||
} else {
|
|
||||||
i - 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => 0
|
|
||||||
};
|
|
||||||
|
|
||||||
self.state.select(Some(selected_row));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
use tui::widgets::TableState;
|
||||||
|
|
||||||
|
pub trait Scrollable {
|
||||||
|
fn scroll_down(&mut self);
|
||||||
|
fn scroll_up(&mut self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct StatefulTable<T> {
|
||||||
|
pub state: TableState,
|
||||||
|
pub items: Vec<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Default for StatefulTable<T> {
|
||||||
|
fn default() -> StatefulTable<T> {
|
||||||
|
StatefulTable {
|
||||||
|
state: TableState::default(),
|
||||||
|
items: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> StatefulTable<T> {
|
||||||
|
pub fn set_items(&mut self, items: Vec<T>) {
|
||||||
|
let items_len = items.len();
|
||||||
|
self.items = items;
|
||||||
|
if !self.items.is_empty() {
|
||||||
|
let selected_row = self.state.selected().map_or(0, |i| {
|
||||||
|
if i > 0 && i < items_len {
|
||||||
|
i
|
||||||
|
} else if i >= items_len {
|
||||||
|
items_len - 1
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
self.state.select(Some(selected_row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn current_selection(&self) -> &T {
|
||||||
|
&self.items[self.state.selected().unwrap_or(0)]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Scrollable for StatefulTable<T> {
|
||||||
|
fn scroll_down(&mut self) {
|
||||||
|
let selected_row = match self.state.selected() {
|
||||||
|
Some(i) => {
|
||||||
|
if i >= self.items.len() - 1 {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
i + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.state.select(Some(selected_row));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll_up(&mut self) {
|
||||||
|
let selected_row = match self.state.selected() {
|
||||||
|
Some(i) => {
|
||||||
|
if i == 0 {
|
||||||
|
self.items.len() - 1
|
||||||
|
} else {
|
||||||
|
i - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.state.select(Some(selected_row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct ScrollableText {
|
||||||
|
pub items: Vec<String>,
|
||||||
|
pub offset: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScrollableText {
|
||||||
|
pub fn with_string(item: String) -> ScrollableText {
|
||||||
|
let items: Vec<&str> = item.split('\n').collect();
|
||||||
|
let items: Vec<String> = items.iter().map(|it| it.to_string()).collect();
|
||||||
|
ScrollableText { items, offset: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_text(&self) -> String {
|
||||||
|
self.items.join("\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Scrollable for ScrollableText {
|
||||||
|
fn scroll_down(&mut self) {
|
||||||
|
if self.offset < self.items.len() as u16 {
|
||||||
|
self.offset += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scroll_up(&mut self) {
|
||||||
|
if self.offset > 0 {
|
||||||
|
self.offset -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-4
@@ -2,7 +2,8 @@ use std::collections::HashMap;
|
|||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
use crate::app::{App, StatefulTable};
|
use crate::app::models::{ScrollableText, StatefulTable};
|
||||||
|
use crate::app::App;
|
||||||
use crate::network::radarr_network::{DownloadRecord, Movie, RadarrEvent};
|
use crate::network::radarr_network::{DownloadRecord, Movie, RadarrEvent};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -14,9 +15,10 @@ pub struct RadarrData {
|
|||||||
pub movies: StatefulTable<Movie>,
|
pub movies: StatefulTable<Movie>,
|
||||||
pub downloads: StatefulTable<DownloadRecord>,
|
pub downloads: StatefulTable<DownloadRecord>,
|
||||||
pub quality_profile_map: HashMap<u64, String>,
|
pub quality_profile_map: HashMap<u64, String>,
|
||||||
|
pub movie_details: ScrollableText,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
pub enum ActiveRadarrBlock {
|
pub enum ActiveRadarrBlock {
|
||||||
AddMovie,
|
AddMovie,
|
||||||
Calendar,
|
Calendar,
|
||||||
@@ -33,13 +35,15 @@ pub enum ActiveRadarrBlock {
|
|||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub(super) async fn dispatch_by_radarr_block(&mut self, active_radarr_block: ActiveRadarrBlock) {
|
pub(super) async fn dispatch_by_radarr_block(&mut self, active_radarr_block: ActiveRadarrBlock) {
|
||||||
|
self.reset_tick_count();
|
||||||
match active_radarr_block {
|
match active_radarr_block {
|
||||||
ActiveRadarrBlock::Downloads => self.dispatch(RadarrEvent::GetDownloads.into()).await,
|
ActiveRadarrBlock::Downloads => self.dispatch(RadarrEvent::GetDownloads.into()).await,
|
||||||
ActiveRadarrBlock::Movies => {
|
ActiveRadarrBlock::Movies => {
|
||||||
self.dispatch(RadarrEvent::GetMovies.into()).await;
|
self.dispatch(RadarrEvent::GetMovies.into()).await;
|
||||||
self.dispatch(RadarrEvent::GetDownloads.into()).await;
|
self.dispatch(RadarrEvent::GetDownloads.into()).await;
|
||||||
},
|
}
|
||||||
_ => ()
|
ActiveRadarrBlock::MovieDetails => self.dispatch(RadarrEvent::GetMovieDetails.into()).await,
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ impl Events {
|
|||||||
.checked_sub(last_tick.elapsed())
|
.checked_sub(last_tick.elapsed())
|
||||||
.unwrap_or_else(|| Duration::from_secs(0));
|
.unwrap_or_else(|| Duration::from_secs(0));
|
||||||
if event::poll(timeout).unwrap() {
|
if event::poll(timeout).unwrap() {
|
||||||
if let CrosstermEvent::Key(key) = event::read().unwrap() {
|
if let CrosstermEvent::Key(key_event) = event::read().unwrap() {
|
||||||
let key = Key::from(key);
|
let key = Key::from(key_event);
|
||||||
event_tx.send(InputEvent::KeyEvent(key)).unwrap();
|
event_tx.send(InputEvent::KeyEvent(key)).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -26,8 +26,7 @@ impl From<KeyEvent> for Key {
|
|||||||
fn from(key_event: KeyEvent) -> Self {
|
fn from(key_event: KeyEvent) -> Self {
|
||||||
match key_event {
|
match key_event {
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
code: KeyCode::Up,
|
code: KeyCode::Up, ..
|
||||||
..
|
|
||||||
} => Key::Up,
|
} => Key::Up,
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
code: KeyCode::Down,
|
code: KeyCode::Down,
|
||||||
@@ -37,6 +36,9 @@ impl From<KeyEvent> for Key {
|
|||||||
code: KeyCode::Enter,
|
code: KeyCode::Enter,
|
||||||
..
|
..
|
||||||
} => Key::Enter,
|
} => Key::Enter,
|
||||||
|
KeyEvent {
|
||||||
|
code: KeyCode::Esc, ..
|
||||||
|
} => Key::Esc,
|
||||||
KeyEvent {
|
KeyEvent {
|
||||||
code: KeyCode::Char(c),
|
code: KeyCode::Char(c),
|
||||||
..
|
..
|
||||||
|
|||||||
+8
-24
@@ -1,29 +1,13 @@
|
|||||||
use crate::app::App;
|
use crate::app::{App, Route};
|
||||||
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
|
||||||
use crate::event::Key;
|
use crate::event::Key;
|
||||||
|
use crate::handlers::radarr_handler::handle_radarr_key_events;
|
||||||
|
|
||||||
|
mod radarr_handler;
|
||||||
|
|
||||||
pub async fn handle_key_events(key: Key, app: &mut App) {
|
pub async fn handle_key_events(key: Key, app: &mut App) {
|
||||||
match key {
|
match *app.get_current_route() {
|
||||||
_ if key == DEFAULT_KEYBINDINGS.up.key => handle_scroll_up(app).await,
|
Route::Radarr(active_radarr_block) => {
|
||||||
_ if key == DEFAULT_KEYBINDINGS.down.key => handle_scroll_down(app).await,
|
handle_radarr_key_events(key, app, active_radarr_block).await
|
||||||
_ if key == DEFAULT_KEYBINDINGS.submit.key => handle_submit(app).await,
|
|
||||||
_ if key == DEFAULT_KEYBINDINGS.esc.key => handle_esc(app).await,
|
|
||||||
_ => ()
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_scroll_up(app: &mut App) {
|
|
||||||
app.data.radarr_data.movies.scroll_up();
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_scroll_down(app: &mut App) {
|
|
||||||
app.data.radarr_data.movies.scroll_down();
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_submit(app: &mut App) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_esc(app: &mut App) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
use crate::app::key_binding::DEFAULT_KEYBINDINGS;
|
||||||
|
use crate::app::models::Scrollable;
|
||||||
|
use crate::app::radarr::ActiveRadarrBlock;
|
||||||
|
use crate::{App, Key};
|
||||||
|
|
||||||
|
pub async fn handle_radarr_key_events(
|
||||||
|
key: Key,
|
||||||
|
app: &mut App,
|
||||||
|
active_radarr_block: ActiveRadarrBlock,
|
||||||
|
) {
|
||||||
|
match key {
|
||||||
|
_ if key == DEFAULT_KEYBINDINGS.up.key => handle_scroll_up(app, active_radarr_block).await,
|
||||||
|
_ if key == DEFAULT_KEYBINDINGS.down.key => handle_scroll_down(app, active_radarr_block).await,
|
||||||
|
_ if key == DEFAULT_KEYBINDINGS.submit.key => handle_submit(app, active_radarr_block).await,
|
||||||
|
_ if key == DEFAULT_KEYBINDINGS.esc.key => handle_esc(app, active_radarr_block).await,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_scroll_up(app: &mut App, active_radarr_block: ActiveRadarrBlock) {
|
||||||
|
match active_radarr_block {
|
||||||
|
ActiveRadarrBlock::Movies => app.data.radarr_data.movies.scroll_up(),
|
||||||
|
ActiveRadarrBlock::MovieDetails => app.data.radarr_data.movie_details.scroll_up(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_scroll_down(app: &mut App, active_radarr_block: ActiveRadarrBlock) {
|
||||||
|
match active_radarr_block {
|
||||||
|
ActiveRadarrBlock::Movies => app.data.radarr_data.movies.scroll_down(),
|
||||||
|
ActiveRadarrBlock::MovieDetails => app.data.radarr_data.movie_details.scroll_down(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_submit(app: &mut App, active_radarr_block: ActiveRadarrBlock) {
|
||||||
|
match active_radarr_block {
|
||||||
|
ActiveRadarrBlock::Movies => app.push_navigation_stack(ActiveRadarrBlock::MovieDetails.into()),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn handle_esc(app: &mut App, active_radarr_block: ActiveRadarrBlock) {
|
||||||
|
match active_radarr_block {
|
||||||
|
ActiveRadarrBlock::MovieDetails => app.pop_navigation_stack(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-2
@@ -8,8 +8,8 @@ use crossterm::terminal::{
|
|||||||
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
|
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
|
||||||
};
|
};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use tokio::sync::{mpsc, Mutex};
|
|
||||||
use tokio::sync::mpsc::Receiver;
|
use tokio::sync::mpsc::Receiver;
|
||||||
|
use tokio::sync::{mpsc, Mutex};
|
||||||
use tui::backend::CrosstermBackend;
|
use tui::backend::CrosstermBackend;
|
||||||
use tui::Terminal;
|
use tui::Terminal;
|
||||||
|
|
||||||
@@ -55,7 +55,10 @@ async fn start_networking(mut network_rx: Receiver<NetworkEvent>, app: &Arc<Mute
|
|||||||
let network = Network::new(reqwest::Client::new(), app);
|
let network = Network::new(reqwest::Client::new(), app);
|
||||||
|
|
||||||
while let Some(network_event) = network_rx.recv().await {
|
while let Some(network_event) = network_rx.recv().await {
|
||||||
debug!("Received network event: {:?}", network_event);
|
debug!(
|
||||||
|
"**************************************MAIN Received network event: {:?}",
|
||||||
|
network_event
|
||||||
|
);
|
||||||
network.handle_network_event(network_event).await;
|
network.handle_network_event(network_event).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +88,7 @@ async fn start_ui(app: &Arc<Mutex<App>>) -> Result<()> {
|
|||||||
|
|
||||||
handlers::handle_key_events(key, &mut app).await;
|
handlers::handle_key_events(key, &mut app).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputEvent::Tick => app.on_tick(is_first_render).await,
|
InputEvent::Tick => app.on_tick(is_first_render).await,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -11,7 +11,7 @@ mod utils;
|
|||||||
|
|
||||||
#[derive(PartialEq, Eq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub enum NetworkEvent {
|
pub enum NetworkEvent {
|
||||||
Radarr(RadarrEvent)
|
Radarr(RadarrEvent),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Network<'a> {
|
pub struct Network<'a> {
|
||||||
@@ -27,7 +27,10 @@ impl<'a> Network<'a> {
|
|||||||
|
|
||||||
pub async fn handle_network_event(&self, network_event: NetworkEvent) {
|
pub async fn handle_network_event(&self, network_event: NetworkEvent) {
|
||||||
match network_event {
|
match network_event {
|
||||||
NetworkEvent::Radarr(radarr_event) => self.handle_radarr_event(radarr_event).await
|
NetworkEvent::Radarr(radarr_event) => self.handle_radarr_event(radarr_event).await,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut app = self.app.lock().await;
|
||||||
|
app.is_loading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+206
-50
@@ -7,8 +7,11 @@ use serde::Deserialize;
|
|||||||
use serde_json::Number;
|
use serde_json::Number;
|
||||||
use tokio::sync::MutexGuard;
|
use tokio::sync::MutexGuard;
|
||||||
|
|
||||||
|
use crate::app::models::ScrollableText;
|
||||||
use crate::app::{App, RadarrConfig};
|
use crate::app::{App, RadarrConfig};
|
||||||
use crate::network::{Network, NetworkEvent, utils};
|
use crate::network::utils::get_movie_status;
|
||||||
|
use crate::network::{utils, Network, NetworkEvent};
|
||||||
|
use crate::utils::{convert_runtime, convert_to_gb};
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum RadarrEvent {
|
pub enum RadarrEvent {
|
||||||
@@ -17,6 +20,7 @@ pub enum RadarrEvent {
|
|||||||
GetOverview,
|
GetOverview,
|
||||||
GetStatus,
|
GetStatus,
|
||||||
GetMovies,
|
GetMovies,
|
||||||
|
GetMovieDetails,
|
||||||
GetQualityProfiles,
|
GetQualityProfiles,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,9 +30,9 @@ impl RadarrEvent {
|
|||||||
RadarrEvent::HealthCheck => "/health",
|
RadarrEvent::HealthCheck => "/health",
|
||||||
RadarrEvent::GetOverview => "/diskspace",
|
RadarrEvent::GetOverview => "/diskspace",
|
||||||
RadarrEvent::GetStatus => "/system/status",
|
RadarrEvent::GetStatus => "/system/status",
|
||||||
RadarrEvent::GetMovies => "/movie",
|
RadarrEvent::GetMovies | RadarrEvent::GetMovieDetails => "/movie",
|
||||||
RadarrEvent::GetDownloads => "/queue",
|
RadarrEvent::GetDownloads => "/queue",
|
||||||
RadarrEvent::GetQualityProfiles => "/qualityprofile"
|
RadarrEvent::GetQualityProfiles => "/qualityprofile",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,6 +69,10 @@ pub struct Movie {
|
|||||||
#[derivative(Default(value = "Number::from(0)"))]
|
#[derivative(Default(value = "Number::from(0)"))]
|
||||||
pub size_on_disk: Number,
|
pub size_on_disk: Number,
|
||||||
pub status: String,
|
pub status: String,
|
||||||
|
pub overview: String,
|
||||||
|
pub path: String,
|
||||||
|
pub studio: String,
|
||||||
|
pub genres: Vec<String>,
|
||||||
#[derivative(Default(value = "Number::from(0)"))]
|
#[derivative(Default(value = "Number::from(0)"))]
|
||||||
pub year: Number,
|
pub year: Number,
|
||||||
pub monitored: bool,
|
pub monitored: bool,
|
||||||
@@ -73,13 +81,29 @@ pub struct Movie {
|
|||||||
pub runtime: Number,
|
pub runtime: Number,
|
||||||
#[derivative(Default(value = "Number::from(0)"))]
|
#[derivative(Default(value = "Number::from(0)"))]
|
||||||
pub quality_profile_id: Number,
|
pub quality_profile_id: Number,
|
||||||
|
pub ratings: RatingsList,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, Deserialize, Debug)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct RatingsList {
|
||||||
|
pub imdb: Option<Rating>,
|
||||||
|
pub tmdb: Option<Rating>,
|
||||||
|
pub rotten_tomatoes: Option<Rating>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Derivative, Deserialize, Debug)]
|
||||||
|
#[derivative(Default)]
|
||||||
|
pub struct Rating {
|
||||||
|
#[derivative(Default(value = "Number::from(0)"))]
|
||||||
|
pub value: Number,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Derivative, Deserialize, Debug)]
|
#[derive(Derivative, Deserialize, Debug)]
|
||||||
#[derivative(Default)]
|
#[derivative(Default)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct DownloadsResponse {
|
pub struct DownloadsResponse {
|
||||||
pub records: Vec<DownloadRecord>
|
pub records: Vec<DownloadRecord>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Derivative, Deserialize, Debug)]
|
#[derive(Derivative, Deserialize, Debug)]
|
||||||
@@ -96,7 +120,7 @@ pub struct DownloadRecord {
|
|||||||
pub sizeleft: Number,
|
pub sizeleft: Number,
|
||||||
pub output_path: String,
|
pub output_path: String,
|
||||||
pub indexer: String,
|
pub indexer: String,
|
||||||
pub download_client: String
|
pub download_client: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Derivative, Deserialize, Debug)]
|
#[derive(Derivative, Deserialize, Debug)]
|
||||||
@@ -105,22 +129,43 @@ pub struct DownloadRecord {
|
|||||||
struct QualityProfile {
|
struct QualityProfile {
|
||||||
#[derivative(Default(value = "Number::from(0)"))]
|
#[derivative(Default(value = "Number::from(0)"))]
|
||||||
pub id: Number,
|
pub id: Number,
|
||||||
pub name: String
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Network<'a> {
|
impl<'a> Network<'a> {
|
||||||
pub async fn handle_radarr_event(&self, radarr_event: RadarrEvent) {
|
pub async fn handle_radarr_event(&self, radarr_event: RadarrEvent) {
|
||||||
match radarr_event {
|
match radarr_event {
|
||||||
RadarrEvent::HealthCheck => self.get_healthcheck(RadarrEvent::HealthCheck.resource()).await,
|
RadarrEvent::HealthCheck => {
|
||||||
RadarrEvent::GetOverview => self.get_diskspace(RadarrEvent::GetOverview.resource()).await,
|
self
|
||||||
|
.get_healthcheck(RadarrEvent::HealthCheck.resource())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
RadarrEvent::GetOverview => {
|
||||||
|
self
|
||||||
|
.get_diskspace(RadarrEvent::GetOverview.resource())
|
||||||
|
.await
|
||||||
|
}
|
||||||
RadarrEvent::GetStatus => self.get_status(RadarrEvent::GetStatus.resource()).await,
|
RadarrEvent::GetStatus => self.get_status(RadarrEvent::GetStatus.resource()).await,
|
||||||
RadarrEvent::GetMovies => self.get_movies(RadarrEvent::GetMovies.resource()).await,
|
RadarrEvent::GetMovies => self.get_movies(RadarrEvent::GetMovies.resource()).await,
|
||||||
RadarrEvent::GetDownloads => self.get_downloads(RadarrEvent::GetDownloads.resource()).await,
|
RadarrEvent::GetMovieDetails => {
|
||||||
RadarrEvent::GetQualityProfiles => self.get_quality_profiles(RadarrEvent::GetQualityProfiles.resource()).await
|
debug!("TEST received GetMovieDetails event");
|
||||||
|
self
|
||||||
|
.get_movie_details(RadarrEvent::GetMovieDetails.resource())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
RadarrEvent::GetDownloads => {
|
||||||
|
self
|
||||||
|
.get_downloads(RadarrEvent::GetDownloads.resource())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
RadarrEvent::GetQualityProfiles => {
|
||||||
|
self
|
||||||
|
.get_quality_profiles(RadarrEvent::GetQualityProfiles.resource())
|
||||||
|
.await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut app = self.app.lock().await;
|
let mut app = self.app.lock().await;
|
||||||
app.reset_tick_count();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_healthcheck(&self, resource: &str) {
|
async fn get_healthcheck(&self, resource: &str) {
|
||||||
@@ -130,43 +175,155 @@ impl<'a> Network<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_diskspace(&self, resource: &str) {
|
async fn get_diskspace(&self, resource: &str) {
|
||||||
self.handle_get_request::<Vec<DiskSpace>>(resource, | disk_space_vec, mut app | {
|
self
|
||||||
let DiskSpace {
|
.handle_get_request::<Vec<DiskSpace>>(resource, |disk_space_vec, mut app| {
|
||||||
free_space,
|
let DiskSpace {
|
||||||
total_space,
|
free_space,
|
||||||
..
|
total_space,
|
||||||
} = &disk_space_vec[0];
|
..
|
||||||
|
} = &disk_space_vec[0];
|
||||||
|
|
||||||
app.data.radarr_data.free_space = free_space.as_u64().unwrap();
|
app.data.radarr_data.free_space = free_space.as_u64().unwrap();
|
||||||
app.data.radarr_data.total_space = total_space.as_u64().unwrap();
|
app.data.radarr_data.total_space = total_space.as_u64().unwrap();
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_status(&self, resource: &str) {
|
async fn get_status(&self, resource: &str) {
|
||||||
self.handle_get_request::<SystemStatus>(resource, | system_status, mut app | {
|
self
|
||||||
app.data.radarr_data.version = system_status.version;
|
.handle_get_request::<SystemStatus>(resource, |system_status, mut app| {
|
||||||
app.data.radarr_data.start_time = system_status.start_time;
|
app.data.radarr_data.version = system_status.version;
|
||||||
}).await;
|
app.data.radarr_data.start_time = system_status.start_time;
|
||||||
|
})
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_movies(&self, resource: &str) {
|
async fn get_movies(&self, resource: &str) {
|
||||||
self.handle_get_request::<Vec<Movie>>(resource, |movie_vec, mut app| {
|
self
|
||||||
app.data.radarr_data.movies.set_items(movie_vec);
|
.handle_get_request::<Vec<Movie>>(resource, |movie_vec, mut app| {
|
||||||
}).await;
|
app.data.radarr_data.movies.set_items(movie_vec);
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_movie_details(&self, resource: &str) {
|
||||||
|
debug!("TEST handling get_movie_details");
|
||||||
|
let movie_id = self
|
||||||
|
.app
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.data
|
||||||
|
.radarr_data
|
||||||
|
.movies
|
||||||
|
.current_selection()
|
||||||
|
.id
|
||||||
|
.clone()
|
||||||
|
.as_u64()
|
||||||
|
.unwrap();
|
||||||
|
let mut url = resource.to_owned();
|
||||||
|
url.push('/');
|
||||||
|
url.push_str(movie_id.to_string().as_str());
|
||||||
|
debug!("TEST sending request{}", url.as_str());
|
||||||
|
self
|
||||||
|
.handle_get_request::<Movie>(url.as_str(), |movie_response, mut app| {
|
||||||
|
let Movie {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
year,
|
||||||
|
overview,
|
||||||
|
path,
|
||||||
|
studio,
|
||||||
|
has_file,
|
||||||
|
quality_profile_id,
|
||||||
|
size_on_disk,
|
||||||
|
genres,
|
||||||
|
runtime,
|
||||||
|
ratings,
|
||||||
|
..
|
||||||
|
} = movie_response;
|
||||||
|
let (hours, minutes) = convert_runtime(runtime.as_u64().unwrap());
|
||||||
|
let size = convert_to_gb(size_on_disk.as_u64().unwrap());
|
||||||
|
let quality_profile = app
|
||||||
|
.data
|
||||||
|
.radarr_data
|
||||||
|
.quality_profile_map
|
||||||
|
.get(&quality_profile_id.as_u64().unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.to_owned();
|
||||||
|
let imdb_rating = if let Some(rating) = ratings.imdb {
|
||||||
|
rating.value.as_f64().unwrap()
|
||||||
|
} else {
|
||||||
|
0f64
|
||||||
|
};
|
||||||
|
|
||||||
|
let tmdb_rating = if let Some(rating) = ratings.tmdb {
|
||||||
|
rating.value.as_u64().unwrap()
|
||||||
|
} else {
|
||||||
|
0u64
|
||||||
|
};
|
||||||
|
|
||||||
|
let rotten_tomatoes_rating = if let Some(rating) = ratings.rotten_tomatoes {
|
||||||
|
rating.value.as_u64().unwrap()
|
||||||
|
} else {
|
||||||
|
0u64
|
||||||
|
};
|
||||||
|
|
||||||
|
let status = get_movie_status(has_file, &app.data.radarr_data.downloads.items, id);
|
||||||
|
|
||||||
|
app.data.radarr_data.movie_details = ScrollableText::with_string(format!(
|
||||||
|
"Title: {}\n
|
||||||
|
Year: {}\n
|
||||||
|
Runtime: {}h {}m\n
|
||||||
|
Status: {}\n
|
||||||
|
Description: {}\n
|
||||||
|
TMDB: {}%\n
|
||||||
|
IMDB: {:.1}\n
|
||||||
|
Rotten Tomatoes: {}%\n
|
||||||
|
Quality Profile: {}\n
|
||||||
|
Size: {:.2} GB\n
|
||||||
|
Path: {}\n
|
||||||
|
Studio: {}\n
|
||||||
|
Genres: {}",
|
||||||
|
title,
|
||||||
|
year,
|
||||||
|
hours,
|
||||||
|
minutes,
|
||||||
|
status,
|
||||||
|
overview,
|
||||||
|
tmdb_rating,
|
||||||
|
imdb_rating,
|
||||||
|
rotten_tomatoes_rating,
|
||||||
|
quality_profile,
|
||||||
|
size,
|
||||||
|
path,
|
||||||
|
studio,
|
||||||
|
genres.join(", ")
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_downloads(&self, resource: &str) {
|
async fn get_downloads(&self, resource: &str) {
|
||||||
self.handle_get_request::<DownloadsResponse>(resource, |queue_response, mut app | {
|
self
|
||||||
app.data.radarr_data.downloads.set_items(queue_response.records);
|
.handle_get_request::<DownloadsResponse>(resource, |queue_response, mut app| {
|
||||||
}).await
|
app
|
||||||
|
.data
|
||||||
|
.radarr_data
|
||||||
|
.downloads
|
||||||
|
.set_items(queue_response.records);
|
||||||
|
})
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_quality_profiles(&self, resource: &str) {
|
async fn get_quality_profiles(&self, resource: &str) {
|
||||||
self.handle_get_request::<Vec<QualityProfile>>(resource, | quality_profiles, mut app | {
|
self
|
||||||
app.data.radarr_data.quality_profile_map = quality_profiles.into_iter()
|
.handle_get_request::<Vec<QualityProfile>>(resource, |quality_profiles, mut app| {
|
||||||
.map(| profile | (profile.id.as_u64().unwrap(), profile.name))
|
app.data.radarr_data.quality_profile_map = quality_profiles
|
||||||
|
.into_iter()
|
||||||
|
.map(|profile| (profile.id.as_u64().unwrap(), profile.name))
|
||||||
.collect();
|
.collect();
|
||||||
}).await;
|
})
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn call_radarr_api(&self, resource: &str) -> RequestBuilder {
|
async fn call_radarr_api(&self, resource: &str) -> RequestBuilder {
|
||||||
@@ -189,23 +346,22 @@ impl<'a> Network<'a> {
|
|||||||
.header("X-Api-Key", api_token)
|
.header("X-Api-Key", api_token)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_get_request<T>(&self, resource: &str, mut app_update_fn: impl FnMut(T, MutexGuard<App>))
|
async fn handle_get_request<T>(
|
||||||
where
|
&self,
|
||||||
T: DeserializeOwned {
|
resource: &str,
|
||||||
match self.call_radarr_api(resource)
|
mut app_update_fn: impl FnMut(T, MutexGuard<App>),
|
||||||
.await
|
) where
|
||||||
.send()
|
T: DeserializeOwned,
|
||||||
.await {
|
{
|
||||||
Ok(response) => {
|
match self.call_radarr_api(resource).await.send().await {
|
||||||
match utils::parse_response::<T>(response).await {
|
Ok(response) => match utils::parse_response::<T>(response).await {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
let app = self.app.lock().await;
|
let app = self.app.lock().await;
|
||||||
app_update_fn(value, app);
|
app_update_fn(value, app);
|
||||||
}
|
|
||||||
Err(e) => error!("Failed to parse response! {:?}", e)
|
|
||||||
}
|
}
|
||||||
}
|
Err(e) => error!("Failed to parse response! {:?}", e),
|
||||||
Err(e) => error!("Failed to fetch resource. {:?}", e)
|
},
|
||||||
|
Err(e) => error!("Failed to fetch resource. {:?}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-2
@@ -1,6 +1,30 @@
|
|||||||
use reqwest::Response;
|
use reqwest::Response;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
use serde_json::Number;
|
||||||
|
|
||||||
|
use crate::network::radarr_network::DownloadRecord;
|
||||||
|
|
||||||
pub async fn parse_response<T: DeserializeOwned>(response: Response) -> Result<T, reqwest::Error> {
|
pub async fn parse_response<T: DeserializeOwned>(response: Response) -> Result<T, reqwest::Error> {
|
||||||
response.json::<T>().await
|
response.json::<T>().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_movie_status(
|
||||||
|
has_file: bool,
|
||||||
|
downloads_vec: &Vec<DownloadRecord>,
|
||||||
|
movie_id: Number,
|
||||||
|
) -> String {
|
||||||
|
if !has_file {
|
||||||
|
if let Some(download) = downloads_vec
|
||||||
|
.iter()
|
||||||
|
.find(|&download| download.movie_id == movie_id)
|
||||||
|
{
|
||||||
|
if download.status == "downloading" {
|
||||||
|
return "Downloading".to_owned();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Missing".to_owned();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"Downloaded".to_owned()
|
||||||
|
}
|
||||||
|
|||||||
+49
-7
@@ -1,18 +1,21 @@
|
|||||||
use tui::backend::Backend;
|
use tui::backend::Backend;
|
||||||
use tui::Frame;
|
|
||||||
use tui::layout::{Constraint, Rect};
|
use tui::layout::{Constraint, Rect};
|
||||||
use tui::widgets::{Block, Borders};
|
use tui::text::Text;
|
||||||
|
use tui::widgets::{Block, Borders, Clear, Paragraph};
|
||||||
|
use tui::Frame;
|
||||||
|
|
||||||
use crate::app::App;
|
use crate::app::radarr::ActiveRadarrBlock;
|
||||||
|
use crate::app::{App, Route};
|
||||||
use crate::logos::{
|
use crate::logos::{
|
||||||
BAZARR_LOGO, LIDARR_LOGO, PROWLARR_LOGO, RADARR_LOGO, READARR_LOGO, SONARR_LOGO,
|
BAZARR_LOGO, LIDARR_LOGO, PROWLARR_LOGO, RADARR_LOGO, READARR_LOGO, SONARR_LOGO,
|
||||||
};
|
};
|
||||||
use crate::ui::utils::{
|
use crate::ui::utils::{
|
||||||
horizontal_chunks, horizontal_chunks_with_margin, vertical_chunks, vertical_chunks_with_margin,
|
centered_rect, horizontal_chunks, horizontal_chunks_with_margin, style_secondary,
|
||||||
|
vertical_chunks, vertical_chunks_with_margin,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod utils;
|
|
||||||
mod radarr_ui;
|
mod radarr_ui;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
static HIGHLIGHT_SYMBOL: &str = "=> ";
|
static HIGHLIGHT_SYMBOL: &str = "=> ";
|
||||||
|
|
||||||
@@ -20,11 +23,37 @@ pub fn ui<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
|||||||
let main_chunks = vertical_chunks_with_margin(
|
let main_chunks = vertical_chunks_with_margin(
|
||||||
vec![Constraint::Length(20), Constraint::Length(0)],
|
vec![Constraint::Length(20), Constraint::Length(0)],
|
||||||
f.size(),
|
f.size(),
|
||||||
1
|
1,
|
||||||
);
|
);
|
||||||
|
|
||||||
draw_context_row(f, app, main_chunks[0]);
|
draw_context_row(f, app, main_chunks[0]);
|
||||||
radarr_ui::draw_radarr_ui(f, app, main_chunks[1]);
|
match *app.get_current_route() {
|
||||||
|
Route::Radarr(active_radarr_block) => match active_radarr_block {
|
||||||
|
ActiveRadarrBlock::Movies => radarr_ui::draw_radarr_ui(f, app, main_chunks[1]),
|
||||||
|
ActiveRadarrBlock::MovieDetails => draw_popup_over(
|
||||||
|
f,
|
||||||
|
app,
|
||||||
|
main_chunks[1],
|
||||||
|
radarr_ui::draw_radarr_ui,
|
||||||
|
radarr_ui::draw_movie_details,
|
||||||
|
),
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn draw_popup_over<B: Backend>(
|
||||||
|
f: &mut Frame<'_, B>,
|
||||||
|
app: &mut App,
|
||||||
|
area: Rect,
|
||||||
|
background_fn: fn(&mut Frame<'_, B>, &mut App, Rect),
|
||||||
|
popup_fn: fn(&mut Frame<'_, B>, &App, Rect),
|
||||||
|
) {
|
||||||
|
background_fn(f, app, area);
|
||||||
|
|
||||||
|
let popup_area = centered_rect(75, 75, f.size());
|
||||||
|
f.render_widget(Clear, popup_area);
|
||||||
|
popup_fn(f, app, popup_area);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_context_row<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
fn draw_context_row<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
||||||
@@ -46,3 +75,16 @@ fn draw_context_row<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
|||||||
|
|
||||||
radarr_ui::draw_logo(f, chunks[4]);
|
radarr_ui::draw_logo(f, chunks[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn loading<B: Backend>(f: &mut Frame<'_, B>, block: Block<'_>, area: Rect, is_loading: bool) {
|
||||||
|
if is_loading {
|
||||||
|
let text = "\n\n Loading ...\n\n".to_owned();
|
||||||
|
let mut text = Text::from(text);
|
||||||
|
text.patch_style(style_secondary());
|
||||||
|
|
||||||
|
let paragraph = Paragraph::new(text).style(style_secondary()).block(block);
|
||||||
|
f.render_widget(paragraph, area);
|
||||||
|
} else {
|
||||||
|
f.render_widget(block, area)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+141
-80
@@ -1,87 +1,136 @@
|
|||||||
use std::ops::Sub;
|
use std::ops::Sub;
|
||||||
|
|
||||||
use chrono::{Duration, Utc};
|
use chrono::{Duration, Utc};
|
||||||
use tui::{Frame, symbols};
|
|
||||||
use tui::backend::Backend;
|
use tui::backend::Backend;
|
||||||
use tui::layout::{Alignment, Constraint, Rect};
|
use tui::layout::{Alignment, Constraint, Rect};
|
||||||
use tui::style::{Color, Modifier, Style};
|
use tui::style::{Color, Modifier, Style};
|
||||||
use tui::text::{Span, Spans, Text};
|
use tui::text::{Span, Spans, Text};
|
||||||
use tui::widgets::{Block, Borders, Cell, LineGauge, Paragraph, Row, Table};
|
use tui::widgets::{Block, Borders, Cell, LineGauge, Paragraph, Row, Table, Wrap};
|
||||||
|
use tui::{symbols, Frame};
|
||||||
|
|
||||||
use crate::app::App;
|
|
||||||
use crate::app::radarr::RadarrData;
|
use crate::app::radarr::RadarrData;
|
||||||
|
use crate::app::App;
|
||||||
use crate::logos::RADARR_LOGO;
|
use crate::logos::RADARR_LOGO;
|
||||||
use crate::network::radarr_network::Movie;
|
use crate::network::radarr_network::Movie;
|
||||||
use crate::ui::HIGHLIGHT_SYMBOL;
|
use crate::ui::utils::{
|
||||||
use crate::ui::utils::{style_default, style_highlight, style_primary, style_secondary, style_tertiary, title_block, vertical_chunks, vertical_chunks_with_margin};
|
style_default, style_highlight, style_primary, style_secondary, style_tertiary, title_block,
|
||||||
|
vertical_chunks, vertical_chunks_with_margin,
|
||||||
|
};
|
||||||
|
use crate::ui::{loading, HIGHLIGHT_SYMBOL};
|
||||||
|
use crate::utils::{convert_runtime, convert_to_gb};
|
||||||
|
|
||||||
pub(super) fn draw_radarr_ui<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
|
pub(super) fn draw_radarr_ui<B: Backend>(f: &mut Frame<'_, B>, app: &mut App, area: Rect) {
|
||||||
let block = Block::default().borders(Borders::ALL).title(Spans::from(vec![
|
let block = Block::default()
|
||||||
Span::styled("Movies", Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD))
|
.borders(Borders::ALL)
|
||||||
]));
|
.title(Spans::from(vec![Span::styled(
|
||||||
|
"Movies",
|
||||||
|
Style::default()
|
||||||
|
.fg(Color::Yellow)
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
|
)]));
|
||||||
|
|
||||||
let rows = app.data.radarr_data.movies.items
|
let movies_vec = &app.data.radarr_data.movies.items;
|
||||||
.iter()
|
|
||||||
.map(|movie| {
|
if !movies_vec.is_empty() {
|
||||||
let runtime = movie.runtime.as_u64().unwrap();
|
let rows = movies_vec.iter().map(|movie| {
|
||||||
let hours = runtime / 60;
|
let (hours, minutes) = convert_runtime(movie.runtime.as_u64().unwrap());
|
||||||
let minutes = runtime % 60;
|
let file_size: f64 = convert_to_gb(movie.size_on_disk.as_u64().unwrap());
|
||||||
let file_size: f64 = movie.size_on_disk.as_u64().unwrap() as f64 / 1024f64.powi(3);
|
|
||||||
|
Row::new(vec![
|
||||||
|
Cell::from(movie.title.to_owned()),
|
||||||
|
Cell::from(movie.year.to_string()),
|
||||||
|
Cell::from(format!("{}h {}m", hours, minutes)),
|
||||||
|
Cell::from(format!("{:.2} GB", file_size)),
|
||||||
|
Cell::from(
|
||||||
|
app
|
||||||
|
.data
|
||||||
|
.radarr_data
|
||||||
|
.quality_profile_map
|
||||||
|
.get(&movie.quality_profile_id.as_u64().unwrap())
|
||||||
|
.unwrap()
|
||||||
|
.to_owned(),
|
||||||
|
),
|
||||||
|
])
|
||||||
|
.style(determine_row_style(app, movie))
|
||||||
|
});
|
||||||
|
|
||||||
Row::new(vec![
|
|
||||||
Cell::from(movie.title.to_owned()),
|
|
||||||
Cell::from(movie.year.to_string()),
|
|
||||||
Cell::from(format!("{:0width$}:{:0width$}", hours, minutes, width = 2)),
|
|
||||||
Cell::from(format!("{:.2} GB", file_size)),
|
|
||||||
Cell::from(app.data.radarr_data.quality_profile_map.get(&movie.quality_profile_id.as_u64().unwrap()).unwrap().to_owned())
|
|
||||||
]).style(determine_row_style(app, movie))
|
|
||||||
});
|
|
||||||
let header_row = Row::new(vec!["Title", "Year", "Runtime", "Size", "Quality Profile"])
|
let header_row = Row::new(vec!["Title", "Year", "Runtime", "Size", "Quality Profile"])
|
||||||
.style(style_default())
|
.style(style_default())
|
||||||
.bottom_margin(0);
|
.bottom_margin(0);
|
||||||
|
|
||||||
let constraints = vec![
|
let constraints = vec![
|
||||||
Constraint::Percentage(20),
|
Constraint::Percentage(20),
|
||||||
Constraint::Percentage(20),
|
Constraint::Percentage(20),
|
||||||
Constraint::Percentage(20),
|
Constraint::Percentage(20),
|
||||||
Constraint::Percentage(20),
|
Constraint::Percentage(20),
|
||||||
Constraint::Percentage(20),
|
Constraint::Percentage(20),
|
||||||
];
|
];
|
||||||
|
|
||||||
let table = Table::new(rows)
|
let table = Table::new(rows)
|
||||||
.header(header_row)
|
.header(header_row)
|
||||||
.block(block)
|
.block(block)
|
||||||
.highlight_style(style_highlight())
|
.highlight_style(style_highlight())
|
||||||
.highlight_symbol(HIGHLIGHT_SYMBOL)
|
.highlight_symbol(HIGHLIGHT_SYMBOL)
|
||||||
.widths(&constraints);
|
.widths(&constraints);
|
||||||
|
|
||||||
f.render_stateful_widget(table, area, &mut app.data.radarr_data.movies.state)
|
f.render_stateful_widget(table, area, &mut app.data.radarr_data.movies.state);
|
||||||
|
} else {
|
||||||
|
loading(f, block, area, app.is_loading);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn draw_movie_details<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
||||||
|
let block = title_block("Movie Details");
|
||||||
|
let movie_details = &app.data.radarr_data.movie_details.get_text();
|
||||||
|
|
||||||
|
if !movie_details.is_empty() {
|
||||||
|
let mut text = Text::from(movie_details.clone());
|
||||||
|
text.patch_style(style_primary());
|
||||||
|
|
||||||
|
let paragraph = Paragraph::new(text)
|
||||||
|
.block(block)
|
||||||
|
.wrap(Wrap { trim: false })
|
||||||
|
.scroll((app.data.radarr_data.movie_details.offset, 0));
|
||||||
|
|
||||||
|
f.render_widget(paragraph, area);
|
||||||
|
} else {
|
||||||
|
loading(f, block, area, app.is_loading);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn draw_stats<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
pub(super) fn draw_stats<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect) {
|
||||||
|
let block = title_block("Stats");
|
||||||
|
|
||||||
|
if !app.data.radarr_data.version.is_empty() {
|
||||||
let RadarrData {
|
let RadarrData {
|
||||||
free_space,
|
free_space,
|
||||||
total_space,
|
total_space,
|
||||||
start_time,
|
start_time,
|
||||||
..
|
..
|
||||||
} = app.data.radarr_data;
|
} = app.data.radarr_data;
|
||||||
let ratio = if total_space == 0 {
|
let ratio = if total_space == 0 {
|
||||||
0f64
|
0f64
|
||||||
} else {
|
} else {
|
||||||
1f64 - (free_space as f64 / total_space as f64)
|
1f64 - (free_space as f64 / total_space as f64)
|
||||||
};
|
};
|
||||||
|
|
||||||
f.render_widget(title_block("Stats"), area);
|
f.render_widget(block, area);
|
||||||
|
|
||||||
let chunks =
|
let chunks = vertical_chunks_with_margin(
|
||||||
vertical_chunks_with_margin(vec![
|
vec![
|
||||||
Constraint::Length(1),
|
Constraint::Length(1),
|
||||||
Constraint::Length(1),
|
Constraint::Length(1),
|
||||||
Constraint::Min(2)], area, 1);
|
Constraint::Min(2),
|
||||||
|
],
|
||||||
|
area,
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
let version_paragraph = Paragraph::new(Text::from(format!(
|
let version_paragraph = Paragraph::new(Text::from(format!(
|
||||||
"Radarr Version: {}",
|
"Radarr Version: {}",
|
||||||
app.data.radarr_data.version
|
app.data.radarr_data.version
|
||||||
))).block(Block::default());
|
)))
|
||||||
|
.block(Block::default());
|
||||||
|
|
||||||
let uptime = Utc::now().sub(start_time);
|
let uptime = Utc::now().sub(start_time);
|
||||||
let days = uptime.num_days();
|
let days = uptime.num_days();
|
||||||
@@ -89,50 +138,62 @@ pub(super) fn draw_stats<B: Backend>(f: &mut Frame<'_, B>, app: &App, area: Rect
|
|||||||
let hours = day_difference.num_hours();
|
let hours = day_difference.num_hours();
|
||||||
let hour_difference = day_difference.sub(Duration::hours(hours));
|
let hour_difference = day_difference.sub(Duration::hours(hours));
|
||||||
let minutes = hour_difference.num_minutes();
|
let minutes = hour_difference.num_minutes();
|
||||||
let seconds = hour_difference.sub(Duration::minutes(minutes)).num_seconds();
|
let seconds = hour_difference
|
||||||
|
.sub(Duration::minutes(minutes))
|
||||||
|
.num_seconds();
|
||||||
|
|
||||||
let uptime_paragraph = Paragraph::new(Text::from(format!(
|
let uptime_paragraph = Paragraph::new(Text::from(format!(
|
||||||
"Uptime: {}d {:0width$}:{:0width$}:{:0width$}",
|
"Uptime: {}d {:0width$}:{:0width$}:{:0width$}",
|
||||||
days, hours, minutes, seconds, width = 2
|
days,
|
||||||
))).block(Block::default());
|
hours,
|
||||||
|
minutes,
|
||||||
|
seconds,
|
||||||
|
width = 2
|
||||||
|
)))
|
||||||
|
.block(Block::default());
|
||||||
|
|
||||||
let space_gauge = LineGauge::default()
|
let space_gauge = LineGauge::default()
|
||||||
.block(Block::default().title("Storage:"))
|
.block(Block::default().title("Storage:"))
|
||||||
.gauge_style(Style::default().fg(Color::Cyan))
|
.gauge_style(Style::default().fg(Color::Cyan))
|
||||||
.line_set(symbols::line::THICK)
|
.line_set(symbols::line::THICK)
|
||||||
.ratio(ratio)
|
.ratio(ratio)
|
||||||
.label(Spans::from(format!("{:.0}%", ratio * 100.0)));
|
.label(Spans::from(format!("{:.0}%", ratio * 100.0)));
|
||||||
|
|
||||||
f.render_widget(version_paragraph, chunks[0]);
|
f.render_widget(version_paragraph, chunks[0]);
|
||||||
f.render_widget(uptime_paragraph, chunks[1]);
|
f.render_widget(uptime_paragraph, chunks[1]);
|
||||||
f.render_widget(space_gauge, chunks[2]);
|
f.render_widget(space_gauge, chunks[2]);
|
||||||
|
} else {
|
||||||
|
loading(f, block, area, app.is_loading);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn draw_logo<B: Backend>(f: &mut Frame<'_, B>, area: Rect) {
|
pub(super) fn draw_logo<B: Backend>(f: &mut Frame<'_, B>, area: Rect) {
|
||||||
let chunks = vertical_chunks(
|
let chunks = vertical_chunks(
|
||||||
vec![Constraint::Percentage(60), Constraint::Percentage(40)],
|
vec![Constraint::Percentage(60), Constraint::Percentage(40)],
|
||||||
area,
|
area,
|
||||||
);
|
);
|
||||||
let logo = Paragraph::new(Text::from(RADARR_LOGO))
|
let logo = Paragraph::new(Text::from(RADARR_LOGO))
|
||||||
.block(Block::default())
|
.block(Block::default())
|
||||||
.alignment(Alignment::Center);
|
.alignment(Alignment::Center);
|
||||||
|
|
||||||
f.render_widget(logo, chunks[0]);
|
f.render_widget(logo, chunks[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn determine_row_style(app: &App, movie: &Movie) -> Style {
|
fn determine_row_style(app: &App, movie: &Movie) -> Style {
|
||||||
let downloads_vec = &app.data.radarr_data.downloads.items;
|
let downloads_vec = &app.data.radarr_data.downloads.items;
|
||||||
|
|
||||||
if !movie.has_file {
|
if !movie.has_file {
|
||||||
if let Some(download) = downloads_vec.iter()
|
if let Some(download) = downloads_vec
|
||||||
.find(|&download | download.movie_id == movie.id) {
|
.iter()
|
||||||
if download.status == "downloading" {
|
.find(|&download| download.movie_id == movie.id)
|
||||||
return style_secondary()
|
{
|
||||||
}
|
if download.status == "downloading" {
|
||||||
}
|
return style_secondary();
|
||||||
|
}
|
||||||
return style_tertiary()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
style_primary()
|
return style_tertiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
style_primary()
|
||||||
|
}
|
||||||
|
|||||||
+35
-9
@@ -50,37 +50,63 @@ pub fn vertical_chunks_with_margin(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn layout_block(title_span: Span<'_>) -> Block<'_> {
|
pub fn layout_block(title_span: Span<'_>) -> Block<'_> {
|
||||||
Block::default().borders(Borders::ALL).title(title_span)
|
Block::default().borders(Borders::ALL).title(title_span)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style_bold() -> Style {
|
pub fn style_bold() -> Style {
|
||||||
Style::default().add_modifier(Modifier::BOLD)
|
Style::default().add_modifier(Modifier::BOLD)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style_highlight() -> Style {
|
pub fn style_highlight() -> Style {
|
||||||
Style::default().add_modifier(Modifier::REVERSED)
|
Style::default().add_modifier(Modifier::REVERSED)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style_default() -> Style {
|
pub fn style_default() -> Style {
|
||||||
Style::default().fg(Color::White)
|
Style::default().fg(Color::White)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style_primary() -> Style {
|
pub fn style_primary() -> Style {
|
||||||
Style::default().fg(Color::Green)
|
Style::default().fg(Color::Green)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style_secondary() -> Style {
|
pub fn style_secondary() -> Style {
|
||||||
Style::default().fg(Color::Magenta)
|
Style::default().fg(Color::Magenta)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style_tertiary() -> Style {
|
pub fn style_tertiary() -> Style {
|
||||||
Style::default().fg(Color::Red)
|
Style::default().fg(Color::Red)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn title_style(title: &str) -> Span<'_> {
|
pub fn title_style(title: &str) -> Span<'_> {
|
||||||
Span::styled(title, style_bold())
|
Span::styled(title, style_bold())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn title_block(title: &str) -> Block<'_> {
|
pub fn title_block(title: &str) -> Block<'_> {
|
||||||
layout_block(title_style(title))
|
layout_block(title_style(title))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
|
||||||
|
let popup_layout = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints(
|
||||||
|
[
|
||||||
|
Constraint::Percentage((100 - percent_y) / 2),
|
||||||
|
Constraint::Percentage(percent_y),
|
||||||
|
Constraint::Percentage((100 - percent_y) / 2),
|
||||||
|
]
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
.split(r);
|
||||||
|
|
||||||
|
Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints(
|
||||||
|
[
|
||||||
|
Constraint::Percentage((100 - percent_x) / 2),
|
||||||
|
Constraint::Percentage(percent_x),
|
||||||
|
Constraint::Percentage((100 - percent_x) / 2),
|
||||||
|
]
|
||||||
|
.as_ref(),
|
||||||
|
)
|
||||||
|
.split(popup_layout[1])[1]
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-13
@@ -1,19 +1,33 @@
|
|||||||
|
use log::LevelFilter;
|
||||||
use log4rs::append::file::FileAppender;
|
use log4rs::append::file::FileAppender;
|
||||||
use log4rs::config::{Appender, Root};
|
use log4rs::config::{Appender, Root};
|
||||||
use log4rs::encode::pattern::PatternEncoder;
|
use log4rs::encode::pattern::PatternEncoder;
|
||||||
use log::LevelFilter;
|
use serde_json::Number;
|
||||||
|
|
||||||
pub fn init_logging_config() -> log4rs::Config {
|
pub fn init_logging_config() -> log4rs::Config {
|
||||||
let file_path = "/tmp/managarr.log";
|
let file_path = "/tmp/managarr.log";
|
||||||
let logfile = FileAppender::builder()
|
let logfile = FileAppender::builder()
|
||||||
.encoder(Box::new(PatternEncoder::new("{l} - {m}\n")))
|
.encoder(Box::new(PatternEncoder::new("{l} - {m}\n")))
|
||||||
.build(file_path)
|
.build(file_path)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
log4rs::Config::builder()
|
log4rs::Config::builder()
|
||||||
.appender(Appender::builder().build("logfile", Box::new(logfile)))
|
.appender(Appender::builder().build("logfile", Box::new(logfile)))
|
||||||
.build(Root::builder()
|
.build(
|
||||||
.appender("logfile")
|
Root::builder()
|
||||||
.build(LevelFilter::Debug))
|
.appender("logfile")
|
||||||
.unwrap()
|
.build(LevelFilter::Debug),
|
||||||
}
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn convert_to_gb(bytes: u64) -> f64 {
|
||||||
|
bytes as f64 / 1024f64.powi(3)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn convert_runtime(runtime: u64) -> (u64, u64) {
|
||||||
|
let hours = runtime / 60;
|
||||||
|
let minutes = runtime % 60;
|
||||||
|
|
||||||
|
(hours, minutes)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user