Add i18n attributes
[oweals/peertube.git] / client / src / app / +my-account / my-account-settings / my-account-settings.component.ts
1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { BytesPipe } from 'ngx-pipes'
4 import { AuthService } from '../../core'
5 import { ServerService } from '../../core/server'
6 import { User } from '../../shared'
7 import { UserService } from '../../shared/users'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
9
10 @Component({
11   selector: 'my-account-settings',
12   templateUrl: './my-account-settings.component.html',
13   styleUrls: [ './my-account-settings.component.scss' ]
14 })
15 export class MyAccountSettingsComponent implements OnInit {
16   @ViewChild('avatarfileInput') avatarfileInput
17
18   user: User = null
19   userVideoQuota = '0'
20   userVideoQuotaUsed = 0
21
22   constructor (
23     private userService: UserService,
24     private authService: AuthService,
25     private serverService: ServerService,
26     private notificationsService: NotificationsService,
27     private i18n: I18n
28   ) {}
29
30   ngOnInit () {
31     this.user = this.authService.getUser()
32
33     this.authService.userInformationLoaded.subscribe(
34       () => {
35         if (this.user.videoQuota !== -1) {
36           this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
37         } else {
38           this.userVideoQuota = this.i18n('Unlimited')
39         }
40       }
41     )
42
43     this.userService.getMyVideoQuotaUsed()
44       .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
45   }
46
47   changeAvatar () {
48     const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
49
50     const formData = new FormData()
51     formData.append('avatarfile', avatarfile)
52
53     this.userService.changeAvatar(formData)
54       .subscribe(
55         data => {
56           this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.'))
57
58           this.user.account.avatar = data.avatar
59         },
60
61         err => this.notificationsService.error(this.i18n('Error'), err.message)
62       )
63   }
64
65   get maxAvatarSize () {
66     return this.serverService.getConfig().avatar.file.size.max
67   }
68
69   get avatarExtensions () {
70     return this.serverService.getConfig().avatar.file.extensions.join(',')
71   }
72 }