]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
Put box-shadow for input focus in variables, apply form-control to p-multiselect
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-settings / my-account-settings.component.ts
1 import { Component, OnInit, AfterViewChecked } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { BytesPipe } from 'ngx-pipes'
4 import { AuthService } from '../../core'
5 import { User } from '../../shared'
6 import { UserService } from '../../shared/users'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { ViewportScroller } from '@angular/common'
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, AfterViewChecked {
16 user: User = null
17
18 userVideoQuota = '0'
19 userVideoQuotaUsed = 0
20 userVideoQuotaPercentage = 15
21
22 userVideoQuotaDaily = '0'
23 userVideoQuotaUsedDaily = 0
24 userVideoQuotaDailyPercentage = 15
25
26 constructor (
27 private viewportScroller: ViewportScroller,
28 private userService: UserService,
29 private authService: AuthService,
30 private notifier: Notifier,
31 private i18n: I18n
32 ) {}
33
34 get userInformationLoaded () {
35 return this.authService.userInformationLoaded
36 }
37
38 ngOnInit () {
39 this.user = this.authService.getUser()
40
41 this.authService.userInformationLoaded.subscribe(
42 () => {
43 if (this.user.videoQuota !== -1) {
44 this.userVideoQuota = new BytesPipe().transform(this.user.videoQuota, 0).toString()
45 this.userVideoQuotaPercentage = this.user.videoQuota * 100 / this.userVideoQuotaUsed
46 } else {
47 this.userVideoQuota = this.i18n('Unlimited')
48 }
49
50 if (this.user.videoQuotaDaily !== -1) {
51 this.userVideoQuotaDaily = new BytesPipe().transform(this.user.videoQuotaDaily, 0).toString()
52 this.userVideoQuotaDailyPercentage = this.user.videoQuotaDaily * 100 / this.userVideoQuotaUsedDaily
53 } else {
54 this.userVideoQuotaDaily = this.i18n('Unlimited')
55 }
56 }
57 )
58
59 this.userService.getMyVideoQuotaUsed()
60 .subscribe(data => {
61 this.userVideoQuotaUsed = data.videoQuotaUsed
62 this.userVideoQuotaUsedDaily = data.videoQuotaUsedDaily
63 })
64 }
65
66 ngAfterViewChecked () {
67 if (window.location.hash) this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
68 }
69
70 onAvatarChange (formData: FormData) {
71 this.userService.changeAvatar(formData)
72 .subscribe(
73 data => {
74 this.notifier.success(this.i18n('Avatar changed.'))
75
76 this.user.updateAccountAvatar(data.avatar)
77 },
78
79 err => this.notifier.error(err.message)
80 )
81 }
82
83 hasDailyQuota () {
84 return this.user.videoQuotaDaily !== -1
85 }
86 }