mirror of https://github.com/TaKO8Ki/gobang
use databasetree
parent
6f4b454e01
commit
694e219020
@ -1,22 +1,45 @@
|
||||
use crate::app::{App, FocusBlock};
|
||||
use crate::components::Component as _;
|
||||
use crate::event::Key;
|
||||
use crate::utils::{get_columns, get_records};
|
||||
use database_tree::Database;
|
||||
|
||||
pub async fn handler(key: Key, app: &mut App, focused: bool) -> anyhow::Result<()> {
|
||||
if focused {
|
||||
match key {
|
||||
Key::Char('j') => app.next_database(),
|
||||
Key::Char('k') => app.previous_database(),
|
||||
Key::Esc => app.focus_block = FocusBlock::DabataseList(false),
|
||||
_ => (),
|
||||
}
|
||||
} else {
|
||||
match key {
|
||||
Key::Char('j') => app.focus_block = FocusBlock::TableList(false),
|
||||
Key::Char('l') => app.focus_block = FocusBlock::RecordTable(false),
|
||||
Key::Char('c') => app.focus_block = FocusBlock::ConnectionList,
|
||||
Key::Enter => app.focus_block = FocusBlock::DabataseList(true),
|
||||
_ => (),
|
||||
pub async fn handler(key: Key, app: &mut App) -> anyhow::Result<()> {
|
||||
app.databases.event(key)?;
|
||||
match key {
|
||||
Key::Esc => app.focus_block = FocusBlock::DabataseList,
|
||||
Key::Right => app.focus_block = FocusBlock::RecordTable,
|
||||
Key::Char('c') => app.focus_block = FocusBlock::ConnectionList,
|
||||
Key::Enter => {
|
||||
if let Some((table, database)) = app.databases.tree.selected_table() {
|
||||
let (headers, records) = get_records(
|
||||
&Database {
|
||||
name: database.clone(),
|
||||
tables: vec![],
|
||||
},
|
||||
&table,
|
||||
app.pool.as_ref().unwrap(),
|
||||
)
|
||||
.await?;
|
||||
app.record_table.state.select(Some(0));
|
||||
app.record_table.headers = headers;
|
||||
app.record_table.rows = records;
|
||||
|
||||
let (headers, records) = get_columns(
|
||||
&Database {
|
||||
name: database,
|
||||
tables: vec![],
|
||||
},
|
||||
&table,
|
||||
app.pool.as_ref().unwrap(),
|
||||
)
|
||||
.await?;
|
||||
app.structure_table.state.select(Some(0));
|
||||
app.structure_table.headers = headers;
|
||||
app.structure_table.rows = records;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,23 +1,15 @@
|
||||
use crate::app::{App, FocusBlock};
|
||||
use crate::event::Key;
|
||||
|
||||
pub async fn handler(key: Key, app: &mut App, focused: bool) -> anyhow::Result<()> {
|
||||
if focused {
|
||||
match key {
|
||||
Key::Char('h') => app.record_table.previous_column(),
|
||||
Key::Char('j') => app.record_table.next(),
|
||||
Key::Char('k') => app.record_table.previous(),
|
||||
Key::Char('l') => app.record_table.next_column(),
|
||||
Key::Esc => app.focus_block = FocusBlock::RecordTable(false),
|
||||
_ => (),
|
||||
}
|
||||
} else {
|
||||
match key {
|
||||
Key::Char('h') => app.focus_block = FocusBlock::TableList(false),
|
||||
Key::Char('c') => app.focus_block = FocusBlock::ConnectionList,
|
||||
Key::Enter => app.focus_block = FocusBlock::RecordTable(true),
|
||||
_ => (),
|
||||
}
|
||||
pub async fn handler(key: Key, app: &mut App) -> anyhow::Result<()> {
|
||||
match key {
|
||||
Key::Char('h') => app.record_table.previous_column(),
|
||||
Key::Char('j') => app.record_table.next(),
|
||||
Key::Char('k') => app.record_table.previous(),
|
||||
Key::Char('l') => app.record_table.next_column(),
|
||||
Key::Left => app.focus_block = FocusBlock::DabataseList,
|
||||
Key::Char('c') => app.focus_block = FocusBlock::ConnectionList,
|
||||
_ => (),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,73 +0,0 @@
|
||||
use crate::app::{App, FocusBlock};
|
||||
use crate::event::Key;
|
||||
use crate::utils::{get_columns, get_records};
|
||||
|
||||
pub async fn handler(key: Key, app: &mut App, focused: bool) -> anyhow::Result<()> {
|
||||
if focused {
|
||||
match key {
|
||||
Key::Char('j') => {
|
||||
if app.selected_database.selected().is_some() {
|
||||
app.next_table();
|
||||
app.record_table.column_index = 0;
|
||||
if let Some(database) = app.selected_database() {
|
||||
if let Some(table) = app.selected_table() {
|
||||
let (headers, records) =
|
||||
get_records(database, table, app.pool.as_ref().unwrap()).await?;
|
||||
app.record_table.state.select(Some(0));
|
||||
app.record_table.headers = headers;
|
||||
app.record_table.rows = records;
|
||||
}
|
||||
}
|
||||
|
||||
app.structure_table.column_index = 0;
|
||||
if let Some(database) = app.selected_database() {
|
||||
if let Some(table) = app.selected_table() {
|
||||
let (headers, records) =
|
||||
get_columns(database, table, app.pool.as_ref().unwrap()).await?;
|
||||
app.structure_table.state.select(Some(0));
|
||||
app.structure_table.headers = headers;
|
||||
app.structure_table.rows = records;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Key::Char('k') => {
|
||||
if app.selected_database.selected().is_some() {
|
||||
app.previous_table();
|
||||
app.record_table.column_index = 0;
|
||||
if let Some(database) = app.selected_database() {
|
||||
if let Some(table) = app.selected_table() {
|
||||
let (headers, records) =
|
||||
get_records(database, table, app.pool.as_ref().unwrap()).await?;
|
||||
app.record_table.state.select(Some(0));
|
||||
app.record_table.headers = headers;
|
||||
app.record_table.rows = records;
|
||||
}
|
||||
}
|
||||
|
||||
app.structure_table.column_index = 0;
|
||||
if let Some(database) = app.selected_database() {
|
||||
if let Some(table) = app.selected_table() {
|
||||
let (headers, records) =
|
||||
get_columns(database, table, app.pool.as_ref().unwrap()).await?;
|
||||
app.structure_table.state.select(Some(0));
|
||||
app.structure_table.headers = headers;
|
||||
app.structure_table.rows = records;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Key::Esc => app.focus_block = FocusBlock::TableList(false),
|
||||
_ => (),
|
||||
}
|
||||
} else {
|
||||
match key {
|
||||
Key::Char('k') => app.focus_block = FocusBlock::DabataseList(false),
|
||||
Key::Char('l') => app.focus_block = FocusBlock::RecordTable(false),
|
||||
Key::Char('c') => app.focus_block = FocusBlock::ConnectionList,
|
||||
Key::Enter => app.focus_block = FocusBlock::TableList(true),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
use crate::app::App;
|
||||
use tui::{backend::Backend, layout::Rect, Frame};
|
||||
|
||||
fn draw_database_list<B: Backend>(
|
||||
f: &mut Frame<'_, B>,
|
||||
app: &mut App,
|
||||
layout_chunk: Rect,
|
||||
) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue