router4 compiled
This commit is contained in:
@@ -12,6 +12,7 @@ use anyhow::Result;
|
|||||||
use crate::components::common::text_editor::TextEditor;
|
use crate::components::common::text_editor::TextEditor;
|
||||||
use crate::services::ui_service::UiService;
|
use crate::services::ui_service::UiService;
|
||||||
use tui_textarea::CursorMove;
|
use tui_textarea::CursorMove;
|
||||||
|
use crate::state::pages::admin::AdminState;
|
||||||
use crate::pages::routing::{Router, Page};
|
use crate::pages::routing::{Router, Page};
|
||||||
|
|
||||||
pub type SaveLogicResultSender = mpsc::Sender<Result<String>>;
|
pub type SaveLogicResultSender = mpsc::Sender<Result<String>>;
|
||||||
@@ -20,14 +21,15 @@ pub fn handle_add_logic_navigation(
|
|||||||
key_event: KeyEvent,
|
key_event: KeyEvent,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
add_logic_state: &mut AddLogicState,
|
|
||||||
is_edit_mode: &mut bool,
|
is_edit_mode: &mut bool,
|
||||||
buffer_state: &mut BufferState,
|
buffer_state: &mut BufferState,
|
||||||
grpc_client: GrpcClient,
|
grpc_client: GrpcClient,
|
||||||
_save_logic_sender: SaveLogicResultSender, // Marked as unused
|
save_logic_sender: SaveLogicResultSender,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
router: &mut Router,
|
router: &mut Router,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
if let Page::AddLogic(add_logic_state) = &mut router.current {
|
||||||
|
|
||||||
// === FULLSCREEN SCRIPT EDITING - COMPLETE ISOLATION ===
|
// === FULLSCREEN SCRIPT EDITING - COMPLETE ISOLATION ===
|
||||||
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
|
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
|
||||||
// === AUTOCOMPLETE HANDLING ===
|
// === AUTOCOMPLETE HANDLING ===
|
||||||
@@ -382,9 +384,9 @@ pub fn handle_add_logic_navigation(
|
|||||||
}
|
}
|
||||||
AddLogicFocus::CancelButton => {
|
AddLogicFocus::CancelButton => {
|
||||||
buffer_state.update_history(AppView::Admin);
|
buffer_state.update_history(AppView::Admin);
|
||||||
router.navigate(Page::Admin(app_state.admin_state().clone()));
|
|
||||||
*command_message = "Cancelled Add Logic".to_string();
|
*command_message = "Cancelled Add Logic".to_string();
|
||||||
*is_edit_mode = false;
|
*is_edit_mode = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription => {
|
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription => {
|
||||||
*is_edit_mode = !*is_edit_mode;
|
*is_edit_mode = !*is_edit_mode;
|
||||||
@@ -423,6 +425,9 @@ pub fn handle_add_logic_navigation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
handled
|
handled
|
||||||
|
} else {
|
||||||
|
return false; // not on AddLogic page
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace_autocomplete_text(
|
fn replace_autocomplete_text(
|
||||||
|
|||||||
@@ -3,20 +3,20 @@
|
|||||||
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::services::grpc_client::GrpcClient;
|
use crate::services::grpc_client::GrpcClient;
|
||||||
use crate::state::{app::state::AppState, pages::auth::LoginState, pages::auth::RegisterState};
|
use crate::state::app::state::AppState;
|
||||||
use crate::modes::common::commands::CommandHandler;
|
use crate::modes::common::commands::CommandHandler;
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
use crate::tui::terminal::core::TerminalCore;
|
||||||
use crate::tui::functions::common::form::{save, revert};
|
use crate::tui::functions::common::form::{save, revert};
|
||||||
use crate::modes::handlers::event::EventOutcome;
|
use crate::modes::handlers::event::EventOutcome;
|
||||||
use crate::tui::functions::common::form::SaveOutcome;
|
use crate::tui::functions::common::form::SaveOutcome;
|
||||||
|
use crate::pages::routing::{Router, Page};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
pub async fn handle_command_event(
|
pub async fn handle_command_event(
|
||||||
key: KeyEvent,
|
key: KeyEvent,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
login_state: &LoginState,
|
router: &mut Router,
|
||||||
register_state: &RegisterState,
|
|
||||||
command_input: &mut String,
|
command_input: &mut String,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
@@ -25,20 +25,19 @@ pub async fn handle_command_event(
|
|||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
) -> Result<EventOutcome> {
|
) -> Result<EventOutcome> {
|
||||||
// Exit command mode (via configurable keybinding)
|
// Exit command mode
|
||||||
if config.is_exit_command_mode(key.code, key.modifiers) {
|
if config.is_exit_command_mode(key.code, key.modifiers) {
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
*command_message = "".to_string();
|
*command_message = "".to_string();
|
||||||
return Ok(EventOutcome::Ok("Exited command mode".to_string()));
|
return Ok(EventOutcome::Ok("Exited command mode".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute command (via configurable keybinding, defaults to Enter)
|
// Execute command
|
||||||
if config.is_command_execute(key.code, key.modifiers) {
|
if config.is_command_execute(key.code, key.modifiers) {
|
||||||
return process_command(
|
return process_command(
|
||||||
config,
|
config,
|
||||||
app_state,
|
app_state,
|
||||||
login_state,
|
router,
|
||||||
register_state,
|
|
||||||
command_input,
|
command_input,
|
||||||
command_message,
|
command_message,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
@@ -46,33 +45,31 @@ pub async fn handle_command_event(
|
|||||||
terminal,
|
terminal,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
).await;
|
)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backspace (via configurable keybinding, defaults to Backspace)
|
// Backspace
|
||||||
if config.is_command_backspace(key.code, key.modifiers) {
|
if config.is_command_backspace(key.code, key.modifiers) {
|
||||||
command_input.pop();
|
command_input.pop();
|
||||||
return Ok(EventOutcome::Ok("".to_string()));
|
return Ok(EventOutcome::Ok("".to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regular character input - accept any character in command mode
|
// Regular character input
|
||||||
if let KeyCode::Char(c) = key.code {
|
if let KeyCode::Char(c) = key.code {
|
||||||
// Accept regular or shifted characters (e.g., 'a' or 'A')
|
|
||||||
if key.modifiers.is_empty() || key.modifiers == KeyModifiers::SHIFT {
|
if key.modifiers.is_empty() || key.modifiers == KeyModifiers::SHIFT {
|
||||||
command_input.push(c);
|
command_input.push(c);
|
||||||
return Ok(EventOutcome::Ok("".to_string()));
|
return Ok(EventOutcome::Ok("".to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore all other keys
|
|
||||||
Ok(EventOutcome::Ok("".to_string()))
|
Ok(EventOutcome::Ok("".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_command(
|
async fn process_command(
|
||||||
config: &Config,
|
config: &Config,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
login_state: &LoginState,
|
router: &mut Router,
|
||||||
register_state: &RegisterState,
|
|
||||||
command_input: &mut String,
|
command_input: &mut String,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
@@ -81,27 +78,18 @@ async fn process_command(
|
|||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
) -> Result<EventOutcome> {
|
) -> Result<EventOutcome> {
|
||||||
// Clone the trimmed command to avoid borrow issues
|
|
||||||
let command = command_input.trim().to_string();
|
let command = command_input.trim().to_string();
|
||||||
if command.is_empty() {
|
if command.is_empty() {
|
||||||
*command_message = "Empty command".to_string();
|
*command_message = "Empty command".to_string();
|
||||||
return Ok(EventOutcome::Ok(command_message.clone()));
|
return Ok(EventOutcome::Ok(command_message.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the action for the command (now checks global and common bindings too)
|
let action = config.get_action_for_command(&command).unwrap_or("unknown");
|
||||||
let action = config.get_action_for_command(&command)
|
|
||||||
.unwrap_or("unknown");
|
|
||||||
|
|
||||||
match action {
|
match action {
|
||||||
"force_quit" | "save_and_quit" | "quit" => {
|
"force_quit" | "save_and_quit" | "quit" => {
|
||||||
let (should_exit, message) = command_handler
|
let (should_exit, message) = command_handler
|
||||||
.handle_command(
|
.handle_command(action, terminal, app_state, router)
|
||||||
action,
|
|
||||||
terminal,
|
|
||||||
app_state,
|
|
||||||
login_state,
|
|
||||||
register_state,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
if should_exit {
|
if should_exit {
|
||||||
@@ -109,12 +97,9 @@ async fn process_command(
|
|||||||
} else {
|
} else {
|
||||||
Ok(EventOutcome::Ok(message))
|
Ok(EventOutcome::Ok(message))
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"save" => {
|
"save" => {
|
||||||
let outcome = save(
|
let outcome = save(app_state, grpc_client).await?;
|
||||||
app_state,
|
|
||||||
grpc_client,
|
|
||||||
).await?;
|
|
||||||
let message = match outcome {
|
let message = match outcome {
|
||||||
SaveOutcome::CreatedNew(_) => "New entry created".to_string(),
|
SaveOutcome::CreatedNew(_) => "New entry created".to_string(),
|
||||||
SaveOutcome::UpdatedExisting => "Entry updated".to_string(),
|
SaveOutcome::UpdatedExisting => "Entry updated".to_string(),
|
||||||
@@ -122,15 +107,12 @@ async fn process_command(
|
|||||||
};
|
};
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
Ok(EventOutcome::DataSaved(outcome, message))
|
Ok(EventOutcome::DataSaved(outcome, message))
|
||||||
},
|
}
|
||||||
"revert" => {
|
"revert" => {
|
||||||
let message = revert(
|
let message = revert(app_state, grpc_client).await?;
|
||||||
app_state,
|
|
||||||
grpc_client,
|
|
||||||
).await?;
|
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
Ok(EventOutcome::Ok(message))
|
Ok(EventOutcome::Ok(message))
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let message = format!("Unhandled action: {}", action);
|
let message = format!("Unhandled action: {}", action);
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
|
|||||||
@@ -369,7 +369,7 @@ impl EventHandler {
|
|||||||
|
|
||||||
match current_mode {
|
match current_mode {
|
||||||
AppMode::General => {
|
AppMode::General => {
|
||||||
if let Page::Admin(admin_state) = &router.current {
|
if let Page::Admin(admin_state) = &mut router.current {
|
||||||
if auth_state.role.as_deref() == Some("admin") {
|
if auth_state.role.as_deref() == Some("admin") {
|
||||||
if admin_nav::handle_admin_navigation(
|
if admin_nav::handle_admin_navigation(
|
||||||
key_event,
|
key_event,
|
||||||
@@ -386,25 +386,23 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Page::AddLogic(add_logic_state) = &mut router.current {
|
|
||||||
let client_clone = self.grpc_client.clone();
|
let client_clone = self.grpc_client.clone();
|
||||||
let sender_clone = self.save_logic_result_sender.clone();
|
let sender_clone = self.save_logic_result_sender.clone();
|
||||||
if add_logic_nav::handle_add_logic_navigation(
|
if add_logic_nav::handle_add_logic_navigation(
|
||||||
key_event,
|
key_event,
|
||||||
config,
|
config,
|
||||||
app_state,
|
app_state,
|
||||||
add_logic_state,
|
|
||||||
&mut self.is_edit_mode,
|
&mut self.is_edit_mode,
|
||||||
buffer_state,
|
buffer_state,
|
||||||
client_clone,
|
client_clone,
|
||||||
sender_clone,
|
sender_clone,
|
||||||
&mut self.command_message,
|
&mut self.command_message,
|
||||||
|
router,
|
||||||
) {
|
) {
|
||||||
return Ok(EventOutcome::Ok(
|
return Ok(EventOutcome::Ok(
|
||||||
self.command_message.clone(),
|
self.command_message.clone(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let Page::AddTable(add_table_state) = &mut router.current {
|
if let Page::AddTable(add_table_state) = &mut router.current {
|
||||||
let client_clone = self.grpc_client.clone();
|
let client_clone = self.grpc_client.clone();
|
||||||
@@ -443,7 +441,7 @@ impl EventHandler {
|
|||||||
buffer_state,
|
buffer_state,
|
||||||
index,
|
index,
|
||||||
);
|
);
|
||||||
if let Page::Admin(admin_state) = &router.current {
|
if let Page::Admin(admin_state) = &mut router.current {
|
||||||
if !app_state
|
if !app_state
|
||||||
.profile_tree
|
.profile_tree
|
||||||
.profiles
|
.profiles
|
||||||
@@ -457,7 +455,7 @@ impl EventHandler {
|
|||||||
format!("Intro Option {} selected", index)
|
format!("Intro Option {} selected", index)
|
||||||
}
|
}
|
||||||
UiContext::Login => {
|
UiContext::Login => {
|
||||||
if let Page::Login(login_state) = &router.current {
|
if let Page::Login(login_state) = &mut router.current {
|
||||||
match index {
|
match index {
|
||||||
0 => login::initiate_login(
|
0 => login::initiate_login(
|
||||||
login_state,
|
login_state,
|
||||||
@@ -478,7 +476,7 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
UiContext::Register => {
|
UiContext::Register => {
|
||||||
if let Page::Register(register_state) = &router.current {
|
if let Page::Register(register_state) = &mut router.current {
|
||||||
match index {
|
match index {
|
||||||
0 => register::initiate_registration(
|
0 => register::initiate_registration(
|
||||||
register_state,
|
register_state,
|
||||||
@@ -807,7 +805,7 @@ impl EventHandler {
|
|||||||
) -> Result<EventOutcome> {
|
) -> Result<EventOutcome> {
|
||||||
match action {
|
match action {
|
||||||
"save" => {
|
"save" => {
|
||||||
if let Page::Login(login_state) = &router.current {
|
if let Page::Login(login_state) = &mut router.current {
|
||||||
let message = crate::tui::functions::common::login::save(
|
let message = crate::tui::functions::common::login::save(
|
||||||
auth_state,
|
auth_state,
|
||||||
login_state,
|
login_state,
|
||||||
@@ -844,7 +842,7 @@ impl EventHandler {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
"save_and_quit" => {
|
"save_and_quit" => {
|
||||||
let message = if let Page::Login(login_state) = &router.current {
|
let message = if let Page::Login(login_state) = &mut router.current {
|
||||||
crate::tui::functions::common::login::save(
|
crate::tui::functions::common::login::save(
|
||||||
auth_state,
|
auth_state,
|
||||||
login_state,
|
login_state,
|
||||||
@@ -873,10 +871,10 @@ impl EventHandler {
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
"revert" => {
|
"revert" => {
|
||||||
let message = if let Page::Login(login_state) = &router.current {
|
let message = if let Page::Login(login_state) = &mut router.current {
|
||||||
crate::tui::functions::common::login::revert(login_state, app_state)
|
crate::tui::functions::common::login::revert(login_state, app_state)
|
||||||
.await
|
.await
|
||||||
} else if let Page::Register(register_state) = &router.current {
|
} else if let Page::Register(register_state) = &mut router.current {
|
||||||
crate::tui::functions::common::register::revert(
|
crate::tui::functions::common::register::revert(
|
||||||
register_state,
|
register_state,
|
||||||
app_state,
|
app_state,
|
||||||
|
|||||||
Reference in New Issue
Block a user