diff --git a/dashboard/users/role-users/role-users.component.ts b/dashboard/users/role-users/role-users.component.ts index 0e3e17c7..222f8530 100644 --- a/dashboard/users/role-users/role-users.component.ts +++ b/dashboard/users/role-users/role-users.component.ts @@ -1,4 +1,4 @@ -import {Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, ViewChild} from '@angular/core'; +import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild} from '@angular/core'; import {UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators} from '@angular/forms'; import {AlertModal} from "../../../utils/modal/alert"; import {UserRegistryService} from "../../../services/user-registry.service"; @@ -77,6 +77,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { this.updateLists(); this.userManagementService.getUserInfo().subscribe(user => { this.user = user; + console.log(this.canDelete) }); } @@ -277,7 +278,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { } public isMe(userId: string) { - return userId.includes(this.user.id) && !this.isCurator; + return userId && userId.includes(this.user.id) && !this.isCurator; } public get isManager(): boolean { diff --git a/login/user.component.ts b/login/user.component.ts index 1fcdc867..15922fe7 100644 --- a/login/user.component.ts +++ b/login/user.component.ts @@ -43,8 +43,8 @@ export class UserComponent { this.loginUrl = this.properties.loginUrl; if (typeof document !== 'undefined') { this.server = false; - this.userManagementsService.updateUserInfo(() => { - this.user = this.userManagementsService.user; + this.userManagementsService.getUserInfo().subscribe( user => { + this.user = user; this.loggedIn = !!this.user; this.errorMessage = ""; this.loading = true; diff --git a/monitor/services/stakeholder.service.ts b/monitor/services/stakeholder.service.ts index 272cbb39..c71f7f8e 100644 --- a/monitor/services/stakeholder.service.ts +++ b/monitor/services/stakeholder.service.ts @@ -58,7 +58,10 @@ export class StakeholderService { } async getStakeholderAsync() { - await this.promise; + if(this.promise) { + await this.promise; + this.promise = null; + } this.clearSubscriptions(); return this.stakeholderSubject.getValue(); } diff --git a/role-verification/role-verification.component.ts b/role-verification/role-verification.component.ts index 253fa91c..9030d636 100644 --- a/role-verification/role-verification.component.ts +++ b/role-verification/role-verification.component.ts @@ -1,4 +1,4 @@ -import {AfterViewInit, Component, Input, OnDestroy, OnInit, ViewChild} from "@angular/core"; +import {AfterViewInit, ChangeDetectorRef, Component, Input, OnDestroy, OnInit, ViewChild} from "@angular/core"; import {User} from "../login/utils/helper.class"; import {ActivatedRoute, Router} from "@angular/router"; import {UserManagementService} from "../services/user-management.service"; @@ -35,7 +35,7 @@ import {ClearCacheService} from "../services/clear-cache.service"; + (alertOutput)="verifyMember()" [okDisabled]="(code.invalid || loading) && !isMember">
You have been invited to join {{name}} Monitor Dashboard as a member. @@ -108,7 +108,8 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn private emailService: EmailService, private userManagementService: UserManagementService, private userRegistryService: UserRegistryService, - private clearCacheService: ClearCacheService) { + private clearCacheService: ClearCacheService, + private cdr: ChangeDetectorRef) { } ngOnInit() { @@ -122,33 +123,42 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn this.paramsSubscription.unsubscribe(); } this.paramsSubscription = this.route.queryParams.subscribe(params => { - if (params && params['verify']) { - if (this.user) { - this.subscriptions.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => { - this.verification = verification; - if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) { - if (this.verification.verificationType === 'manager') { - this.openManagerModal(); - } else if (this.verification.verificationType === 'member' && this.service === "monitor") { - this.openMemberModal(); + if (params) { + this.isMember = !!params['isMember']; + this.cdr.detectChanges(); + if(params['verify'] && !this.isMember) { + if (this.user) { + this.subscriptions.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => { + this.verification = verification; + if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) { + if (this.verification.verificationType === 'manager') { + this.openManagerModal(); + } else if (this.verification.verificationType === 'member' && this.service === "monitor") { + this.openMemberModal(); + } else { + this.openErrorModal(); + } } else { this.openErrorModal(); } - } else { + }, error => { this.openErrorModal(); - } - }, error => { - this.openErrorModal(); - })); - } else { - this.router.navigate(['user-info'], { - queryParams: { - 'errorCode': LoginErrorCodes.NOT_LOGIN, - 'redirectUrl': this.router.url - }, - relativeTo: this.route - }); + })); + } else { + this.router.navigate(['user-info'], { + queryParams: { + 'errorCode': LoginErrorCodes.NOT_LOGIN, + 'redirectUrl': this.router.url + }, + relativeTo: this.route + }); + } + } else if(this.isMember) { + this.openMemberModal(); } + } else { + this.isMember = false; + this.cdr.detectChanges(); } }); })); @@ -177,12 +187,18 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn public openMemberModal() { this.error = null; - this.isMember = false; + if(this.isMember) { + this.memberModal.cancelButton = false; + this.memberModal.okButtonText = 'Close'; + } else { + this.memberModal.cancelButton = true; + this.memberModal.okButtonText = 'Accept'; + } this.memberModal.okButtonLeft = false; - this.memberModal.okButtonText = 'Accept'; this.memberModal.stayOpen = true; this.memberModal.cancelButtonText = 'Cancel'; this.memberModal.alertTitle = 'Member Invitation'; + this.cdr.detectChanges(); this.memberModal.open(); } @@ -239,9 +255,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn this.loading = false; this.error = null; this.userManagementService.updateUserInfo(() => { - this.memberModal.cancelButton = false; - this.memberModal.okButtonText = 'Close'; - this.isMember = true; + this.router.navigate([], {queryParams: {'verify': null, 'isMember': true}}); }); }, error => { this.loading = false; @@ -257,6 +271,6 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn } cancel() { - this.router.navigate([this.router.url.split('?')[0]]); + this.router.navigate([], {queryParams: {'verify': null, 'isMember': null}}); } } diff --git a/utils/modal/alert.ts b/utils/modal/alert.ts index be4bb605..8f7fada7 100644 --- a/utils/modal/alert.ts +++ b/utils/modal/alert.ts @@ -1,4 +1,14 @@ -import {Component, ElementRef, EventEmitter, Input, Output, ViewChild, ViewEncapsulation} from '@angular/core'; +import { + AfterViewInit, + Component, + ElementRef, + EventEmitter, + Input, OnDestroy, + OnInit, + Output, + ViewChild, + ViewEncapsulation +} from '@angular/core'; declare var UIkit: any; @@ -48,7 +58,7 @@ declare var UIkit: any; /** * API to an open alert window. */ -export class AlertModal { +export class AlertModal implements OnInit, AfterViewInit, OnDestroy { private static MODAL_COUNTER: number = 0; id: string = "modal"; @@ -136,6 +146,7 @@ export class AlertModal { @Output() public cancelOutput: EventEmitter = new EventEmitter(); @ViewChild('element') element: ElementRef; + private subscriptions: any[] = []; constructor() { } @@ -145,6 +156,14 @@ export class AlertModal { this.id = 'modal-' + AlertModal.MODAL_COUNTER; } + ngAfterViewInit() { + if(this.element) { + this.subscriptions.push(UIkit.util.on(document, 'hide', '#' + this.id, () => { + this.cancelOutput.emit(true); + })); + } + } + ngOnDestroy() { if(typeof document !== "undefined") { const element = document.getElementById("modal-container"); @@ -155,6 +174,11 @@ export class AlertModal { } } } + this.subscriptions.forEach(subscription => { + if(subscription instanceof Function) { + subscription(); + } + }); } /** @@ -186,6 +210,5 @@ export class AlertModal { */ cancel() { UIkit.modal(this.element.nativeElement).hide(); - this.cancelOutput.emit(true); } }