Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Konstantina Galouni 2024-04-12 11:19:33 +03:00
commit c7817731f0
7 changed files with 48 additions and 73 deletions

View File

@ -20,7 +20,7 @@ import {StakeholderBaseComponent} from "../../utils/stakeholder-base.component";
template: `
<div class="uk-margin-medium-bottom">
<form *ngIf="stakeholderFb" [formGroup]="stakeholderFb">
<div class="uk-grid uk-grid-large" uk-grid>
<div class="uk-grid" uk-grid>
<div class="uk-width-1-2@m">
<div input id="name" [formInput]="stakeholderFb.get('name')"
placeholder="Name"></div>
@ -126,6 +126,19 @@ import {StakeholderBaseComponent} from "../../utils/stakeholder-base.component";
</div>
</div>
</div>
<div *ngIf="canChangeCopy" class="uk-width-1-1">
<h6>Instance Type</h6>
<div class="uk-width-auto uk-flex uk-flex-middle">
<label class="uk-margin-right">
<input type="radio" [value]="true" formControlName="copy"/>
<span class="uk-margin-xsmall-left">Copy</span>
</label>
<label class="uk-margin-right">
<input type="radio" [value]="false" formControlName="copy"/>
<span class="uk-margin-xsmall-left">Reference</span>
</label>
</div>
</div>
</div>
</form>
<div #notify [class.uk-hidden]="!stakeholderFb" notify-form
@ -145,6 +158,7 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
public stakeholder: Stakeholder;
public isDefault: boolean;
public isNew: boolean;
public isFull: boolean;
public loading: boolean = false;
public typesByRole: Option[];
public statsProfiles: string[];
@ -172,7 +186,7 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
super.ngOnDestroy();
}
public init(stakeholder: Stakeholder, alias: string[], defaultStakeholders: Stakeholder[], isDefault: boolean, isNew: boolean) {
public init(stakeholder: Stakeholder, alias: string[], defaultStakeholders: Stakeholder[], isDefault: boolean, isNew: boolean, isFull: boolean = false) {
this.reset();
this.deleteCurrentPhoto = false;
this.stakeholder = stakeholder;
@ -183,6 +197,7 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
this.defaultStakeholders = defaultStakeholders;
this.isDefault = isDefault;
this.isNew = isNew;
this.isFull = isFull;
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
this.user = user;
if (this.isCurator) {
@ -220,6 +235,7 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
funderType: this.fb.control(this.stakeholder.funderType),
topics: this.fb.control(this.stakeholder.topics),
isUpload: this.fb.control(this.stakeholder.isUpload),
copy: this.fb.control(this.stakeholder.copy),
logoUrl: this.fb.control(this.stakeholder.logoUrl),
});
if (this.stakeholder.isUpload) {
@ -246,7 +262,7 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
this.subscriptions.push(this.stakeholderFb.get('type').valueChanges.subscribe(value => {
this.onTypeChange(value, defaultStakeholders);
}));
this.stakeholderFb.setControl('defaultId', this.fb.control(stakeholder.defaultId, (this.isDefault && !this.isNew) ? [] : Validators.required));
this.stakeholderFb.setControl('defaultId', this.fb.control(this.stakeholder.defaultId, (this.isDefault && !this.isNew) ? [] : Validators.required));
if (!this.isNew) {
this.notification = NotificationUtils.editStakeholder(this.user.firstname + ' ' + this.user.lastname, this.stakeholder.name);
this.notify.reset(this.notification.message);
@ -304,6 +320,13 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
return this.isNew && this.stakeholderFb.get('type').valid && !!this.defaultStakeholdersOptions;
}
public get canChangeCopy(): boolean {
return this.isCurator &&
!this.stakeholderFb.get('isDefault').getRawValue() &&
this.stakeholderFb.get('defaultId').getRawValue() &&
this.stakeholderFb.get('defaultId').getRawValue() !== '-1';
}
reset() {
this.uploadError = null;
this.stakeholderFb = null;
@ -350,15 +373,15 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
public saveStakeholder(callback: Function, errorCallback: Function = null) {
if (this.isNew) {
let defaultStakeholder = this.defaultStakeholders.find(value => value._id === this.stakeholderFb.getRawValue().defaultId);
this.stakeholderFb.setValue(this.stakeholderUtils.createFunderFromDefaultProfile(this.stakeholderFb.getRawValue(),
(defaultStakeholder ? defaultStakeholder.topics : []), this.stakeholderFb.getRawValue().isDefault));
this.removePhoto();
let copyId = null;
if (this.stakeholderFb.getRawValue().isDefault) {
copyId = this.stakeholderFb.getRawValue().defaultId !== '-1'?this.stakeholderFb.getRawValue().defaultId:null;
this.stakeholderFb.get('defaultId').setValue(null);
this.stakeholderFb.removeControl('isDefault');
}
this.removePhoto();
this.subscriptions.push(this.stakeholderService.buildStakeholder(this.properties.monitorServiceAPIURL,
this.stakeholderFb.getRawValue()).subscribe(stakeholder => {
this.stakeholderFb.getRawValue(), copyId).subscribe(stakeholder => {
this.notification.entity = stakeholder._id;
this.notification.stakeholder = stakeholder.alias;
this.notification.stakeholderType = stakeholder.type;
@ -375,7 +398,7 @@ export class EditStakeholderComponent extends StakeholderBaseComponent {
this.loading = false;
}));
} else {
this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.getRawValue()).subscribe(stakeholder => {
this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.stakeholderFb.getRawValue(), [], this.isFull).subscribe(stakeholder => {
this.notification.entity = stakeholder._id;
this.notification.stakeholder = stakeholder.alias;
this.notification.stakeholderType = stakeholder.type;

View File

@ -5,9 +5,10 @@ import {InputModule} from "../../../sharedComponents/input/input.module";
import {ReactiveFormsModule} from "@angular/forms";
import {IconsModule} from "../../../utils/icons/icons.module";
import {NotifyFormModule} from "../../../notifications/notify-form/notify-form.module";
import {MatSlideToggleModule} from "@angular/material/slide-toggle";
@NgModule({
imports: [CommonModule, InputModule, ReactiveFormsModule, IconsModule, NotifyFormModule],
imports: [CommonModule, InputModule, ReactiveFormsModule, IconsModule, NotifyFormModule, MatSlideToggleModule],
declarations: [EditStakeholderComponent],
exports: [EditStakeholderComponent]
})

View File

@ -48,7 +48,7 @@ export class GeneralComponent extends BaseComponent implements OnInit {
}
public reset() {
this.editStakeholderComponent.init(this.stakeholder, this.alias, this.defaultStakeholders, this.stakeholder.defaultId == null, false)
this.editStakeholderComponent.init(this.stakeholder, this.alias, this.defaultStakeholders, this.stakeholder.defaultId == null, false, true)
}
public save() {

View File

@ -31,7 +31,7 @@
<div *ngIf="!loading" uk-height-match="target: .titleContainer; row: false">
<div uk-height-match="target: .logoContainer; row: false">
<div *ngIf="tab != 'profiles' && isCurator()" class="uk-section">
<div class="uk-flex uk-flex-middle uk-flex-between uk-margin-small-bottom">
<div class="uk-flex uk-flex-middle uk-flex-between uk-margin-bottom">
<h4 class="uk-margin-remove">Profile Templates</h4>
<paging-no-load *ngIf="displayDefaultStakeholders?.length > pageSize"
(pageChange)="updateCurrentTemplatesPage($event)"
@ -39,8 +39,7 @@
[totalResults]="displayDefaultStakeholders.length">
</paging-no-load>
</div>
<div class="uk-grid uk-child-width-1-3@l uk-child-width-1-2@m uk-child-width-1-1 uk-grid-match"
uk-grid>
<div class="uk-grid uk-child-width-1-3@l uk-child-width-1-2@m uk-child-width-1-1 uk-grid-match" uk-grid>
<ng-template ngFor
[ngForOf]="displayDefaultStakeholders.slice((currentTemplatesPage-1)*pageSize, currentTemplatesPage*pageSize)"
let-stakeholder>
@ -59,7 +58,7 @@
</h4>
</div>
<div *ngIf="tab != 'templates' && isManager()" class="uk-section">
<div class="uk-flex uk-flex-middle uk-flex-between uk-margin-small-bottom">
<div class="uk-flex uk-flex-middle uk-flex-between uk-margin-bottom">
<h4 class="uk-margin-remove">Profiles</h4>
<paging-no-load *ngIf="displayStakeholders?.length > pageSize"
(pageChange)="updateCurrentPage($event)"

View File

@ -127,60 +127,6 @@ export class StakeholderUtils {
return types;
}
public createFunderFromDefaultProfile(funder: Stakeholder, defaultTopics: Topic[], isDefault: boolean = false): Stakeholder {
funder.topics = HelperFunctions.copy(defaultTopics);
for (let topic of funder.topics) {
topic.defaultId = !isDefault ? topic._id : null;
topic._id = null;
for (let category of topic.categories) {
category.defaultId = !isDefault ? category._id : null;
category._id = null;
let subTokeep: SubCategory[] = [];
for (let subCategory of category.subCategories) {
subCategory.defaultId = !isDefault ? subCategory._id : null;
subCategory._id = null;
subTokeep.push(subCategory);
for (let section of subCategory.charts) {
let chartsTokeep: Indicator[] = [];
section.defaultId = !isDefault ? section._id : null;
section.stakeholderAlias = funder.alias;
section._id = null;
for (let indicator of section.indicators) {
indicator.defaultId = !isDefault ? indicator._id : null;
indicator._id = null;
chartsTokeep.push(indicator);
for (let indicatorPath of indicator.indicatorPaths) {
if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => {
if (key == "index_name") {
indicatorPath.parameters[key] = funder.index_name;
} else if (key == "index_id") {
indicatorPath.parameters[key] = funder.index_id;
} else if (key == "index_shortName") {
indicatorPath.parameters[key] = funder.index_shortName.toLowerCase();
}
});
}
}
}
section.indicators = chartsTokeep;
}
for (let section of subCategory.numbers) {
section.defaultId = !isDefault ? section._id : null;
section.stakeholderAlias = funder.alias;
section._id = null;
for (let indicator of section.indicators) {
indicator.defaultId = !isDefault ? indicator._id : null;
indicator._id = null;
}
}
}
category.subCategories = subTokeep;
}
}
return funder;
}
aliasValidatorString(elements: string[]): ValidatorFn {
return (control: AbstractControl): { [key: string]: string } | null => {

View File

@ -37,6 +37,7 @@ export class Stakeholder {
isUpload: boolean = false;
description: string;
topics: any[];
copy: boolean = true;
details?: any;
constructor(_id: string, type: StakeholderType, index_id: string, index_name: string, index_shortName: string, alias: string, visibility: Visibility, logoUrl: string, defaultId: string = null, description: string = null) {
@ -50,6 +51,7 @@ export class Stakeholder {
this.visibility = visibility;
this.logoUrl = logoUrl;
this.description = description;
this.copy = !!this.defaultId && this.defaultId !== '-1';
this.topics = [];
}

View File

@ -116,11 +116,15 @@ export class StakeholderService {
}));
}
buildStakeholder(url: string, stakeholder: Stakeholder): Observable<Stakeholder> {
buildStakeholder(url: string, stakeholder: Stakeholder, copyId: string): Observable<Stakeholder> {
if (stakeholder.alias && stakeholder.alias.startsWith('/')) {
stakeholder.alias = stakeholder.alias.slice(1);
}
return this.http.post<Stakeholder>(url + '/build-stakeholder', stakeholder, CustomOptions.registryOptions()).pipe(map(stakeholder => {
let copy = {
stakeholder: stakeholder,
copyId: copyId
}
return this.http.post<Stakeholder>(url + '/build-stakeholder', copy, CustomOptions.registryOptions()).pipe(map(stakeholder => {
return HelperFunctions.copy(Stakeholder.checkIsUpload(stakeholder));
}));
}
@ -129,12 +133,12 @@ export class StakeholderService {
return this.http.post<Visibility>(url + '/' + path.join('/') + '/change-visibility' + '?visibility=' + visibility + (propagate ? '&propagate=true' : ''), null, CustomOptions.registryOptions());
}
saveElement(url: string, element: any, path: string[] = []): Observable<any> {
saveElement(url: string, element: any, path: string[] = [], isFull: boolean = false): Observable<any> {
if (element.alias && element.alias.startsWith('/')) {
element.alias = element.alias.slice(1);
}
return this.http.post<any>(url + ((path.length > 0) ? '/' : '') + path.join('/') +
'/save', element, CustomOptions.registryOptions()).pipe(map(element => {
'/save' + (isFull?'/full':''), element, CustomOptions.registryOptions()).pipe(map(element => {
if (path.length === 0) {
return HelperFunctions.copy(Stakeholder.checkIsUpload(element));
} else {