]>
Commit | Line | Data |
---|---|---|
d3217560 | 1 | import { ReplaySubject } from 'rxjs' |
d3217560 | 2 | import { filter } from 'rxjs/operators' |
67ed6552 C |
3 | import { Component, OnInit, ViewChild } from '@angular/core' |
4 | import { AuthService, AuthStatus, LocalStorageService, User, UserService } from '@app/core' | |
5 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | |
6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | |
7 | import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |
d3217560 RK |
8 | |
9 | @Component({ | |
10 | selector: 'my-quick-settings', | |
11 | templateUrl: './quick-settings-modal.component.html', | |
12 | styleUrls: [ './quick-settings-modal.component.scss' ] | |
13 | }) | |
14 | export class QuickSettingsModalComponent extends FormReactive implements OnInit { | |
15 | @ViewChild('modal', { static: true }) modal: NgbModal | |
16 | ||
17 | user: User | |
18 | userInformationLoaded = new ReplaySubject<boolean>(1) | |
19 | ||
20 | private openedModal: NgbModalRef | |
21 | ||
22 | constructor ( | |
23 | protected formValidatorService: FormValidatorService, | |
24 | private modalService: NgbModal, | |
25 | private userService: UserService, | |
26 | private authService: AuthService, | |
27 | private localStorageService: LocalStorageService | |
28 | ) { | |
29 | super() | |
30 | } | |
31 | ||
32 | ngOnInit () { | |
33 | this.user = this.userService.getAnonymousUser() | |
5c20a455 C |
34 | this.localStorageService.watch() |
35 | .subscribe( | |
36 | () => this.user = this.userService.getAnonymousUser() | |
37 | ) | |
38 | ||
d3217560 RK |
39 | this.userInformationLoaded.next(true) |
40 | ||
41 | this.authService.loginChangedSource | |
42 | .pipe(filter(status => status !== AuthStatus.LoggedIn)) | |
43 | .subscribe( | |
44 | () => { | |
45 | this.user = this.userService.getAnonymousUser() | |
46 | this.userInformationLoaded.next(true) | |
47 | } | |
48 | ) | |
49 | } | |
50 | ||
51 | isUserLoggedIn () { | |
52 | return this.authService.isLoggedIn() | |
53 | } | |
54 | ||
55 | show () { | |
56 | this.openedModal = this.modalService.open(this.modal, { centered: true }) | |
57 | } | |
58 | ||
59 | hide () { | |
60 | this.openedModal.close() | |
61 | this.form.reset() | |
62 | } | |
63 | } |