use new community API for filters and paging
This commit is contained in:
parent
9603b117f9
commit
6824746d8a
|
@ -1,8 +1,6 @@
|
||||||
import {Component, ViewChild} from '@angular/core';
|
import {Component, ViewChild} from '@angular/core';
|
||||||
import {ActivatedRoute} from '@angular/router';
|
import {ActivatedRoute} from '@angular/router';
|
||||||
|
|
||||||
import {AdvancedField, Filter, Value} from '../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class';
|
import {AdvancedField, Filter, Value} from '../../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class';
|
||||||
|
|
||||||
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
||||||
import {ErrorMessagesComponent} from '../../openaireLibrary/utils/errorMessages.component';
|
import {ErrorMessagesComponent} from '../../openaireLibrary/utils/errorMessages.component';
|
||||||
import {SearchFields} from '../../openaireLibrary/utils/properties/searchFields';
|
import {SearchFields} from '../../openaireLibrary/utils/properties/searchFields';
|
||||||
|
@ -14,6 +12,7 @@ import {CommunityService} from "../../openaireLibrary/connect/community/communit
|
||||||
import {Subscriber} from "rxjs";
|
import {Subscriber} from "rxjs";
|
||||||
import {NewSearchPageComponent} from "../../openaireLibrary/searchPages/searchUtils/newSearchPage.component";
|
import {NewSearchPageComponent} from "../../openaireLibrary/searchPages/searchUtils/newSearchPage.component";
|
||||||
import {SearchResult} from "../../openaireLibrary/utils/entities/searchResult";
|
import {SearchResult} from "../../openaireLibrary/utils/entities/searchResult";
|
||||||
|
import {StringUtils} from "../../openaireLibrary/utils/string-utils.class";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'openaire-search-projects',
|
selector: 'openaire-search-projects',
|
||||||
|
@ -50,8 +49,9 @@ export class OpenaireSearchProjectsComponent {
|
||||||
private errorMessages: ErrorMessagesComponent;
|
private errorMessages: ErrorMessagesComponent;
|
||||||
public columnNames = ['Project', 'GrantId', 'Funder'];
|
public columnNames = ['Project', 'GrantId', 'Funder'];
|
||||||
public results =[];
|
public results =[];
|
||||||
public originalFilters =[];
|
public originalFunders =[];
|
||||||
public filters =[];
|
public filters =[];
|
||||||
|
selectedFunder = null;
|
||||||
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
||||||
subscriptions = [];
|
subscriptions = [];
|
||||||
public searchFields:SearchFields = new SearchFields();
|
public searchFields:SearchFields = new SearchFields();
|
||||||
|
@ -64,7 +64,6 @@ export class OpenaireSearchProjectsComponent {
|
||||||
private communityId: string = '';
|
private communityId: string = '';
|
||||||
customFilter: SearchCustomFilter = null;
|
customFilter: SearchCustomFilter = null;
|
||||||
initialLoad = true;
|
initialLoad = true;
|
||||||
public allResults =[];
|
|
||||||
@ViewChild(NewSearchPageComponent, { static: true }) searchPage: NewSearchPageComponent;
|
@ViewChild(NewSearchPageComponent, { static: true }) searchPage: NewSearchPageComponent;
|
||||||
public fieldIds: string[] = this.searchFields.PROJECT_ADVANCED_FIELDS;
|
public fieldIds: string[] = this.searchFields.PROJECT_ADVANCED_FIELDS;
|
||||||
public fieldIdsMap= this.searchFields.PROJECT_FIELDS;
|
public fieldIdsMap= this.searchFields.PROJECT_FIELDS;
|
||||||
|
@ -88,14 +87,15 @@ export class OpenaireSearchProjectsComponent {
|
||||||
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
||||||
let page = (params['page'] === undefined) ? 1 : +params['page'];
|
let page = (params['page'] === undefined) ? 1 : +params['page'];
|
||||||
this.searchUtils.page = (page <= 0) ? 1 : page;
|
this.searchUtils.page = (page <= 0) ? 1 : page;
|
||||||
|
this.selectedFunder = params["funder"]?StringUtils.unquote(params["funder"]):null;
|
||||||
this.searchUtils.validateSize(params['size']);
|
this.searchUtils.validateSize(params['size']);
|
||||||
|
|
||||||
this.keyword = decodeURIComponent(params['fv0']?params['fv0']:(params['keyword']?params['keyword']:''));
|
this.keyword = decodeURIComponent(params['fv0']?params['fv0']:(params['keyword']?params['keyword']:''));
|
||||||
this.selectedFields = [];
|
this.selectedFields = [];
|
||||||
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, this.customFilter, params, "project");
|
this.searchPage.prepareSearchPage(this.fieldIds, this.selectedFields, this.refineFields, [], this.fieldIdsMap, this.customFilter, params, "project");
|
||||||
if(this.initialLoad) {
|
if(this.initialLoad) {
|
||||||
this.initialLoad = false;
|
this.initialLoad = false;
|
||||||
this._getResults();
|
this._getResults();
|
||||||
|
this._getCommunityFunders();
|
||||||
}else{
|
}else{
|
||||||
this._getResults();
|
this._getResults();
|
||||||
}
|
}
|
||||||
|
@ -119,13 +119,18 @@ export class OpenaireSearchProjectsComponent {
|
||||||
this.disableForms = true;
|
this.disableForms = true;
|
||||||
this.disableRefineForms = true;
|
this.disableRefineForms = true;
|
||||||
this.enableSearchView = false;
|
this.enableSearchView = false;
|
||||||
if(this.allResults) {
|
this.subscriptions.push(this._searchProjectsService.searchProjectsWithPaging(this.properties, this.communityId, this.searchUtils.page, this.searchUtils.size, this.searchUtils.keyword, this.selectedFunder, "name" ).subscribe(
|
||||||
this.subscriptions.push(this._searchProjectsService.searchProjects(this.properties, this.communityId).subscribe(
|
|
||||||
data => {
|
data => {
|
||||||
this.originalFilters = this.createFilters(data.content).slice(); //copy array
|
this.searchUtils.totalResults = data['totalElements'];
|
||||||
this.allResults = this.parseResults(data.content);
|
this.filters = this.selectedFunder?this.createFilters([this.selectedFunder]):this.createFilters(this.originalFunders);
|
||||||
this.filters = this.searchPage.prepareFiltersToShow(this.originalFilters, this.allResults.length);
|
this.results = this.parseResults(data.content);
|
||||||
this.filterResults();
|
this.oldTotalResults = data['totalElements'];
|
||||||
|
this.searchUtils.totalResults = data['totalElements'];
|
||||||
|
this.searchUtils.status = this.results.length == 0 ? this.errorCodes.NONE: this.errorCodes.DONE;
|
||||||
|
this.disableForms = false;
|
||||||
|
this.disableRefineForms = false;
|
||||||
|
this.enableSearchView = true;
|
||||||
|
this.searchUtils.refineStatus = this.errorCodes.DONE;
|
||||||
},
|
},
|
||||||
err => {
|
err => {
|
||||||
this.handleError("Error getting projects for community with id: " + this.communityId, err);
|
this.handleError("Error getting projects for community with id: " + this.communityId, err);
|
||||||
|
@ -133,59 +138,41 @@ export class OpenaireSearchProjectsComponent {
|
||||||
this.enableSearchView = true;
|
this.enableSearchView = true;
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
}else{
|
|
||||||
this.filters = this.searchPage.prepareFiltersToShow(this.originalFilters, this.allResults.length);
|
|
||||||
this.filterResults();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private createFilters(data):Filter[] {
|
private createFilters(data):Filter[] {
|
||||||
let length = Array.isArray(data) ? data.length : 1;
|
|
||||||
|
|
||||||
var filter_names=["Funder"];
|
|
||||||
var filter_ids=["funder"];
|
|
||||||
var filter_original_ids = ["funder"];
|
|
||||||
|
|
||||||
var value_names=[];
|
|
||||||
var value_original_ids=[];
|
|
||||||
|
|
||||||
var funders = new Set<String>();
|
var funders = new Set<String>();
|
||||||
var value_name = [];
|
var value_name = [];
|
||||||
var value_original_id = [];
|
var value_original_id = [];
|
||||||
let i;
|
for(let funder of data) {
|
||||||
for(i=0; i<length; i++) {
|
funders.add(funder);
|
||||||
let resData = Array.isArray(data) ? data[i] : data;
|
value_name.push(funder);
|
||||||
if(resData.funder && !funders.has(resData.funder)) {
|
value_original_id.push(funder);
|
||||||
funders.add(resData.funder);
|
|
||||||
value_name.push(resData.funder);
|
|
||||||
value_original_id.push(resData.funder.trim());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
value_names.push(value_name);
|
|
||||||
value_original_ids.push(value_original_id);
|
|
||||||
|
|
||||||
var filters: Filter[] =[];
|
var filters: Filter[] =[];
|
||||||
for(i =0 ; i < filter_names.length;i++){
|
if(value_name.length > 0) {
|
||||||
if(value_names[i].length > 0) {
|
|
||||||
var values: Value[] = [];
|
var values: Value[] = [];
|
||||||
for (var j = 0; j < value_names[i].length; j++) {
|
for (var j = 0; j < value_name.length; j++) {
|
||||||
var value: Value = {name: value_names[i][j], id: value_original_ids[i][j], number: j, selected: false}
|
var value: Value = {name: value_name[j], id:value_name[j], number: 0, selected: this.selectedFunder == value_name[j] }
|
||||||
values.push(value);
|
values.push(value);
|
||||||
}
|
}
|
||||||
var filter: Filter = {
|
var filter: Filter = {
|
||||||
title: filter_names[i],
|
title: "Funder",
|
||||||
filterId: filter_ids[i],
|
filterId: "funder",
|
||||||
originalFilterId: filter_original_ids[i],
|
originalFilterId: "funder",
|
||||||
values: values,
|
values: values,
|
||||||
countSelectedValues: 0,
|
countSelectedValues: this.selectedFunder?1:0,
|
||||||
"filterOperator": 'or',
|
"filterOperator": 'or',
|
||||||
valueIsExact: true,
|
valueIsExact: true,
|
||||||
filterType: "checkbox"
|
filterType: "checkbox"
|
||||||
};
|
};
|
||||||
filters.push(filter);
|
filters.push(filter);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return filters;
|
return filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,33 +190,31 @@ export class OpenaireSearchProjectsComponent {
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
filterResults(){
|
getFunderFilterValue(){
|
||||||
let results = this.allResults.filter(value => { return value.title.name && value.title.name.toLowerCase().indexOf(this.keyword.toLowerCase()) !=-1 || value.acronym && value.acronym.toLowerCase().indexOf(this.keyword.toLowerCase()) !=-1});
|
|
||||||
let funderFilterValues = [];
|
|
||||||
for(let filter of this.filters){
|
for(let filter of this.filters){
|
||||||
if(filter.countSelectedValues > 0){
|
if(filter.countSelectedValues > 0){
|
||||||
for(let value of filter.values){
|
for(let value of filter.values){
|
||||||
if(value.selected) {
|
if(value.selected) {
|
||||||
funderFilterValues.push(value.name);
|
return value.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(funderFilterValues.length > 0) {
|
return null;
|
||||||
results = results.filter(value => {
|
|
||||||
return funderFilterValues.indexOf(value.funderShortname) != -1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.oldTotalResults = results.length;
|
|
||||||
this.searchUtils.totalResults = results.length;
|
|
||||||
this.results = results.slice((this.searchUtils.page - 1) * this.searchUtils.size, this.searchUtils.page *this.searchUtils.size );
|
|
||||||
this.searchUtils.status = this.results.length == 0 ? this.errorCodes.NONE: this.errorCodes.DONE;
|
|
||||||
this.disableForms = false;
|
|
||||||
this.disableRefineForms = false;
|
|
||||||
this.enableSearchView = true;
|
|
||||||
this.searchUtils.refineStatus = this.errorCodes.DONE;
|
|
||||||
}
|
}
|
||||||
private handleError(message: string, error) {
|
private handleError(message: string, error) {
|
||||||
console.error("Projects simple Search Page: "+message, error);
|
console.error("Projects simple Search Page: "+message, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _getCommunityFunders() {
|
||||||
|
this.subscriptions.push(this._searchProjectsService.getProjectFunders(this.properties, this.communityId).subscribe(
|
||||||
|
data => {
|
||||||
|
this.originalFunders = data
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue