[angular-16-irish-monitor]: Add condition for notification. Fix infinite loop with user-info.

This commit is contained in:
Konstantinos Triantafyllou 2024-01-09 10:51:03 +02:00
parent bc259c7c3c
commit d6d3c7bab9
4 changed files with 37 additions and 35 deletions

View File

@ -277,7 +277,7 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
if (!this.pending.includes(response.email)) { if (!this.pending.includes(response.email)) {
this.pending.push(response.email); this.pending.push(response.email);
} }
if(this.notificationFn) { if(this.notificationFn && properties.notificationsAPIURL) {
return this.notificationService.sendNotification(this.notificationFn(this.name, response.email, this.role, response.invitation)).pipe(map(notification => { return this.notificationService.sendNotification(this.notificationFn(this.name, response.email, this.role, response.invitation)).pipe(map(notification => {
return notification; return notification;
}), tap(() => { }), tap(() => {

View File

@ -43,6 +43,7 @@ import {NotifyFormComponent} from "../../notifications/notify-form/notify-form.c
import {NotificationService} from "../../notifications/notification.service"; import {NotificationService} from "../../notifications/notification.service";
import {NotificationHandler} from "../../utils/notification-handler"; import {NotificationHandler} from "../../utils/notification-handler";
import {IndicatorStakeholderBaseComponent} from "../utils/stakeholder-base.component"; import {IndicatorStakeholderBaseComponent} from "../utils/stakeholder-base.component";
import {properties} from "../../../../environments/environment";
declare var UIkit; declare var UIkit;
declare var copy; declare var copy;
@ -845,6 +846,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
this.setCharts(); this.setCharts();
this.setNumbers(); this.setNumbers();
this.initReorder(); this.initReorder();
if(properties.notificationsAPIURL) {
this.notification = NotificationUtils.importIndicators(this.user.fullname, this.stakeholder.alias); this.notification = NotificationUtils.importIndicators(this.user.fullname, this.stakeholder.alias);
this.notification.entity = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index]._id; this.notification.entity = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.index]._id;
this.notification.name = this.user.firstname; this.notification.name = this.user.firstname;
@ -872,6 +874,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
stakeholders.forEach(value => { stakeholders.forEach(value => {
this.notification.groups.push(Role.manager(value.type, value.alias)) this.notification.groups.push(Role.manager(value.type, value.alias))
}); });
this.notificationService.sendNotification(this.notification).subscribe(notification => { this.notificationService.sendNotification(this.notification).subscribe(notification => {
NotificationHandler.rise('A notification has been <b>sent</b> successfully'); NotificationHandler.rise('A notification has been <b>sent</b> successfully');
}, error => { }, error => {
@ -879,6 +882,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
}); });
}); });
} }
}
this.editing = false; this.editing = false;
this.importLoading = false; this.importLoading = false;
NotificationHandler.rise('Indicators have been <b>imported</b> successfully!'); NotificationHandler.rise('Indicators have been <b>imported</b> successfully!');

View File

@ -109,7 +109,7 @@ export class NotifyFormComponent extends BaseComponent implements OnInit {
} }
sendNotification(notification: Notification = null) { sendNotification(notification: Notification = null) {
if (this.message) { if (this.message && this.properties.notificationsAPIURL) {
if(notification === null) { if(notification === null) {
notification = new Notification('CUSTOM', [this.service], null, null); notification = new Notification('CUSTOM', [this.service], null, null);
notification.groups = this.parseGroups(); notification.groups = this.parseGroups();

View File

@ -44,7 +44,7 @@ export class UserManagementService {
return this.getUserInfoSubject.asObservable(); return this.getUserInfoSubject.asObservable();
} }
public getUserInfoAt(index = 1): Observable<User> { public getUserInfoAt(index = 0): Observable<User> {
return this.http.get<User>((isArray(properties.loginServiceURL)?properties.loginServiceURL[index]:properties.loginServiceURL) + return this.http.get<User>((isArray(properties.loginServiceURL)?properties.loginServiceURL[index]:properties.loginServiceURL) +
UserManagementService.USERINFO, CustomOptions.registryOptions()).pipe(map(userInfo => { UserManagementService.USERINFO, CustomOptions.registryOptions()).pipe(map(userInfo => {
return new User(userInfo); return new User(userInfo);
@ -54,7 +54,6 @@ export class UserManagementService {
public updateUserInfo(resolve: Function = null) { public updateUserInfo(resolve: Function = null) {
this.subscription = this.getUserInfoAt().subscribe(user => { this.subscription = this.getUserInfoAt().subscribe(user => {
// console.log(user)
this.getUserInfoSubject.next(user); this.getUserInfoSubject.next(user);
if (resolve) { if (resolve) {
resolve(); resolve();
@ -114,7 +113,6 @@ export class UserManagementService {
} }
setURL(url: string | string[]) { setURL(url: string | string[]) {
console.log(url);
if(isArray(url)) { if(isArray(url)) {
let redirectURL = ''; let redirectURL = '';
url.forEach((url, index) => { url.forEach((url, index) => {