]>
Commit | Line | Data |
---|---|---|
c5911fd3 C |
1 | import { Component, OnInit, ViewChild } from '@angular/core' |
2 | import { NotificationsService } from 'angular2-notifications' | |
c30745f3 | 3 | import { AuthService } from '../../core' |
01de67b9 C |
4 | import { ServerService } from '../../core/server' |
5 | import { User } from '../../shared' | |
c5911fd3 | 6 | import { UserService } from '../../shared/users' |
c30745f3 C |
7 | |
8 | @Component({ | |
9 | selector: 'my-account-settings', | |
10 | templateUrl: './account-settings.component.html', | |
11 | styleUrls: [ './account-settings.component.scss' ] | |
12 | }) | |
13 | export class AccountSettingsComponent implements OnInit { | |
c5911fd3 C |
14 | @ViewChild('avatarfileInput') avatarfileInput |
15 | ||
c30745f3 C |
16 | user: User = null |
17 | ||
c5911fd3 C |
18 | constructor ( |
19 | private userService: UserService, | |
20 | private authService: AuthService, | |
01de67b9 | 21 | private serverService: ServerService, |
c5911fd3 C |
22 | private notificationsService: NotificationsService |
23 | ) {} | |
c30745f3 C |
24 | |
25 | ngOnInit () { | |
26 | this.user = this.authService.getUser() | |
27 | } | |
2295ce6c | 28 | |
c5911fd3 C |
29 | getAvatarUrl () { |
30 | return this.user.getAvatarUrl() | |
31 | } | |
32 | ||
33 | changeAvatar () { | |
34 | const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ] | |
35 | ||
36 | const formData = new FormData() | |
37 | formData.append('avatarfile', avatarfile) | |
38 | ||
39 | this.userService.changeAvatar(formData) | |
40 | .subscribe( | |
41 | data => { | |
42 | this.notificationsService.success('Success', 'Avatar changed.') | |
43 | ||
44 | this.user.account.avatar = data.avatar | |
45 | }, | |
46 | ||
47 | err => this.notificationsService.error('Error', err.message) | |
48 | ) | |
2295ce6c | 49 | } |
01de67b9 C |
50 | |
51 | get maxAvatarSize () { | |
52 | return this.serverService.getConfig().avatar.file.size.max | |
53 | } | |
54 | ||
55 | get avatarExtensions () { | |
56 | return this.serverService.getConfig().avatar.file.extensions.join(',') | |
57 | } | |
c30745f3 | 58 | } |