|
|
|
@ -85,7 +85,7 @@ export class StakeholderUtils {
|
|
|
|
|
visibilityIcon: Map<Visibility, string> = new Map<Visibility, string>(this.visibilities.map(option => [option.value, option.icon]));
|
|
|
|
|
|
|
|
|
|
defaultValue(options: Option[]) {
|
|
|
|
|
return options.length === 1?options[0].value:null;
|
|
|
|
|
return options.length === 1 ? options[0].value : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showField(options: Option[]) {
|
|
|
|
@ -94,7 +94,7 @@ export class StakeholderUtils {
|
|
|
|
|
|
|
|
|
|
getLabel(options: Option[], 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[] {
|
|
|
|
@ -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)
|
|
|
|
|
}
|
|
|
|
@ -394,12 +395,12 @@ export class IndicatorUtils {
|
|
|
|
|
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 = [];
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
@ -408,7 +409,7 @@ export class IndicatorUtils {
|
|
|
|
|
let filterResults = this.addFilter(replacedUrl, 'fundingL0', fundingL0);
|
|
|
|
|
replacedUrl = filterResults.url;
|
|
|
|
|
indicatorPath.filtersApplied += filterResults.filtersApplied;
|
|
|
|
|
filterSubtitleText.push( "Funding level 0: " ) ;
|
|
|
|
|
filterSubtitleText.push("Funding level 0: ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (startYear) {
|
|
|
|
@ -425,7 +426,7 @@ export class IndicatorUtils {
|
|
|
|
|
indicatorPath.filtersApplied += filterResults.filtersApplied;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(startYear || endYear) {
|
|
|
|
|
if (startYear || endYear) {
|
|
|
|
|
filterSubtitleText.push(startYear && endYear ? (startYear + ' - ' + endYear) : (endYear ? ('until ' + endYear) : ''));
|
|
|
|
|
}
|
|
|
|
|
if (coFunded) {
|
|
|
|
@ -433,33 +434,33 @@ export class IndicatorUtils {
|
|
|
|
|
let filterResults = this.addFilter(replacedUrl, 'co-funded', coFunded);
|
|
|
|
|
replacedUrl = filterResults.url;
|
|
|
|
|
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) {
|
|
|
|
|
let filterResults = this.addFilter(replacedUrl, 'publicly-funded', publiclyFunded);
|
|
|
|
|
replacedUrl = filterResults.url;
|
|
|
|
|
indicatorPath.filtersApplied += filterResults.filtersApplied;
|
|
|
|
|
filterSubtitleText.push( "Publicly funded: " + (publiclyFunded?'yes':'no') ) ;
|
|
|
|
|
filterSubtitleText.push("Publicly funded: " + (publiclyFunded ? 'yes' : 'no'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (foslvl1) {
|
|
|
|
|
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
|
|
|
|
|
let filterResults = this.addFilter(replacedUrl, 'foslvl1', foslvl1);
|
|
|
|
|
replacedUrl = filterResults.url;
|
|
|
|
|
indicatorPath.filtersApplied +=filterResults.filtersApplied?foslvl1.length:0;
|
|
|
|
|
let filterResults = this.addFilter(replacedUrl, 'foslvl1', foslvl1);
|
|
|
|
|
replacedUrl = filterResults.url;
|
|
|
|
|
indicatorPath.filtersApplied += filterResults.filtersApplied ? foslvl1.length : 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (foslvl2) {
|
|
|
|
|
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
|
|
|
|
|
let filterResults = this.addFilter(replacedUrl, 'foslvl2', foslvl2);
|
|
|
|
|
replacedUrl = filterResults.url;
|
|
|
|
|
indicatorPath.filtersApplied += filterResults.filtersApplied?foslvl2.length:0;
|
|
|
|
|
let filterResults = this.addFilter(replacedUrl, 'foslvl2', foslvl2);
|
|
|
|
|
replacedUrl = filterResults.url;
|
|
|
|
|
indicatorPath.filtersApplied += filterResults.filtersApplied ? 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(", ") ) ;
|
|
|
|
|
if ((foslvl1 && foslvl1.length > 0) || (foslvl2 && foslvl2.length > 0)) {
|
|
|
|
|
filterSubtitleText.push("Field of Science: " + foslvl1.join(', ') + (foslvl1.length > 0 && foslvl2.length > 0 ? ', ' : '') + foslvl2.join(", "));
|
|
|
|
|
}
|
|
|
|
|
if (indicatorPath.parameters) {
|
|
|
|
|
Object.keys(indicatorPath.parameters).forEach(key => {
|
|
|
|
@ -484,7 +485,7 @@ export class IndicatorUtils {
|
|
|
|
|
replacedValue = stakeholder.index_shortName.toLowerCase();
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
});
|
|
|
|
@ -577,7 +578,7 @@ export class IndicatorUtils {
|
|
|
|
|
/*Chart with proper json object*/
|
|
|
|
|
//apply the filter in any select fields
|
|
|
|
|
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) {
|
|
|
|
|
let filter = JSON.parse(filterString);
|
|
|
|
|
//check if filter already exists
|
|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
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') {
|
|
|
|
@ -806,10 +807,10 @@ export class IndicatorUtils {
|
|
|
|
|
for (let gfilter of filter["groupFilters"]) {
|
|
|
|
|
//ignore field No Of Funders
|
|
|
|
|
let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters);
|
|
|
|
|
if(replacedValue) { // don't proceed in replacement if no replaced value matches
|
|
|
|
|
if ((gfilter["field"].indexOf(" funder") != -1 && gfilter["field"].indexOf(" funders") == -1 ) ||
|
|
|
|
|
(gfilter["field"].indexOf(".funder") != -1) ||
|
|
|
|
|
(gfilter["field"].indexOf(".funder.id") != -1)) {
|
|
|
|
|
if (replacedValue) { // don't proceed in replacement if no replaced value matches
|
|
|
|
|
if ((gfilter["field"].indexOf(" funder") != -1 && gfilter["field"].indexOf(" funders") == -1) ||
|
|
|
|
|
(gfilter["field"].indexOf(".funder") != -1) ||
|
|
|
|
|
(gfilter["field"].indexOf(".funder.id") != -1)) {
|
|
|
|
|
gfilter["values"][0] = replacedValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -832,9 +833,9 @@ export class IndicatorUtils {
|
|
|
|
|
for (let filter of query["query"]["filters"]) {
|
|
|
|
|
for (let gfilter of filter["groupFilters"]) {
|
|
|
|
|
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)
|
|
|
|
|
|| (gfilter["field"].indexOf(".context.id") != -1)) {
|
|
|
|
|
|| (gfilter["field"].indexOf(".context.id") != -1)) {
|
|
|
|
|
gfilter["values"][0] = replacedValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -859,9 +860,9 @@ export class IndicatorUtils {
|
|
|
|
|
for (let filter of query["query"]["filters"]) {
|
|
|
|
|
for (let gfilter of filter["groupFilters"]) {
|
|
|
|
|
let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters);
|
|
|
|
|
if(replacedValue) { // don't proceed in replacement if no replaced value matches
|
|
|
|
|
if ((gfilter["field"].indexOf(".organization.name") != -1)||
|
|
|
|
|
(gfilter["field"].indexOf(".organization.id") != -1)) {
|
|
|
|
|
if (replacedValue) { // don't proceed in replacement if no replaced value matches
|
|
|
|
|
if ((gfilter["field"].indexOf(".organization.name") != -1) ||
|
|
|
|
|
(gfilter["field"].indexOf(".organization.id") != -1)) {
|
|
|
|
|
gfilter["values"][0] = replacedValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -869,6 +870,7 @@ export class IndicatorUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private extractDatasource(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
|
|
|
|
|
// works for .datasource.name and .HostedBy datasource
|
|
|
|
|
// and .datasource.id
|
|
|
|
@ -885,9 +887,9 @@ export class IndicatorUtils {
|
|
|
|
|
for (let filter of query["query"]["filters"]) {
|
|
|
|
|
for (let gfilter of filter["groupFilters"]) {
|
|
|
|
|
let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters);
|
|
|
|
|
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)||
|
|
|
|
|
(gfilter["field"].indexOf(".datasource.id") != -1) || (gfilter["field"].indexOf(".hostedby") != -1)) {
|
|
|
|
|
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) ||
|
|
|
|
|
(gfilter["field"].indexOf(".datasource.id") != -1) || (gfilter["field"].indexOf(".hostedby") != -1)) {
|
|
|
|
|
gfilter["values"][0] = replacedValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -895,6 +897,7 @@ export class IndicatorUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private extractResearcher(obj, indicatorPath: IndicatorPath, stakeholder: Stakeholder) {
|
|
|
|
|
// works for .orcid
|
|
|
|
|
if (stakeholder.type != "researcher") {
|
|
|
|
@ -910,8 +913,8 @@ export class IndicatorUtils {
|
|
|
|
|
for (let filter of query["query"]["filters"]) {
|
|
|
|
|
for (let gfilter of filter["groupFilters"]) {
|
|
|
|
|
let replacedValue = this.replaceIndexValues(gfilter["values"][0], stakeholder, indicatorPath.parameters);
|
|
|
|
|
if(replacedValue) { // don't proceed in replacement if no replaced value matches
|
|
|
|
|
if ((gfilter["field"].indexOf(".orcid") != -1 )) {
|
|
|
|
|
if (replacedValue) { // don't proceed in replacement if no replaced value matches
|
|
|
|
|
if ((gfilter["field"].indexOf(".orcid") != -1)) {
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
|
return ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)]) {
|
|
|
|
|