]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/account/account-settings/account-settings.component.ts
Fix changelog bullet points
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-settings / 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',
11 templateUrl: './account-settings.component.html',
12 styleUrls: [ './account-settings.component.scss' ]
13})
14export class AccountSettingsComponent 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 getAvatarUrl () {
46 return this.user.getAvatarUrl()
47 }
48
49 changeAvatar () {
50 const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ]
51
52 const formData = new FormData()
53 formData.append('avatarfile', avatarfile)
54
55 this.userService.changeAvatar(formData)
56 .subscribe(
57 data => {
58 this.notificationsService.success('Success', 'Avatar changed.')
59
60 this.user.account.avatar = data.avatar
61 },
62
63 err => this.notificationsService.error('Error', err.message)
64 )
2295ce6c 65 }
01de67b9
C
66
67 get maxAvatarSize () {
68 return this.serverService.getConfig().avatar.file.size.max
69 }
70
71 get avatarExtensions () {
72 return this.serverService.getConfig().avatar.file.extensions.join(',')
73 }
c30745f3 74}