Describe user video settings checkboxes, put emphasis on p2p
[oweals/peertube.git] / client / src / app / +my-account / shared / actor-avatar-info.component.ts
index 7b80b1ed439368a14467fe9f927da99d6e4c0956..8e4a7a602654809b0d040ee339bb6cbeaf99fbfd 100644 (file)
@@ -1,30 +1,48 @@
-import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'
+import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
 import { ServerService } from '../../core/server'
-import { NotificationsService } from 'angular2-notifications'
 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
 import { Account } from '@app/shared/account/account.model'
+import { Notifier } from '@app/core'
+import { ServerConfig } from '@shared/models'
+import { BytesPipe } from 'ngx-pipes'
+import { I18n } from '@ngx-translate/i18n-polyfill'
 
 @Component({
   selector: 'my-actor-avatar-info',
   templateUrl: './actor-avatar-info.component.html',
   styleUrls: [ './actor-avatar-info.component.scss' ]
 })
-export class ActorAvatarInfoComponent {
-  @ViewChild('avatarfileInput') avatarfileInput
+export class ActorAvatarInfoComponent implements OnInit {
+  @ViewChild('avatarfileInput') avatarfileInput: ElementRef<HTMLInputElement>
 
   @Input() actor: VideoChannel | Account
 
   @Output() avatarChange = new EventEmitter<FormData>()
 
+  maxSizeText: string
+
+  private serverConfig: ServerConfig
+  private bytesPipe: BytesPipe
+
   constructor (
     private serverService: ServerService,
-    private notificationsService: NotificationsService
-  ) {}
+    private notifier: Notifier,
+    private i18n: I18n
+  ) {
+    this.bytesPipe = new BytesPipe()
+    this.maxSizeText = this.i18n('max size')
+  }
+
+  ngOnInit (): void {
+    this.serverConfig = this.serverService.getTmpConfig()
+    this.serverService.getConfig()
+        .subscribe(config => this.serverConfig = config)
+  }
 
   onAvatarChange () {
     const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
     if (avatarfile.size > this.maxAvatarSize) {
-      this.notificationsService.error('Error', 'This image is too large.')
+      this.notifier.error('Error', 'This image is too large.')
       return
     }
 
@@ -35,10 +53,14 @@ export class ActorAvatarInfoComponent {
   }
 
   get maxAvatarSize () {
-    return this.serverService.getConfig().avatar.file.size.max
+    return this.serverConfig.avatar.file.size.max
+  }
+
+  get maxAvatarSizeInBytes () {
+    return this.bytesPipe.transform(this.maxAvatarSize)
   }
 
   get avatarExtensions () {
-    return this.serverService.getConfig().avatar.file.extensions.join(',')
+    return this.serverConfig.avatar.file.extensions.join(', ')
   }
 }