]>
Commit | Line | Data |
---|---|---|
c5911fd3 C |
1 | import { Component, OnInit, ViewChild } from '@angular/core' |
2 | import { NotificationsService } from 'angular2-notifications' | |
234b535d | 3 | import { BytesPipe } from 'ngx-pipes' |
c30745f3 | 4 | import { AuthService } from '../../core' |
01de67b9 C |
5 | import { ServerService } from '../../core/server' |
6 | import { User } from '../../shared' | |
c5911fd3 | 7 | import { UserService } from '../../shared/users' |
b1d40cff | 8 | import { 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 | 15 | export class MyAccountSettingsComponent implements OnInit { |
c30745f3 | 16 | user: User = null |
234b535d | 17 | userVideoQuota = '0' |
ce5496d6 | 18 | userVideoQuotaUsed = 0 |
c30745f3 | 19 | |
c5911fd3 C |
20 | constructor ( |
21 | private userService: UserService, | |
22 | private authService: AuthService, | |
01de67b9 | 23 | private serverService: ServerService, |
b1d40cff C |
24 | private notificationsService: NotificationsService, |
25 | private i18n: I18n | |
c5911fd3 | 26 | ) {} |
c30745f3 | 27 | |
d18d6478 C |
28 | get userInformationLoaded () { |
29 | return this.authService.userInformationLoaded | |
30 | } | |
31 | ||
c30745f3 C |
32 | ngOnInit () { |
33 | this.user = this.authService.getUser() | |
ce5496d6 | 34 | |
234b535d C |
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 { | |
b1d40cff | 40 | this.userVideoQuota = this.i18n('Unlimited') |
234b535d C |
41 | } |
42 | } | |
43 | ) | |
44 | ||
ce5496d6 C |
45 | this.userService.getMyVideoQuotaUsed() |
46 | .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed) | |
c30745f3 | 47 | } |
2295ce6c | 48 | |
52d9f792 | 49 | onAvatarChange (formData: FormData) { |
c5911fd3 C |
50 | this.userService.changeAvatar(formData) |
51 | .subscribe( | |
52 | data => { | |
b1d40cff | 53 | this.notificationsService.success(this.i18n('Success'), this.i18n('Avatar changed.')) |
c5911fd3 | 54 | |
0c237b19 | 55 | this.user.updateAccountAvatar(data.avatar) |
c5911fd3 C |
56 | }, |
57 | ||
b1d40cff | 58 | err => this.notificationsService.error(this.i18n('Error'), err.message) |
c5911fd3 | 59 | ) |
2295ce6c | 60 | } |
c30745f3 | 61 | } |