Compare commits

...

10 Commits

Author SHA1 Message Date
filipriec
b408abe8c6 quick prod check .sqlx 2025-03-26 00:50:25 +01:00
filipriec
722c63af54 fixed the navigation previous function, therefore we are now moving into the login properly, lets implement the auth now 2025-03-26 00:46:59 +01:00
filipriec
4601ba4094 unused stuff removed 2025-03-26 00:43:42 +01:00
filipriec
3e2b8a36df fixing warnings 2025-03-26 00:39:27 +01:00
filipriec
11214734ae functions are now in the file dedicated to the functions belonging to the page 2025-03-26 00:26:36 +01:00
filipriec
92045a4e67 unused stuff 2025-03-26 00:16:38 +01:00
filipriec
9564bd8524 login page is now being properly displayed 2025-03-26 00:04:30 +01:00
filipriec
ad64df2ec3 nothing is fixed, it doesnt work, i cant see a login page 2025-03-25 23:23:47 +01:00
filipriec
aab11c1cba login logic in the components 2025-03-25 22:56:24 +01:00
filipriec
1fe139e0c5 we compiled 2025-03-25 22:01:09 +01:00
23 changed files with 267 additions and 197 deletions

View File

@@ -4,3 +4,5 @@ RUST_DB_USER=multi_psql_dev
RUST_DB_PASSWORD=3 RUST_DB_PASSWORD=3
RUST_DB_HOST=localhost RUST_DB_HOST=localhost
RUST_DB_PORT=5432 RUST_DB_PORT=5432
JWT_SECRET=<YOUR-JWT-HERE>

6
Cargo.lock generated
View File

@@ -421,7 +421,7 @@ dependencies = [
[[package]] [[package]]
name = "client" name = "client"
version = "0.2.0" version = "0.2.5"
dependencies = [ dependencies = [
"common", "common",
"crossterm", "crossterm",
@@ -457,7 +457,7 @@ dependencies = [
[[package]] [[package]]
name = "common" name = "common"
version = "0.2.0" version = "0.2.5"
dependencies = [ dependencies = [
"prost", "prost",
"serde", "serde",
@@ -2588,7 +2588,7 @@ dependencies = [
[[package]] [[package]]
name = "server" name = "server"
version = "0.2.0" version = "0.2.5"
dependencies = [ dependencies = [
"bcrypt", "bcrypt",
"chrono", "chrono",

View File

@@ -5,7 +5,7 @@ resolver = "2"
[workspace.package] [workspace.package]
# TODO: idk how to do the name, fix later # TODO: idk how to do the name, fix later
# name = "Multieko2" # name = "Multieko2"
version = "0.2.0" version = "0.2.5"
edition = "2021" edition = "2021"
license = "GPL-3.0-or-later" license = "GPL-3.0-or-later"
authors = ["Filip Priečinský <filippriec@gmail.com>"] authors = ["Filip Priečinský <filippriec@gmail.com>"]

View File

@@ -3,4 +3,3 @@ pub mod login;
pub mod register; pub mod register;
pub use login::*; pub use login::*;
pub use register::*;

View File

@@ -1,111 +1,58 @@
// src/components/login/login.rs // src/components/auth/login.rs
use ratatui::{ use ratatui::{
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
style::Style,
text::{Line, Span, Text},
layout::{Alignment, Constraint, Direction, Layout, Rect}, layout::{Alignment, Constraint, Direction, Layout, Rect},
style::Style,
widgets::{Block, BorderType, Borders, Paragraph},
Frame, Frame,
}; };
use crate::config::colors::themes::Theme; use crate::{
config::colors::themes::Theme,
state::pages::auth::AuthState
};
pub struct LoginState { pub fn render_login(f: &mut Frame, area: Rect, theme: &Theme, state: &mut AuthState) {
pub fields: Vec<String>, let block = Block::default()
pub values: Vec<String>, .borders(Borders::ALL)
pub selected_field: usize, .border_type(BorderType::Rounded)
} .border_style(Style::default().fg(theme.accent))
.style(Style::default().bg(theme.bg))
impl LoginState { .title(" Login ");
pub fn new() -> Self {
Self { let inner_area = block.inner(area);
fields: vec!["Username".to_string(), "Password".to_string()], f.render_widget(block, area);
values: vec![String::new(), String::new()],
selected_field: 0, let chunks = Layout::default()
} .direction(Direction::Vertical)
} .constraints([
Constraint::Percentage(40),
pub fn next_field(&mut self) { Constraint::Length(3),
self.selected_field = (self.selected_field + 1) % self.fields.len(); Constraint::Percentage(40),
} ])
.split(inner_area);
pub fn previous_field(&mut self) {
self.selected_field = if self.selected_field == 0 { let button_style = if state.return_selected {
self.fields.len() - 1 Style::default()
} else { .fg(theme.highlight)
self.selected_field - 1 .add_modifier(ratatui::style::Modifier::BOLD)
}; } else {
} Style::default().fg(theme.fg)
};
pub fn render(&mut self, f: &mut Frame, area: Rect, theme: &Theme) {
let block = Block::default() f.render_widget(
.borders(Borders::ALL) Paragraph::new("Return to Intro")
.border_type(BorderType::Rounded) .style(button_style)
.border_style(Style::default().fg(theme.accent)) .alignment(Alignment::Center)
.style(Style::default().bg(theme.bg)); .block(
Block::default()
let inner_area = block.inner(area); .borders(Borders::ALL)
f.render_widget(block, area); .border_type(BorderType::Plain)
.border_style(if state.return_selected {
let chunks = Layout::default() Style::default().fg(theme.accent)
.direction(Direction::Vertical) } else {
.constraints([ Style::default().fg(theme.border)
Constraint::Length(3), }),
Constraint::Length(5), ),
Constraint::Min(1), chunks[1]
]) );
.split(inner_area);
// Title
let title = Line::from(Span::styled("Login", Style::default().fg(theme.highlight)));
let title_widget = Paragraph::new(title).alignment(Alignment::Center);
f.render_widget(title_widget, chunks[0]);
// Login form
let form_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(3),
Constraint::Length(3),
Constraint::Length(3),
])
.split(chunks[1]);
// Username field
let username_block = Block::default()
.title("Username")
.borders(Borders::ALL)
.border_style(if self.selected_field == 0 {
Style::default().fg(theme.highlight)
} else {
Style::default().fg(theme.border)
});
let username = Paragraph::new(self.values[0].as_str())
.block(username_block);
f.render_widget(username, form_chunks[0]);
// Password field
let password_block = Block::default()
.title("Password")
.borders(Borders::ALL)
.border_style(if self.selected_field == 1 {
Style::default().fg(theme.highlight)
} else {
Style::default().fg(theme.border)
});
let password = Paragraph::new("*".repeat(self.values[1].len()))
.block(password_block);
f.render_widget(password, form_chunks[1]);
// Submit button
let submit_block = Block::default()
.borders(Borders::ALL)
.border_style(if self.selected_field == 2 {
Style::default().fg(theme.highlight)
} else {
Style::default().fg(theme.border)
});
let submit = Paragraph::new("Submit")
.block(submit_block)
.alignment(Alignment::Center);
f.render_widget(submit, form_chunks[2]);
}
} }

View File

@@ -118,16 +118,4 @@ impl IntroState {
pub fn previous_option(&mut self) { pub fn previous_option(&mut self) {
self.selected_option = if self.selected_option == 0 { 2 } else { self.selected_option - 1 }; self.selected_option = if self.selected_option == 0 { 2 } else { self.selected_option - 1 };
} }
pub fn handle_selection(&self, app_state: &mut crate::state::state::AppState) {
match self.selected_option {
0 => { /* Continue logic */ }
1 => { /* Admin logic */ }
2 => {
app_state.ui.show_intro = false;
app_state.ui.show_login = true;
}
_ => {}
}
}
} }

View File

@@ -1,10 +1,8 @@
// src/modes/canvas/common.rs // src/modes/canvas/common.rs
use crossterm::event::{KeyEvent};
use crate::config::binds::config::Config; use crate::config::binds::config::Config;
use crate::tui::terminal::grpc_client::GrpcClient; use crate::tui::terminal::grpc_client::GrpcClient;
use crate::tui::terminal::core::TerminalCore; use crate::tui::terminal::core::TerminalCore;
use crate::tui::controls::commands::CommandHandler;
use crate::state::pages::form::FormState; use crate::state::pages::form::FormState;
use crate::state::state::AppState; use crate::state::state::AppState;
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest}; use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
@@ -14,7 +12,6 @@ pub async fn handle_core_action(
action: &str, action: &str,
form_state: &mut FormState, form_state: &mut FormState,
grpc_client: &mut GrpcClient, grpc_client: &mut GrpcClient,
command_handler: &mut CommandHandler,
terminal: &mut TerminalCore, terminal: &mut TerminalCore,
app_state: &mut AppState, app_state: &mut AppState,
current_position: &mut u64, current_position: &mut u64,

View File

@@ -4,6 +4,7 @@ use crossterm::event::KeyEvent;
use crate::config::binds::config::Config; use crate::config::binds::config::Config;
use crate::state::state::AppState; use crate::state::state::AppState;
use crate::state::pages::form::FormState; use crate::state::pages::form::FormState;
use crate::tui::functions::{intro, admin};
pub async fn handle_navigation_event( pub async fn handle_navigation_event(
key: KeyEvent, key: KeyEvent,
@@ -21,16 +22,11 @@ pub async fn handle_navigation_event(
return Ok((false, String::new())); return Ok((false, String::new()));
} }
"move_down" => { "move_down" => {
let item_count = if app_state.ui.show_intro { move_down(app_state);
2 // Intro options count
} else {
app_state.profile_tree.profiles.len() // Admin panel items
};
move_down(app_state, item_count);
return Ok((false, String::new())); return Ok((false, String::new()));
} }
"next_option" => { "next_option" => {
next_option(app_state, 2); // Intro has 2 options next_option(app_state); // Intro has 2 options
return Ok((false, String::new())); return Ok((false, String::new()));
} }
"previous_option" => { "previous_option" => {
@@ -84,7 +80,7 @@ pub fn move_up(app_state: &mut AppState) {
} }
} }
pub fn move_down(app_state: &mut AppState, item_count: usize) { pub fn move_down(app_state: &mut AppState) {
if app_state.ui.show_intro { if app_state.ui.show_intro {
app_state.ui.intro_state.next_option(); app_state.ui.intro_state.next_option();
} else if app_state.ui.show_admin { } else if app_state.ui.show_admin {
@@ -98,11 +94,12 @@ pub fn move_down(app_state: &mut AppState, item_count: usize) {
} }
} }
pub fn next_option(app_state: &mut AppState, option_count: usize) { pub fn next_option(app_state: &mut AppState) { // Remove option_count parameter
if app_state.ui.show_intro { if app_state.ui.show_intro {
app_state.ui.intro_state.next_option(); app_state.ui.intro_state.next_option();
} else { } else {
// For other screens that might have options // Get option count from state instead of parameter
let option_count = app_state.profile_tree.profiles.len();
app_state.general.current_option = (app_state.general.current_option + 1) % option_count; app_state.general.current_option = (app_state.general.current_option + 1) % option_count;
} }
} }
@@ -111,36 +108,20 @@ pub fn previous_option(app_state: &mut AppState) {
if app_state.ui.show_intro { if app_state.ui.show_intro {
app_state.ui.intro_state.previous_option(); app_state.ui.intro_state.previous_option();
} else { } else {
// For other screens that might have options let option_count = app_state.profile_tree.profiles.len();
if app_state.general.current_option == 0 { app_state.general.current_option = if app_state.general.current_option == 0 {
// We'd need the option count here, but since it's not passed we can't wrap around correctly option_count.saturating_sub(1) // Wrap to last option
// For now, just stay at 0
} else { } else {
app_state.general.current_option -= 1; app_state.general.current_option - 1
} };
} }
} }
pub fn select(app_state: &mut AppState) { pub fn select(app_state: &mut AppState) {
if app_state.ui.show_intro { if app_state.ui.show_intro {
// Handle selection in intro screen intro::handle_intro_selection(app_state);
if app_state.ui.intro_state.selected_option == 0 {
// First option selected - show form
app_state.ui.show_form = true;
app_state.ui.show_admin = false;
} else {
// Second option selected - show admin
app_state.ui.show_form = false;
app_state.ui.show_admin = true;
}
app_state.ui.show_intro = false;
} else if app_state.ui.show_admin { } else if app_state.ui.show_admin {
// Handle selection in admin panel admin::handle_admin_selection(app_state);
let profiles = &app_state.profile_tree.profiles;
if !profiles.is_empty() && app_state.general.selected_item < profiles.len() {
// Set the selected profile
app_state.selected_profile = Some(profiles[app_state.general.selected_item].name.clone());
}
} }
} }

View File

@@ -1,5 +1,5 @@
// src/modes/handlers/event.rs // src/modes/handlers/event.rs
use crossterm::event::{Event, KeyEvent}; use crossterm::event::Event;
use crossterm::cursor::SetCursorStyle; use crossterm::cursor::SetCursorStyle;
use crate::tui::terminal::{ use crate::tui::terminal::{
core::TerminalCore, core::TerminalCore,
@@ -129,7 +129,6 @@ impl EventHandler {
action, action,
form_state, form_state,
grpc_client, grpc_client,
command_handler,
terminal, terminal,
app_state, app_state,
current_position, current_position,
@@ -188,7 +187,6 @@ impl EventHandler {
action, action,
form_state, form_state,
grpc_client, grpc_client,
command_handler,
terminal, terminal,
app_state, app_state,
current_position, current_position,

View File

@@ -1,3 +1,4 @@
// src/state/pages.rs // src/state/pages.rs
pub mod form; pub mod form;
pub mod auth;

View File

@@ -0,0 +1,20 @@
// src/state/pages/auth.rs
#[derive(Default)]
pub struct AuthState {
pub return_selected: bool,
pub username: String,
pub password: String,
pub error_message: Option<String>,
}
impl AuthState {
pub fn new() -> Self {
Self {
return_selected: false,
username: String::new(),
password: String::new(),
error_message: None,
}
}
}

View File

@@ -0,0 +1,7 @@
// src/tui/functions.rs
pub mod admin;
pub mod intro;
pub use admin::*;
pub use intro::*;

View File

@@ -0,0 +1,8 @@
use crate::state::state::AppState;
pub fn handle_admin_selection(app_state: &mut AppState) {
let profiles = &app_state.profile_tree.profiles;
if !profiles.is_empty() && app_state.general.selected_item < profiles.len() {
app_state.selected_profile = Some(profiles[app_state.general.selected_item].name.clone());
}
}

View File

@@ -0,0 +1,23 @@
use crate::state::state::AppState;
pub fn handle_intro_selection(app_state: &mut AppState) {
match app_state.ui.intro_state.selected_option {
0 => { // Continue
app_state.ui.show_form = true;
app_state.ui.show_admin = false;
app_state.ui.show_login = false;
}
1 => { // Admin
app_state.ui.show_form = false;
app_state.ui.show_admin = true;
app_state.ui.show_login = false;
}
2 => { // Login
app_state.ui.show_form = false;
app_state.ui.show_admin = false;
app_state.ui.show_login = true;
}
_ => {}
}
app_state.ui.show_intro = false;
}

View File

@@ -1,4 +1,5 @@
// src/tui/mod.rs // src/tui/mod.rs
pub mod terminal; pub mod terminal;
pub mod controls; pub mod controls;
pub mod functions;

View File

@@ -6,18 +6,20 @@ use crate::components::{
render_status_line, render_status_line,
handlers::sidebar::{self, calculate_sidebar_layout}, handlers::sidebar::{self, calculate_sidebar_layout},
form::form::render_form, form::form::render_form,
intro::{intro},
admin::{admin_panel::AdminPanelState}, admin::{admin_panel::AdminPanelState},
auth::login::render_login,
}; };
use crate::config::colors::themes::Theme; use crate::config::colors::themes::Theme;
use ratatui::layout::{Constraint, Direction, Layout}; use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::Frame; use ratatui::Frame;
use crate::state::pages::form::FormState; use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::state::state::AppState; use crate::state::state::AppState;
pub fn render_ui( pub fn render_ui(
f: &mut Frame, f: &mut Frame,
form_state: &mut FormState, form_state: &mut FormState,
auth_state: &mut AuthState,
theme: &Theme, theme: &Theme,
is_edit_mode: bool, is_edit_mode: bool,
total_count: u64, total_count: u64,
@@ -44,6 +46,8 @@ pub fn render_ui(
if app_state.ui.show_intro { if app_state.ui.show_intro {
// Use app_state's intro_state directly // Use app_state's intro_state directly
app_state.ui.intro_state.render(f, main_content_area, theme); app_state.ui.intro_state.render(f, main_content_area, theme);
}else if app_state.ui.show_login {
render_login(f, main_content_area, theme, auth_state);
} else if app_state.ui.show_admin { } else if app_state.ui.show_admin {
// Create temporary AdminPanelState for rendering // Create temporary AdminPanelState for rendering
let mut admin_state = AdminPanelState::new( let mut admin_state = AdminPanelState::new(

View File

@@ -8,10 +8,9 @@ use crate::config::colors::themes::Theme;
use crate::config::binds::config::Config; use crate::config::binds::config::Config;
use crate::ui::handlers::render::render_ui; use crate::ui::handlers::render::render_ui;
use crate::state::pages::form::FormState; use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::modes::handlers::event::EventHandler; use crate::modes::handlers::event::EventHandler;
use crate::state::state::AppState; use crate::state::state::AppState;
use crate::components::admin::{admin_panel::AdminPanelState};
use crate::components::intro::{intro::IntroState};
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()?;
@@ -19,7 +18,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let mut grpc_client = GrpcClient::new().await?; let mut grpc_client = GrpcClient::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 intro_state = IntroState::new(); let mut auth_state = AuthState::default();
// Initialize app_state first // Initialize app_state first
let mut app_state = AppState::new()?; let mut app_state = AppState::new()?;
@@ -28,13 +27,6 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let profile_tree = grpc_client.get_profile_tree().await?; let profile_tree = grpc_client.get_profile_tree().await?;
app_state.profile_tree = profile_tree; app_state.profile_tree = profile_tree;
// Now create admin panel with profiles from app_state
if intro_state.selected_option == 1 {
app_state.ui.show_admin = true;
app_state.general.selected_item = 0;
app_state.general.current_option = 0;
}
// Fetch table structure at startup (one-time) // Fetch table structure at startup (one-time)
let table_structure = grpc_client.get_table_structure().await?; let table_structure = grpc_client.get_table_structure().await?;
@@ -66,6 +58,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
render_ui( render_ui(
f, f,
&mut form_state, &mut form_state,
&mut auth_state,
&theme, &theme,
event_handler.is_edit_mode, event_handler.is_edit_mode,
app_state.total_count, app_state.total_count,

View File

@@ -0,0 +1,22 @@
{
"db_name": "PostgreSQL",
"query": "SELECT ltd.table_name\n FROM table_definition_links tdl\n JOIN table_definitions ltd ON tdl.linked_table_id = ltd.id\n WHERE tdl.source_table_id = $1",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "table_name",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false
]
},
"hash": "468bb5bb4fdaefcb4b280761d7880a556d40c172568ad3a1ed13156fbef72776"
}

View File

@@ -0,0 +1,42 @@
{
"db_name": "PostgreSQL",
"query": "\n INSERT INTO users (username, email, password_hash, role)\n VALUES ($1, $2, $3, 'accountant')\n RETURNING id, username, email, role\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Uuid"
},
{
"ordinal": 1,
"name": "username",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "email",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "role",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Varchar",
"Varchar",
"Varchar"
]
},
"nullable": [
false,
false,
true,
false
]
},
"hash": "48d0a6d393dac121bfa4230830a105aede2179b07395f97750ab2fa1970afacd"
}

View File

@@ -0,0 +1,34 @@
{
"db_name": "PostgreSQL",
"query": "\n SELECT id, password_hash, role\n FROM users\n WHERE username = $1 OR email = $1\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "id",
"type_info": "Uuid"
},
{
"ordinal": 1,
"name": "password_hash",
"type_info": "Varchar"
},
{
"ordinal": 2,
"name": "role",
"type_info": "Varchar"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
true,
false
]
},
"hash": "6be0bb23ad1ba85add309f6e4f55495a5d248901fb0d23fea908815747a0bd50"
}

View File

@@ -0,0 +1,23 @@
{
"db_name": "PostgreSQL",
"query": "SELECT table_name FROM table_definitions\n WHERE profile_id = $1 AND table_name LIKE $2",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "table_name",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Int8",
"Text"
]
},
"nullable": [
false
]
},
"hash": "80f0f7f9ab12a8fe07ea71b548d27bcd6253b598ac4486b72b3d960f03df47f3"
}

View File

@@ -1,22 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "SELECT ltd.table_name \n FROM table_definition_links tdl\n JOIN table_definitions ltd ON tdl.linked_table_id = ltd.id\n WHERE tdl.source_table_id = $1 AND tdl.is_required = true",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "table_name",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Int8"
]
},
"nullable": [
false
]
},
"hash": "b097f30f98490b979939759d85327a20ca7ade4866052a5cfdb0451fb76fbf15"
}

View File

@@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "db_name": "PostgreSQL",
"query": "INSERT INTO table_scripts\n (table_definitions_id, target_column, target_column_type, script, description)\n VALUES ($1, $2, $3, $4, $5)\n RETURNING id", "query": "INSERT INTO table_scripts\n (table_definitions_id, target_table, target_column,\n target_column_type, script, description, profile_id)\n VALUES ($1, $2, $3, $4, $5, $6, $7)\n RETURNING id",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@@ -15,12 +15,14 @@
"Text", "Text",
"Text", "Text",
"Text", "Text",
"Text" "Text",
"Text",
"Int8"
] ]
}, },
"nullable": [ "nullable": [
false false
] ]
}, },
"hash": "4cd5de4d3332ca35a9975ffb32728041978435e14f97c559e2ffec4a82d567ae" "hash": "c07a8511e5f32bf230240b28cb292d40f862b6ec58883f21ee8e1937860585d6"
} }