diff options
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 | 74 |
1 files changed, 74 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..91420cc6f --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-settings.component.ts | |||
@@ -0,0 +1,74 @@ | |||
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 | 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 | ) | ||
65 | } | ||
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 | } | ||
74 | } | ||