trying to do the count
This commit is contained in:
@@ -16,6 +16,8 @@ pub fn render_form(
|
|||||||
inputs: &[&String],
|
inputs: &[&String],
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool,
|
||||||
|
total_count: u64, // Add total count
|
||||||
|
current_id: u64, // Add current ID
|
||||||
) {
|
) {
|
||||||
// Create Adresar card
|
// Create Adresar card
|
||||||
let adresar_card = Block::default()
|
let adresar_card = Block::default()
|
||||||
@@ -60,10 +62,29 @@ pub fn render_form(
|
|||||||
|
|
||||||
// Input area inside borders
|
// Input area inside borders
|
||||||
let input_area = input_container.inner(input_container_area);
|
let input_area = input_container.inner(input_container_area);
|
||||||
|
|
||||||
|
// Add a new layout for the count and ID display
|
||||||
|
let count_id_layout = Layout::default()
|
||||||
|
.direction(Direction::Vertical)
|
||||||
|
.constraints([
|
||||||
|
Constraint::Length(1), // For count and ID
|
||||||
|
Constraint::Min(1), // For the rest of the form
|
||||||
|
])
|
||||||
|
.split(input_area);
|
||||||
|
|
||||||
|
// Render the count and ID
|
||||||
|
let count_id_text = format!("Total: {} | Current ID: {}", total_count, current_id);
|
||||||
|
let count_id_paragraph = Paragraph::new(count_id_text)
|
||||||
|
.style(Style::default().fg(theme.fg))
|
||||||
|
.alignment(Alignment::Left);
|
||||||
|
|
||||||
|
f.render_widget(count_id_paragraph, count_id_layout[0]);
|
||||||
|
|
||||||
|
// Split the remaining area for the form inputs
|
||||||
let input_rows = Layout::default()
|
let input_rows = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints(vec![Constraint::Length(1); fields.len()])
|
.constraints(vec![Constraint::Length(1); fields.len()])
|
||||||
.split(input_area);
|
.split(count_id_layout[1]);
|
||||||
|
|
||||||
// Render labels close to the border
|
// Render labels close to the border
|
||||||
for (i, field) in fields.iter().enumerate() {
|
for (i, field) in fields.iter().enumerate() {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use std::io::{self, stdout};
|
|||||||
use tonic::transport::Channel;
|
use tonic::transport::Channel;
|
||||||
use crate::proto::multieko2::adresar_client::AdresarClient;
|
use crate::proto::multieko2::adresar_client::AdresarClient;
|
||||||
use crate::client::config::Config;
|
use crate::client::config::Config;
|
||||||
|
use crate::proto::multieko2::{Empty, CountResponse, PositionRequest, AdresarResponse};
|
||||||
use crate::proto::multieko2::PostAdresarRequest;
|
use crate::proto::multieko2::PostAdresarRequest;
|
||||||
|
|
||||||
pub struct AppTerminal {
|
pub struct AppTerminal {
|
||||||
@@ -83,4 +84,18 @@ impl AppTerminal {
|
|||||||
_ => Ok((false, format!("Action not recognized: {}", action))),
|
_ => Ok((false, format!("Action not recognized: {}", action))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a method to get the total count of Adresar entries
|
||||||
|
pub async fn get_adresar_count(&self) -> Result<u64, Box<dyn std::error::Error>> {
|
||||||
|
let request = tonic::Request::new(Empty {});
|
||||||
|
let response: CountResponse = self.grpc_client.get_adresar_count(request).await?.into_inner();
|
||||||
|
Ok(response.count as u64)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a method to get an Adresar entry by its position
|
||||||
|
pub async fn get_adresar_by_position(&self, position: u64) -> Result<AdresarResponse, Box<dyn std::error::Error>> {
|
||||||
|
let request = tonic::Request::new(PositionRequest { position: position as i64 });
|
||||||
|
let response: AdresarResponse = self.grpc_client.get_adresar_by_position(request).await?.into_inner();
|
||||||
|
Ok(response)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use ratatui::layout::{Constraint, Direction, Layout};
|
|||||||
use std::env;
|
use std::env;
|
||||||
use crate::proto::multieko2::PostAdresarRequest;
|
use crate::proto::multieko2::PostAdresarRequest;
|
||||||
|
|
||||||
|
|
||||||
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let config = Config::load()?;
|
let config = Config::load()?;
|
||||||
let mut app_terminal = AppTerminal::new().await?;
|
let mut app_terminal = AppTerminal::new().await?;
|
||||||
@@ -51,6 +52,14 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let mut is_edit_mode = false;
|
let mut is_edit_mode = false;
|
||||||
let mut edit_mode_cooldown = false;
|
let mut edit_mode_cooldown = false;
|
||||||
|
|
||||||
|
// Fetch the total count of Adresar entries
|
||||||
|
let total_count = app_terminal.get_adresar_count().await?;
|
||||||
|
|
||||||
|
// Fetch the current Adresar entry by position (e.g., position 1)
|
||||||
|
let current_position = 1; // You can change this dynamically based on user input
|
||||||
|
let current_adresar = app_terminal.get_adresar_by_position(current_position).await?;
|
||||||
|
let current_id = current_adresar.id as u64;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
app_terminal.draw(|f| {
|
app_terminal.draw(|f| {
|
||||||
let root = Layout::default()
|
let root = Layout::default()
|
||||||
@@ -80,6 +89,8 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
],
|
],
|
||||||
&theme,
|
&theme,
|
||||||
is_edit_mode,
|
is_edit_mode,
|
||||||
|
total_count, // Pass total count
|
||||||
|
current_id, // Pass current ID
|
||||||
);
|
);
|
||||||
|
|
||||||
// Right panel - Preview Card
|
// Right panel - Preview Card
|
||||||
@@ -99,7 +110,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
render_command_line(f, root[2], &command_input, command_mode, &theme, &command_message);
|
render_command_line(f, root[2], &command_input, command_mode, &theme, &command_message);
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Event handling
|
// Event handling (unchanged)
|
||||||
if let Event::Key(key) = app_terminal.read_event()? {
|
if let Event::Key(key) = app_terminal.read_event()? {
|
||||||
// Handle enter/edit mode keys
|
// Handle enter/edit mode keys
|
||||||
if !is_edit_mode && config.is_enter_edit_mode(key.code, key.modifiers) {
|
if !is_edit_mode && config.is_enter_edit_mode(key.code, key.modifiers) {
|
||||||
|
|||||||
Reference in New Issue
Block a user