Implemented ability to delete a library and ensure that after adding or deleting, the manage library page refreshes.

This commit is contained in:
Joseph Milazzo 2021-01-02 12:59:33 -06:00
parent 1816b6c68d
commit c8bbbceecd
3 changed files with 21 additions and 13 deletions

View file

@ -41,4 +41,8 @@ export class LibraryService {
return this.httpClient.post(this.baseUrl + 'library/create', model); return this.httpClient.post(this.baseUrl + 'library/create', model);
} }
delete(libraryId: number) {
return this.httpClient.delete(this.baseUrl + 'library/delete?libraryId=' + libraryId, {});
}
} }

View file

@ -10,7 +10,7 @@
<h4> <h4>
{{library.name | titlecase}} {{library.name | titlecase}}
<div class="pull-right"> <div class="pull-right">
<button class="btn btn-danger mr-2 btn-sm"><i class="fa fa-trash" title="Delete {{library.name | titlecase}}"></i></button> <button class="btn btn-danger mr-2 btn-sm" (click)="deleteLibrary(library)"><i class="fa fa-trash" title="Delete {{library.name | titlecase}}"></i></button>
<button class="btn btn-primary btn-sm" ><i class="fa fa-pencil" title="Edit {{library.name | titlecase}}"></i></button> <button class="btn btn-primary btn-sm" ><i class="fa fa-pencil" title="Edit {{library.name | titlecase}}"></i></button>
</div> </div>
</h4> </h4>
@ -24,5 +24,3 @@
<app-library-editor-modal></app-library-editor-modal> <app-library-editor-modal></app-library-editor-modal>
</ng-template> </ng-template>
</div> </div>
<button class="btn btn-primary" (click)="addFolder('')">Add Folder</button>

View file

@ -19,25 +19,31 @@ export class ManageLibraryComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.getLibraries();
}
getLibraries() {
this.libraryService.getLibraries().subscribe(libraries => { this.libraryService.getLibraries().subscribe(libraries => {
this.libraries = libraries; this.libraries = libraries;
}); });
} }
addLibrary() { addLibrary() {
const modalRef = this.modalService.open(LibraryEditorModalComponent); const modalRef = this.modalService.open(LibraryEditorModalComponent);
} modalRef.closed.subscribe(refresh => {
if (refresh) {
addFolder(library: string) { this.getLibraries();
const modalRef = this.modalService.open(DirectoryPickerComponent);
modalRef.closed.subscribe((closeResult: DirectoryPickerResult) => {
console.log('Closed Result', closeResult);
if (closeResult.success) {
console.log('Add folder path to Library');
} }
}); });
}
deleteLibrary(library: Library) {
if (confirm('Are you sure you want to delete this library? You cannot undo this action.')) {
this.libraryService.delete(library.id).subscribe(() => {
this.getLibraries();
});
}
} }
} }