add object delete button
This commit is contained in:
@@ -20,7 +20,8 @@ Objects
|
||||
|
||||
<ul>
|
||||
{% for object in table.objects %}
|
||||
<li><a href="/object/detail/{{object.id}}">{{object.name}}</a> (<a href="/object/update/{{object.id}}">Edit</a>)
|
||||
<li><a href="/object/detail/{{object.id}}">{{object.name}}</a> (<a href="/object/update/{{object.id}}">Edit</a>,
|
||||
<a href="/object/delete/{{object.id}}" onclick="return confirm('Delete object?')">Delete</a>)
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
{% block nav -%}
|
||||
<a href="/">Home</a>
|
||||
<a href="/object/update/{{object.id}}">Edit</a>
|
||||
<a href="/object/delete/{{object.id}}" onclick="return confirm('Delete object?')">Delete</a>
|
||||
{%- endblock %}
|
||||
|
||||
{% block content -%}
|
||||
|
||||
@@ -160,6 +160,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.service(routes::objects::detail)
|
||||
.service(routes::objects::update_form)
|
||||
.service(routes::objects::update)
|
||||
.service(routes::objects::delete)
|
||||
//
|
||||
.service(static_files)
|
||||
.default_service(web::to(|| HttpResponse::NotFound().body("File or endpoint not found")))
|
||||
|
||||
@@ -137,7 +137,7 @@ pub(crate) async fn delete(
|
||||
Err(e) => {
|
||||
warn!("Error deleting object model: {}", e);
|
||||
session.flash_error(e.to_string());
|
||||
redirect("/") // back?
|
||||
redirect("/models") // back?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,8 +436,8 @@ pub(crate) async fn update_form(
|
||||
relations: relation_map
|
||||
};
|
||||
|
||||
let _ = form.dot_remove("model_id");
|
||||
form.dot_set("object", object);
|
||||
form.dot_remove("model_id").unwrap();
|
||||
form.dot_set("object", object).unwrap();
|
||||
context.insert("form_data", &form);
|
||||
|
||||
TERA.build_response("objects/object_update", &context)
|
||||
@@ -474,3 +474,24 @@ pub(crate) async fn update(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/object/delete/{id}")]
|
||||
pub(crate) async fn delete(
|
||||
id: web::Path<ID>,
|
||||
store: crate::YopaStoreWrapper,
|
||||
session: Session,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let mut wg = store.write().await;
|
||||
match wg.delete_object(*id) {
|
||||
Ok(obj) => {
|
||||
debug!("Object deleted, redirecting to root");
|
||||
session.flash_success(format!("Object \"{}\" deleted.", obj.name));
|
||||
redirect("/")
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Error deleting object: {}", e);
|
||||
session.flash_error(e.to_string());
|
||||
redirect("/") // back?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user