|
|
|
@ -23,6 +23,12 @@ struct RelationModelDisplay<'a> { |
|
|
|
|
properties: Vec<&'a PropertyModel>, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn redirect(path : impl AsRef<str>) -> actix_web::Result<impl Responder> { |
|
|
|
|
Ok(HttpResponse::SeeOther() |
|
|
|
|
.header("location", path.as_ref()) // back - to where?
|
|
|
|
|
.finish()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[get("/")] |
|
|
|
|
pub(crate) async fn index(session : Session, store : crate::YopaStoreWrapper) -> actix_web::Result<impl Responder> { |
|
|
|
|
|
|
|
|
@ -99,19 +105,75 @@ pub(crate) async fn object_model_create( |
|
|
|
|
Ok(_id) => { |
|
|
|
|
debug!("Object created, redirecting to root"); |
|
|
|
|
session.flash_success(format!("Object model \"{}\" created.", form.name)); |
|
|
|
|
redirect("/") |
|
|
|
|
} |
|
|
|
|
Err(e) => { |
|
|
|
|
warn!("Error creating model: {:?}", e); |
|
|
|
|
session.flash_error(e.to_string()); |
|
|
|
|
redirect("/model/object/create") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ok(HttpResponse::SeeOther() |
|
|
|
|
.header("location", "/") |
|
|
|
|
.finish()) |
|
|
|
|
#[get("/model/object/delete/{id}")] |
|
|
|
|
pub(crate) async fn object_model_delete( |
|
|
|
|
id : web::Path<String>, |
|
|
|
|
store : crate::YopaStoreWrapper, |
|
|
|
|
session : Session |
|
|
|
|
) -> actix_web::Result<impl Responder> { |
|
|
|
|
let mut wg = store.write().await; |
|
|
|
|
match wg.undefine_object(id.parse().map_err(|e| actix_web::error::ErrorBadRequest(e))?) { |
|
|
|
|
Ok(om) => { |
|
|
|
|
debug!("Object model deleted, redirecting to root"); |
|
|
|
|
session.flash_success(format!("Object model \"{}\" deleted.", om.name)); |
|
|
|
|
redirect("/") |
|
|
|
|
} |
|
|
|
|
Err(e) => { |
|
|
|
|
warn!("Error creating model: {}", e); |
|
|
|
|
warn!("Error deleting object model: {:?}", e); |
|
|
|
|
session.flash_error(e.to_string()); |
|
|
|
|
redirect("/") // back?
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Redirect back
|
|
|
|
|
Ok(HttpResponse::SeeOther() |
|
|
|
|
.header("location", "/model/object/create") |
|
|
|
|
.finish()) |
|
|
|
|
#[get("/model/relation/delete/{id}")] |
|
|
|
|
pub(crate) async fn relation_model_delete( |
|
|
|
|
id : web::Path<String>, |
|
|
|
|
store : crate::YopaStoreWrapper, |
|
|
|
|
session : Session |
|
|
|
|
) -> actix_web::Result<impl Responder> { |
|
|
|
|
let mut wg = store.write().await; |
|
|
|
|
match wg.undefine_relation(id.parse().map_err(|e| actix_web::error::ErrorBadRequest(e))?) { |
|
|
|
|
Ok(rm) => { |
|
|
|
|
debug!("Relation deleted, redirecting to root"); |
|
|
|
|
session.flash_success(format!("Relation model \"{}\" deleted.", rm.name)); |
|
|
|
|
redirect("/") |
|
|
|
|
} |
|
|
|
|
Err(e) => { |
|
|
|
|
warn!("Error deleting relation model: {:?}", e); |
|
|
|
|
session.flash_error(e.to_string()); |
|
|
|
|
redirect("/") // back?
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[get("/model/property/delete/{id}")] |
|
|
|
|
pub(crate) async fn property_model_delete( |
|
|
|
|
id : web::Path<String>, |
|
|
|
|
store : crate::YopaStoreWrapper, |
|
|
|
|
session : Session |
|
|
|
|
) -> actix_web::Result<impl Responder> { |
|
|
|
|
let mut wg = store.write().await; |
|
|
|
|
match wg.undefine_property(id.parse().map_err(|e| actix_web::error::ErrorBadRequest(e))?) { |
|
|
|
|
Ok(rm) => { |
|
|
|
|
debug!("Property deleted, redirecting to root"); |
|
|
|
|
session.flash_success(format!("Property \"{}\" deleted.", rm.name)); |
|
|
|
|
redirect("/") |
|
|
|
|
} |
|
|
|
|
Err(e) => { |
|
|
|
|
warn!("Error deleting property: {:?}", e); |
|
|
|
|
session.flash_error(e.to_string()); |
|
|
|
|
redirect("/") // back?
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|