use crate::auth; use auth::AuthUser; use crate::Db; use rocket_dyn_templates::{Template, context}; use rocket::form::Form; use rocket::response::Redirect; use inventur_db; use rocket::serde::{Serialize, Deserialize, json::Json}; use rocket::http::{Status, Cookie, CookieJar, SameSite}; use inventur_db::FIELDTYPE; #[derive(FromForm)] struct DeleteColumn { tblid: i32, id_in_table: i32, } #[derive(FromForm)] struct NewEntry { tblid: i32, cells: Vec, } #[derive(FromForm)] struct EditEntry { tblid: i32, cells: Vec, row_pos: i32, } #[derive(FromForm)] struct DeleteEntry { tblid: i32, row_pos: i32, } #[derive(FromForm)] struct EditTname { tblid: i32, new_name: String, } #[derive(FromForm)] struct NewTable { name: String, field_names: Vec, field_types: Vec, } #[derive(Deserialize)] #[serde(crate = "rocket::serde")] struct ImportTable { name: String, columns: Vec, rows: Vec>, } #[derive(FromForm)] struct DeleteTable { tblid: i32, } #[derive(Serialize)] #[serde(crate = "rocket::serde")] struct JRows { rows: Vec>, } pub async fn get_tids(conn: &Db, uid: i32) -> (Vec, Vec) { let mut tids = conn.run(move |c| inventur_db::get_user_tblids(c, uid)).await; let tnames; if tids.is_none() { tids = Some(Vec::new()); tnames = Some(Vec::new()); }else { let tids = tids.clone().unwrap(); tnames = conn.run(move |c| inventur_db::get_tblnames(c, tids)).await; } (tids.unwrap(), tnames.unwrap()) } #[get("/", rank=2)] pub async fn table_sec(conn: Db, tid: i32, user: AuthUser) -> Redirect { let nus : Option = None; let nu8 : Option = None; let nvi32 : Option> = None; let ns : Option = None; Redirect::to(uri!("/table", table(tid, nu8, nus, nvi32, ns))) } #[get("/?&&&")] pub async fn table(conn: Db, tid: i32, sort_dir: Option, sort_field: Option, search_fields: Option>, search_value: Option, user: AuthUser) -> Option