]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
15f977e586477aa74303c185c64a8efb186df324
[github/Chocobozzz/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 get userInformationLoaded () {
31 return this.authService.userInformationLoaded
32 }
33
34 ngOnInit () {
35 this.user = this.authService.getUser()
36
37 this.authService.userInformationLoaded.subscribe(
38 () => {
39 if (this.user.videoQuota !== -1) {
40 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
41 } else {
42 this.userVideoQuota = this.i18n('Unlimited')
43 }
44 }
45 )
46
47 this.userService.getMyVideoQuotaUsed()
48 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
49 }
50
51 changeAvatar () {
52 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
53
54 const formData = new FormData()
55 formData.append('avatarfile', avatarfile)
56
57 this.userService.changeAvatar(formData)
58 .subscribe(
59 data => {
60 this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.'))
61
62 this.user.account.avatar = data.avatar
63 },
64
65 err => this.notificationsService.error(this.i18n('Error'), err.message)
66 )
67 }
68
69 get maxAvatarSize () {
70 return this.serverService.getConfig().avatar.file.size.max
71 }
72
73 get avatarExtensions () {
74 return this.serverService.getConfig().avatar.file.extensions.join(',')
75 }
76 }