Auth activity OK!

This commit is contained in:
veeso 2021-03-14 20:56:36 +01:00
parent 28f8c82ccf
commit 2c898a91da
2 changed files with 126 additions and 56 deletions

View file

@ -31,7 +31,7 @@ use super::{
COMPONENT_RADIO_BOOKMARK_SAVE_PWD, COMPONENT_RADIO_PROTOCOL, COMPONENT_RADIO_QUIT, COMPONENT_RADIO_BOOKMARK_SAVE_PWD, COMPONENT_RADIO_PROTOCOL, COMPONENT_RADIO_QUIT,
COMPONENT_RECENTS_LIST, COMPONENT_TEXT_ERROR, COMPONENT_TEXT_HELP, COMPONENT_RECENTS_LIST, COMPONENT_TEXT_ERROR, COMPONENT_TEXT_HELP,
}; };
use crate::ui::layout::{props::TextParts, Msg, Payload}; use crate::ui::layout::{Msg, Payload};
// ext // ext
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
@ -193,10 +193,14 @@ impl AuthActivity {
// Enter // Enter
(COMPONENT_BOOKMARKS_LIST, Msg::OnSubmit(Payload::Unsigned(idx))) => { (COMPONENT_BOOKMARKS_LIST, Msg::OnSubmit(Payload::Unsigned(idx))) => {
self.load_bookmark(*idx); self.load_bookmark(*idx);
// Give focus to input password
self.view.active(COMPONENT_INPUT_PASSWORD);
None None
} }
(COMPONENT_RECENTS_LIST, Msg::OnSubmit(Payload::Unsigned(idx))) => { (COMPONENT_RECENTS_LIST, Msg::OnSubmit(Payload::Unsigned(idx))) => {
self.load_recent(*idx); self.load_recent(*idx);
// Give focus to input password
self.view.active(COMPONENT_INPUT_PASSWORD);
None None
} }
// Bookmark radio // Bookmark radio
@ -216,21 +220,7 @@ impl AuthActivity {
// Delete bookmark // Delete bookmark
self.del_bookmark(index); self.del_bookmark(index);
// Update bookmarks // Update bookmarks
match self.view.get_props(COMPONENT_BOOKMARKS_LIST).as_mut() { self.view_bookmarks()
None => None,
Some(props) => {
let msg = self.view.update(
COMPONENT_BOOKMARKS_LIST,
props
.with_texts(TextParts::new(
Some(String::from("Bookmarks")),
Some(self.view_bookmarks()),
))
.build(),
);
self.update(msg)
}
}
} }
_ => None, _ => None,
} }
@ -250,21 +240,7 @@ impl AuthActivity {
// Delete recent // Delete recent
self.del_recent(index); self.del_recent(index);
// Update bookmarks // Update bookmarks
match self.view.get_props(COMPONENT_RECENTS_LIST).as_mut() { self.view_recent_connections()
None => None,
Some(props) => {
let msg = self.view.update(
COMPONENT_RECENTS_LIST,
props
.with_texts(TextParts::new(
Some(String::from("Recent connections")),
Some(self.view_recent_connections()),
))
.build(),
);
self.update(msg)
}
}
} }
_ => None, _ => None,
} }
@ -360,7 +336,8 @@ impl AuthActivity {
self.save_bookmark(bookmark_name, save_pwd); self.save_bookmark(bookmark_name, save_pwd);
// Umount popup // Umount popup
self.umount_bookmark_save_dialog(); self.umount_bookmark_save_dialog();
None // Reload bookmarks
self.view_bookmarks()
} }
// Hide save bookmark // Hide save bookmark
(COMPONENT_INPUT_BOOKMARK_NAME, &MSG_KEY_ESC) (COMPONENT_INPUT_BOOKMARK_NAME, &MSG_KEY_ESC)
@ -384,6 +361,10 @@ impl AuthActivity {
self.umount_quit(); self.umount_quit();
None None
} }
(COMPONENT_RADIO_QUIT, &MSG_KEY_ESC) => {
self.umount_quit();
None
}
// On submit on any unhandled (connect) // On submit on any unhandled (connect)
(_, Msg::OnSubmit(_)) | (_, &MSG_KEY_ENTER) => { (_, Msg::OnSubmit(_)) | (_, &MSG_KEY_ENTER) => {
// Match <ENTER> key for all other components // Match <ENTER> key for all other components

View file

@ -27,18 +27,18 @@
use super::{AuthActivity, Context, FileTransferProtocol}; use super::{AuthActivity, Context, FileTransferProtocol};
use crate::ui::layout::components::{ use crate::ui::layout::components::{
bookmark_list::BookmarkList, ctext::CText, input::Input, radio_group::RadioGroup, table::Table, bookmark_list::BookmarkList, ctext::CText, input::Input, radio_group::RadioGroup, table::Table,
text::Text, text::Text, title::Title,
}; };
use crate::ui::layout::props::{ use crate::ui::layout::props::{
InputType, PropValue, PropsBuilder, TableBuilder, TextParts, TextSpan, TextSpanBuilder, InputType, PropValue, PropsBuilder, TableBuilder, TextParts, TextSpan, TextSpanBuilder,
}; };
use crate::ui::layout::utils::draw_area_in; use crate::ui::layout::utils::draw_area_in;
use crate::ui::layout::Payload; use crate::ui::layout::{Msg, Payload};
// Ext // Ext
use tui::{ use tui::{
layout::{Constraint, Direction, Layout}, layout::{Constraint, Direction, Layout},
style::Color, style::Color,
widgets::Clear, widgets::{Borders, Clear},
}; };
impl AuthActivity { impl AuthActivity {
@ -48,9 +48,9 @@ impl AuthActivity {
pub(super) fn init(&mut self) { pub(super) fn init(&mut self) {
// Header // Header
self.view.mount(super::COMPONENT_TEXT_HEADER, Box::new( self.view.mount(super::COMPONENT_TEXT_HEADER, Box::new(
Text::new( Title::new(
PropsBuilder::default().with_foreground(Color::White).with_texts( PropsBuilder::default().with_foreground(Color::White).with_texts(
TextParts::new(None, Some(vec![TextSpan::from(" _____ ____ ____ ____ \n|_ _|__ _ __ _ __ ___ / ___| / ___| _ \\ \n | |/ _ \\ '__| '_ ` _ \\\\___ \\| | | |_) |\n | | __/ | | | | | | |___) | |___| __/ \n |_|\\___|_| |_| |_| |_|____/ \\____|_| \n")])) TextParts::new(Some(String::from(" _____ ____ ____ ____ \n|_ _|__ _ __ _ __ ___ / ___| / ___| _ \\ \n | |/ _ \\ '__| '_ ` _ \\\\___ \\| | | |_) |\n | | __/ | | | | | | |___) | |___| __/ \n |_|\\___|_| |_| |_| |_|____/ \\____|_| \n")), None)
).bold().build() ).bold().build()
) )
)); ));
@ -100,7 +100,7 @@ impl AuthActivity {
.with_texts(TextParts::new(Some(String::from("Port number")), None)) .with_texts(TextParts::new(Some(String::from("Port number")), None))
.with_input(InputType::Number) .with_input(InputType::Number)
.with_input_len(5) .with_input_len(5)
.with_value(PropValue::Unsigned(22)) .with_value(PropValue::Str(String::from("22")))
.build(), .build(),
)), )),
); );
@ -110,6 +110,7 @@ impl AuthActivity {
Box::new(RadioGroup::new( Box::new(RadioGroup::new(
PropsBuilder::default() PropsBuilder::default()
.with_foreground(Color::LightGreen) .with_foreground(Color::LightGreen)
.with_background(Color::Black)
.with_texts(TextParts::new( .with_texts(TextParts::new(
Some(String::from("Protocol")), Some(String::from("Protocol")),
Some(vec![ Some(vec![
@ -161,27 +162,28 @@ impl AuthActivity {
super::COMPONENT_BOOKMARKS_LIST, super::COMPONENT_BOOKMARKS_LIST,
Box::new(BookmarkList::new( Box::new(BookmarkList::new(
PropsBuilder::default() PropsBuilder::default()
.with_foreground(Color::LightGreen) .with_background(Color::LightGreen)
.with_texts(TextParts::new( .with_foreground(Color::Black)
Some(String::from("Bookmarks")), .with_texts(TextParts::new(Some(String::from("Bookmarks")), None))
Some(self.view_bookmarks()),
))
.build(), .build(),
)), )),
); );
let _ = self.view_bookmarks();
// Recents // Recents
self.view.mount( self.view.mount(
super::COMPONENT_RECENTS_LIST, super::COMPONENT_RECENTS_LIST,
Box::new(BookmarkList::new( Box::new(BookmarkList::new(
PropsBuilder::default() PropsBuilder::default()
.with_foreground(Color::LightBlue) .with_background(Color::LightBlue)
.with_foreground(Color::Black)
.with_texts(TextParts::new( .with_texts(TextParts::new(
Some(String::from("Recent connections")), Some(String::from("Recent connections")),
Some(self.view_recent_connections()), None,
)) ))
.build(), .build(),
)), )),
); );
let _ = self.view_recent_connections();
// Active address // Active address
self.view.active(super::COMPONENT_INPUT_ADDR); self.view.active(super::COMPONENT_INPUT_ADDR);
} }
@ -306,10 +308,20 @@ impl AuthActivity {
// make popup // make popup
let popup = draw_area_in(f.size(), 20, 20); let popup = draw_area_in(f.size(), 20, 20);
f.render_widget(Clear, popup); f.render_widget(Clear, popup);
let popup_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(
[
Constraint::Length(3), // Input form
Constraint::Length(2), // Yes/No
]
.as_ref(),
)
.split(popup);
self.view self.view
.render(super::COMPONENT_INPUT_BOOKMARK_NAME, f, popup); .render(super::COMPONENT_INPUT_BOOKMARK_NAME, f, popup_chunks[0]);
self.view self.view
.render(super::COMPONENT_RADIO_BOOKMARK_SAVE_PWD, f, popup); .render(super::COMPONENT_RADIO_BOOKMARK_SAVE_PWD, f, popup_chunks[1]);
} }
} }
}); });
@ -321,21 +333,92 @@ impl AuthActivity {
/// ### view_bookmarks /// ### view_bookmarks
/// ///
/// Make text span from bookmarks /// Make text span from bookmarks
pub(super) fn view_bookmarks(&self) -> Vec<TextSpan> { pub(super) fn view_bookmarks(&mut self) -> Option<(String, Msg)> {
self.bookmarks_list let bookmarks: Vec<TextSpan> = self
.bookmarks_list
.iter() .iter()
.map(|x| TextSpan::from(x.as_str())) .map(|x| {
.collect() let entry: (String, u16, FileTransferProtocol, String, _) = self
.bookmarks_client
.as_ref()
.unwrap()
.get_bookmark(x)
.unwrap();
TextSpan::from(
format!(
"{} ({}://{}@{}:{})",
x,
entry.2.to_string().to_lowercase(),
entry.3,
entry.0,
entry.1
)
.as_str(),
)
})
.collect();
match self
.view
.get_props(super::COMPONENT_BOOKMARKS_LIST)
.as_mut()
{
None => None,
Some(props) => {
let msg = self.view.update(
super::COMPONENT_BOOKMARKS_LIST,
props
.with_texts(TextParts::new(
Some(String::from("Bookmarks")),
Some(bookmarks),
))
.build(),
);
msg
}
}
} }
/// ### view_recent_connections /// ### view_recent_connections
/// ///
/// View recent connections /// View recent connections
pub(super) fn view_recent_connections(&self) -> Vec<TextSpan> { pub(super) fn view_recent_connections(&mut self) -> Option<(String, Msg)> {
self.recents_list let bookmarks: Vec<TextSpan> = self
.recents_list
.iter() .iter()
.map(|x| TextSpan::from(x.as_str())) .map(|x| {
.collect() let entry: (String, u16, FileTransferProtocol, String) = self
.bookmarks_client
.as_ref()
.unwrap()
.get_recent(x)
.unwrap();
TextSpan::from(
format!(
"{}://{}@{}:{}",
entry.2.to_string().to_lowercase(),
entry.3,
entry.0,
entry.1
)
.as_str(),
)
})
.collect();
match self.view.get_props(super::COMPONENT_RECENTS_LIST).as_mut() {
None => None,
Some(props) => {
let msg = self.view.update(
super::COMPONENT_RECENTS_LIST,
props
.with_texts(TextParts::new(
Some(String::from("Recent connections")),
Some(bookmarks),
))
.build(),
);
msg
}
}
} }
// -- mount // -- mount
@ -376,6 +459,7 @@ impl AuthActivity {
Box::new(RadioGroup::new( Box::new(RadioGroup::new(
PropsBuilder::default() PropsBuilder::default()
.with_foreground(Color::Yellow) .with_foreground(Color::Yellow)
.with_background(Color::Black)
.with_texts(TextParts::new( .with_texts(TextParts::new(
Some(String::from("Quit TermSCP?")), Some(String::from("Quit TermSCP?")),
Some(vec![TextSpan::from("Yes"), TextSpan::from("No")]), Some(vec![TextSpan::from("Yes"), TextSpan::from("No")]),
@ -402,6 +486,7 @@ impl AuthActivity {
Box::new(RadioGroup::new( Box::new(RadioGroup::new(
PropsBuilder::default() PropsBuilder::default()
.with_foreground(Color::Yellow) .with_foreground(Color::Yellow)
.with_background(Color::Black)
.with_texts(TextParts::new( .with_texts(TextParts::new(
Some(String::from("Delete bookmark?")), Some(String::from("Delete bookmark?")),
Some(vec![TextSpan::from("Yes"), TextSpan::from("No")]), Some(vec![TextSpan::from("Yes"), TextSpan::from("No")]),
@ -432,6 +517,7 @@ impl AuthActivity {
Box::new(RadioGroup::new( Box::new(RadioGroup::new(
PropsBuilder::default() PropsBuilder::default()
.with_foreground(Color::Yellow) .with_foreground(Color::Yellow)
.with_background(Color::Black)
.with_texts(TextParts::new( .with_texts(TextParts::new(
Some(String::from("Delete bookmark?")), Some(String::from("Delete bookmark?")),
Some(vec![TextSpan::from("Yes"), TextSpan::from("No")]), Some(vec![TextSpan::from("Yes"), TextSpan::from("No")]),
@ -459,10 +545,12 @@ impl AuthActivity {
super::COMPONENT_INPUT_BOOKMARK_NAME, super::COMPONENT_INPUT_BOOKMARK_NAME,
Box::new(Input::new( Box::new(Input::new(
PropsBuilder::default() PropsBuilder::default()
.with_foreground(Color::LightCyan)
.with_texts(TextParts::new( .with_texts(TextParts::new(
Some(String::from("Save bookmark as...")), Some(String::from("Save bookmark as...")),
None, None,
)) ))
//.with_borders(Borders::TOP | Borders::RIGHT | Borders::LEFT)
.build(), .build(),
)), )),
); );
@ -471,11 +559,12 @@ impl AuthActivity {
Box::new(RadioGroup::new( Box::new(RadioGroup::new(
PropsBuilder::default() PropsBuilder::default()
.with_foreground(Color::Red) .with_foreground(Color::Red)
//.with_borders(Borders::BOTTOM | Borders::RIGHT | Borders::LEFT)
.with_texts(TextParts::new( .with_texts(TextParts::new(
Some(String::from("Save password?")), Some(String::from("Save password?")),
Some(vec![TextSpan::from("Yes"), TextSpan::from("No")]), Some(vec![TextSpan::from("Yes"), TextSpan::from("No")]),
)) ))
.with_value(PropValue::Unsigned(1)) //.with_value(PropValue::Unsigned(1))
.build(), .build(),
)), )),
); );