Added add column button
This commit is contained in:
@@ -67,7 +67,7 @@ async fn rocket() -> _ {
|
||||
.mount("/", routes![auth::oauth_login, auth::oauth_callback, home, login_home])
|
||||
.mount("/table", routes![table::table, table::table_sec, table::edit_tname, table::create, table::import_table, table::delete_table])
|
||||
.mount("/row", routes![table::new_entry, table::edit_entry, table::delete_entry])
|
||||
.mount("/column", routes![table::delete_column])
|
||||
.mount("/column", routes![table::delete_column, table::edit_column])
|
||||
.register("/", catchers![auth::redirect_to_login])
|
||||
.mount("/static", FileServer::from(relative!("static")))
|
||||
|
||||
|
||||
38
src/table.rs
38
src/table.rs
@@ -17,6 +17,21 @@ struct DeleteColumn {
|
||||
id_in_table: i32,
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct EditColumn {
|
||||
tblid: i32,
|
||||
id_in_table: i32,
|
||||
name: String,
|
||||
column_type: isize,
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct NewColumn {
|
||||
tblid: i32,
|
||||
name: String,
|
||||
column_type: isize,
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct NewEntry {
|
||||
tblid: i32,
|
||||
@@ -201,6 +216,29 @@ pub async fn delete_entry(conn: Db, data: Form<DeleteEntry>, user: AuthUser) ->
|
||||
Ok(Redirect::to(uri!("/table", table_sec(tblid))))
|
||||
}
|
||||
|
||||
#[post("/create", data="<data>")]
|
||||
pub async fn create_column(conn: Db, data: Form<NewColumn>, user: AuthUser) -> Result<Redirect, Status> {
|
||||
let uid = user.uid;
|
||||
let tblid = data.tblid;
|
||||
let coltype = FIELDTYPE::from(data.column_type);
|
||||
if conn.run(move |c| inventur_db::add_column(c, tblid, data.name.clone(), coltype, uid)).await.is_none() {
|
||||
return Err(Status::Forbidden);
|
||||
}
|
||||
Ok(Redirect::to(uri!("/table", table_sec(tblid))))
|
||||
}
|
||||
|
||||
#[post("/edit", data="<data>")]
|
||||
pub async fn edit_column(conn: Db, data: Form<EditColumn>, user: AuthUser) -> Result<Redirect, Status> {
|
||||
let uid = user.uid;
|
||||
let tblid = data.tblid;
|
||||
let idintbl = data.id_in_table;
|
||||
let clmtype = FIELDTYPE::from(data.column_type);
|
||||
if conn.run(move |c| inventur_db::edit_column(c, tblid, idintbl, &data.name, clmtype, uid)).await.is_none() {
|
||||
return Err(Status::Forbidden);
|
||||
}
|
||||
Ok(Redirect::to(uri!("/table", table_sec(tblid))))
|
||||
}
|
||||
|
||||
#[post("/delete", data="<data>")]
|
||||
pub async fn delete_column(conn: Db, data: Form<DeleteColumn>, user: AuthUser) -> Result<Redirect, Status> {
|
||||
let uid = user.uid;
|
||||
|
||||
Reference in New Issue
Block a user