]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
164a46a4813ac276d4e9dc1fe4209178493d7bc3
[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 user: User = null
17 userVideoQuota = '0'
18 userVideoQuotaUsed = 0
19
20 constructor (
21 private userService: UserService,
22 private authService: AuthService,
23 private serverService: ServerService,
24 private notificationsService: NotificationsService,
25 private i18n: I18n
26 ) {}
27
28 get userInformationLoaded () {
29 return this.authService.userInformationLoaded
30 }
31
32 ngOnInit () {
33 this.user = this.authService.getUser()
34
35 this.authService.userInformationLoaded.subscribe(
36 () => {
37 if (this.user.videoQuota !== -1) {
38 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
39 } else {
40 this.userVideoQuota = this.i18n('Unlimited')
41 }
42 }
43 )
44
45 this.userService.getMyVideoQuotaUsed()
46 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
47 }
48
49 onAvatarChange (formData: FormData) {
50 this.userService.changeAvatar(formData)
51 .subscribe(
52 data => {
53 this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.'))
54
55 this.user.updateAccountAvatar(data.avatar)
56 },
57
58 err => this.notificationsService.error(this.i18n('Error'), err.message)
59 )
60 }
61 }