add htmx for delete

This commit is contained in:
manuel 2022-06-04 16:34:16 +02:00
parent 10f891b1cd
commit 9b5bc5c4da
5 changed files with 7 additions and 14 deletions

View File

@ -42,7 +42,7 @@ impl ActixAdminBuilderTrait for ActixAdminBuilder {
.route("/create", web::post().to(create_post::<T, E>))
.route("/edit/{id}", web::get().to(edit_get::<T, E>))
.route("/edit/{id}", web::post().to(edit_post::<T, E>))
.route("/delete/{id}", web::post().to(delete_post::<T, E>)),
.route("/delete/{id}", web::post().to(delete_post::<T, E>))
);
self.actix_admin.entity_names.push(E::get_entity_name());

View File

@ -12,14 +12,11 @@ pub async fn delete_post<T: ActixAdminAppDataTrait, E: ActixAdminViewModelTrait>
let db = &data.get_db();
let entity_name = E::get_entity_name();
let actix_admin = data.get_actix_admin();
let view_model = actix_admin.view_models.get(&entity_name).unwrap();
//let view_model = actix_admin.view_models.get(&entity_name).unwrap();
// TODO:handle any errors
let _result = E::delete_entity(db, id.into_inner()).await;
Ok(HttpResponse::Found()
.append_header((
header::LOCATION,
format!("/admin/{}/list", view_model.entity_name),
))
Ok(HttpResponse::Ok()
.finish())
}

View File

@ -6,6 +6,7 @@
<title>Actix Admin</title>
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@latest/css/pico.classless.min.css">
<script src="https://unpkg.com/htmx.org@1.7.0"></script>
</head>
<body>

View File

@ -14,7 +14,7 @@
</th>
</tr>
</thead>
<tbody>
<tbody hx-confirm="Are you sure?" hx-target="closest tr" hx-swap="outerHTML">
{% for entity in entities -%}
<tr>
{% for model_field in view_model.fields -%}
@ -22,12 +22,7 @@
{%- endfor %}
<td>
<a href="edit/{{ entity.values | get(key=view_model.fields[0][0]) }}">&#9998;</a>
<a href="delete/{{ entity.values | get(key=view_model.fields[0][0]) }}">&#128465;</a>
<!--
<form method="post" action="delete/{{ entity.values | get(key=view_model.fields[0][0]) }}">
<button type="submit">&#128465;</button>
</form>
-->
<a hx-post="delete/{{ entity.values | get(key=view_model.fields[0][0]) }}">&#128465;</a>
</td>
</tr>
{%- endfor %}

Binary file not shown.