forms page moved more2
This commit is contained in:
@@ -6,7 +6,7 @@ use crate::state::app::state::AppState;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::services::auth::AuthClient;
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
use crate::tui::functions::common::form::SaveOutcome;
|
||||
crate::pages::forms::logic::SaveOutcome;
|
||||
use anyhow::{Context, Result};
|
||||
use crate::tui::functions::common::{
|
||||
form::{save as form_save, revert as form_revert},
|
||||
|
||||
@@ -6,9 +6,8 @@ use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::modes::common::commands::CommandHandler;
|
||||
use crate::tui::terminal::core::TerminalCore;
|
||||
use crate::tui::functions::common::form::{save, revert};
|
||||
use crate::pages::forms::logic::{save, revert ,SaveOutcome};
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
use crate::tui::functions::common::form::SaveOutcome;
|
||||
use crate::pages::routing::{Router, Page};
|
||||
use anyhow::Result;
|
||||
|
||||
|
||||
@@ -29,13 +29,14 @@ use crate::state::{
|
||||
intro::IntroState,
|
||||
},
|
||||
};
|
||||
use crate::tui::common::{register, login};
|
||||
use crate::pages::routing::{Router, Page};
|
||||
use crate::pages::forms::FormState;
|
||||
use crate::pages::forms::logic::{save, revert, SaveOutcome};
|
||||
use crate::search::state::SearchState;
|
||||
use crate::tui::functions::common::login::LoginResult;
|
||||
use crate::tui::functions::common::register::RegisterResult;
|
||||
use crate::tui::{
|
||||
functions::common::{form::SaveOutcome, login, register},
|
||||
terminal::core::TerminalCore,
|
||||
{admin, intro},
|
||||
};
|
||||
@@ -816,7 +817,7 @@ impl EventHandler {
|
||||
Ok(EventOutcome::Ok(message))
|
||||
} else {
|
||||
let save_outcome = if let Page::Form(_) = &router.current {
|
||||
crate::tui::functions::common::form::save(
|
||||
save(
|
||||
app_state,
|
||||
&mut self.grpc_client,
|
||||
)
|
||||
@@ -851,7 +852,7 @@ impl EventHandler {
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
let save_outcome = crate::tui::functions::common::form::save(
|
||||
let save_outcome = save(
|
||||
app_state,
|
||||
&mut self.grpc_client,
|
||||
).await?;
|
||||
@@ -882,7 +883,7 @@ impl EventHandler {
|
||||
.await
|
||||
} else {
|
||||
if let Page::Form(_) = &router.current {
|
||||
crate::tui::functions::common::form::revert(
|
||||
revert(
|
||||
app_state,
|
||||
&mut self.grpc_client,
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// src/tui/functions/common/form.rs
|
||||
// src/pages/forms/logic.rs
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::pages::forms::FormState;
|
||||
use crate::utils::data_converter;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use std::collections::HashMap;
|
||||
@@ -21,7 +22,6 @@ pub async fn save(
|
||||
return Ok(SaveOutcome::NoChange);
|
||||
}
|
||||
|
||||
// Copy out what we need before dropping the mutable borrow
|
||||
let profile_name = fs.profile_name.clone();
|
||||
let table_name = fs.table_name.clone();
|
||||
let fields = fs.fields.clone();
|
||||
@@ -146,3 +146,37 @@ pub async fn revert(
|
||||
Ok("Nothing to revert".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn handle_action(
|
||||
action: &str,
|
||||
form_state: &mut FormState,
|
||||
_grpc_client: &mut GrpcClient,
|
||||
ideal_cursor_column: &mut usize,
|
||||
) -> Result<String> {
|
||||
if form_state.has_unsaved_changes() {
|
||||
return Ok(
|
||||
"Unsaved changes. Save (Ctrl+S) or Revert (Ctrl+R) before navigating."
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
let total_count = form_state.total_count;
|
||||
|
||||
match action {
|
||||
"previous_entry" => {
|
||||
if form_state.current_position > 1 {
|
||||
form_state.current_position -= 1;
|
||||
*ideal_cursor_column = 0;
|
||||
}
|
||||
}
|
||||
"next_entry" => {
|
||||
if form_state.current_position <= total_count {
|
||||
form_state.current_position += 1;
|
||||
*ideal_cursor_column = 0;
|
||||
}
|
||||
}
|
||||
_ => return Err(anyhow!("Unknown form action: {}", action)),
|
||||
}
|
||||
|
||||
Ok(String::new())
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
pub mod ui;
|
||||
pub mod state;
|
||||
pub mod logic;
|
||||
|
||||
pub use ui::*;
|
||||
pub use state::*;
|
||||
pub use logic::*;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::add_logic::AddLogicState;
|
||||
use crate::tui::functions::common::form::SaveOutcome;
|
||||
use crate::pages::forms::logic::SaveOutcome;
|
||||
use crate::utils::columns::filter_user_columns;
|
||||
use crate::pages::forms::{FieldDefinition, FormState};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
pub mod admin;
|
||||
pub mod intro;
|
||||
pub mod login;
|
||||
pub mod form;
|
||||
pub mod common;
|
||||
|
||||
pub use admin::*;
|
||||
pub use intro::*;
|
||||
pub use form::*;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// src/tui/functions/common.rs
|
||||
|
||||
pub mod form;
|
||||
pub mod login;
|
||||
pub mod logout;
|
||||
pub mod register;
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
// src/tui/functions/form.rs
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::pages::forms::FormState;
|
||||
use anyhow::{anyhow, Result};
|
||||
|
||||
pub async fn handle_action(
|
||||
action: &str,
|
||||
form_state: &mut FormState,
|
||||
_grpc_client: &mut GrpcClient,
|
||||
ideal_cursor_column: &mut usize,
|
||||
) -> Result<String> {
|
||||
if form_state.has_unsaved_changes() {
|
||||
return Ok(
|
||||
"Unsaved changes. Save (Ctrl+S) or Revert (Ctrl+R) before navigating."
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
let total_count = form_state.total_count;
|
||||
|
||||
match action {
|
||||
"previous_entry" => {
|
||||
// Only decrement if the current position is greater than the first record.
|
||||
// This prevents wrapping from 1 to total_count.
|
||||
// It also correctly handles moving from "New Entry" (total_count + 1) to the last record.
|
||||
if form_state.current_position > 1 {
|
||||
form_state.current_position -= 1;
|
||||
*ideal_cursor_column = 0;
|
||||
}
|
||||
}
|
||||
"next_entry" => {
|
||||
// Only increment if the current position is not yet at the "New Entry" stage.
|
||||
// The "New Entry" position is total_count + 1.
|
||||
// This allows moving from the last record to "New Entry", but stops there.
|
||||
if form_state.current_position <= total_count {
|
||||
form_state.current_position += 1;
|
||||
*ideal_cursor_column = 0;
|
||||
}
|
||||
}
|
||||
_ => return Err(anyhow!("Unknown form action: {}", action)),
|
||||
}
|
||||
|
||||
Ok(String::new())
|
||||
}
|
||||
Reference in New Issue
Block a user