Add new methods in role-users and subscribers.

This commit is contained in:
Konstantinos Triantafyllou 2021-09-17 20:13:35 +03:00
parent 9d65eaab72
commit aae1a2a0d0
5 changed files with 35 additions and 50 deletions

View File

@ -38,9 +38,8 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
@Input() @Input()
public inviteDisableMessage: string; public inviteDisableMessage: string;
public user: User = null; public user: User = null;
public active: any[]; public active: any[] = [];
public showActive: any[] = []; public showActive: any[] = [];
public managers: any[];
public pending: any[]; public pending: any[];
public showPending: any[] = []; public showPending: any[] = [];
public showCurrent: boolean = true; public showCurrent: boolean = true;
@ -114,24 +113,11 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
updateLists() { updateLists() {
this.loadActive = true; this.loadActive = true;
this.loadPending = true; this.loadPending = true;
this.subs.push(this.userRegistryService.getActiveEmail(this.type, this.id, this.role).subscribe(users => { this.subs.push(this.userRegistryService.getActive(this.type, this.id, this.role).subscribe(users => {
if (this.role === 'member') { this.active = users;
this.subs.push(this.userRegistryService.getActiveEmail(this.type, this.id, 'manager').subscribe(managers => { this.filterActiveBySearch(this.filterForm.value.active);
this.managers = managers; this.loadActive = false;
this.active = users; this.exists = true;
this.active.forEach(user => {
user['isManager'] = this.managers.find(manager => manager.email === user.email);
});
this.filterActiveBySearch(this.filterForm.value.active);
this.loadActive = false;
this.exists = true;
}))
} else {
this.active = users;
this.filterActiveBySearch(this.filterForm.value.active);
this.loadActive = false;
this.exists = true;
}
}, error => { }, error => {
this.active = []; this.active = [];
this.showActive = []; this.showActive = [];
@ -191,11 +177,12 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
this.createRoleModal.okButtonLeft = false; this.createRoleModal.okButtonLeft = false;
this.createRoleModal.okButtonText = 'Create'; this.createRoleModal.okButtonText = 'Create';
this.roleFb = this.fb.group({ this.roleFb = this.fb.group({
name: this.fb.control(Role.mapType(this.type, (this.role === 'manager')) + '.' + this.id, Validators.required), name: this.fb.control(Role.mapType(this.type) + '.' + this.id, Validators.required),
description: this.fb.control('', Validators.required) description: this.fb.control(Role.mapType(this.type) + ' ' + this.id, Validators.required)
}); });
setTimeout(() => { setTimeout(() => {
this.roleFb.get('name').disable(); this.roleFb.get('name').disable();
this.roleFb.get('description').disable();
}, 0); }, 0);
this.createRoleModal.open(); this.createRoleModal.open();
} }
@ -204,7 +191,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
this.loadActive = true; this.loadActive = true;
this.subs.push(this.userRegistryService.remove(this.type, this.id, this.selectedUser, this.role).subscribe(() => { this.subs.push(this.userRegistryService.remove(this.type, this.id, this.selectedUser, this.role).subscribe(() => {
this.active = this.active.filter(user => user.email != this.selectedUser); this.active = this.active.filter(user => user.email != this.selectedUser);
if(this.currentActivePage.length === 0) { if (this.currentActivePage.length === 0) {
this.activePage = 1; this.activePage = 1;
} }
this.filterActiveBySearch(this.filterForm.value.active); this.filterActiveBySearch(this.filterForm.value.active);
@ -230,7 +217,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
this.subs.push(this.userRegistryService.cancelInvitation(this.type, this.id, this.selectedUser, this.role).subscribe(() => { this.subs.push(this.userRegistryService.cancelInvitation(this.type, this.id, this.selectedUser, this.role).subscribe(() => {
this.pending = this.pending.filter(user => user != this.selectedUser); this.pending = this.pending.filter(user => user != this.selectedUser);
this.filterPendingBySearch(this.filterForm.value.pending); this.filterPendingBySearch(this.filterForm.value.pending);
if(this.currentPendingPage.length === 0) { if (this.currentPendingPage.length === 0) {
this.pendingPage = 1; this.pendingPage = 1;
} }
UIkit.notification(StringUtils.capitalize(this.role) + ' invitation to ' + this.selectedUser + ' has been <b>canceled</b>', { UIkit.notification(StringUtils.capitalize(this.role) + ' invitation to ' + this.selectedUser + ' has been <b>canceled</b>', {
@ -260,7 +247,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
this.subs.push(this.userRegistryService.invite(this.type, this.id, details, this.role).subscribe(invitation => { this.subs.push(this.userRegistryService.invite(this.type, this.id, details, this.role).subscribe(invitation => {
if (!this.pending.includes(this.invited.value)) { if (!this.pending.includes(this.invited.value)) {
this.pending.push(this.invited.value); this.pending.push(this.invited.value);
this.pendingPage = Math.ceil(this.pending.length/this.pageSize); this.pendingPage = Math.ceil(this.pending.length / this.pageSize);
this.filterPendingBySearch(this.filterForm.value.pending); this.filterPendingBySearch(this.filterForm.value.pending);
} }
if (this.notificationFn) { if (this.notificationFn) {
@ -298,7 +285,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
this.loadActive = true; this.loadActive = true;
this.loadPending = true; this.loadPending = true;
this.roleFb.get('name').enable(); this.roleFb.get('name').enable();
this.userRegistryService.createRole(this.type, this.id, this.roleFb.value).subscribe(() => { this.userRegistryService.createRole(this.type, this.id).subscribe(() => {
UIkit.notification('Group has been <b> successfully created</b>', { UIkit.notification('Group has been <b> successfully created</b>', {
status: 'success', status: 'success',
timeout: 6000, timeout: 6000,

View File

@ -40,7 +40,6 @@ export class SubscribersComponent implements OnInit, OnDestroy, OnChanges {
@Input() @Input()
public inviteDisableMessage: string; public inviteDisableMessage: string;
public user: User = null; public user: User = null;
public managers: any[];
public subscribers: any[]; public subscribers: any[];
public showSubscribers: any[]; public showSubscribers: any[];
public subs: any[] = []; public subs: any[] = [];
@ -104,14 +103,8 @@ export class SubscribersComponent implements OnInit, OnDestroy, OnChanges {
updateList() { updateList() {
this.loading = true; this.loading = true;
let data = zip(this.userRegistryService.getActiveEmail(this.type, this.id, 'manager'), this.subs.push( this.userRegistryService.getActive(this.type, this.id, 'member').subscribe(users => {
this.userRegistryService.getActiveEmail(this.type, this.id, 'member')); this.subscribers = users;
this.subs.push(data.subscribe(users => {
this.managers = users[0];
this.subscribers = users[1];
this.subscribers.forEach(subscriber => {
subscriber['isManager'] = this.managers.find(manager => manager.email === subscriber.email);
});
this.filterBySearch(this.filterForm.value.keyword); this.filterBySearch(this.filterForm.value.keyword);
this.loading = false; this.loading = false;
this.exists = true; this.exists = true;
@ -147,10 +140,11 @@ export class SubscribersComponent implements OnInit, OnDestroy, OnChanges {
this.createRoleModal.okButtonText = 'create'; this.createRoleModal.okButtonText = 'create';
this.roleFb = this.fb.group({ this.roleFb = this.fb.group({
name: this.fb.control(Role.mapType(this.type) + '.' + this.id, Validators.required), name: this.fb.control(Role.mapType(this.type) + '.' + this.id, Validators.required),
description: this.fb.control('', Validators.required) description: this.fb.control(Role.mapType(this.type) + ' ' + this.id, Validators.required)
}); });
setTimeout(() => { setTimeout(() => {
this.roleFb.get('name').disable(); this.roleFb.get('name').disable();
this.roleFb.get('description').disable();
}, 0); }, 0);
this.createRoleModal.open(); this.createRoleModal.open();
} }
@ -182,8 +176,7 @@ export class SubscribersComponent implements OnInit, OnDestroy, OnChanges {
createGroup() { createGroup() {
this.loading = true; this.loading = true;
this.roleFb.get('name').enable(); this.userRegistryService.createRole(this.type, this.id).subscribe(() => {
this.userRegistryService.createRole(this.type, this.id, this.roleFb.value).subscribe(() => {
UIkit.notification('Group has been <b> successfully created</b>', { UIkit.notification('Group has been <b> successfully created</b>', {
status: 'success', status: 'success',
timeout: 6000, timeout: 6000,

View File

@ -32,7 +32,7 @@ export class ErrorInterceptorService implements HttpInterceptor {
} }
isService(req: HttpRequest<any>, service: string | string[]):boolean { isService(req: HttpRequest<any>, service: string | string[]):boolean {
if(isArray(service)) { if(Array.isArray(service)) {
return !!service.find(element => req.url.indexOf(element) !== -1); return !!service.find(element => req.url.indexOf(element) !== -1);
} else { } else {
return req.url.indexOf(service) !== -1; return req.url.indexOf(service) !== -1;

View File

@ -28,6 +28,10 @@ export class StakeholderService {
constructor(private http: HttpClient, private route: ActivatedRoute) { constructor(private http: HttpClient, private route: ActivatedRoute) {
this.stakeholderSubject = new BehaviorSubject<Stakeholder>(null); this.stakeholderSubject = new BehaviorSubject<Stakeholder>(null);
/* let source = new EventSource(properties.monitorServiceAPIURL + "/stakeholder/events", {withCredentials: true});
source.addEventListener('message', message => {
console.log(message.data);
});*/
} }
ngOnDestroy() { ngOnDestroy() {

View File

@ -1,5 +1,5 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http'; import {HttpClient, HttpErrorResponse} from '@angular/common/http';
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
import {properties} from '../../../environments/environment'; import {properties} from '../../../environments/environment';
import {CustomOptions} from './servicesUtils/customOptions.class'; import {CustomOptions} from './servicesUtils/customOptions.class';
@ -13,8 +13,8 @@ export class UserRegistryService {
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
} }
public createRole(type: string, id: string, role): Observable<any[]> { public createRole(type: string, id: string): Observable<any[]> {
return this.http.post<any>(properties.registryUrl + 'createRole', role, return this.http.post<any>(properties.registryUrl + 'create/' + encodeURIComponent(type) + '/' + encodeURIComponent(id), null,
CustomOptions.registryOptions()).pipe(map((response: any) => response.response)); CustomOptions.registryOptions()).pipe(map((response: any) => response.response));
} }
@ -56,14 +56,15 @@ export class UserRegistryService {
return this.http.delete<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions()); return this.http.delete<any>(properties.registryUrl + 'verification/' + encodeURIComponent(id), CustomOptions.registryOptions());
} }
public getActiveEmail(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> { public getActive(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/email', return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's',
CustomOptions.registryOptions()).pipe(map((response:any) => response.response)); CustomOptions.registryOptions()).pipe(map((response:any) => response.response), map(users => {
} if(users.length > 0 && !users[0].email) {
return [];
public getActiveNames(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> { } else {
return this.http.get<any>(properties.registryUrl + encodeURIComponent(type) + '/' + encodeURIComponent(id) + "/" + role + 's/', return users;
CustomOptions.registryOptions()).pipe(map((response:any) => response.response)); }
}));
} }
public getPending(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> { public getPending(type: string, id: string, role: "member" | "manager" = "manager"): Observable<any[]> {