[grouped-queries | DONE | CHANGED] funders.component.ts: Replaced search & stakeholders queries of funders (in Funders page) with grouped query for Funders page of EXPLORE

This commit is contained in:
Konstantina Galouni 2024-02-07 22:56:11 +02:00
parent 36f1ed105d
commit af50558136
2 changed files with 159 additions and 93 deletions

View File

@ -17,6 +17,7 @@ import {NumberUtils} from '../openaireLibrary/utils/number-utils.class';
import {LayoutService} from '../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service'; import {LayoutService} from '../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service';
import {FormBuilder, FormControl} from '@angular/forms'; import {FormBuilder, FormControl} from '@angular/forms';
import {debounceTime, distinctUntilChanged} from 'rxjs/operators'; import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
import {GroupedRequestsService} from "../openaireLibrary/services/groupedRequests.service";
@Component({ @Component({
selector: 'funders', selector: 'funders',
@ -85,7 +86,8 @@ export class FundersComponent implements OnInit {
private stakeholderService: StakeholderService, private stakeholderService: StakeholderService,
private layoutService: LayoutService, private layoutService: LayoutService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fb: FormBuilder,) { private fb: FormBuilder,
private groupedRequestsService: GroupedRequestsService) {
} }
ngOnInit() { ngOnInit() {
@ -142,100 +144,155 @@ export class FundersComponent implements OnInit {
} }
private getFunders() { private getFunders() {
let refineParams = '&fq=resultbestaccessright%20exact%20%22Open%20Access%22'; this.subscriptions.push(this.groupedRequestsService.funders().subscribe(data => {
this.subscriptions.push( let funders = data["funders"];
zip( funders.forEach(queriedFunder => {
this.refineFieldResultsService.getAllRefineFieldResultsByFieldName('relfunder', 'result', this.properties), let id = queriedFunder.id;
this.refineFieldResultsService.getAllRefineFieldResultsByFieldName('relfunder', 'result', this.properties, refineParams), let funder = {
this.refineFieldResultsService.getAllRefineFieldResultsByFieldName('funder', 'project', this.properties), "id": id,
this.stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL, 'funder') "name": this.removePartAfterCharacters(queriedFunder.name, "||"),
).subscribe((data: any[]) => { "alias": '',
// storing all needed data to a map "researchProducts": +queriedFunder.results,
// 1st call "openAccessResearchProducts": +queriedFunder.openResults,
let queriedFunders1 = data[0][1][0].values; "openAccessPercentage": 0,
queriedFunders1.forEach(queriedFunder => { "projects": +queriedFunder.projects,
this.fundersMap.set(queriedFunder.id, { "monitorDashboard": '',
"id": queriedFunder.id, "monitorDashboardStatus": '',
"name": queriedFunder.name, "logoUrl": ''
"alias": '', };
"researchProducts": +queriedFunder.number,
"openAccessResearchProducts": 0,
"openAccessPercentage": 0,
"projects": 0,
"monitorDashboard": '',
"monitorDashboardStatus": '',
"logoUrl": ''
});
});
// 2nd call if((!funder.researchProducts || funder.researchProducts == 0) && (!funder.projects || funder.projects == 0)) {
let queriedFunders2 = data[1][1][0].values; return;
queriedFunders2.forEach(queriedFunder => { }
if(this.fundersMap.has(queriedFunder.id)) {
this.fundersMap.get(queriedFunder.id).openAccessResearchProducts = +queriedFunder.number;
}
});
// 3rd call if(queriedFunder.stakeholder) {
let queriedFunders3 = data[2][1][0].values; let stakeholder = queriedFunder.stakeholder;
queriedFunders3.forEach(queriedFunder => { funder.alias = stakeholder.alias;
if(+queriedFunder.number > 1) { funder.monitorDashboard = stakeholder.alias;
if (this.fundersMap.has(queriedFunder.id)) { funder.monitorDashboardStatus = stakeholder.visibility;
this.fundersMap.get(queriedFunder.id).projects = +queriedFunder.number; funder.logoUrl = (stakeholder.isUpload ? properties.utilsService + "/download/" : "")+ (stakeholder.logoUrl);
} else { }
this.fundersMap.set(queriedFunder.id, {
"id": queriedFunder.id,
"name": queriedFunder.name,
"alias": '',
"researchProducts": 0,
"openAccessResearchProducts": 0,
"openAccessPercentage": 0,
"projects": +queriedFunder.number,
"monitorDashboard": '',
"monitorDashboardStatus": '',
"logoUrl": ''
});
}
}
});
// 4th call if(funder.openAccessResearchProducts && funder.researchProducts) {
let queriedFunders4 = data[3]; funder.openAccessPercentage = Math.round((funder.openAccessResearchProducts / funder.researchProducts) * 100);
queriedFunders4.forEach(queriedFunder => { }
let id = queriedFunder.index_id + '||' + queriedFunder.index_name + '||' + queriedFunder.index_shortName;
if(this.fundersMap.has(id) && ( if(!funder.logoUrl && this.staticLogos.has(funder.id)) {
!this.fundersMap.get(id).monitorDashboardStatus let split = funder.id.split("||");
|| let shortname = (split && split.length==3) ? funder.id.split("||")[2] : funder.id;
(this.fundersMap.get(id).monitorDashboardStatus == "RESTRICTED" && queriedFunder.visibility == "PUBLIC") funder.logoUrl = "assets/explore-assets/funders/logos/"+shortname+".png";
|| }
(this.fundersMap.get(id).monitorDashboardStatus == "PRIVATE" && (queriedFunder.visibility == "RESTRICTED" || queriedFunder.visibility == "PUBLIC")))) {
this.fundersMap.get(id).alias = queriedFunder.alias; this.fundersMap.set(queriedFunder.id, funder);
this.fundersMap.get(id).monitorDashboard = queriedFunder.alias; });
this.fundersMap.get(id).monitorDashboardStatus = queriedFunder.visibility; // convert funders map into an array
this.fundersMap.get(id).logoUrl = (queriedFunder.isUpload ? properties.utilsService + "/download/" : "")+ (queriedFunder.logoUrl); this.funders = Array.from(this.fundersMap.values());
} // calculate total numbers for intro content
}); this.fundersNumber = data.count;
this.fundersMap.forEach((value) => { this.researchProductsNumber = data.results;
if(value.openAccessResearchProducts > 0) { this.projectsNumber = data.projects;
value.openAccessPercentage = Math.round((value.openAccessResearchProducts / value.researchProducts) * 100); // sort funders
} this.funders.sort((a, b) => a['name'].localeCompare(b['name']));
if(!value.logoUrl && this.staticLogos.has(value.id)) { // initialize displayedFunders
let split = value.id.split("||"); this.displayedFunders = this.funders;
let shortname = (split && split.length==3) ? value.id.split("||")[2] : value.id; this.showLoading = false;
value.logoUrl = "assets/explore-assets/funders/logos/"+shortname+".png"; }))
}
}); // let refineParams = '&fq=resultbestaccessright%20exact%20%22Open%20Access%22';
// convert funders map into an array // this.subscriptions.push(
this.funders = Array.from(this.fundersMap.values()); // zip(
// calculate total numbers for intro content // this.refineFieldResultsService.getAllRefineFieldResultsByFieldName('relfunder', 'result', this.properties),
this.calculateNumbers(); // this.refineFieldResultsService.getAllRefineFieldResultsByFieldName('relfunder', 'result', this.properties, refineParams),
// sort funders // this.refineFieldResultsService.getAllRefineFieldResultsByFieldName('funder', 'project', this.properties),
this.funders.sort((a, b) => a['name'].localeCompare(b['name'])); // this.stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL, 'funder')
// initialize displayedFunders // ).subscribe((data: any[]) => {
this.displayedFunders = this.funders; // // storing all needed data to a map
this.showLoading = false; // // 1st call
}) // let queriedFunders1 = data[0][1][0].values;
); // queriedFunders1.forEach(queriedFunder => {
// this.fundersMap.set(queriedFunder.id, {
// "id": queriedFunder.id,
// "name": queriedFunder.name,
// "alias": '',
// "researchProducts": +queriedFunder.number,
// "openAccessResearchProducts": 0,
// "openAccessPercentage": 0,
// "projects": 0,
// "monitorDashboard": '',
// "monitorDashboardStatus": '',
// "logoUrl": ''
// });
// });
//
// // 2nd call
// let queriedFunders2 = data[1][1][0].values;
// queriedFunders2.forEach(queriedFunder => {
// if(this.fundersMap.has(queriedFunder.id)) {
// this.fundersMap.get(queriedFunder.id).openAccessResearchProducts = +queriedFunder.number;
// }
// });
//
// // 3rd call
// let queriedFunders3 = data[2][1][0].values;
// queriedFunders3.forEach(queriedFunder => {
// if(+queriedFunder.number > 1) {
// if (this.fundersMap.has(queriedFunder.id)) {
// this.fundersMap.get(queriedFunder.id).projects = +queriedFunder.number;
// } else {
// this.fundersMap.set(queriedFunder.id, {
// "id": queriedFunder.id,
// "name": queriedFunder.name,
// "alias": '',
// "researchProducts": 0,
// "openAccessResearchProducts": 0,
// "openAccessPercentage": 0,
// "projects": +queriedFunder.number,
// "monitorDashboard": '',
// "monitorDashboardStatus": '',
// "logoUrl": ''
// });
// }
// }
// });
//
// // 4th call
// let queriedFunders4 = data[3];
// queriedFunders4.forEach(queriedFunder => {
// let id = queriedFunder.index_id + '||' + queriedFunder.index_name + '||' + queriedFunder.index_shortName;
// if(this.fundersMap.has(id) && (
// !this.fundersMap.get(id).monitorDashboardStatus
// ||
// (this.fundersMap.get(id).monitorDashboardStatus == "RESTRICTED" && queriedFunder.visibility == "PUBLIC")
// ||
// (this.fundersMap.get(id).monitorDashboardStatus == "PRIVATE" && (queriedFunder.visibility == "RESTRICTED" || queriedFunder.visibility == "PUBLIC")))) {
// this.fundersMap.get(id).alias = queriedFunder.alias;
// this.fundersMap.get(id).monitorDashboard = queriedFunder.alias;
// this.fundersMap.get(id).monitorDashboardStatus = queriedFunder.visibility;
// this.fundersMap.get(id).logoUrl = (queriedFunder.isUpload ? properties.utilsService + "/download/" : "")+ (queriedFunder.logoUrl);
// }
// });
// this.fundersMap.forEach((value) => {
// if(value.openAccessResearchProducts > 0) {
// value.openAccessPercentage = Math.round((value.openAccessResearchProducts / value.researchProducts) * 100);
// }
// if(!value.logoUrl && this.staticLogos.has(value.id)) {
// let split = value.id.split("||");
// let shortname = (split && split.length==3) ? value.id.split("||")[2] : value.id;
// value.logoUrl = "assets/explore-assets/funders/logos/"+shortname+".png";
// }
// });
// // convert funders map into an array
// this.funders = Array.from(this.fundersMap.values());
// // calculate total numbers for intro content
// this.calculateNumbers();
// // sort funders
// this.funders.sort((a, b) => a['name'].localeCompare(b['name']));
// // initialize displayedFunders
// this.displayedFunders = this.funders;
// console.log(this.funders);
// this.showLoading = false;
// })
// );
} }
private calculateSum(array, property) { private calculateSum(array, property) {
@ -305,4 +362,12 @@ export class FundersComponent implements OnInit {
this.currentPage = $event.value; this.currentPage = $event.value;
HelperFunctions.scrollToId('target'); HelperFunctions.scrollToId('target');
} }
private removePartAfterCharacters(field, characters):string {
if(field && field.indexOf(characters) !=-1){
return field.split(characters)[0];
}
return field;
}
} }

View File

@ -20,6 +20,7 @@ import {closed_access} from '../openaireLibrary/utils/icons/icons';
import {InputModule} from '../openaireLibrary/sharedComponents/input/input.module'; import {InputModule} from '../openaireLibrary/sharedComponents/input/input.module';
import {PagingModule} from '../openaireLibrary/utils/paging.module'; import {PagingModule} from '../openaireLibrary/utils/paging.module';
import {SearchInputModule} from '../openaireLibrary/sharedComponents/search-input/search-input.module'; import {SearchInputModule} from '../openaireLibrary/sharedComponents/search-input/search-input.module';
import {GroupedRequestsServiceModule} from "../openaireLibrary/services/groupedRequestsService.module";
@NgModule({ @NgModule({
@ -27,7 +28,7 @@ import {SearchInputModule} from '../openaireLibrary/sharedComponents/search-inpu
FundersRoutingModule, CommonModule, RouterModule, AlertModalModule, FundersRoutingModule, CommonModule, RouterModule, AlertModalModule,
Schema2jsonldModule, SEOServiceModule, BreadcrumbsModule, LoadingModule, Schema2jsonldModule, SEOServiceModule, BreadcrumbsModule, LoadingModule,
RefineFieldResultsServiceModule, LogoUrlPipeModule, IconsModule, InputModule, RefineFieldResultsServiceModule, LogoUrlPipeModule, IconsModule, InputModule,
PagingModule, SearchInputModule PagingModule, SearchInputModule, GroupedRequestsServiceModule
], ],
declarations: [ declarations: [
FundersComponent FundersComponent