]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
Fix i18n in components
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-settings.component.ts
CommitLineData
c5911fd3
C
1import { Component, OnInit, ViewChild } from '@angular/core'
2import { NotificationsService } from 'angular2-notifications'
234b535d 3import { BytesPipe } from 'ngx-pipes'
c30745f3 4import { AuthService } from '../../core'
01de67b9
C
5import { ServerService } from '../../core/server'
6import { User } from '../../shared'
c5911fd3 7import { UserService } from '../../shared/users'
b1d40cff 8import { I18n } from '@ngx-translate/i18n-polyfill'
c30745f3
C
9
10@Component({
11 selector: 'my-account-settings',
4bb6886d
C
12 templateUrl: './my-account-settings.component.html',
13 styleUrls: [ './my-account-settings.component.scss' ]
c30745f3 14})
4bb6886d 15export class MyAccountSettingsComponent implements OnInit {
c5911fd3
C
16 @ViewChild('avatarfileInput') avatarfileInput
17
c30745f3 18 user: User = null
234b535d 19 userVideoQuota = '0'
ce5496d6 20 userVideoQuotaUsed = 0
c30745f3 21
c5911fd3
C
22 constructor (
23 private userService: UserService,
24 private authService: AuthService,
01de67b9 25 private serverService: ServerService,
b1d40cff
C
26 private notificationsService: NotificationsService,
27 private i18n: I18n
c5911fd3 28 ) {}
c30745f3
C
29
30 ngOnInit () {
31 this.user = this.authService.getUser()
ce5496d6 32
234b535d
C
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 {
b1d40cff 38 this.userVideoQuota = this.i18n('Unlimited')
234b535d
C
39 }
40 }
41 )
42
ce5496d6
C
43 this.userService.getMyVideoQuotaUsed()
44 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
c30745f3 45 }
2295ce6c 46
c5911fd3
C
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 => {
b1d40cff 56 this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.'))
c5911fd3
C
57
58 this.user.account.avatar = data.avatar
59 },
60
b1d40cff 61 err => this.notificationsService.error(this.i18n('Error'), err.message)
c5911fd3 62 )
2295ce6c 63 }
01de67b9
C
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 }
c30745f3 72}