[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[]) => {
// storing all needed data to a map
// 1st call
let queriedFunders1 = data[0][1][0].values;
queriedFunders1.forEach(queriedFunder => {
this.fundersMap.set(queriedFunder.id, {
"id": queriedFunder.id,
"name": queriedFunder.name,
"alias": '', "alias": '',
"researchProducts": +queriedFunder.number, "researchProducts": +queriedFunder.results,
"openAccessResearchProducts": 0, "openAccessResearchProducts": +queriedFunder.openResults,
"openAccessPercentage": 0, "openAccessPercentage": 0,
"projects": 0, "projects": +queriedFunder.projects,
"monitorDashboard": '', "monitorDashboard": '',
"monitorDashboardStatus": '', "monitorDashboardStatus": '',
"logoUrl": '' "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) && (
!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(!funder.logoUrl && this.staticLogos.has(funder.id)) {
if(value.openAccessResearchProducts > 0) { let split = funder.id.split("||");
value.openAccessPercentage = Math.round((value.openAccessResearchProducts / value.researchProducts) * 100); let shortname = (split && split.length==3) ? funder.id.split("||")[2] : funder.id;
} funder.logoUrl = "assets/explore-assets/funders/logos/"+shortname+".png";
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";
} }
this.fundersMap.set(queriedFunder.id, funder);
}); });
// convert funders map into an array // convert funders map into an array
this.funders = Array.from(this.fundersMap.values()); this.funders = Array.from(this.fundersMap.values());
// calculate total numbers for intro content // calculate total numbers for intro content
this.calculateNumbers(); this.fundersNumber = data.count;
this.researchProductsNumber = data.results;
this.projectsNumber = data.projects;
// sort funders // sort funders
this.funders.sort((a, b) => a['name'].localeCompare(b['name'])); this.funders.sort((a, b) => a['name'].localeCompare(b['name']));
// initialize displayedFunders // initialize displayedFunders
this.displayedFunders = this.funders; this.displayedFunders = this.funders;
this.showLoading = false; this.showLoading = false;
}) }))
);
// let refineParams = '&fq=resultbestaccessright%20exact%20%22Open%20Access%22';
// this.subscriptions.push(
// zip(
// this.refineFieldResultsService.getAllRefineFieldResultsByFieldName('relfunder', 'result', this.properties),
// this.refineFieldResultsService.getAllRefineFieldResultsByFieldName('relfunder', 'result', this.properties, refineParams),
// this.refineFieldResultsService.getAllRefineFieldResultsByFieldName('funder', 'project', this.properties),
// this.stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL, 'funder')
// ).subscribe((data: any[]) => {
// // storing all needed data to a map
// // 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