add htmx for delete
This commit is contained in:
parent
10f891b1cd
commit
9b5bc5c4da
@ -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());
|
||||
|
@ -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())
|
||||
}
|
@ -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>
|
||||
|
@ -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]) }}">✎</a>
|
||||
<a href="delete/{{ entity.values | get(key=view_model.fields[0][0]) }}">🗑</a>
|
||||
<!--
|
||||
<form method="post" action="delete/{{ entity.values | get(key=view_model.fields[0][0]) }}">
|
||||
<button type="submit">🗑</button>
|
||||
</form>
|
||||
-->
|
||||
<a hx-post="delete/{{ entity.values | get(key=view_model.fields[0][0]) }}">🗑</a>
|
||||
</td>
|
||||
</tr>
|
||||
{%- endfor %}
|
||||
|
BIN
database.db-wal
BIN
database.db-wal
Binary file not shown.
Loading…
Reference in New Issue
Block a user