Compare commits

..

4 Commits

Author SHA1 Message Date
filipriec
060cff3f0f compiled 2025-03-31 17:10:51 +02:00
filipriec
07c48985e4 proper pass of the arguments 2025-03-31 16:25:11 +02:00
filipriec
3d266c2ad0 switching of the views done 2025-03-31 16:23:25 +02:00
filipriec
e2c326bf1e login gRPC 2025-03-31 16:16:07 +02:00
4 changed files with 49 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ use crate::tui::terminal::core::TerminalCore;
use crate::state::pages::{form::FormState, auth::AuthState}; use crate::state::pages::{form::FormState, auth::AuthState};
use crate::state::state::AppState; use crate::state::state::AppState;
use crate::services::grpc_client::GrpcClient; use crate::services::grpc_client::GrpcClient;
use crate::services::auth::AuthClient;
use crate::tui::functions::common::{ use crate::tui::functions::common::{
form::{save as form_save, revert}, form::{save as form_save, revert},
login::{save as login_save, cancel} login::{save as login_save, cancel}
@@ -14,6 +15,7 @@ pub async fn handle_core_action(
form_state: &mut FormState, form_state: &mut FormState,
auth_state: &mut AuthState, auth_state: &mut AuthState,
grpc_client: &mut GrpcClient, grpc_client: &mut GrpcClient,
auth_client: &mut AuthClient,
terminal: &mut TerminalCore, terminal: &mut TerminalCore,
app_state: &mut AppState, app_state: &mut AppState,
current_position: &mut u64, current_position: &mut u64,
@@ -22,7 +24,7 @@ pub async fn handle_core_action(
match action { match action {
"save" => { "save" => {
if app_state.ui.show_login { if app_state.ui.show_login {
let message = login_save(auth_state, grpc_client).await?; let message = login_save(auth_state, auth_client, app_state).await?;
Ok((false, message)) Ok((false, message))
} else { } else {
let message = form_save( let message = form_save(
@@ -41,7 +43,7 @@ pub async fn handle_core_action(
}, },
"save_and_quit" => { "save_and_quit" => {
let message = if app_state.ui.show_login { let message = if app_state.ui.show_login {
login_save(auth_state, grpc_client).await? login_save(auth_state, auth_client, app_state).await?
} else { } else {
form_save( form_save(
form_state, form_state,
@@ -56,7 +58,7 @@ pub async fn handle_core_action(
}, },
"revert" => { "revert" => {
if app_state.ui.show_login { if app_state.ui.show_login {
let message = cancel(auth_state).await; let message = cancel(auth_state, app_state).await;
Ok((false, message)) Ok((false, message))
} else { } else {
let message = revert( let message = revert(

View File

@@ -5,6 +5,7 @@ use crate::tui::terminal::{
core::TerminalCore, core::TerminalCore,
}; };
use crate::services::grpc_client::GrpcClient; use crate::services::grpc_client::GrpcClient;
use crate::services::auth::AuthClient;
use crate::tui::functions::common::commands::CommandHandler; use crate::tui::functions::common::commands::CommandHandler;
use crate::config::binds::config::Config; use crate::config::binds::config::Config;
use crate::state::pages::form::FormState; use crate::state::pages::form::FormState;
@@ -27,11 +28,12 @@ pub struct EventHandler {
pub ideal_cursor_column: usize, pub ideal_cursor_column: usize,
pub key_sequence_tracker: KeySequenceTracker, pub key_sequence_tracker: KeySequenceTracker,
pub auth_state: AuthState, pub auth_state: AuthState,
pub auth_client: AuthClient,
} }
impl EventHandler { impl EventHandler {
pub fn new() -> Self { pub async fn new() -> Result<Self, Box<dyn std::error::Error>> {
EventHandler { Ok(EventHandler {
command_mode: false, command_mode: false,
command_input: String::new(), command_input: String::new(),
command_message: String::new(), command_message: String::new(),
@@ -40,7 +42,8 @@ impl EventHandler {
ideal_cursor_column: 0, ideal_cursor_column: 0,
key_sequence_tracker: KeySequenceTracker::new(800), key_sequence_tracker: KeySequenceTracker::new(800),
auth_state: AuthState::new(), auth_state: AuthState::new(),
} auth_client: AuthClient::new().await?,
})
} }
pub async fn handle_event( pub async fn handle_event(
@@ -133,6 +136,7 @@ impl EventHandler {
form_state, form_state,
&mut self.auth_state, &mut self.auth_state,
grpc_client, grpc_client,
&mut self.auth_client,
terminal, terminal,
app_state, app_state,
current_position, current_position,
@@ -194,6 +198,7 @@ impl EventHandler {
form_state, form_state,
&mut self.auth_state, &mut self.auth_state,
grpc_client, grpc_client,
&mut self.auth_client,
terminal, terminal,
app_state, app_state,
current_position, current_position,

View File

@@ -1,18 +1,45 @@
// src/tui/functions/common/login.rs // src/tui/functions/common/login.rs
use crate::services::auth::AuthClient;
use crate::state::pages::auth::AuthState; use crate::state::pages::auth::AuthState;
use crate::services::grpc_client::GrpcClient; use crate::state::state::AppState;
pub async fn save( pub async fn save(
auth_state: &mut AuthState, auth_state: &mut AuthState,
grpc_client: &mut GrpcClient, auth_client: &mut AuthClient,
app_state: &mut AppState,
) -> Result<String, Box<dyn std::error::Error>> { ) -> Result<String, Box<dyn std::error::Error>> {
// Implement your login-specific save logic here let identifier = auth_state.username.clone();
Ok("Login credentials saved - not implemented yet".to_string()) let password = auth_state.password.clone();
match auth_client.login(identifier, password).await {
Ok(response) => {
auth_state.auth_token = Some(response.access_token);
auth_state.user_id = Some(response.user_id);
auth_state.role = Some(response.role);
auth_state.error_message = None;
// Update app state to show main interface
app_state.ui.show_login = false;
app_state.ui.show_form = true;
Ok("Login successful!".to_string())
}
Err(e) => {
let error_message = format!("Login failed: {}", e);
auth_state.error_message = Some(error_message.clone());
Ok(error_message)
}
}
} }
pub async fn cancel( pub async fn cancel(
auth_state: &mut AuthState, auth_state: &mut AuthState,
app_state: &mut AppState,
) -> String { ) -> String {
"Login credentials canceled - not implemented yet".to_string() auth_state.username.clear();
auth_state.password.clear();
auth_state.error_message = None;
app_state.ui.show_login = false;
app_state.ui.show_intro = true;
"Login canceled".to_string()
} }

View File

@@ -2,6 +2,7 @@
use crate::tui::terminal::TerminalCore; use crate::tui::terminal::TerminalCore;
use crate::services::grpc_client::GrpcClient; use crate::services::grpc_client::GrpcClient;
use crate::services::auth::AuthClient;
use crate::services::ui_service::UiService; // Add this import use crate::services::ui_service::UiService; // Add this import
use crate::tui::terminal::EventReader; use crate::tui::terminal::EventReader;
use crate::tui::functions::common::CommandHandler; use crate::tui::functions::common::CommandHandler;
@@ -17,6 +18,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load()?; let config = Config::load()?;
let mut terminal = TerminalCore::new()?; let mut terminal = TerminalCore::new()?;
let mut grpc_client = GrpcClient::new().await?; let mut grpc_client = GrpcClient::new().await?;
let mut auth_client = AuthClient::new().await?;
let mut command_handler = CommandHandler::new(); let mut command_handler = CommandHandler::new();
let theme = Theme::from_str(&config.colors.theme); let theme = Theme::from_str(&config.colors.theme);
let mut auth_state = AuthState::default(); let mut auth_state = AuthState::default();
@@ -31,7 +33,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let mut form_state = FormState::new(column_names); let mut form_state = FormState::new(column_names);
// The rest of your UI initialization remains the same // The rest of your UI initialization remains the same
let mut event_handler = EventHandler::new(); let mut event_handler = EventHandler::new().await?;
let event_reader = EventReader::new(); let event_reader = EventReader::new();
// Fetch the total count of Adresar entries // Fetch the total count of Adresar entries