Merge changes from monitor-production

This commit is contained in:
Konstantinos Triantafyllou 2023-03-21 14:05:21 +02:00
commit 5bcc25fe84
5 changed files with 80 additions and 39 deletions

View File

@ -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 {UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators} from '@angular/forms';
import {AlertModal} from "../../../utils/modal/alert"; import {AlertModal} from "../../../utils/modal/alert";
import {UserRegistryService} from "../../../services/user-registry.service"; import {UserRegistryService} from "../../../services/user-registry.service";
@ -77,6 +77,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
this.updateLists(); this.updateLists();
this.userManagementService.getUserInfo().subscribe(user => { this.userManagementService.getUserInfo().subscribe(user => {
this.user = user; this.user = user;
console.log(this.canDelete)
}); });
} }
@ -277,7 +278,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
} }
public isMe(userId: string) { 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 { public get isManager(): boolean {

View File

@ -43,8 +43,8 @@ export class UserComponent {
this.loginUrl = this.properties.loginUrl; this.loginUrl = this.properties.loginUrl;
if (typeof document !== 'undefined') { if (typeof document !== 'undefined') {
this.server = false; this.server = false;
this.userManagementsService.updateUserInfo(() => { this.userManagementsService.getUserInfo().subscribe( user => {
this.user = this.userManagementsService.user; this.user = user;
this.loggedIn = !!this.user; this.loggedIn = !!this.user;
this.errorMessage = ""; this.errorMessage = "";
this.loading = true; this.loading = true;

View File

@ -58,7 +58,10 @@ export class StakeholderService {
} }
async getStakeholderAsync() { async getStakeholderAsync() {
await this.promise; if(this.promise) {
await this.promise;
this.promise = null;
}
this.clearSubscriptions(); this.clearSubscriptions();
return this.stakeholderSubject.getValue(); return this.stakeholderSubject.getValue();
} }

View File

@ -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 {User} from "../login/utils/helper.class";
import {ActivatedRoute, Router} from "@angular/router"; import {ActivatedRoute, Router} from "@angular/router";
import {UserManagementService} from "../services/user-management.service"; import {UserManagementService} from "../services/user-management.service";
@ -35,7 +35,7 @@ import {ClearCacheService} from "../services/clear-cache.service";
</div> </div>
</modal-alert> </modal-alert>
<modal-alert #memberModal [overflowBody]="false" *ngIf="service == 'monitor'" (cancelOutput)="cancel()" <modal-alert #memberModal [overflowBody]="false" *ngIf="service == 'monitor'" (cancelOutput)="cancel()"
(alertOutput)="verifyMember()" [okDisabled]="code.invalid || loading"> (alertOutput)="verifyMember()" [okDisabled]="(code.invalid || loading) && !isMember">
<div *ngIf="!isMember"> <div *ngIf="!isMember">
<div> <div>
You have been invited to join <span class="uk-text-bold">{{name}}</span> Monitor Dashboard as a member. You have been invited to join <span class="uk-text-bold">{{name}}</span> Monitor Dashboard as a member.
@ -108,7 +108,8 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
private emailService: EmailService, private emailService: EmailService,
private userManagementService: UserManagementService, private userManagementService: UserManagementService,
private userRegistryService: UserRegistryService, private userRegistryService: UserRegistryService,
private clearCacheService: ClearCacheService) { private clearCacheService: ClearCacheService,
private cdr: ChangeDetectorRef) {
} }
ngOnInit() { ngOnInit() {
@ -122,33 +123,42 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
this.paramsSubscription.unsubscribe(); this.paramsSubscription.unsubscribe();
} }
this.paramsSubscription = this.route.queryParams.subscribe(params => { this.paramsSubscription = this.route.queryParams.subscribe(params => {
if (params && params['verify']) { if (params) {
if (this.user) { this.isMember = !!params['isMember'];
this.subscriptions.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => { this.cdr.detectChanges();
this.verification = verification; if(params['verify'] && !this.isMember) {
if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) { if (this.user) {
if (this.verification.verificationType === 'manager') { this.subscriptions.push(this.userRegistryService.getInvitation(params['verify']).subscribe(verification => {
this.openManagerModal(); this.verification = verification;
} else if (this.verification.verificationType === 'member' && this.service === "monitor") { if (this.user.email === this.verification.email.toLowerCase() && this.id === this.verification.entity && this.type === this.verification.type) {
this.openMemberModal(); if (this.verification.verificationType === 'manager') {
this.openManagerModal();
} else if (this.verification.verificationType === 'member' && this.service === "monitor") {
this.openMemberModal();
} else {
this.openErrorModal();
}
} else { } else {
this.openErrorModal(); this.openErrorModal();
} }
} else { }, error => {
this.openErrorModal(); this.openErrorModal();
} }));
}, error => { } else {
this.openErrorModal(); this.router.navigate(['user-info'], {
})); queryParams: {
} else { 'errorCode': LoginErrorCodes.NOT_LOGIN,
this.router.navigate(['user-info'], { 'redirectUrl': this.router.url
queryParams: { },
'errorCode': LoginErrorCodes.NOT_LOGIN, relativeTo: this.route
'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() { public openMemberModal() {
this.error = null; 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.okButtonLeft = false;
this.memberModal.okButtonText = 'Accept';
this.memberModal.stayOpen = true; this.memberModal.stayOpen = true;
this.memberModal.cancelButtonText = 'Cancel'; this.memberModal.cancelButtonText = 'Cancel';
this.memberModal.alertTitle = 'Member Invitation'; this.memberModal.alertTitle = 'Member Invitation';
this.cdr.detectChanges();
this.memberModal.open(); this.memberModal.open();
} }
@ -239,9 +255,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
this.loading = false; this.loading = false;
this.error = null; this.error = null;
this.userManagementService.updateUserInfo(() => { this.userManagementService.updateUserInfo(() => {
this.memberModal.cancelButton = false; this.router.navigate([], {queryParams: {'verify': null, 'isMember': true}});
this.memberModal.okButtonText = 'Close';
this.isMember = true;
}); });
}, error => { }, error => {
this.loading = false; this.loading = false;
@ -257,6 +271,6 @@ export class RoleVerificationComponent implements OnInit, OnDestroy, AfterViewIn
} }
cancel() { cancel() {
this.router.navigate([this.router.url.split('?')[0]]); this.router.navigate([], {queryParams: {'verify': null, 'isMember': null}});
} }
} }

View File

@ -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; declare var UIkit: any;
@ -48,7 +58,7 @@ declare var UIkit: any;
/** /**
* API to an open alert window. * API to an open alert window.
*/ */
export class AlertModal { export class AlertModal implements OnInit, AfterViewInit, OnDestroy {
private static MODAL_COUNTER: number = 0; private static MODAL_COUNTER: number = 0;
id: string = "modal"; id: string = "modal";
@ -136,6 +146,7 @@ export class AlertModal {
@Output() public cancelOutput: EventEmitter<any> = new EventEmitter(); @Output() public cancelOutput: EventEmitter<any> = new EventEmitter();
@ViewChild('element') element: ElementRef; @ViewChild('element') element: ElementRef;
private subscriptions: any[] = [];
constructor() { constructor() {
} }
@ -145,6 +156,14 @@ export class AlertModal {
this.id = 'modal-' + AlertModal.MODAL_COUNTER; 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() { ngOnDestroy() {
if(typeof document !== "undefined") { if(typeof document !== "undefined") {
const element = document.getElementById("modal-container"); 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() { cancel() {
UIkit.modal(this.element.nativeElement).hide(); UIkit.modal(this.element.nativeElement).hide();
this.cancelOutput.emit(true);
} }
} }