FarmMapsLib/projects/common/src/fm/components/avatar/avatar.component.ts

48 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-03-01 11:32:14 +00:00
import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges } from '@angular/core';
2021-02-25 16:17:52 +00:00
import { IUser } from '../../models/user';
2021-02-27 09:16:07 +00:00
import { AppConfig } from '../../shared/app.config';
2021-02-25 16:17:52 +00:00
@Component({
selector: 'fm-avatar',
templateUrl: './avatar.component.html',
2021-05-04 14:22:46 +00:00
styleUrls: ['./avatar.component.css']
2021-02-25 16:17:52 +00:00
})
2021-03-01 11:38:16 +00:00
export class AvatarComponent implements OnInit {
2021-02-25 16:17:52 +00:00
@Input() user: IUser;
@Input() bgColor: string;
@Input() fgColor: string;
2023-03-06 13:04:14 +00:00
@Input() size = 75;
@Input() round = true;
2021-02-25 16:17:52 +00:00
@Output() click = new EventEmitter();
2021-03-01 11:32:14 +00:00
src : string = null;
name : string = null;
2021-02-27 09:16:07 +00:00
constructor(private appConfig: AppConfig) {
}
2021-02-25 16:17:52 +00:00
ngOnInit(): void {
}
2021-03-01 11:32:14 +00:00
ngOnChanges(changes: SimpleChanges): void {
if (changes['user']) {
const user: IUser = changes['user'].currentValue;
this.refresh(user);
}
2021-02-27 09:16:07 +00:00
}
2021-03-01 11:32:14 +00:00
onClick(event: MouseEvent) {
event.stopPropagation();
this.click.emit();
2021-02-25 16:17:52 +00:00
}
2021-03-01 11:32:14 +00:00
refresh(user: IUser) {
if (!user) return null;
const apiEndpoint = this.appConfig.getConfig("apiEndPoint");
this.src = `${apiEndpoint}/api/v1/users/${user.code}/avatar`;
this.name = user.firstName && user.lastName ?
user.firstName + ' ' + user.lastName : user.name;
2021-02-25 16:17:52 +00:00
}
2021-03-01 11:32:14 +00:00
}