admin page

This commit is contained in:
Priec
2025-08-28 09:15:14 +02:00
parent a794f22366
commit e142f56706
9 changed files with 276 additions and 272 deletions

View File

@@ -9,7 +9,7 @@ use crate::functions::modes::navigation::add_logic_nav::SaveLogicResultSender;
use crate::functions::modes::navigation::add_table_nav::SaveTableResultSender;
use crate::functions::modes::navigation::add_table_nav;
use crate::pages::admin::main::logic::handle_admin_navigation;
use crate::pages::admin::main::tui::handle_admin_selection;
use crate::pages::admin::admin::tui::handle_admin_selection;
use crate::modes::general::command_navigation::{
handle_command_navigation_event, NavigationState,
};
@@ -33,6 +33,7 @@ use crate::pages::intro;
use crate::pages::login::logic::LoginResult;
use crate::pages::register::RegisterResult;
use crate::pages::routing::{Router, Page};
use crate::movement::MovementAction;
use crate::dialog;
use crate::pages::forms::FormState;
use crate::pages::forms::logic::{save, revert, SaveOutcome};
@@ -404,8 +405,34 @@ impl EventHandler {
}
}
Page::Admin(state) => {
if state.handle_movement(app_state, ma) {
return Ok(EventOutcome::Ok(String::new()));
if auth_state.role.as_deref() == Some("admin") {
if state.handle_movement(app_state, ma) {
return Ok(EventOutcome::Ok(String::new()));
}
} else {
// Non-admin: simple profile navigation
match ma {
MovementAction::Up | MovementAction::Previous => {
state.previous();
return Ok(EventOutcome::Ok(String::new()));
}
MovementAction::Down | MovementAction::Next => {
state.next();
return Ok(EventOutcome::Ok(String::new()));
}
MovementAction::Select => {
if let Some(idx) = state.get_selected_index() {
if let Some(profile) = app_state.profile_tree.profiles.get(idx) {
app_state.selected_profile = Some(profile.name.clone());
return Ok(EventOutcome::Ok(format!(
"Profile '{}' selected",
profile.name
)));
}
}
}
_ => {}
}
}
}
Page::Intro(state) => {
@@ -420,6 +447,7 @@ impl EventHandler {
// Optional page-specific handlers (non-movement or rich actions)
if let Page::Admin(admin_state) = &mut router.current {
if auth_state.role.as_deref() == Some("admin") {
// Full admin navigation
if handle_admin_navigation(
key_event,
config,
@@ -428,9 +456,30 @@ impl EventHandler {
buffer_state,
&mut self.command_message,
) {
return Ok(EventOutcome::Ok(
self.command_message.clone(),
));
return Ok(EventOutcome::Ok(self.command_message.clone()));
}
} else {
// Non-admin: allow simple profile navigation
if let Some(action) = config.get_general_action(key_event.code, key_event.modifiers) {
match action {
"move_up" => {
admin_state.previous();
return Ok(EventOutcome::Ok(String::new()));
}
"move_down" => {
admin_state.next();
return Ok(EventOutcome::Ok(String::new()));
}
"select" => {
if let Some(idx) = admin_state.get_selected_index() {
if let Some(profile) = app_state.profile_tree.profiles.get(idx) {
app_state.selected_profile = Some(profile.name.clone());
}
}
return Ok(EventOutcome::Ok("Profile selected".to_string()));
}
_ => {}
}
}
}
}
@@ -471,10 +520,8 @@ impl EventHandler {
}
// Generic navigation for the rest (Intro/Login/Register/Form)
let nav_outcome = if matches!(
&router.current,
Page::Admin(_) | Page::AddTable(_) | Page::AddLogic(_)
) {
let nav_outcome = if matches!(&router.current, Page::AddTable(_) | Page::AddLogic(_)) {
// Skip generic navigation for AddTable/AddLogic (they have their own handlers)
Ok(EventOutcome::Ok(String::new()))
} else {
navigation::handle_navigation_event(