2024-06-11 16:32:16 +02:00
|
|
|
import {ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild} from "@angular/core";
|
2023-11-02 10:30:59 +01:00
|
|
|
import {StakeholderService} from "../../monitor/services/stakeholder.service";
|
2023-11-13 14:00:05 +01:00
|
|
|
import {Stakeholder, Visibility} from "../../monitor/entities/stakeholder";
|
2023-11-02 10:30:59 +01:00
|
|
|
import {AlertModal} from "../../utils/modal/alert";
|
|
|
|
import {Session} from "../../login/utils/helper.class";
|
|
|
|
import {EditStakeholderComponent} from "../general/edit-stakeholder/edit-stakeholder.component";
|
|
|
|
import {CacheIndicatorsService} from "../utils/cache-indicators/cache-indicators.service";
|
|
|
|
import {NotificationHandler} from "../../utils/notification-handler";
|
2024-06-11 16:32:16 +02:00
|
|
|
import {FilteredStakeholdersBaseComponent} from "../shared/filtered-stakeholders-base.component";
|
2023-11-02 10:30:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
declare var UIkit;
|
|
|
|
|
|
|
|
@Component({
|
2024-06-11 16:32:16 +02:00
|
|
|
selector: 'manage-stakeholders',
|
|
|
|
templateUrl: "manageStakeholders.component.html",
|
|
|
|
styleUrls: ["manageStakeholders.component.less"]
|
2023-11-02 10:30:59 +01:00
|
|
|
})
|
2024-06-11 16:32:16 +02:00
|
|
|
export class ManageStakeholdersComponent extends FilteredStakeholdersBaseComponent {
|
|
|
|
@Input()
|
2023-11-02 10:30:59 +01:00
|
|
|
public defaultStakeholders: Stakeholder[];
|
2024-06-11 16:32:16 +02:00
|
|
|
/**
|
|
|
|
* List of aliases
|
|
|
|
* */
|
|
|
|
@Input()
|
|
|
|
public aliases: string[];
|
|
|
|
@Output()
|
|
|
|
public aliasesChange = new EventEmitter<string[]>();
|
|
|
|
/**
|
|
|
|
* Edit/Create/Delete
|
|
|
|
* */
|
|
|
|
public message: string;
|
|
|
|
public deleteLoading: boolean = false;
|
2023-11-02 10:30:59 +01:00
|
|
|
public stakeholder: Stakeholder;
|
|
|
|
public index: number;
|
2024-06-11 16:32:16 +02:00
|
|
|
@Input()
|
2023-11-02 10:30:59 +01:00
|
|
|
public user = null;
|
|
|
|
public callback: Function;
|
|
|
|
/**
|
|
|
|
* Grid or List View
|
|
|
|
*/
|
|
|
|
@ViewChild('editStakeholderModal', { static: true }) editStakeholderModal: AlertModal;
|
|
|
|
@ViewChild('deleteStakeholderModal', { static: true }) deleteStakeholderModal: AlertModal;
|
|
|
|
@ViewChild('editStakeholderComponent', { static: true }) editStakeholderComponent: EditStakeholderComponent;
|
|
|
|
|
|
|
|
constructor(private stakeholderService: StakeholderService,
|
|
|
|
private cacheIndicatorsService: CacheIndicatorsService,
|
2024-06-11 16:32:16 +02:00
|
|
|
protected cdr: ChangeDetectorRef) {
|
2023-11-02 15:39:14 +01:00
|
|
|
super();
|
2023-11-02 10:30:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2024-06-11 16:32:16 +02:00
|
|
|
super.ngOnInit();
|
|
|
|
if(this.stakeholderCategory.value === 'templates') {
|
|
|
|
this.message = 'Create a new ' + this.stakeholderCategory.name + ' profile.';
|
2023-12-28 12:28:39 +01:00
|
|
|
} else {
|
2024-06-11 16:32:16 +02:00
|
|
|
this.message = 'Create a new ' + this.stakeholderCategory.name +
|
|
|
|
' profile by selecting a type and generate indicators based on a default or a blank profile.';
|
2023-12-28 12:28:39 +01:00
|
|
|
}
|
|
|
|
}
|
2023-11-02 10:30:59 +01:00
|
|
|
|
2024-06-11 16:32:16 +02:00
|
|
|
hide(element: any) {
|
|
|
|
UIkit.dropdown(element).hide();
|
2023-11-02 10:30:59 +01:00
|
|
|
}
|
2023-12-28 12:28:39 +01:00
|
|
|
|
2024-06-11 16:32:16 +02:00
|
|
|
changed() {
|
|
|
|
this.aliasesChange.emit(this.aliases);
|
|
|
|
super.changed();
|
2023-12-28 12:28:39 +01:00
|
|
|
}
|
2023-11-02 10:30:59 +01:00
|
|
|
|
2024-06-11 16:32:16 +02:00
|
|
|
public editStakeholder(stakeholder: Stakeholder = null) {
|
|
|
|
this.index = (stakeholder) ? this.stakeholders.findIndex(value => value._id === stakeholder._id) : -1;
|
2023-11-02 10:30:59 +01:00
|
|
|
if (!stakeholder) {
|
|
|
|
this.stakeholder = new Stakeholder(null, null, null,
|
|
|
|
null, null, null, null, null);
|
|
|
|
} else {
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
}
|
2024-06-11 16:32:16 +02:00
|
|
|
this.editStakeholderComponent.init(this.stakeholder, this.aliases, this.defaultStakeholders, this.stakeholderCategory, this.index === -1);
|
2023-11-02 10:30:59 +01:00
|
|
|
if (this.index !== -1) {
|
|
|
|
this.callback = (stakeholder: Stakeholder) => {
|
2024-06-11 16:32:16 +02:00
|
|
|
let index: number = this.aliases.findIndex(value => value == this.stakeholders[this.index].alias);
|
|
|
|
this.stakeholders[this.index] = stakeholder;
|
2023-11-02 10:30:59 +01:00
|
|
|
if(index != -1) {
|
2024-06-11 16:32:16 +02:00
|
|
|
this.aliases[index] = stakeholder.alias;
|
2023-11-02 10:30:59 +01:00
|
|
|
}
|
|
|
|
this.editStakeholderModal.cancel();
|
|
|
|
};
|
|
|
|
this.editStakeholderModal.alertTitle = 'Edit ' + this.stakeholder.name;
|
|
|
|
this.editStakeholderModal.okButtonText = 'Save Changes';
|
|
|
|
} else {
|
|
|
|
this.callback = (stakeholder: Stakeholder) => {
|
2024-06-11 16:32:16 +02:00
|
|
|
this.stakeholders.push(stakeholder);
|
|
|
|
this.aliases.push(stakeholder.alias)
|
|
|
|
this.changed();
|
2023-11-02 10:30:59 +01:00
|
|
|
this.editStakeholderModal.cancel();
|
|
|
|
};
|
2024-06-11 16:32:16 +02:00
|
|
|
this.editStakeholderModal.alertTitle = 'Create a new ' + this.stakeholderCategory.name + ' profile';
|
2023-11-02 10:30:59 +01:00
|
|
|
this.editStakeholderModal.okButtonText = 'Create';
|
|
|
|
}
|
|
|
|
this.editStakeholderModal.cancelButtonText = 'Cancel';
|
|
|
|
this.editStakeholderModal.okButtonLeft = false;
|
|
|
|
this.editStakeholderModal.alertMessage = false;
|
|
|
|
this.editStakeholderModal.stayOpen = true;
|
|
|
|
this.editStakeholderModal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public createReport(stakeholder: Stakeholder) {
|
|
|
|
this.cacheIndicatorsService.createReport(stakeholder.alias).subscribe(report => {
|
|
|
|
NotificationHandler.rise('A caching process for ' + stakeholder.name + ' has been started.' )
|
|
|
|
}, error => {
|
|
|
|
console.log(error);
|
|
|
|
NotificationHandler.rise(error.message(), 'danger');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public deleteStakeholderOpen(stakeholder: Stakeholder) {
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
this.deleteStakeholderModal.alertTitle = 'Delete ' + this.stakeholder.index_name;
|
|
|
|
this.deleteStakeholderModal.cancelButtonText = 'No';
|
|
|
|
this.deleteStakeholderModal.okButtonText = 'Yes';
|
|
|
|
this.deleteStakeholderModal.alertMessage = false;
|
|
|
|
this.deleteStakeholderModal.stayOpen = true;
|
|
|
|
this.deleteStakeholderModal.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
public deleteStakeholder() {
|
|
|
|
this.deleteLoading = true;
|
2024-06-11 16:32:16 +02:00
|
|
|
this.index = (this.stakeholder) ? this.stakeholders.findIndex(value => value._id === this.stakeholder._id) : -1;
|
2023-11-02 10:30:59 +01:00
|
|
|
this.subscriptions.push(this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, [this.stakeholder._id]).subscribe(() => {
|
|
|
|
UIkit.notification(this.stakeholder.name+ ' has been <b>successfully deleted</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2024-06-11 16:32:16 +02:00
|
|
|
this.stakeholders.splice(this.index, 1);
|
|
|
|
this.aliases = this.aliases.filter(item => item !== this.stakeholder.alias);
|
|
|
|
this.changed();
|
2023-11-02 10:30:59 +01:00
|
|
|
this.deleteLoading = false;
|
|
|
|
this.deleteStakeholderModal.cancel();
|
|
|
|
}, error => {
|
|
|
|
UIkit.notification('An error has occurred. Please try again later', {
|
|
|
|
status: 'danger',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
this.deleteLoading = false;
|
|
|
|
this.deleteStakeholderModal.cancel();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
changeStakeholderStatus(stakeholder: Stakeholder, visibility: Visibility) {
|
|
|
|
let path = [
|
|
|
|
stakeholder._id
|
|
|
|
];
|
|
|
|
this.subscriptions.push(this.stakeholderService.changeVisibility(this.properties.monitorServiceAPIURL, path, visibility).subscribe(returnedElement => {
|
|
|
|
stakeholder.visibility = returnedElement.visibility;
|
|
|
|
UIkit.notification(stakeholder.name+ '\'s status has been <b>successfully changed</b> to ' + stakeholder.visibility.toLowerCase(), {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
}, error => {
|
|
|
|
UIkit.notification('An error has occurred. Please try again later', {
|
|
|
|
status: 'danger',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}
|
2024-06-11 16:32:16 +02:00
|
|
|
|
|
|
|
public isManager(stakeholder: Stakeholder): boolean {
|
2023-11-02 10:30:59 +01:00
|
|
|
return this.isCurator() || (Session.isManager(stakeholder.type, stakeholder.alias, this.user));
|
|
|
|
}
|
2024-06-11 16:32:16 +02:00
|
|
|
|
2023-11-02 10:30:59 +01:00
|
|
|
public isCurator(): boolean {
|
|
|
|
return this.isAdmin() || Session.isMonitorCurator(this.user);
|
|
|
|
}
|
2024-06-11 16:32:16 +02:00
|
|
|
|
2023-11-02 10:30:59 +01:00
|
|
|
public isAdmin(): boolean {
|
|
|
|
return Session.isPortalAdministrator(this.user);
|
|
|
|
}
|
|
|
|
}
|