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

View File

@ -85,7 +85,7 @@ export class StakeholderUtils {
visibilityIcon: Map<Visibility, string> = new Map<Visibility, string>(this.visibilities.map(option => [option.value, option.icon])); visibilityIcon: Map<Visibility, string> = new Map<Visibility, string>(this.visibilities.map(option => [option.value, option.icon]));
defaultValue(options: Option[]) { defaultValue(options: Option[]) {
return options.length === 1?options[0].value:null; return options.length === 1 ? options[0].value : null;
} }
showField(options: Option[]) { showField(options: Option[]) {
@ -94,7 +94,7 @@ export class StakeholderUtils {
getLabel(options: Option[], value) { getLabel(options: Option[], value) {
let option = options.find(option => option.value === value); let option = options.find(option => option.value === value);
return option?option.label:null; return option ? option.label : null;
} }
getTypesByUserRoles(user, id: string = null): Option[] { getTypesByUserRoles(user, id: string = null): Option[] {
@ -317,8 +317,9 @@ export class IndicatorUtils {
public getFullUrl(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null): string { public getFullUrl(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null): string {
let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url; let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if(indicatorPath.statsProfile) { if (indicatorPath.parameters.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(indicatorPath.statsProfile) console.log(indicatorPath.parameters.statsProfile)
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(indicatorPath.parameters.statsProfile)
} else if (stakeholder.statsProfile) { } else if (stakeholder.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(stakeholder.statsProfile) replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(stakeholder.statsProfile)
} }
@ -394,12 +395,12 @@ export class IndicatorUtils {
return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl); return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl);
} }
public getFullUrlWithFilters(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, coFunded: boolean = false, foslvl1:string[]=[], foslvl2:string[]=[], publiclyFunded: "all"| "true"| "false"= "all" ): string { public getFullUrlWithFilters(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, coFunded: boolean = false, foslvl1: string[] = [], foslvl2: string[] = [], publiclyFunded: "all" | "true" | "false" = "all"): string {
let filterSubtitleText = []; let filterSubtitleText = [];
indicatorPath.filtersApplied = 0; indicatorPath.filtersApplied = 0;
let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url; let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if(indicatorPath.statsProfile) { if (indicatorPath.parameters.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(indicatorPath.statsProfile) replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(indicatorPath.parameters.statsProfile)
} else if (stakeholder.statsProfile) { } else if (stakeholder.statsProfile) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(stakeholder.statsProfile) replacedUrl = replacedUrl.split(ChartHelper.prefix + this.statsProfileParameter + ChartHelper.suffix).join(stakeholder.statsProfile)
} }
@ -408,7 +409,7 @@ export class IndicatorUtils {
let filterResults = this.addFilter(replacedUrl, 'fundingL0', fundingL0); let filterResults = this.addFilter(replacedUrl, 'fundingL0', fundingL0);
replacedUrl = filterResults.url; replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied; indicatorPath.filtersApplied += filterResults.filtersApplied;
filterSubtitleText.push( "Funding level 0: " ) ; filterSubtitleText.push("Funding level 0: ");
} }
} }
if (startYear) { if (startYear) {
@ -425,7 +426,7 @@ export class IndicatorUtils {
indicatorPath.filtersApplied += filterResults.filtersApplied; indicatorPath.filtersApplied += filterResults.filtersApplied;
} }
} }
if(startYear || endYear) { if (startYear || endYear) {
filterSubtitleText.push(startYear && endYear ? (startYear + ' - ' + endYear) : (endYear ? ('until ' + endYear) : '')); filterSubtitleText.push(startYear && endYear ? (startYear + ' - ' + endYear) : (endYear ? ('until ' + endYear) : ''));
} }
if (coFunded) { if (coFunded) {
@ -433,33 +434,33 @@ export class IndicatorUtils {
let filterResults = this.addFilter(replacedUrl, 'co-funded', coFunded); let filterResults = this.addFilter(replacedUrl, 'co-funded', coFunded);
replacedUrl = filterResults.url; replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied; indicatorPath.filtersApplied += filterResults.filtersApplied;
filterSubtitleText.push( "Co-funded: " + (coFunded?'yes':'no') ) ; filterSubtitleText.push("Co-funded: " + (coFunded ? 'yes' : 'no'));
} }
} }
if (publiclyFunded && publiclyFunded !="all") { if (publiclyFunded && publiclyFunded != "all") {
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) { if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'publicly-funded', publiclyFunded); let filterResults = this.addFilter(replacedUrl, 'publicly-funded', publiclyFunded);
replacedUrl = filterResults.url; replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied; indicatorPath.filtersApplied += filterResults.filtersApplied;
filterSubtitleText.push( "Publicly funded: " + (publiclyFunded?'yes':'no') ) ; filterSubtitleText.push("Publicly funded: " + (publiclyFunded ? 'yes' : 'no'));
} }
} }
if (foslvl1) { if (foslvl1) {
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) { if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'foslvl1', foslvl1); let filterResults = this.addFilter(replacedUrl, 'foslvl1', foslvl1);
replacedUrl = filterResults.url; replacedUrl = filterResults.url;
indicatorPath.filtersApplied +=filterResults.filtersApplied?foslvl1.length:0; indicatorPath.filtersApplied += filterResults.filtersApplied ? foslvl1.length : 0;
} }
} }
if (foslvl2) { if (foslvl2) {
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) { if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'foslvl2', foslvl2); let filterResults = this.addFilter(replacedUrl, 'foslvl2', foslvl2);
replacedUrl = filterResults.url; replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied?foslvl2.length:0; indicatorPath.filtersApplied += filterResults.filtersApplied ? foslvl2.length : 0;
} }
} }
if((foslvl1 && foslvl1.length > 0) || (foslvl2 && foslvl2.length > 0)){ if ((foslvl1 && foslvl1.length > 0) || (foslvl2 && foslvl2.length > 0)) {
filterSubtitleText.push( "Field of Science: " + foslvl1.join(', ') + ( foslvl1.length > 0 && foslvl2.length > 0? ', ': '') + foslvl2.join(", ") ) ; filterSubtitleText.push("Field of Science: " + foslvl1.join(', ') + (foslvl1.length > 0 && foslvl2.length > 0 ? ', ' : '') + foslvl2.join(", "));
} }
if (indicatorPath.parameters) { if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => { Object.keys(indicatorPath.parameters).forEach(key => {
@ -484,7 +485,7 @@ export class IndicatorUtils {
replacedValue = stakeholder.index_shortName.toLowerCase(); replacedValue = stakeholder.index_shortName.toLowerCase();
} }
if (key == "subtitle" && filterSubtitleText.length > 0) { if (key == "subtitle" && filterSubtitleText.length > 0) {
replacedValue = replacedValue + (replacedValue.length > 0 ? ' - ':'') + ' Active filters: ('+filterSubtitleText.join(", ") + ')'; replacedValue = replacedValue + (replacedValue.length > 0 ? ' - ' : '') + ' Active filters: (' + filterSubtitleText.join(", ") + ')';
} }
replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue) replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
}); });
@ -577,7 +578,7 @@ export class IndicatorUtils {
/*Chart with proper json object*/ /*Chart with proper json object*/
//apply the filter in any select fields //apply the filter in any select fields
for (let select of queries["query"]["select"]) { for (let select of queries["query"]["select"]) {
let filterString = IndicatorFilterUtils.getFilter(select["field"], filterType,filterValue); let filterString = IndicatorFilterUtils.getFilter(select["field"], filterType, filterValue);
if (filterString) { if (filterString) {
let filter = JSON.parse(filterString); let filter = JSON.parse(filterString);
//check if filter already exists //check if filter already exists
@ -639,21 +640,19 @@ export class IndicatorUtils {
return values.length > 1; 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, let indicator: Indicator = new Indicator(form.name, form.description, form.additionalDescription, type,
form.width, form.height, form.visibility, indicatorPaths, form.defaultId); form.width, form.height, form.visibility, indicatorPaths, form.defaultId);
indicator._id = form._id; indicator._id = form._id;
form.indicatorPaths.forEach((indicatorPath, index) => { form.indicatorPaths.forEach((indicatorPath, index) => {
indicator.indicatorPaths[index].type = indicatorPath.type; indicator.indicatorPaths[index].type = indicatorPath.type;
indicator.indicatorPaths[index].format = indicatorPath.format; indicator.indicatorPaths[index].format = indicatorPath.format;
if (addParameters) { indicatorPath.parameters.forEach(parameter => {
indicatorPath.parameters.forEach(parameter => { indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value; if (parameter.key === 'type') {
if (parameter.key === 'type') { indicator.indicatorPaths[index].type = parameter.value;
indicator.indicatorPaths[index].type = parameter.value; }
} });
});
}
}); });
return indicator; return indicator;
} }
@ -667,6 +666,7 @@ export class IndicatorUtils {
let chart = JSON.parse(indicatorPath.chartObject); let chart = JSON.parse(indicatorPath.chartObject);
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder); this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
this.extractStakeHolders(chart, indicatorPath, stakeholder); this.extractStakeHolders(chart, indicatorPath, stakeholder);
this.addProfile(indicatorPath);
indicatorPath.chartObject = JSON.stringify(chart); indicatorPath.chartObject = JSON.stringify(chart);
if (!jsonPath || jsonPath.length == 0 || (jsonPath.length == 1 && jsonPath[0] == "")) { if (!jsonPath || jsonPath.length == 0 || (jsonPath.length == 1 && jsonPath[0] == "")) {
indicatorPath.jsonPath = ["data", "0", "0", "0"]; indicatorPath.jsonPath = ["data", "0", "0", "0"];
@ -726,6 +726,7 @@ export class IndicatorUtils {
this.extractStakeHolders(chart, indicatorPath, stakeholder); this.extractStakeHolders(chart, indicatorPath, stakeholder);
this.extractStartYear(chart, indicatorPath); this.extractStartYear(chart, indicatorPath);
this.extractEndYear(chart, indicatorPath); this.extractEndYear(chart, indicatorPath);
this.addProfile(indicatorPath);
indicatorPath.chartObject = JSON.stringify(chart); indicatorPath.chartObject = JSON.stringify(chart);
} }
} else if (source === 'old') { } else if (source === 'old') {
@ -806,10 +807,10 @@ export class IndicatorUtils {
for (let gfilter of filter["groupFilters"]) { for (let gfilter of filter["groupFilters"]) {
//ignore field No Of Funders //ignore field No Of Funders
let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters); let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters);
if(replacedValue) { // don't proceed in replacement if no replaced value matches if (replacedValue) { // don't proceed in replacement if no replaced value matches
if ((gfilter["field"].indexOf(" funder") != -1 && gfilter["field"].indexOf(" funders") == -1 ) || if ((gfilter["field"].indexOf(" funder") != -1 && gfilter["field"].indexOf(" funders") == -1) ||
(gfilter["field"].indexOf(".funder") != -1) || (gfilter["field"].indexOf(".funder") != -1) ||
(gfilter["field"].indexOf(".funder.id") != -1)) { (gfilter["field"].indexOf(".funder.id") != -1)) {
gfilter["values"][0] = replacedValue; gfilter["values"][0] = replacedValue;
} }
} }
@ -832,9 +833,9 @@ export class IndicatorUtils {
for (let filter of query["query"]["filters"]) { for (let filter of query["query"]["filters"]) {
for (let gfilter of filter["groupFilters"]) { for (let gfilter of filter["groupFilters"]) {
let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters); let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters);
if(replacedValue) { // don't proceed in replacement if no replaced value matches if (replacedValue) { // don't proceed in replacement if no replaced value matches
if ((gfilter["field"].indexOf(".context.name") != -1) if ((gfilter["field"].indexOf(".context.name") != -1)
|| (gfilter["field"].indexOf(".context.id") != -1)) { || (gfilter["field"].indexOf(".context.id") != -1)) {
gfilter["values"][0] = replacedValue; gfilter["values"][0] = replacedValue;
} }
} }
@ -859,9 +860,9 @@ export class IndicatorUtils {
for (let filter of query["query"]["filters"]) { for (let filter of query["query"]["filters"]) {
for (let gfilter of filter["groupFilters"]) { for (let gfilter of filter["groupFilters"]) {
let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters); let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters);
if(replacedValue) { // don't proceed in replacement if no replaced value matches if (replacedValue) { // don't proceed in replacement if no replaced value matches
if ((gfilter["field"].indexOf(".organization.name") != -1)|| if ((gfilter["field"].indexOf(".organization.name") != -1) ||
(gfilter["field"].indexOf(".organization.id") != -1)) { (gfilter["field"].indexOf(".organization.id") != -1)) {
gfilter["values"][0] = replacedValue; gfilter["values"][0] = replacedValue;
} }
} }
@ -869,6 +870,7 @@ export class IndicatorUtils {
} }
} }
} }
private extractDatasource(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) { private extractDatasource(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
// works for .datasource.name and .HostedBy datasource // works for .datasource.name and .HostedBy datasource
// and .datasource.id // and .datasource.id
@ -885,9 +887,9 @@ export class IndicatorUtils {
for (let filter of query["query"]["filters"]) { for (let filter of query["query"]["filters"]) {
for (let gfilter of filter["groupFilters"]) { for (let gfilter of filter["groupFilters"]) {
let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters); let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters);
if(replacedValue) { // don't proceed in replacement if no replaced value matches if (replacedValue) { // don't proceed in replacement if no replaced value matches
if ((gfilter["field"].indexOf(".datasource.name") != -1 || gfilter["field"].indexOf(".HostedBy datasource") != -1)|| if ((gfilter["field"].indexOf(".datasource.name") != -1 || gfilter["field"].indexOf(".HostedBy datasource") != -1) ||
(gfilter["field"].indexOf(".datasource.id") != -1) || (gfilter["field"].indexOf(".hostedby") != -1)) { (gfilter["field"].indexOf(".datasource.id") != -1) || (gfilter["field"].indexOf(".hostedby") != -1)) {
gfilter["values"][0] = replacedValue; gfilter["values"][0] = replacedValue;
} }
} }
@ -895,6 +897,7 @@ export class IndicatorUtils {
} }
} }
} }
private extractResearcher(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) { private extractResearcher(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
// works for .orcid // works for .orcid
if (stakeholder.type != "researcher") { if (stakeholder.type != "researcher") {
@ -910,8 +913,8 @@ export class IndicatorUtils {
for (let filter of query["query"]["filters"]) { for (let filter of query["query"]["filters"]) {
for (let gfilter of filter["groupFilters"]) { for (let gfilter of filter["groupFilters"]) {
let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters); let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters);
if(replacedValue) { // don't proceed in replacement if no replaced value matches if (replacedValue) { // don't proceed in replacement if no replaced value matches
if ((gfilter["field"].indexOf(".orcid") != -1 )) { if ((gfilter["field"].indexOf(".orcid") != -1)) {
gfilter["values"][0] = replacedValue; gfilter["values"][0] = replacedValue;
} }
} }
@ -919,19 +922,21 @@ export class IndicatorUtils {
} }
} }
} }
private replaceIndexValues(currentValue, stakeholder, parameters ){
if(currentValue == stakeholder.index_name){ private replaceIndexValues(currentValue, stakeholder, parameters) {
if (currentValue == stakeholder.index_name) {
parameters["index_name"] = stakeholder.index_name; parameters["index_name"] = stakeholder.index_name;
return ChartHelper.prefix + "index_name" + ChartHelper.suffix; return ChartHelper.prefix + "index_name" + ChartHelper.suffix;
}else if(currentValue == stakeholder.index_id){ } else if (currentValue == stakeholder.index_id) {
parameters["index_id"] = stakeholder.index_id; parameters["index_id"] = stakeholder.index_id;
return ChartHelper.prefix + "index_id" + ChartHelper.suffix; return ChartHelper.prefix + "index_id" + ChartHelper.suffix;
}else if(currentValue == stakeholder.index_shortName) { } else if (currentValue == stakeholder.index_shortName) {
parameters["index_shortName"] = stakeholder.index_shortName; parameters["index_shortName"] = stakeholder.index_shortName;
return ChartHelper.prefix + "index_shortName" + ChartHelper.suffix; return ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
} }
} }
private extractStartYear(obj, indicatorPath: IndicatorPath) { private extractStartYear(obj, indicatorPath: IndicatorPath) {
let start_year; let start_year;
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) { 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) { private parameterizeDefaultQuery(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
let name = ""; let name = "";
for (let query of this.getQueryObjectName(obj) ? obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)] : obj[this.getDescriptionObjectName(obj)]) { 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; parameters: any;
filters: any; filters: any;
filtersApplied: number = 0; filtersApplied: number = 0;
statsProfile: string;
format: Format; format: Format;
constructor(type: IndicatorPathType, source: SourceType, url: string, chartObject: string, jsonPath: string[], format: Format = 'NUMBER') { 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() @Input()
set options(options: (Option | string | number) []) { set options(options: (Option | string | number) []) {
this.optionsArray = options.map(option => { 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 { return {
label: option.toString(), label: option.toString(),
value: option value: option