Compare commits

...

6 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
20 changed files with 186 additions and 92 deletions

View File

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

6
Cargo.lock generated
View File

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

View File

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

View File

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

View File

@@ -118,14 +118,4 @@ impl IntroState {
pub fn previous_option(&mut self) {
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 => {}
2 => {}
_ => {}
}
}
}

View File

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

View File

@@ -4,6 +4,7 @@ use crossterm::event::KeyEvent;
use crate::config::binds::config::Config;
use crate::state::state::AppState;
use crate::state::pages::form::FormState;
use crate::tui::functions::{intro, admin};
pub async fn handle_navigation_event(
key: KeyEvent,
@@ -21,16 +22,11 @@ pub async fn handle_navigation_event(
return Ok((false, String::new()));
}
"move_down" => {
let item_count = if app_state.ui.show_intro {
2 // Intro options count
} else {
app_state.profile_tree.profiles.len() // Admin panel items
};
move_down(app_state, item_count);
move_down(app_state);
return Ok((false, String::new()));
}
"next_option" => {
next_option(app_state, 2); // Intro has 2 options
next_option(app_state); // Intro has 2 options
return Ok((false, String::new()));
}
"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 {
app_state.ui.intro_state.next_option();
} 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 {
app_state.ui.intro_state.next_option();
} 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;
}
}
@@ -111,45 +108,20 @@ pub fn previous_option(app_state: &mut AppState) {
if app_state.ui.show_intro {
app_state.ui.intro_state.previous_option();
} else {
// For other screens that might have options
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
// For now, just stay at 0
let option_count = app_state.profile_tree.profiles.len();
app_state.general.current_option = if app_state.general.current_option == 0 {
option_count.saturating_sub(1) // Wrap to last option
} else {
app_state.general.current_option -= 1;
}
app_state.general.current_option - 1
};
}
}
pub fn select(app_state: &mut AppState) {
if app_state.ui.show_intro {
// Handle selection in intro screen
match app_state.ui.intro_state.selected_option {
0 => { // Continue - show form
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;
}
_ => {} // Other options (shouldn't happen)
}
app_state.ui.show_intro = false;
intro::handle_intro_selection(app_state);
} else if app_state.ui.show_admin {
// Handle selection in admin panel
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());
}
admin::handle_admin_selection(app_state);
}
}

View File

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

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
pub mod terminal;
pub mod controls;
pub mod functions;

View File

@@ -6,7 +6,6 @@ use crate::components::{
render_status_line,
handlers::sidebar::{self, calculate_sidebar_layout},
form::form::render_form,
intro::{intro},
admin::{admin_panel::AdminPanelState},
auth::login::render_login,
};

View File

@@ -11,8 +11,6 @@ use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::modes::handlers::event::EventHandler;
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>> {
let config = Config::load()?;
@@ -20,7 +18,6 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let mut grpc_client = GrpcClient::new().await?;
let mut command_handler = CommandHandler::new();
let theme = Theme::from_str(&config.colors.theme);
let mut intro_state = IntroState::new();
let mut auth_state = AuthState::default();
// Initialize app_state first

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",
"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": {
"columns": [
{
@@ -15,12 +15,14 @@
"Text",
"Text",
"Text",
"Text"
"Text",
"Text",
"Int8"
]
},
"nullable": [
false
]
},
"hash": "4cd5de4d3332ca35a9975ffb32728041978435e14f97c559e2ffec4a82d567ae"
"hash": "c07a8511e5f32bf230240b28cb292d40f862b6ec58883f21ee8e1937860585d6"
}