]>
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', | |
266947e5 | 11 | templateUrl: './quick-settings-modal.component.html' |
d3217560 RK |
12 | }) |
13 | export class QuickSettingsModalComponent extends FormReactive implements OnInit { | |
14 | @ViewChild('modal', { static: true }) modal: NgbModal | |
15 | ||
16 | user: User | |
17 | userInformationLoaded = new ReplaySubject<boolean>(1) | |
18 | ||
19 | private openedModal: NgbModalRef | |
20 | ||
21 | constructor ( | |
22 | protected formValidatorService: FormValidatorService, | |
23 | private modalService: NgbModal, | |
24 | private userService: UserService, | |
25 | private authService: AuthService, | |
26 | private localStorageService: LocalStorageService | |
27 | ) { | |
28 | super() | |
29 | } | |
30 | ||
31 | ngOnInit () { | |
32 | this.user = this.userService.getAnonymousUser() | |
5c20a455 C |
33 | this.localStorageService.watch() |
34 | .subscribe( | |
35 | () => this.user = this.userService.getAnonymousUser() | |
36 | ) | |
37 | ||
d3217560 RK |
38 | this.userInformationLoaded.next(true) |
39 | ||
40 | this.authService.loginChangedSource | |
41 | .pipe(filter(status => status !== AuthStatus.LoggedIn)) | |
42 | .subscribe( | |
43 | () => { | |
44 | this.user = this.userService.getAnonymousUser() | |
45 | this.userInformationLoaded.next(true) | |
46 | } | |
47 | ) | |
48 | } | |
49 | ||
50 | isUserLoggedIn () { | |
51 | return this.authService.isLoggedIn() | |
52 | } | |
53 | ||
54 | show () { | |
55 | this.openedModal = this.modalService.open(this.modal, { centered: true }) | |
56 | } | |
57 | ||
58 | hide () { | |
59 | this.openedModal.close() | |
60 | this.form.reset() | |
61 | } | |
62 | } |