US04: Make it possible to delete horses from the UI
This commit is contained in:
parent
a3f6276fc4
commit
361a09b082
@ -71,7 +71,7 @@
|
||||
<a class="btn btn-success" href="horse/{{ horse.id }}/edit"><i class="fas fa-edit"></i></a>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-danger"><i class="fas fa-trash"></i></button>
|
||||
<button class="btn btn-danger" (click)="deleteHorse(horse.id, horse.name)"><i class="fas fa-trash"></i></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -91,6 +91,17 @@ export class ListHorsesComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
public deleteHorse(id: number, name: string) {
|
||||
if(confirm("Are you sure you want to delete " + name + ". This action is irreversible.")) {
|
||||
this.horseService.deleteHorse(id).subscribe(
|
||||
(res) => {
|
||||
console.log('Successfully deleted horse');
|
||||
this.loadAllHorses();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private defaultServiceErrorHandling(error: any) {
|
||||
console.log(error);
|
||||
this.error = true;
|
||||
|
@ -48,13 +48,28 @@ export class HorseService {
|
||||
return this.httpClient.post<Horse>(this.messageBaseUri, horse);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific horse with the supplied values
|
||||
* @param horse
|
||||
*/
|
||||
updateHorse(horse: Horse): Observable<Horse> {
|
||||
console.log('Update horse with id ' + horse.id + ': '+ JSON.stringify(horse));
|
||||
return this.httpClient.put<Horse>(this.messageBaseUri + '/' + horse.id, horse);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Delete a horse from the backend
|
||||
* @param id
|
||||
*/
|
||||
deleteHorse(id: number): Observable<Object> {
|
||||
console.log('Delete horse with id ' + id);
|
||||
return this.httpClient.delete(this.messageBaseUri + '/' + id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads a file to the remote server
|
||||
* @param fileToUpload
|
||||
* @param newFileName
|
||||
*/
|
||||
postFile(fileToUpload: File, newFileName: string): Observable<Object> {
|
||||
// Prepare the form
|
||||
|
Reference in New Issue
Block a user