diff options
author | Chocobozzz <me@florianbigard.com> | 2018-05-09 09:26:41 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-05-09 09:32:26 +0200 |
commit | 62e62f118d5da57acd3494fece2e8ed357564ffe (patch) | |
tree | ff5b7c6ec5708d71a76a2eb5744d810015ae29a5 /client/src/app/+my-account/my-account-settings/my-account-settings.component.ts | |
parent | 1952a538baa330b13bd11631b3975f7ef1c37e70 (diff) | |
download | PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.tar.gz PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.tar.zst PeerTube-62e62f118d5da57acd3494fece2e8ed357564ffe.zip |
Load my-account module lazily
Diffstat (limited to 'client/src/app/+my-account/my-account-settings/my-account-settings.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-settings/my-account-settings.component.ts | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts new file mode 100644 index 000000000..06d1138e7 --- /dev/null +++ b/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts | |||
@@ -0,0 +1,70 @@ | |||
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 | |||
9 | @Component({ | ||
10 | selector: 'my-account-settings', | ||
11 | templateUrl: './my-account-settings.component.html', | ||
12 | styleUrls: [ './my-account-settings.component.scss' ] | ||
13 | }) | ||
14 | export class MyAccountSettingsComponent implements OnInit { | ||
15 | @ViewChild('avatarfileInput') avatarfileInput | ||
16 | |||
17 | user: User = null | ||
18 | userVideoQuota = '0' | ||
19 | userVideoQuotaUsed = 0 | ||
20 | |||
21 | constructor ( | ||
22 | private userService: UserService, | ||
23 | private authService: AuthService, | ||
24 | private serverService: ServerService, | ||
25 | private notificationsService: NotificationsService | ||
26 | ) {} | ||
27 | |||
28 | ngOnInit () { | ||
29 | this.user = this.authService.getUser() | ||
30 | |||
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 | |||
41 | this.userService.getMyVideoQuotaUsed() | ||
42 | .subscribe(data => this.userVideoQuotaUsed = data.videoQuotaUsed) | ||
43 | } | ||
44 | |||
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 | ) | ||
61 | } | ||
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 | } | ||
70 | } | ||