US08: Allow the user to delete an owner using the UI

This commit is contained in:
Ivaylo Ivanov 2020-03-25 13:55:17 +01:00
parent 5c8e2c1c39
commit 6c4fa0df90
3 changed files with 23 additions and 1 deletions

View File

@ -30,7 +30,7 @@
<td>{{ owner.name }}</td>
<td>
<a class="btn btn-success" href="owner/{{ owner.id }}/edit"><i class="fas fa-edit"></i></a>
<button class="btn btn-danger"><i class="fas fa-trash"></i></button>
<button class="btn btn-danger" (click)="deleteOwner(owner.id, owner.name)"><i class="fas fa-trash"></i></button>
</td>
</tr>
</tbody>

View File

@ -71,6 +71,19 @@ export class ListOwnersComponent implements OnInit {
);
}
public deleteOwner(id: number, name: string) {
if(confirm("Are you sure you want to delete " + name + ". This action is irreversible.")) {
this.ownerService.deleteOwner(id).subscribe(
(res) => {
console.log('Successfully deleted owner');
this.loadAllOwners();
}, (error) => {
this.defaultServiceErrorHandling(error);
}
);
}
}
private defaultServiceErrorHandling(error: any) {
console.log(error);
this.error = true;

View File

@ -57,4 +57,13 @@ export class OwnerService {
console.log('Update owner with id ' + owner.id + ': '+ JSON.stringify(owner));
return this.httpClient.put<Owner>(this.messageBaseUri + '/' + owner.id, owner);
}
/**
* Delete an owner from the backend
* @param id
*/
deleteOwner(id: number): Observable<Object> {
console.log('Delete owner with id ' + id);
return this.httpClient.delete(this.messageBaseUri + '/' + id);
}
}