X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fshared-main%2Faccount%2Factor-avatar-info.component.ts;h=87e9e917c6fb6db69ec0d4e997994ba6988bf863;hb=282695e699a35b65441b548061ef0db5de9b3971;hp=0c04ae4a64e71c4f7430387aa3fa78271dc19633;hpb=67ed6552b831df66713bac9e672738796128d33f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts b/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts index 0c04ae4a6..87e9e917c 100644 --- a/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts +++ b/client/src/app/shared/shared-main/account/actor-avatar-info.component.ts @@ -1,64 +1,77 @@ -import { BytesPipe } from 'ngx-pipes' -import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' +import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core' import { Notifier, ServerService } from '@app/core' -import { Account, VideoChannel } from '@app/shared/shared-main' -import { I18n } from '@ngx-translate/i18n-polyfill' -import { ServerConfig } from '@shared/models' +import { NgbPopover } from '@ng-bootstrap/ng-bootstrap' +import { getBytes } from '@root-helpers/bytes' +import { Account } from '../account/account.model' +import { VideoChannel } from '../video-channel/video-channel.model' +import { Actor } from './actor.model' @Component({ selector: 'my-actor-avatar-info', templateUrl: './actor-avatar-info.component.html', styleUrls: [ './actor-avatar-info.component.scss' ] }) -export class ActorAvatarInfoComponent implements OnInit { +export class ActorAvatarInfoComponent implements OnInit, OnChanges { @ViewChild('avatarfileInput') avatarfileInput: ElementRef + @ViewChild('avatarPopover') avatarPopover: NgbPopover @Input() actor: VideoChannel | Account @Output() avatarChange = new EventEmitter() + @Output() avatarDelete = new EventEmitter() - maxSizeText: string + avatarFormat = '' + maxAvatarSize = 0 + avatarExtensions = '' - private serverConfig: ServerConfig - private bytesPipe: BytesPipe + private avatarUrl: string constructor ( private serverService: ServerService, - private notifier: Notifier, - private i18n: I18n - ) { - this.bytesPipe = new BytesPipe() - this.maxSizeText = this.i18n('max size') - } + private notifier: Notifier + ) { } ngOnInit (): void { - this.serverConfig = this.serverService.getTmpConfig() this.serverService.getConfig() - .subscribe(config => this.serverConfig = config) + .subscribe(config => { + this.maxAvatarSize = config.avatar.file.size.max + this.avatarExtensions = config.avatar.file.extensions.join(', ') + + this.avatarFormat = `${$localize`max size`}: 192*192px, ` + + `${getBytes(this.maxAvatarSize)} ${$localize`extensions`}: ${this.avatarExtensions}` + }) } - onAvatarChange () { + ngOnChanges (changes: SimpleChanges) { + if (changes['actor']) { + this.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.actor) + } + } + + onAvatarChange (input: HTMLInputElement) { + this.avatarfileInput = new ElementRef(input) + const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ] if (avatarfile.size > this.maxAvatarSize) { - this.notifier.error('Error', 'This image is too large.') + this.notifier.error('Error', $localize`This image is too large.`) return } const formData = new FormData() formData.append('avatarfile', avatarfile) - + this.avatarPopover?.close() this.avatarChange.emit(formData) } - get maxAvatarSize () { - return this.serverConfig.avatar.file.size.max + deleteAvatar () { + this.avatarDelete.emit() } - get maxAvatarSizeInBytes () { - return this.bytesPipe.transform(this.maxAvatarSize) + hasAvatar () { + return !!this.avatarUrl } - get avatarExtensions () { - return this.serverConfig.avatar.file.extensions.join(', ') + isChannel () { + return !!(this.actor as VideoChannel).ownerAccount } }