Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing table.edit_view #83

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Config {
pub asset_path: Option<String>,
pub template_path: Option<String>,
pub actions: IndexMap<String, ActionConfig>,
pub table: Vec<SerdeMap>,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialOrd, Ord, PartialEq, Eq)]
Expand Down Expand Up @@ -353,6 +354,7 @@ impl Config {
}
},
actions: user.actions.unwrap_or_default(),
table: vec![],
};

Ok(config)
Expand Down
27 changes: 10 additions & 17 deletions src/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// we can use the valve config (which is now available) instead of running db requests. But do
// this later.

use crate::config::Config;
use crate::config::{Config, SerdeMap};
use crate::error::GetError;
use crate::sql::{
get_count_from_pool, get_message_counts_from_pool, get_table_from_pool, get_total_from_pool,
Expand All @@ -17,19 +17,16 @@ use minijinja::{Environment, Source};
use ontodev_sqlrest::{Direction, OrderByColumn, Select};
use ontodev_valve::{
toolkit,
valve::{ValveChange, ValveColumnConfig, ValveMessage, ValveTableConfig},
valve::{ValveChange, ValveColumnConfig, ValveMessage},
};
use regex::Regex;
use serde_json::{json, to_string_pretty, Map, Value};
use std::collections::HashMap;
use std::fs;
use std::io::Write;
use std::path::Path;
use tabwriter::TabWriter;
use urlencoding::decode;

pub type SerdeMap = serde_json::Map<String, serde_json::Value>;

pub async fn get_table(
config: &Config,
table: &str,
Expand Down Expand Up @@ -128,7 +125,7 @@ pub async fn get_rows(
}
}
"page" => {
let page = match get_page(&config, &select, &table_config, &column_configs).await {
let page = match get_page(&config, &select, &column_configs).await {
Ok(page) => page,
Err(e) => return Err(GetError::new(e.to_string())),
};
Expand All @@ -152,7 +149,6 @@ pub async fn get_rows(
async fn get_page(
config: &Config,
select: &Select,
table_map: &HashMap<String, ValveTableConfig>,
column_configs: &Vec<ValveColumnConfig>,
) -> Result<Value, GetError> {
let table = &unquote(&select.table).unwrap();
Expand Down Expand Up @@ -403,16 +399,13 @@ async fn get_page(
}

let end = select.offset.unwrap_or(0) + cell_rows.len();

let mut this_table = json!(table_map.get(&unquoted_table).ok_or(GetError::new(format!(
"No '{}' in {:?}",
unquoted_table, table_map
)))?);
let this_table = this_table.as_object_mut().ok_or(GetError::new(format!(
"Could not parse table config for {} as a JSON object",
unquoted_table
)))?;

let mut this_table = config
.table
.iter()
.filter(|x| x.get("table").unwrap() == &json!(unquoted_table))
.next()
.unwrap()
.clone();
this_table.insert("table".to_string(), json!(unquoted_table.clone()));
this_table.insert("href".to_string(), json!(unquoted_table.clone()));
this_table.insert("start".to_string(), json!(select.offset.unwrap_or(0) + 1));
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{config::Config, error::NanobotError, serve::build_app};
use crate::{config::Config, error::NanobotError, serve::build_app, sql::get_table_from_pool};
use axum_test_helper::{TestClient, TestResponse};
use clap::{arg, command, value_parser, Command};
use ontodev_sqlrest::Select;
use ontodev_valve::valve::Valve;
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -158,6 +159,11 @@ async fn build_valve(config: &mut Config) -> Result<(), NanobotError> {
(config.valve, config.pool) = {
let valve = Valve::build(&config.valve_path, &config.connection).await?;
let pool = valve.pool.clone();
let table_select = Select::new("\"table\"");
config.table = get_table_from_pool(&pool, &table_select)
.await
.unwrap()
.clone();
(Some(valve), Some(pool))
};
Ok(())
Expand Down
Loading