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 {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 {

View File

@ -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;

View File

@ -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();
}

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 {ActivatedRoute, Router} from "@angular/router";
import {UserManagementService} from "../services/user-management.service";
@ -35,7 +35,7 @@ import {ClearCacheService} from "../services/clear-cache.service";
</div>
</modal-alert>
<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>
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 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}});
}
}

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;
@ -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<any> = 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);
}
}