From 460cbdfc9a3427181a7404012f179c604d74a7ca Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 5 Aug 2022 14:59:08 +0300 Subject: [PATCH] Revert special item with previous style. Add type managers and members in notification form --- .../sidebar/sideBar.component.html | 32 ++++++++------ login/utils/helper.class.ts | 16 +++++++ .../notifications-sidebar.component.ts | 4 +- .../notify-form/notify-form.component.ts | 44 +++++++++++++++---- sharedComponents/input/input.component.ts | 7 +-- 5 files changed, 76 insertions(+), 27 deletions(-) diff --git a/dashboard/sharedComponents/sidebar/sideBar.component.html b/dashboard/sharedComponents/sidebar/sideBar.component.html index 1ca0877f..3b52b12d 100644 --- a/dashboard/sharedComponents/sidebar/sideBar.component.html +++ b/dashboard/sharedComponents/sidebar/sideBar.component.html @@ -1,19 +1,6 @@ diff --git a/login/utils/helper.class.ts b/login/utils/helper.class.ts index 63f5a7c6..ca98fd5c 100644 --- a/login/utils/helper.class.ts +++ b/login/utils/helper.class.ts @@ -212,6 +212,22 @@ export class Role { return "CURATOR_" + this.mapType(type, true).toUpperCase(); } + /** + * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT + * + * */ + public static typeManager(type: string): string { + return "MANAGER_" + this.mapType(type, true).toUpperCase(); + } + + /** + * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT + * + * */ + public static typeMember(type: string): string { + return this.mapType(type, false).toUpperCase(); + } + /** * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT * diff --git a/notifications/notifications-sidebar/notifications-sidebar.component.ts b/notifications/notifications-sidebar/notifications-sidebar.component.ts index 94df2e22..4b4edcdc 100644 --- a/notifications/notifications-sidebar/notifications-sidebar.component.ts +++ b/notifications/notifications-sidebar/notifications-sidebar.component.ts @@ -51,7 +51,7 @@ declare var UIkit; -
+
@@ -85,6 +85,8 @@ export class NotificationsSidebarComponent implements OnInit, OnDestroy { @Input() public availableGroups: Option[] = []; @Input() + public entities: string[] = []; + @Input() public service: string; public notification: Notification; private subscriptions: any[] = []; diff --git a/notifications/notify-form/notify-form.component.ts b/notifications/notify-form/notify-form.component.ts index 96ac4481..469d7ca7 100644 --- a/notifications/notify-form/notify-form.component.ts +++ b/notifications/notify-form/notify-form.component.ts @@ -1,6 +1,6 @@ import {ChangeDetectorRef, Component, Input, OnDestroy, OnInit, ViewChild, ViewEncapsulation} from "@angular/core"; import {FormArray, FormBuilder, FormGroup} from "@angular/forms"; -import {User} from "../../login/utils/helper.class"; +import {Role, User} from "../../login/utils/helper.class"; import {UserManagementService} from "../../services/user-management.service"; import {Subscription} from "rxjs"; import {NotificationService} from "../notification.service"; @@ -22,7 +22,7 @@ import {NotificationHandler} from "../../utils/notification-handler";
-
@@ -50,10 +50,11 @@ export class NotifyFormComponent implements OnInit, OnDestroy { public form: FormGroup; @Input() public availableGroups: Option[] = null; + public groups: Option[] = []; @Input() service: string; + public types: string[] = []; public user: User; public focused: boolean = false; - public groups: string[] = []; @ViewChild('recipients', { static: false }) recipients: InputComponent; private notification: Notification; private subscriptions: any[] = []; @@ -65,6 +66,12 @@ export class NotifyFormComponent implements OnInit, OnDestroy { private notificationService: NotificationService) { } + @Input() + set entities(entities: string[]) { + this.types = entities.map(entity => Role.typeMember(entity)); + this.types = this.types.concat(entities.map(entity => Role.typeManager(entity))); + } + ngOnInit() { this.reset(); this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => { @@ -96,11 +103,12 @@ export class NotifyFormComponent implements OnInit, OnDestroy { groups: this.fb.array([]), message: this.fb.control(message) }); - this.groups = []; + this.groups = this.availableGroups; this.subscriptions.push(this.form.get('groups').valueChanges.subscribe(value => { - this.groups = []; - value.forEach(group => { - this.groups.push(this.availableGroups.find(available => available.value === group).label); + let typeGroups = this.typeGroups; + this.groups = this.availableGroups.map(group => { + group.hidden = typeGroups.includes(group.value) + return group; }); this.cdr.detectChanges(); })); @@ -111,7 +119,7 @@ export class NotifyFormComponent implements OnInit, OnDestroy { if (this.message) { if(notification === null) { notification = new Notification('CUSTOM', [this.service], null, null); - notification.groups = this.groupsAsFromArray.value; + notification.groups = this.parseGroups(); this.sending = true; } this.notification = notification; @@ -119,7 +127,7 @@ export class NotifyFormComponent implements OnInit, OnDestroy { // TODO remove this.notification.name = this.user.firstname; this.notification.surname = this.user.lastname; - this.subscriptions.push(this.notificationService.sendNotification(this.notification).subscribe(notification => { + this.subscriptions.push(this.notificationService.sendNotification(this.notification).subscribe(() => { this.sending = false; NotificationHandler.rise('A notification has been sent successfully'); this.reset(); @@ -131,6 +139,24 @@ export class NotifyFormComponent implements OnInit, OnDestroy { } } + parseGroups(): string[] { + let typeGroups = this.typeGroups; + return this.groupsAsFromArray.getRawValue().filter(group => !this.types.includes(group) && !typeGroups.includes(group)).concat(typeGroups); + } + + get typeGroups(): string[] { + let groups: string[] = []; + this.groupsAsFromArray.getRawValue().filter(group => this.types.includes(group)).forEach(roleType => { + if(roleType.includes("MANAGER_")) { + let type = roleType.replace("MANAGER_", ""); + groups = groups.concat(this.availableGroups.map(option => option.value).filter(group => group.includes(type) && group.includes("_MANAGER"))); + } else { + groups = groups.concat(this.availableGroups.map(option => option.value).filter(group => group.includes(roleType + "_") && !group.includes("_MANAGER") && !group.includes("MANAGER_"))); + } + }); + return groups; + } + get groupsAsFromArray(): FormArray { return this.form.get('groups')?(this.form.get('groups')):null; } diff --git a/sharedComponents/input/input.component.ts b/sharedComponents/input/input.component.ts index 35560870..b2d1afaf 100644 --- a/sharedComponents/input/input.component.ts +++ b/sharedComponents/input/input.component.ts @@ -28,7 +28,8 @@ export interface Option { value: any, label: string, tooltip?: string, - disabled?: boolean + disabled?: boolean, + hidden?: boolean } export interface Placeholder { @@ -141,7 +142,7 @@ declare var UIkit;