|
|
@ -24,7 +24,8 @@ pub enum Focus {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub struct App {
|
|
|
|
pub struct App {
|
|
|
|
record_table: RecordTableComponent,
|
|
|
|
record_table: RecordTableComponent,
|
|
|
|
structure_table: TableComponent,
|
|
|
|
column_table: TableComponent,
|
|
|
|
|
|
|
|
constraint_table: TableComponent,
|
|
|
|
focus: Focus,
|
|
|
|
focus: Focus,
|
|
|
|
tab: TabComponent,
|
|
|
|
tab: TabComponent,
|
|
|
|
help: HelpComponent,
|
|
|
|
help: HelpComponent,
|
|
|
@ -42,7 +43,8 @@ impl App {
|
|
|
|
config: config.clone(),
|
|
|
|
config: config.clone(),
|
|
|
|
connections: ConnectionsComponent::new(config.key_config.clone(), config.conn),
|
|
|
|
connections: ConnectionsComponent::new(config.key_config.clone(), config.conn),
|
|
|
|
record_table: RecordTableComponent::new(config.key_config.clone()),
|
|
|
|
record_table: RecordTableComponent::new(config.key_config.clone()),
|
|
|
|
structure_table: TableComponent::new(config.key_config.clone()),
|
|
|
|
column_table: TableComponent::new(config.key_config.clone()),
|
|
|
|
|
|
|
|
constraint_table: TableComponent::new(config.key_config.clone()),
|
|
|
|
tab: TabComponent::new(config.key_config.clone()),
|
|
|
|
tab: TabComponent::new(config.key_config.clone()),
|
|
|
|
help: HelpComponent::new(config.key_config.clone()),
|
|
|
|
help: HelpComponent::new(config.key_config.clone()),
|
|
|
|
databases: DatabasesComponent::new(config.key_config.clone()),
|
|
|
|
databases: DatabasesComponent::new(config.key_config.clone()),
|
|
|
@ -93,10 +95,15 @@ impl App {
|
|
|
|
self.record_table
|
|
|
|
self.record_table
|
|
|
|
.draw(f, right_chunks[1], matches!(self.focus, Focus::Table))?
|
|
|
|
.draw(f, right_chunks[1], matches!(self.focus, Focus::Table))?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Tab::Structure => {
|
|
|
|
Tab::Columns => {
|
|
|
|
self.structure_table
|
|
|
|
self.column_table
|
|
|
|
.draw(f, right_chunks[1], matches!(self.focus, Focus::Table))?
|
|
|
|
.draw(f, right_chunks[1], matches!(self.focus, Focus::Table))?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Tab::Constraints => self.constraint_table.draw(
|
|
|
|
|
|
|
|
f,
|
|
|
|
|
|
|
|
right_chunks[1],
|
|
|
|
|
|
|
|
matches!(self.focus, Focus::Table),
|
|
|
|
|
|
|
|
)?,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.error.draw(f, Rect::default(), false)?;
|
|
|
|
self.error.draw(f, Rect::default(), false)?;
|
|
|
|
self.help.draw(f, Rect::default(), false)?;
|
|
|
|
self.help.draw(f, Rect::default(), false)?;
|
|
|
@ -162,6 +169,7 @@ impl App {
|
|
|
|
async fn update_table(&mut self) -> anyhow::Result<()> {
|
|
|
|
async fn update_table(&mut self) -> anyhow::Result<()> {
|
|
|
|
if let Some((database, table)) = self.databases.tree().selected_table() {
|
|
|
|
if let Some((database, table)) = self.databases.tree().selected_table() {
|
|
|
|
self.focus = Focus::Table;
|
|
|
|
self.focus = Focus::Table;
|
|
|
|
|
|
|
|
self.record_table.reset();
|
|
|
|
let (headers, records) = self
|
|
|
|
let (headers, records) = self
|
|
|
|
.pool
|
|
|
|
.pool
|
|
|
|
.as_ref()
|
|
|
|
.as_ref()
|
|
|
@ -171,14 +179,42 @@ impl App {
|
|
|
|
self.record_table
|
|
|
|
self.record_table
|
|
|
|
.update(records, headers, database.clone(), table.clone());
|
|
|
|
.update(records, headers, database.clone(), table.clone());
|
|
|
|
|
|
|
|
|
|
|
|
let (headers, records) = self
|
|
|
|
self.column_table.reset();
|
|
|
|
|
|
|
|
let columns = self
|
|
|
|
.pool
|
|
|
|
.pool
|
|
|
|
.as_ref()
|
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
.get_columns(&database, &table)
|
|
|
|
.get_columns(&database, &table)
|
|
|
|
.await?;
|
|
|
|
.await?;
|
|
|
|
self.structure_table
|
|
|
|
if !columns.is_empty() {
|
|
|
|
.update(records, headers, database.clone(), table.clone());
|
|
|
|
self.column_table.update(
|
|
|
|
|
|
|
|
columns
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(|c| c.columns())
|
|
|
|
|
|
|
|
.collect::<Vec<Vec<String>>>(),
|
|
|
|
|
|
|
|
columns.get(0).unwrap().fields(),
|
|
|
|
|
|
|
|
database.clone(),
|
|
|
|
|
|
|
|
table.clone(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.constraint_table.reset();
|
|
|
|
|
|
|
|
let constraints = self
|
|
|
|
|
|
|
|
.pool
|
|
|
|
|
|
|
|
.as_ref()
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.get_constraints(&database, &table)
|
|
|
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
if !constraints.is_empty() {
|
|
|
|
|
|
|
|
self.constraint_table.update(
|
|
|
|
|
|
|
|
constraints
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(|c| c.columns())
|
|
|
|
|
|
|
|
.collect::<Vec<Vec<String>>>(),
|
|
|
|
|
|
|
|
constraints.get(0).unwrap().fields(),
|
|
|
|
|
|
|
|
database.clone(),
|
|
|
|
|
|
|
|
table.clone(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
self.table_status
|
|
|
|
self.table_status
|
|
|
|
.update(self.record_table.len() as u64, table);
|
|
|
|
.update(self.record_table.len() as u64, table);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -303,13 +339,24 @@ impl App {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Tab::Structure => {
|
|
|
|
Tab::Columns => {
|
|
|
|
if self.structure_table.event(key)?.is_consumed() {
|
|
|
|
if self.column_table.event(key)?.is_consumed() {
|
|
|
|
|
|
|
|
return Ok(EventState::Consumed);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if key == self.config.key_config.copy {
|
|
|
|
|
|
|
|
if let Some(text) = self.column_table.selected_cells() {
|
|
|
|
|
|
|
|
copy_to_clipboard(text.as_str())?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Tab::Constraints => {
|
|
|
|
|
|
|
|
if self.constraint_table.event(key)?.is_consumed() {
|
|
|
|
return Ok(EventState::Consumed);
|
|
|
|
return Ok(EventState::Consumed);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if key == self.config.key_config.copy {
|
|
|
|
if key == self.config.key_config.copy {
|
|
|
|
if let Some(text) = self.structure_table.selected_cells() {
|
|
|
|
if let Some(text) = self.column_table.selected_cells() {
|
|
|
|
copy_to_clipboard(text.as_str())?
|
|
|
|
copy_to_clipboard(text.as_str())?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|