diff --git a/src/app/_services/library.service.ts b/src/app/_services/library.service.ts index 5243bf517..1e801b03e 100644 --- a/src/app/_services/library.service.ts +++ b/src/app/_services/library.service.ts @@ -33,6 +33,8 @@ export class LibraryService { return this.httpClient.post(this.baseUrl + 'library/update-for', {username, selectedLibraries}); } - + scan(libraryId: number) { + return this.httpClient.post(this.baseUrl + 'library/scan?libraryId=' + libraryId, {}); + } } diff --git a/src/app/library/library.component.html b/src/app/library/library.component.html index 666f33e34..cb906425e 100644 --- a/src/app/library/library.component.html +++ b/src/app/library/library.component.html @@ -2,6 +2,7 @@

Libraries

- + +
\ No newline at end of file diff --git a/src/app/library/library.component.ts b/src/app/library/library.component.ts index c4f027c73..cc268287b 100644 --- a/src/app/library/library.component.ts +++ b/src/app/library/library.component.ts @@ -17,29 +17,16 @@ export class LibraryComponent implements OnInit { user: User | undefined; libraries: Library[] = []; - actions: CardItemAction[] = []; constructor(public accountService: AccountService, private libraryService: LibraryService, private router: Router) { } ngOnInit(): void { this.accountService.currentUser$.pipe(take(1)).subscribe(user => { this.user = user; - if (this.accountService.hasAdminRole(user)) { - this.actions = [ - {title: 'Scan Library', callback: (data: Library) => { - console.log('You tried to scan library: ' + data.name); - }} - ]; - } this.libraryService.getLibrariesForMember(this.user.username).subscribe(libraries => { this.libraries = libraries; - console.log('Libraries: ', this.libraries); }); }); } - handleNavigation(event: any, library: Library) { - this.router.navigateByUrl('/library/' + library.id); - } - } diff --git a/src/app/shared/card-item/card-item.component.html b/src/app/shared/card-item/card-item.component.html index 976a075f8..bb102cbd2 100644 --- a/src/app/shared/card-item/card-item.component.html +++ b/src/app/shared/card-item/card-item.component.html @@ -1,4 +1,5 @@
+ {{title}}
diff --git a/src/app/shared/card-item/card-item.component.ts b/src/app/shared/card-item/card-item.component.ts index ff41443ee..e4a8b431e 100644 --- a/src/app/shared/card-item/card-item.component.ts +++ b/src/app/shared/card-item/card-item.component.ts @@ -19,6 +19,7 @@ export class CardItemComponent implements OnInit { @Input() entity: any; // This is the entity we are representing. It will be returned if an action is executed. @Output() clicked = new EventEmitter(); + placeholderImage = 'assets/images/image-placeholder.jpg'; constructor() { } diff --git a/src/app/shared/library-card/library-card.component.html b/src/app/shared/library-card/library-card.component.html new file mode 100644 index 000000000..fb6fa8b97 --- /dev/null +++ b/src/app/shared/library-card/library-card.component.html @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/app/shared/library-card/library-card.component.scss b/src/app/shared/library-card/library-card.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/shared/library-card/library-card.component.ts b/src/app/shared/library-card/library-card.component.ts new file mode 100644 index 000000000..773fa3d98 --- /dev/null +++ b/src/app/shared/library-card/library-card.component.ts @@ -0,0 +1,60 @@ +import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core'; +import { Router } from '@angular/router'; +import { ToastrService } from 'ngx-toastr'; +import { take } from 'rxjs/operators'; +import { Library } from 'src/app/_models/library'; +import { User } from 'src/app/_models/user'; +import { AccountService } from 'src/app/_services/account.service'; +import { LibraryService } from 'src/app/_services/library.service'; +import { CardItemAction } from '../card-item/card-item.component'; + +// Represents a library type card. Uses a app-card-item internally +@Component({ + selector: 'app-library-card', + templateUrl: './library-card.component.html', + styleUrls: ['./library-card.component.scss'] +}) +export class LibraryCardComponent implements OnInit, OnChanges { + @Input() data: Library | undefined; + @Output() clicked = new EventEmitter(); + + isAdmin = false; + actions: CardItemAction[] = []; + + constructor(private accountService: AccountService, private router: Router, + private libraryService: LibraryService, private toastr: ToastrService) { + this.accountService.currentUser$.pipe(take(1)).subscribe(user => { + if (user) { + this.isAdmin = this.accountService.hasAdminRole(user); + } + }); + } + + ngOnInit(): void { + } + + ngOnChanges(changes: any) { + if (this.data) { + this.generateActions(); + } + } + + generateActions() { + this.actions = []; + + if (this.isAdmin) { + this.actions.push({title: 'Scan Library', callback: (data: Library) => { + console.log('You tried to scan library: ' + data.name); + this.libraryService.scan(data?.id).subscribe((res: any) => { + this.toastr.success('Scan started for ' + data.name); + }); + }}); + } + } + + handleClick() { + this.clicked.emit(this.data); + this.router.navigate(['library', this.data?.id]); + } + +} diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 01a2b702f..adcc30dc2 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -4,11 +4,12 @@ import { RegisterMemberComponent } from './register-member/register-member.compo import { ReactiveFormsModule } from '@angular/forms'; import { CardItemComponent } from './card-item/card-item.component'; import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; +import { LibraryCardComponent } from './library-card/library-card.component'; @NgModule({ - declarations: [RegisterMemberComponent, CardItemComponent], + declarations: [RegisterMemberComponent, CardItemComponent, LibraryCardComponent], imports: [ CommonModule, ReactiveFormsModule, @@ -16,7 +17,8 @@ import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; ], exports: [ RegisterMemberComponent, - CardItemComponent + CardItemComponent, + LibraryCardComponent ] }) export class SharedModule { }