2019-03-03 17:30:12 +08:00
|
|
|
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
|
|
|
|
import {RouterLink} from '@angular/router';
|
|
|
|
import {PersonDTO} from '../../../../../common/entities/PersonDTO';
|
|
|
|
import {SearchTypes} from '../../../../../common/entities/AutoCompleteItem';
|
|
|
|
import {DomSanitizer} from '@angular/platform-browser';
|
|
|
|
import {PersonThumbnail, ThumbnailManagerService} from '../../gallery/thumbnailManager.service';
|
2019-03-04 04:17:42 +08:00
|
|
|
import {FacesService} from '../faces.service';
|
|
|
|
import {AuthenticationService} from '../../../model/network/authentication.service';
|
|
|
|
import {Config} from '../../../../../common/config/public/Config';
|
2019-03-03 17:30:12 +08:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-face',
|
|
|
|
templateUrl: './face.component.html',
|
|
|
|
styleUrls: ['./face.component.css'],
|
|
|
|
providers: [RouterLink],
|
|
|
|
})
|
|
|
|
export class FaceComponent implements OnInit, OnDestroy {
|
|
|
|
@Input() person: PersonDTO;
|
|
|
|
@Input() size: number;
|
|
|
|
|
|
|
|
thumbnail: PersonThumbnail = null;
|
|
|
|
SearchTypes = SearchTypes;
|
|
|
|
|
|
|
|
constructor(private thumbnailService: ThumbnailManagerService,
|
2019-03-04 04:17:42 +08:00
|
|
|
private _sanitizer: DomSanitizer,
|
|
|
|
private faceService: FacesService,
|
|
|
|
public authenticationService: AuthenticationService) {
|
2019-03-03 17:30:12 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-04 04:17:42 +08:00
|
|
|
get CanUpdate(): boolean {
|
|
|
|
return this.authenticationService.user.getValue().role >= Config.Client.Faces.writeAccessMinRole;
|
|
|
|
}
|
|
|
|
|
2019-03-03 17:30:12 +08:00
|
|
|
ngOnInit() {
|
|
|
|
this.thumbnail = this.thumbnailService.getPersonThumbnail(this.person);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
getSanitizedThUrl() {
|
|
|
|
return this._sanitizer.bypassSecurityTrustStyle('url(' +
|
|
|
|
encodeURI(this.thumbnail.Src)
|
|
|
|
.replace(/\(/g, '%28')
|
|
|
|
.replace(/'/g, '%27')
|
|
|
|
.replace(/\)/g, '%29') + ')');
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.thumbnail != null) {
|
|
|
|
this.thumbnail.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 04:17:42 +08:00
|
|
|
async toggleFavourite($event: MouseEvent) {
|
|
|
|
$event.preventDefault();
|
|
|
|
$event.stopPropagation();
|
|
|
|
await this.faceService.setFavourite(this.person, !this.person.isFavourite).catch(console.error);
|
|
|
|
}
|
2019-03-03 17:30:12 +08:00
|
|
|
}
|
|
|
|
|