[develop | ADDED]: Add statsProfile in indicatorPath parameters and in form in order to override stakeholder's one.

This commit is contained in:
Konstantinos Triantafyllou 2024-02-22 09:41:57 +02:00
parent fbf7e9f527
commit a45122565a
5 changed files with 146 additions and 76 deletions

View File

@ -271,6 +271,12 @@
[options]="indicatorUtils.formats" type="select">
</div>
</div>
<div class="uk-width-1-2@m" formArrayName="parameters">
<div *ngIf="getParameter(i, 'statsProfile', 'number') && statsProfiles" input [formInput]="getParameter(i, 'statsProfile', 'number').get('value')"
[type]="'select'"
[options]="statsProfiles"
placeholder="Stats Profile"></div>
</div>
</div>
</div>
<div formArrayName="jsonPath" class="uk-width-1-1">
@ -327,6 +333,20 @@
</a>
</div>
</div>
<div *ngIf="hasDifference(i, 'number')"
class="uk-width-1-1 uk-height-1-1 refresh-indicator">
<div class="uk-position-relative uk-height-1-1">
<a class="uk-position-center uk-text-center uk-text-small uk-link-reset"
[class.uk-disabled]="numberIndicatorPaths.at(i).get('url').invalid"
(click)="refreshIndicator('number')">
<div>
<icon name="refresh"></icon>
</div>
<span>Calculate</span>
<span *ngIf="numberIndicatorPaths.at(i).get('result').errors?.validating">Calculating...</span>
</a>
</div>
</div>
</div>
</div>
</div>
@ -400,6 +420,8 @@
placeholder="Year (From)"></div>
<div *ngIf="getParameter(i, 'end_year')" input class="uk-width-1-3@s" [formInput]="getParameter(i, 'end_year').get('value')"
placeholder="Year (To)"></div>
<div *ngIf="getParameter(i, 'statsProfile') && statsProfiles" input class="uk-width-1-3@s" [formInput]="getParameter(i, 'statsProfile').get('value')"
[type]="'select'" [options]="statsProfiles" placeholder="Stats Profile"></div>
</div>
</div>
<div *ngIf="indicator && indicator.indicatorPaths[i] && indicator.indicatorPaths[i].safeResourceUrl"

View File

@ -44,6 +44,7 @@ import {NotificationService} from "../../notifications/notification.service";
import {NotificationHandler} from "../../utils/notification-handler";
import {IndicatorStakeholderBaseComponent} from "../utils/stakeholder-base.component";
import {properties} from "../../../../environments/environment";
import {StatsProfilesService} from "../utils/services/stats-profiles.service";
declare var UIkit;
declare var copy;
@ -68,6 +69,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
@Input()
public user: User = null;
public preview: string;
public statsProfiles = [];
public numberIndicatorFb: UntypedFormGroup;
public chartIndicatorFb: UntypedFormGroup;
public chartSections: UntypedFormArray;
@ -119,6 +121,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
constructor(private layoutService: LayoutService,
private stakeholderService: StakeholderService,
private statisticsService: StatisticsService,
private statsProfileService: StatsProfilesService,
private notificationService: NotificationService,
private fb: UntypedFormBuilder,
protected _router: Router,
@ -137,7 +140,16 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
this.setCharts();
this.setNumbers();
this.initReorder();
})
});
if (this.isCurator) {
this.subscriptions.push(this.statsProfileService.getStatsProfiles().subscribe(statsProfiles => {
this.statsProfiles = [null].concat(statsProfiles);
}, error => {
this.statsProfiles = [];
}));
} else {
this.statsProfiles = [];
}
}
ngOnDestroy(): void {
@ -400,7 +412,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
this.getJsonPath(index).disable();
}
indicatorPath.get('result').setErrors({validating: true});
this.subscriptions.push(this.statisticsService.getNumbers(null, indicatorPath.get('url').value).subscribe(response => {
this.subscriptions.push(this.statisticsService.getNumbers(indicatorPath.get('source').value, this.indicatorUtils.getFullUrl(this.stakeholder, this.indicator.indicatorPaths[index])).subscribe(response => {
let result = JSON.parse(JSON.stringify(response));
this.getJsonPath(index).controls.forEach(jsonPath => {
if (result) {
@ -448,12 +460,16 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
return this.section.indicators[this.index].indicatorPaths[index].jsonPath;
}
public getParameters(index: number): UntypedFormArray {
public getParameters(index: number, type: IndicatorType = 'chart'): UntypedFormArray {
if(type === 'chart') {
return this.chartIndicatorPaths.at(index).get('parameters') as UntypedFormArray;
} else {
return this.numberIndicatorPaths.at(index).get('parameters') as UntypedFormArray;
}
}
public getParameter(index: number, key: string): UntypedFormControl {
return this.getParameters(index).controls.filter(control => control.value.key === key)[0] as UntypedFormControl;
public getParameter(index: number, key: string, type: IndicatorType = 'chart'): UntypedFormControl {
return this.getParameters(index, type).controls.filter(control => control.value.key === key)[0] as UntypedFormControl;
}
private getSecureUrlByStakeHolder(indicatorPath: IndicatorPath) {
@ -474,6 +490,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
jsonPath: jsonPath,
result: this.fb.control(0, Validators.required),
source: this.fb.control(source, Validators.required),
parameters: parameters,
format: this.fb.control(format, Validators.required)
}
));
@ -506,6 +523,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
if (indicatorPath.source) {
this.numberIndicatorPaths.at(index).get('source').setValue(indicatorPath.source);
}
(this.numberIndicatorPaths.at(index) as UntypedFormGroup).setControl('parameters', this.getParametersAsFormArray(indicatorPath));
if (indicatorPath.jsonPath.length > 1 && this.getJsonPath(index).length == 1) {
let paths = indicatorPath.jsonPath;
for (let i = 0; i < paths.length; i++) {
@ -568,8 +586,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
}
this.checkForSchemaEnhancements(this.chartIndicatorPaths.at(index).get('url').value);
(this.chartIndicatorPaths.at(index) as UntypedFormGroup).get('type').setValue(indicatorPath.type);
let parameters = this.getParametersAsFormArray(indicatorPath);
(this.chartIndicatorPaths.at(index) as UntypedFormGroup).setControl('parameters', parameters);
(this.chartIndicatorPaths.at(index) as UntypedFormGroup).setControl('parameters', this.getParametersAsFormArray(indicatorPath));
if (!this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index] = indicatorPath;
this.indicator.indicatorPaths[index].safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath);
@ -642,7 +659,7 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
defaultId: this.fb.control(this.indicator.defaultId)
});
this.indicator.indicatorPaths.forEach(indicatorPath => {
this.addNumberIndicatorPath(this.indicatorUtils.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)), indicatorPath.parameters, indicatorPath.source, this.getJsonPathAsFormArray(indicatorPath), indicatorPath.format);
this.addNumberIndicatorPath(this.indicatorUtils.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)), this.getParametersAsFormArray(indicatorPath), indicatorPath.source, this.getJsonPathAsFormArray(indicatorPath), indicatorPath.format);
});
} else {
this.indicator = new Indicator('', '', '', 'number', 'small', 'small', "PUBLIC", []);
@ -754,11 +771,11 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
this.editing = true;
if (this.indicator.type === 'chart') {
this.chartIndicatorFb.get('description').enable();
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, this.indicator.type, true);
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, this.indicator.type);
this.section = this.charts.find(section => section._id === this.section._id);
} else {
this.numberIndicatorFb.get('description').enable();
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.numberIndicatorFb.value, this.indicator.indicatorPaths, this.indicator.type, false);
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.numberIndicatorFb.value, this.indicator.indicatorPaths, this.indicator.type);
this.section = this.numbers.find(section => section._id === this.section._id);
}
let path = [
@ -917,9 +934,10 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
}));
}
hasDifference(index: number): boolean {
hasDifference(index: number, type: IndicatorType = 'chart'): boolean {
let hasDifference = false;
this.chartIndicatorPaths.at(index).value.parameters.forEach((parameter) => {
if(type === 'chart') {
this.chartIndicatorPaths.at(index).value.parameters.forEach(parameter => {
if (parameter.value !== this.indicator.indicatorPaths[index].parameters[parameter.key]) {
hasDifference = true;
return;
@ -927,6 +945,16 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
});
return hasDifference || this.indicator.indicatorPaths[index].safeResourceUrl.toString() !==
this.getSecureUrlByStakeHolder(this.indicator.indicatorPaths[index]).toString();
} else if(type === 'number') {
let indicatorPath = this.numberIndicatorPaths.at(index).value;
indicatorPath.parameters.forEach(parameter => {
if (parameter.value !== this.indicator.indicatorPaths[index].parameters[parameter.key]) {
hasDifference = true;
return;
}
});
}
return hasDifference;
}
public get isAdministrator(): boolean {
@ -937,11 +965,18 @@ export class IndicatorsComponent extends IndicatorStakeholderBaseComponent imple
return this.isAdministrator || Session.isCurator(this.stakeholder.type, this.user);
}
refreshIndicator() {
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, 'chart', true);
refreshIndicator(type: IndicatorType = 'chart') {
if(type === 'chart') {
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, 'chart');
this.indicator.indicatorPaths.forEach(indicatorPath => {
indicatorPath.safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath);
});
} else if(type === 'number') {
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.numberIndicatorFb.value, this.indicator.indicatorPaths, 'number');
this.indicator.indicatorPaths.forEach((indicatorPath, index) => {
this.validateJsonPath(index);
});
}
}
deleteIndicatorOpen(section: Section, indicatorId: string, type: string, childrenAction: string = null) {

View File

@ -317,8 +317,9 @@ export class IndicatorUtils {
public getFullUrl(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null): string {
let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if(indicatorPath.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(indicatorPath.statsProfile)
if (indicatorPath.parameters.statsProfile) {
console.log(indicatorPath.parameters.statsProfile)
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(indicatorPath.parameters.statsProfile)
} else if (stakeholder.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(stakeholder.statsProfile)
}
@ -398,8 +399,8 @@ export class IndicatorUtils {
let filterSubtitleText = [];
indicatorPath.filtersApplied = 0;
let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if(indicatorPath.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(indicatorPath.statsProfile)
if (indicatorPath.parameters.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(indicatorPath.parameters.statsProfile)
} else if (stakeholder.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(stakeholder.statsProfile)
}
@ -639,21 +640,19 @@ export class IndicatorUtils {
return values.length > 1;
}
generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[], type: IndicatorType, addParameters: boolean = true): Indicator {
generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[], type: IndicatorType): Indicator {
let indicator: Indicator = new Indicator(form.name, form.description, form.additionalDescription, type,
form.width, form.height, form.visibility, indicatorPaths, form.defaultId);
indicator._id = form._id;
form.indicatorPaths.forEach((indicatorPath, index) => {
indicator.indicatorPaths[index].type = indicatorPath.type;
indicator.indicatorPaths[index].format = indicatorPath.format;
if (addParameters) {
indicatorPath.parameters.forEach(parameter => {
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
if (parameter.key === 'type') {
indicator.indicatorPaths[index].type = parameter.value;
}
});
}
});
return indicator;
}
@ -667,6 +666,7 @@ export class IndicatorUtils {
let chart = JSON.parse(indicatorPath.chartObject);
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
this.extractStakeHolders(chart, indicatorPath, stakeholder);
this.addProfile(indicatorPath);
indicatorPath.chartObject = JSON.stringify(chart);
if (!jsonPath || jsonPath.length == 0 || (jsonPath.length == 1 && jsonPath[0] == "")) {
indicatorPath.jsonPath = ["data", "0", "0", "0"];
@ -726,6 +726,7 @@ export class IndicatorUtils {
this.extractStakeHolders(chart, indicatorPath, stakeholder);
this.extractStartYear(chart, indicatorPath);
this.extractEndYear(chart, indicatorPath);
this.addProfile(indicatorPath);
indicatorPath.chartObject = JSON.stringify(chart);
}
} else if (source === 'old') {
@ -869,6 +870,7 @@ export class IndicatorUtils {
}
}
}
private extractDatasource(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
// works for .datasource.name and .HostedBy datasource
// and .datasource.id
@ -895,6 +897,7 @@ export class IndicatorUtils {
}
}
}
private extractResearcher(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
// works for .orcid
if (stakeholder.type != "researcher") {
@ -919,6 +922,7 @@ export class IndicatorUtils {
}
}
}
private replaceIndexValues(currentValue, stakeholder, parameters) {
if (currentValue == stakeholder.index_name) {
parameters["index_name"] = stakeholder.index_name;
@ -932,6 +936,7 @@ export class IndicatorUtils {
}
}
private extractStartYear(obj, indicatorPath: IndicatorPath) {
let start_year;
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
@ -968,6 +973,10 @@ export class IndicatorUtils {
}
}
private addProfile(indicatorPath: IndicatorPath) {
indicatorPath.parameters['statsProfile'] = null;
}
private parameterizeDefaultQuery(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
let name = "";
for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) {

View File

@ -210,7 +210,6 @@ export class IndicatorPath {
parameters: any;
filters: any;
filtersApplied: number = 0;
statsProfile: string;
format: Format;
constructor(type: IndicatorPathType, source: SourceType, url: string, chartObject: string, jsonPath: string[], format: Format = 'NUMBER') {

View File

@ -336,7 +336,12 @@ export class InputComponent implements OnInit, OnDestroy, AfterViewInit, OnChang
@Input()
set options(options: (Option | string | number) []) {
this.optionsArray = options.map(option => {
if (typeof option === 'string' || typeof option === 'number') {
if(option === null) {
return {
label: this.noValueSelected,
value: ''
};
} else if (typeof option === 'string' || typeof option === 'number') {
return {
label: option.toString(),
value: option