]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/my-account/my-account-settings/my-account-settings.component.ts
Fix account link in the menu
[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'
c30745f3
C
8
9@Component({
10 selector: 'my-account-settings',
4bb6886d
C
11 templateUrl: './my-account-settings.component.html',
12 styleUrls: [ './my-account-settings.component.scss' ]
c30745f3 13})
4bb6886d 14export class MyAccountSettingsComponent implements OnInit {
c5911fd3
C
15 @ViewChild('avatarfileInput') avatarfileInput
16
c30745f3 17 user: User = null
234b535d 18 userVideoQuota = '0'
ce5496d6 19 userVideoQuotaUsed = 0
c30745f3 20
c5911fd3
C
21 constructor (
22 private userService: UserService,
23 private authService: AuthService,
01de67b9 24 private serverService: ServerService,
c5911fd3
C
25 private notificationsService: NotificationsService
26 ) {}
c30745f3
C
27
28 ngOnInit () {
29 this.user = this.authService.getUser()
ce5496d6 30
234b535d
C
31 this.authService.userInformationLoaded.subscribe(
32 () => {
33 if (this.user.videoQuota !== -1) {
34 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
35 } else {
36 this.userVideoQuota = 'Unlimited'
37 }
38 }
39 )
40
ce5496d6
C
41 this.userService.getMyVideoQuotaUsed()
42 .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed)
c30745f3 43 }
2295ce6c 44
c5911fd3
C
45 changeAvatar () {
46 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
47
48 const formData = new FormData()
49 formData.append('avatarfile', avatarfile)
50
51 this.userService.changeAvatar(formData)
52 .subscribe(
53 data => {
54 this.notificationsService.success('Success', 'Avatar changed.')
55
56 this.user.account.avatar = data.avatar
57 },
58
59 err => this.notificationsService.error('Error', err.message)
60 )
2295ce6c 61 }
01de67b9
C
62
63 get maxAvatarSize () {
64 return this.serverService.getConfig().avatar.file.size.max
65 }
66
67 get avatarExtensions () {
68 return this.serverService.getConfig().avatar.file.extensions.join(',')
69 }
c30745f3 70}