From e926893ea430455c04db93723de3a2007b382db9 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Wed, 12 Oct 2016 13:43:18 +0000 Subject: [PATCH] Commiting a first draft with refine fields - using a dummy results from project refine results git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44048 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../compatibleDataProviders.component.ts | 20 +- .../searchDataproviders.component.ts | 90 +-- .../searchPages/searchDatasets.component.ts | 90 +-- .../searchOrganizations.component.ts | 80 +-- .../app/searchPages/searchPeople.component.ts | 2 +- .../searchPages/searchProjects.component.ts | 171 +++-- .../searchUtils/searchFilter.component.ts | 11 +- .../searchUtils/searchHelperClasses.class.ts | 10 +- .../searchUtils/searchPage.component.ts | 77 +- .../searchUtils/searchPaging.component.ts | 4 +- .../services/searchOrganizations.service.ts | 5 +- .../app/services/searchProjects.service.ts | 1 + portal-2/src/app/services/services.module.ts | 5 +- .../servicesUtils/refineResults.class.ts | 17 + .../servicesUtils/refineResuts.service.ts | 48 ++ .../app/utils/pagingFormatter.component.ts | 2 +- .../utils/properties/openaireProperties.ts | 6 +- .../src/app/utils/properties/searchFields.ts | 33 + portal-2/src/server.ts | 680 +++++++++++++++++- 19 files changed, 1055 insertions(+), 297 deletions(-) create mode 100644 portal-2/src/app/services/servicesUtils/refineResults.class.ts create mode 100644 portal-2/src/app/services/servicesUtils/refineResuts.service.ts create mode 100644 portal-2/src/app/utils/properties/searchFields.ts diff --git a/portal-2/src/app/searchPages/dataProviders/compatibleDataProviders.component.ts b/portal-2/src/app/searchPages/dataProviders/compatibleDataProviders.component.ts index 36eb0296..941d804d 100644 --- a/portal-2/src/app/searchPages/dataProviders/compatibleDataProviders.component.ts +++ b/portal-2/src/app/searchPages/dataProviders/compatibleDataProviders.component.ts @@ -6,6 +6,7 @@ import { Filter, Value} from '../searchUtils/searchHelperClasses.class'; import {SearchDataprovidersService} from '../../services/searchDataproviders.service'; import {SearchResult} from '../../utils/entities/searchResult'; import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties'; +import {SearchFields} from '../../utils/properties/searchFields'; @Component({ selector: 'search-dataproviders', @@ -102,20 +103,19 @@ export class SearchCompatibleDataprovidersComponent { private createFilters():Filter[] { var filter_names=["Type","Compatibility Level"]; var filter_ids=["type","compatibility"]; - var filter_original_ids=["datasourcetypeid","openairecompatibilityid"]; - + var searchFields = new SearchFields(); + var filter_original_ids = searchFields.COMPATIBLE_DATAPROVIDER_FIELDS; //["datasourcetypeid","openairecompatibilityid"]; var value_names=[ ["Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository", "Publication Repositories Aggregators", "Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"], ["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)"]]; - var value_ids=[ - ["instRepo","thematicRepo", "otherRepo", "pubRepoAggr", - "dataRepo", "dataRepoAggr", "jRepo", "jRepoAggr", "cris", "pubCat"], - ["compBasic","comp2", "comp2plus", "comp3","comp2data"]]; - var value_original_ids=[ - ["pubsrepository::institutional","pubsrepository::thematic", "pubsrepository::unknown", "aggregator::pubsrepository::thematic or aggregator::pubsrepository::institutional or aggregator::pubsrepository::unknown", - "datarepository::unknown", "aggregator::datarepository", "pubsrepository::journal", "aggregator::pubsrepository::journals", "cris", "pubscatalogue::unknown"], - ["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]]; + var value_ids=[ + ["instRepo","thematicRepo", "otherRepo", "pubRepoAggr", "dataRepo", "dataRepoAggr", "jRepo", "jRepoAggr", "cris", "pubCat"], + ["compBasic","comp2", "comp2plus", "comp3","comp2data"]]; + var value_original_ids=[ + ["pubsrepository::institutional","pubsrepository::thematic", "pubsrepository::unknown", "aggregator::pubsrepository::thematic or aggregator::pubsrepository::institutional or aggregator::pubsrepository::unknown", + "datarepository::unknown", "aggregator::datarepository", "pubsrepository::journal", "aggregator::pubsrepository::journals", "cris", "pubscatalogue::unknown"], + ["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]]; var filters: Filter[] =[]; for(var i =0 ; i < filter_names.length;i++){ var values:Value[] = []; diff --git a/portal-2/src/app/searchPages/searchDataproviders.component.ts b/portal-2/src/app/searchPages/searchDataproviders.component.ts index 656c79ad..dd3846dc 100644 --- a/portal-2/src/app/searchPages/searchDataproviders.component.ts +++ b/portal-2/src/app/searchPages/searchDataproviders.component.ts @@ -6,6 +6,7 @@ import { Filter, Value} from './searchUtils/searchHelperClasses.class'; import {SearchDataprovidersService} from '../services/searchDataproviders.service'; import {SearchResult} from '../utils/entities/searchResult'; import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties'; +import {SearchFields} from '../utils/properties/searchFields'; @Component({ selector: 'search-dataproviders', @@ -42,63 +43,9 @@ export class SearchDataprovidersComponent { this.sub = this.route.queryParams.subscribe(params => { this.keyword = (params['keyword']?params['keyword']:''); this.page = (params['page']=== undefined)?1:+params['page']; - for(var i=0; i<5 ; i++){ - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "name"+j, id: "filter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter:Filter = {title: "title"+i, filterId: "filter_"+i, originalFilterId: "filter_"+i, values : values, countSelectedValues:0, "filterOperator": 'and'} - if(i==0) { - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "MYname"+j, id: "MYfilter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter1:Filter = {title: "MYtitle"+i, filterId: "MYfilter_"+i, originalFilterId: "MYfilter_"+i, values : values, countSelectedValues:0, "filterOperator": 'or'} - this.filters.push(filter1); - this.getResults(this.keyword, this.page, this.size); - - } - - - - console.info(params); - if(params[filter.filterId] != undefined) { - let values = params[filter.filterId].split(","); - for(let value of values) { - for(let filterValue of filter.values) { - if(filterValue.id == value) { - filterValue.selected = true; - filter.countSelectedValues++; - } - } - } - } - } - + + this.filters = this.createFilters(); + this.getResults(this.keyword, this.page, this.size); }); } @@ -143,5 +90,32 @@ export class SearchDataprovidersComponent { this.getResults(parameters, this.page, this.size); } - + private createFilters():Filter[] { + var filter_names=["Type","Compatibility Level"]; + var filter_ids=["type","compatibility"]; + var searchFields = new SearchFields(); + var filter_original_ids = searchFields.COMPATIBLE_DATAPROVIDER_FIELDS; //["datasourcetypeid","openairecompatibilityid"]; + var value_names=[ + ["Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository", "Publication Repositories Aggregators", + "Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"], + ["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)"]]; + var value_ids=[ + ["instRepo","thematicRepo", "otherRepo", "pubRepoAggr", "dataRepo", "dataRepoAggr", "jRepo", "jRepoAggr", "cris", "pubCat"], + ["compBasic","comp2", "comp2plus", "comp3","comp2data"]]; + var value_original_ids=[ + ["pubsrepository::institutional","pubsrepository::thematic", "pubsrepository::unknown", "aggregator::pubsrepository::thematic or aggregator::pubsrepository::institutional or aggregator::pubsrepository::unknown", + "datarepository::unknown", "aggregator::datarepository", "pubsrepository::journal", "aggregator::pubsrepository::journals", "cris", "pubscatalogue::unknown"], + ["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]]; + var filters: Filter[] =[]; + for(var i =0 ; i < filter_names.length;i++){ + var values:Value[] = []; + for(var j =0 ; j < value_names[i].length;j++){ + var value:Value = {name: value_names[i][j], id: value_ids[i][j], number:j, selected:false} + values.push(value); + } + var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or'} + filters.push(filter); + } + return filters; + } } diff --git a/portal-2/src/app/searchPages/searchDatasets.component.ts b/portal-2/src/app/searchPages/searchDatasets.component.ts index 6b5dfde9..0e288192 100644 --- a/portal-2/src/app/searchPages/searchDatasets.component.ts +++ b/portal-2/src/app/searchPages/searchDatasets.component.ts @@ -3,10 +3,12 @@ import { ActivatedRoute} from '@angular/router'; import { Filter, Value} from './searchUtils/searchHelperClasses.class'; +import {RefineResultsService} from '../services/servicesUtils/refineResuts.service'; import {SearchDatasetsService} from '../services/searchDatasets.service'; import {SearchResult} from '../utils/entities/searchResult'; import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties'; - +import {SearchFields} from '../utils/properties/searchFields'; +import {SearchPageComponent } from './searchUtils/searchPage.component'; @Component({ selector: 'search-datasets', template: ` @@ -21,7 +23,7 @@ import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProper }) export class SearchDatasetsComponent { public results =[]; - private filters =[]; + private filters: Filter[] =[]; public totalResults:number = 0 ; private baseUrl:string; public status:number; @@ -30,74 +32,26 @@ export class SearchDatasetsComponent { private size :number = 10; private sub: any; - constructor (private route: ActivatedRoute, private _searchDatasetsService: SearchDatasetsService ) { - //this.results =[]; - //this.filters =[]; + @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; + constructor (private route: ActivatedRoute, private _searchDatasetsService: SearchDatasetsService, private _refineResultsService:RefineResultsService ) { + var errorCodes:ErrorCodes = new ErrorCodes(); this.status =errorCodes.LOADING; this.baseUrl = OpenaireProperties.getLinkToSearchDatasets(); } private ngOnInit() { + this.sub = this.route.queryParams.subscribe(params => { this.keyword = (params['keyword']?params['keyword']:''); this.page = (params['page']=== undefined)?1:+params['page']; - for(var i=0; i<5 ; i++){ - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "name"+j, id: "filter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter:Filter = {title: "title"+i, filterId: "filter_"+i, originalFilterId: "filter_"+i, values : values, countSelectedValues:0, "filterOperator": 'and'} - if(i==0) { - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "MYname"+j, id: "MYfilter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter1:Filter = {title: "MYtitle"+i, filterId: "MYfilter_"+i, originalFilterId: "MYfilter_"+i, values : values, countSelectedValues:0, "filterOperator": 'or'} - this.filters.push(filter1); - this.getResults(this.keyword, this.page, this.size); - - } + this.getRefineResults(); + this.getResults(this.keyword, this.page, this.size); + + - console.info(params); - if(params[filter.filterId] != undefined) { - let values = params[filter.filterId].split(","); - for(let value of values) { - for(let filterValue of filter.values) { - if(filterValue.id == value) { - filterValue.selected = true; - filter.countSelectedValues++; - } - } - } - } - } }); } @@ -105,14 +59,32 @@ export class SearchDatasetsComponent { private ngOnDestroy() { this.sub.unsubscribe(); } + public getRefineResults (){ + // this._refineResultsService.getRefineResults(this.searchPage.getFields()).subscribe( + this._refineResultsService.getRefineResults(["projectendyear","projectstartyear","funderid","projectecsc39"]).subscribe( + data => { + + this.filters = data; + + }, + err => { + console.error(err); + //TODO check erros (service not available, bad request) + // if( ){ + // this.status = ErrorCodes.ERROR; + // } + + } + ); + } public getResults(parameters:string, page: number, size: number){ console.info("getResults: Execute search query "+parameters); this._searchDatasetsService.searchDatasets(parameters, page, size).subscribe( data => { this.totalResults = data[0]; - console.info("searchPubl total="+this.totalResults); + console.info("searchDataset total="+this.totalResults); this.results = data[1]; var errorCodes:ErrorCodes = new ErrorCodes(); this.status = errorCodes.DONE; diff --git a/portal-2/src/app/searchPages/searchOrganizations.component.ts b/portal-2/src/app/searchPages/searchOrganizations.component.ts index 14a59f3f..a56ec346 100644 --- a/portal-2/src/app/searchPages/searchOrganizations.component.ts +++ b/portal-2/src/app/searchPages/searchOrganizations.component.ts @@ -3,9 +3,11 @@ import { ActivatedRoute} from '@angular/router'; import { Filter, Value} from './searchUtils/searchHelperClasses.class'; +import {RefineResultsService} from '../services/servicesUtils/refineResuts.service'; import {SearchOrganizationsService} from '../services/searchOrganizations.service'; import {SearchResult} from '../utils/entities/searchResult'; import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties'; +import {SearchPageComponent } from './searchUtils/searchPage.component'; @Component({ selector: 'search-organizations', @@ -30,7 +32,7 @@ export class SearchOrganizationsComponent { private size :number = 10; private sub: any; - constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService ) { + constructor (private route: ActivatedRoute, private _searchOrganizationsService: SearchOrganizationsService, private _refineResultsService:RefineResultsService ) { //this.results =[]; //this.filters =[]; var errorCodes:ErrorCodes = new ErrorCodes(); @@ -42,70 +44,34 @@ export class SearchOrganizationsComponent { this.sub = this.route.queryParams.subscribe(params => { this.keyword = (params['keyword']?params['keyword']:''); this.page = (params['page']=== undefined)?1:+params['page']; - for(var i=0; i<5 ; i++){ - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "name"+j, id: "filter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter:Filter = {title: "title"+i, filterId: "filter_"+i, originalFilterId: "filter_"+i, values : values, countSelectedValues:0, "filterOperator": 'and'} - if(i==0) { - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "MYname"+j, id: "MYfilter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter1:Filter = {title: "MYtitle"+i, filterId: "MYfilter_"+i, originalFilterId: "MYfilter_"+i, values : values, countSelectedValues:0, "filterOperator": 'or'} - this.filters.push(filter1); - this.getResults(this.keyword, this.page, this.size); - - } - - - - console.info(params); - if(params[filter.filterId] != undefined) { - let values = params[filter.filterId].split(","); - for(let value of values) { - for(let filterValue of filter.values) { - if(filterValue.id == value) { - filterValue.selected = true; - filter.countSelectedValues++; - } - } - } - } - } + this.getRefineResults(); + this.getResults(this.keyword, this.page, this.size); }); } private ngOnDestroy() { this.sub.unsubscribe(); } + public getRefineResults (){ + // this._refineResultsService.getRefineResults(this.searchPage.getFields()).subscribe( + this._refineResultsService.getRefineResults(["projectendyear","projectstartyear","funderid","projectecsc39"]).subscribe( + data => { + + this.filters = data; + + }, + err => { + console.error(err); + //TODO check erros (service not available, bad request) + // if( ){ + // this.status = ErrorCodes.ERROR; + // } + + } + ); + } public getResults(parameters:string, page: number, size: number){ console.info("getResults: Execute search query "+parameters); diff --git a/portal-2/src/app/searchPages/searchPeople.component.ts b/portal-2/src/app/searchPages/searchPeople.component.ts index 9994d2a4..cbeaa8f3 100644 --- a/portal-2/src/app/searchPages/searchPeople.component.ts +++ b/portal-2/src/app/searchPages/searchPeople.component.ts @@ -13,7 +13,7 @@ import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProper + [(page)] = "page" [(size)] = "size" [(status)] = "status" [baseUrl] = "baseUrl" (queryChange)="queryChanged($event)" [showRefine]=false > ` diff --git a/portal-2/src/app/searchPages/searchProjects.component.ts b/portal-2/src/app/searchPages/searchProjects.component.ts index f5c22344..85c49aae 100644 --- a/portal-2/src/app/searchPages/searchProjects.component.ts +++ b/portal-2/src/app/searchPages/searchProjects.component.ts @@ -2,11 +2,13 @@ import {Component, Input, ViewChild} from '@angular/core'; import { ActivatedRoute} from '@angular/router'; import { Filter, Value} from './searchUtils/searchHelperClasses.class'; +import {RefineResultsService} from '../services/servicesUtils/refineResuts.service'; import {SearchProjectsService} from '../services/searchProjects.service'; import {SearchResult} from '../utils/entities/searchResult'; import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties'; - +import {SearchFields} from '../utils/properties/searchFields'; +import {SearchPageComponent } from './searchUtils/searchPage.component'; @Component({ selector: 'search-projects', template: ` @@ -15,13 +17,13 @@ import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProper [(results)] = "results" [(totalResults)] = "totalResults" [(keyword)] = "keyword" [(page)] = "page" [(size)] = "size" [(status)] = "status" [baseUrl] = "baseUrl" (queryChange)="queryChanged($event)" > - + ` }) export class SearchProjectsComponent { public results =[]; - private filters =[]; + private filters: Filter[] =[]; public totalResults:number = 0 ; public status:number; private baseUrl:string; @@ -29,75 +31,53 @@ export class SearchProjectsComponent { private page :number = 1; private size :number = 10; private sub: any; + private refineParameters = []; + private searchFields:SearchFields = new SearchFields(); - constructor (private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService ) { - //this.results =[]; - //this.filters =[]; + @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; + + constructor (private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService, private _refineResultsService:RefineResultsService ) { var errorCodes:ErrorCodes = new ErrorCodes(); this.status =errorCodes.LOADING; this.baseUrl = OpenaireProperties.getLinkToSearchProjects(); } private ngOnInit() { + this.refineParameters = this.searchFields.getPROJECT_FIELDS(); + this.searchPage.refineParameters = this.refineParameters; //TODO make it work as a directive + this.sub = this.route.queryParams.subscribe(params => { this.keyword = (params['keyword']?params['keyword']:''); this.page = (params['page']=== undefined)?1:+params['page']; - for(var i=0; i<5 ; i++){ - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "name"+j, id: "filter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter:Filter = {title: "title"+i, filterId: "filter_"+i, originalFilterId: "filter_"+i, values : values, countSelectedValues:0, "filterOperator": 'and'} - if(i==0) { - var values = []; - for(var j=0; j<10 ; j++){ - var value:Value = {name: "MYname"+j, id: "MYfilter_"+i+ "_id_"+j, number:j, selected:false} - values.push(value); - } - values.sort((n2,n1) => { - if (n1.number > n2.number) { - return 1; - } - - if (n1.number < n2.number) { - return -1; - } - - return 0; - }); - var filter1:Filter = {title: "MYtitle"+i, filterId: "MYfilter_"+i, originalFilterId: "MYfilter_"+i, values : values, countSelectedValues:0, "filterOperator": 'or'} - this.filters.push(filter1); - this.getResults(this.keyword, this.page, this.size); + var selected_filters = []; + var searchFields:SearchFields = new SearchFields(); + for(var i=0; i< searchFields.PROJECT_FIELDS.length ; i++){ + var filterId = searchFields.PROJECT_FIELDS[i]; + var filterParam = searchFields.PROJECT_PARAM_FIELDS[i]; + if(params[filterParam] != undefined) { + selected_filters.push(filterId); } + } + this.getResults(this.keyword, this.page, this.size); + this.getRefineResults(); + // var filters = this.createFilters(selected_filters); - - - console.info(params); - if(params[filter.filterId] != undefined) { - let values = params[filter.filterId].split(","); - for(let value of values) { - for(let filterValue of filter.values) { - if(filterValue.id == value) { - filterValue.selected = true; - filter.countSelectedValues++; - } - } - } - } - } + // for(var i=0; i< filters.length ; i++){ + // var filter:Filter = filters[i]; + // if(params[filter.filterId] != undefined) { + // let values = params[filter.filterId].split(","); + // for(let value of values) { + // for(let filterValue of filter.values) { + // if(filterValue.id == value) { + // filterValue.selected = true; + // filter.countSelectedValues++; + // } + // } + // } + // } + // } + // this.filters = filters; }); } @@ -105,14 +85,32 @@ export class SearchProjectsComponent { private ngOnDestroy() { this.sub.unsubscribe(); } + public getRefineResults (){ + // this._refineResultsService.getRefineResults(this.searchPage.getFields()).subscribe( + this._refineResultsService.getRefineResults(["projectendyear","projectstartyear","funderid","projectecsc39"]).subscribe( + data => { + + this.filters = data; + + }, + err => { + console.error(err); + //TODO check erros (service not available, bad request) + // if( ){ + // this.status = ErrorCodes.ERROR; + // } + + } + ); + } public getResults(parameters:string, page: number, size: number){ - console.info("getResults: Execute search query "+parameters); + // var refine = "&refine=true"+this.searchPage.getRefineFieldsQuery(this.searchPage.getSelectedFilters()); this._searchProjectsService.searchProjects(parameters, page, size).subscribe( data => { this.totalResults = data[0]; - console.info("search Projects total="+this.totalResults); + console.info("search Projects: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]"); this.results = data[1]; var errorCodes:ErrorCodes = new ErrorCodes(); this.status = errorCodes.DONE; @@ -122,13 +120,12 @@ export class SearchProjectsComponent { }, err => { console.error(err); - console.info("error"); - //TODO check erros (service not available, bad request) + //TODO check erros (service not available, bad request) // if( ){ // this.status = ErrorCodes.ERROR; // } var errorCodes:ErrorCodes = new ErrorCodes(); - this.status = errorCodes.NOT_AVAILABLE; + this.status = errorCodes.ERROR; } ); } @@ -139,9 +136,53 @@ export class SearchProjectsComponent { private queryChanged($event) { var parameters = $event.value; - console.info("queryChanged: Execute search query "+parameters); + // this.filters = this.createFilters(this.searchPage.getSelectedFilters()); + // this.getRefineResults(); this.getResults(parameters, this.page, this.size); } + private createFilters(selected_filters:string[]):Filter[] { + + var filter_original_ids = this.searchFields.PROJECT_FIELDS; // ["funderid","fundinglevel0_id","fundinglevel1_id","fundinglevel2_id","projectstartyear","projectendyear","projectecsc39"]; + var filter_names = ["Funder","Funding level 0", "Funding level 1","Funding level 2", "Start Year","End Year","Special Clause 39"]; + var filter_ids = this.searchFields.PROJECT_PARAM_FIELDS; + + var dependent: { [key:string]:string } = this.searchFields.DEPENDENT_FIELDS; + + var hidden_filter_original_ids = this.searchFields.HIDDEN_FIELDS; + + var value_names=[["EC","FP7"],["1-fl0","2-fl0"],["1-fl1","2-fl1"],["1-fl2","2-fl2"],["2001","2005"],["2011","2015"],["yes","no"] ]; + var value_ids=[["EC","FP7"],["1-fl0","2-fl0"],["1-fl1","2-fl1"],["1-fl2","2-fl2"],["2001","2005"],["2011","2015"],["yes","no"] ]; + var value_original_ids=[["EC","FP7"],["1-fl0","2-fl0"],["1-fl1","2-fl1"],["1-fl2","2-fl2"],["2001","2005"],["2011","2015"],["yes","no"] ]; + var filters: Filter[] =[]; + for(var i =0 ; i < filter_original_ids.length;i++){ + var dependentTo = dependent[filter_original_ids[i]]; + // var old_filter = + + //if filter is not marked as hidden OR it is hidden but it is dependent to a field that it IS selected + //dependentTo != undefined && + if(hidden_filter_original_ids.indexOf(filter_original_ids[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) ){ + var filter:Filter ; + if(selected_filters.indexOf(filter_original_ids[i]) && this.filters.length > 0){ + for(var j =0 ; j < this.filters.length;j++){ + if(filter_original_ids[i] == this.filters[j].filterId){ + filter = this.filters[j]; + } + } + }else{ + var values:Value[] = []; + for(var j =0 ; j < value_names[i].length;j++){ + var value:Value = {name: value_names[i][j], id: value_ids[i][j], number:j, selected:false} + values.push(value); + } + filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or'} + + } + filters.push(filter); + } + + } + return filters; + } } diff --git a/portal-2/src/app/searchPages/searchUtils/searchFilter.component.ts b/portal-2/src/app/searchPages/searchUtils/searchFilter.component.ts index 4c6398b9..32470ad8 100644 --- a/portal-2/src/app/searchPages/searchUtils/searchFilter.component.ts +++ b/portal-2/src/app/searchPages/searchUtils/searchFilter.component.ts @@ -6,7 +6,7 @@ import { Filter, Value} from './searchHelperClasses.class'; @Component({ selector: 'search-filter', template: ` -

{{filter.title}}

+

{{filter.title}}

{{value.name}} ({{value.number}}) @@ -25,10 +25,10 @@ import { Filter, Value} from './searchHelperClasses.class'; }) export class SearchFilterComponent { - @Input() title; - @Input() filterId; - @Input() values; //array[] " name, id, number, selected" - @Input() countSelectedValues:number = 0; //array[] " name, id, number, selected" + // @Input() title; + // @Input() filterId; + // @Input() values; //array[] " name, id, number, selected" + // @Input() countSelectedValues:number = 0; //array[] " name, id, number, selected" //@Output() change = new EventEmitter(); @Input() test:{value:number} ; @Input() filter:Filter; @@ -40,7 +40,6 @@ export class SearchFilterComponent { } ngOnInit() { - console.info(" showResultCount "+this.showResultCount + " (this.showResultCount == true): " + (this.showResultCount == true)+ " (this.showResultCount == false): "+(this.showResultCount == false)); } diff --git a/portal-2/src/app/searchPages/searchUtils/searchHelperClasses.class.ts b/portal-2/src/app/searchPages/searchUtils/searchHelperClasses.class.ts index 0296722c..e55dbc0f 100644 --- a/portal-2/src/app/searchPages/searchUtils/searchHelperClasses.class.ts +++ b/portal-2/src/app/searchPages/searchUtils/searchHelperClasses.class.ts @@ -2,14 +2,14 @@ export class Filter{ public title: string; // eg Type public filterId: string; // type (name in url parameter) public originalFilterId: string; // (in index) - public countSelectedValues: number; - public values: Value[]; - public filterOperator: string; + public countSelectedValues: number = 0; + public values: Value[] = []; + public filterOperator: string ='or'; } export class Value{ public name: string; //eg Article, Journal public id: string; //0001 - public selected: boolean; - public number: number; + public selected: boolean = false; + public number: number = 0; } diff --git a/portal-2/src/app/searchPages/searchUtils/searchPage.component.ts b/portal-2/src/app/searchPages/searchUtils/searchPage.component.ts index 02f26f5f..df52b673 100644 --- a/portal-2/src/app/searchPages/searchUtils/searchPage.component.ts +++ b/portal-2/src/app/searchPages/searchUtils/searchPage.component.ts @@ -4,6 +4,7 @@ import {Location} from '@angular/common'; import { Filter, Value} from './searchHelperClasses.class'; import {SearchResult} from '../../utils/entities/searchResult'; +import {SearchFields} from '../../utils/properties/searchFields'; @Component({ selector: 'search-page', @@ -14,7 +15,7 @@ import {SearchResult} from '../../utils/entities/searchResult';

{{pageTitle}}

-
+
Clear Filters

@@ -28,6 +29,13 @@ import {SearchResult} from '../../utils/entities/searchResult';

+
+ + + + + +
@@ -46,14 +54,18 @@ export class SearchPageComponent { @Output() queryChange = new EventEmitter(); @Input() baseUrl:string = ''; @Input() showResultCount:boolean = true; + @Input() showRefine:boolean = true; + // @Input() + refineParameters = []; + private searchFields:SearchFields = new SearchFields(); constructor (private location: Location) { + console.log("Search page constr"+ this.refineParameters.length); } ngOnInit() { - console.info("searchPage total="+this.totalResults); - console.info("searchPage: results.length = "+this.results.length); + } changekeyword(){ @@ -99,9 +111,8 @@ export class SearchPageComponent { } } if(this.keyword.length > 0 ){ - allLimits+=((allLimits.length == 0)?'':' and ') /*+ ' keyword=' */+ this.keyword; + allLimits+= this.keyword + ((allLimits.length == 0)?'':'&') /*+ ' keyword=' */; } - console.info("QueryParams: "+allLimits); return allLimits; } private isFiltered(){ @@ -136,31 +147,59 @@ export class SearchPageComponent { } goTo(page:number = 1){ - console.info("goto"); - console.info("keyword: "+this.keyword); this.page = page; var urlParameters = this.createUrlParameters(); var queryParameters = this.createQueryParameters(); - console.info(location.pathname); - this.location.go(location.pathname,urlParameters); + this.location.go(location.pathname,urlParameters); this.queryChange.emit({ value: queryParameters }); } filterChanged($event){ - console.info("filterChanged"); - this.goTo(1); + this.goTo(1); } keywordChanged($event) { - console.info("keywordChanged"); - this.keyword = $event.value; - console.info("searchPage: keyword= "+this.keyword); - this.goTo(1); + this.keyword = $event.value; + this.goTo(1); } - // pageChanged($event) { - // this.page = +$event.value; - // this.goTo(this.page); - // } + public getSelectedFilters():string[] { + var selected:string[] = []; + for(var i=0; i < this.filters.length; i++){ + var filter:Filter = this.filters[i]; + if(filter.countSelectedValues > 0){ + selected.push(filter.filterId); + + } + } + return selected; + } + public getFields():string[] { + var selected_filters:string[] = this.getSelectedFilters(); + var fields:string[] = []; + for(var i =0 ; i < this.refineParameters.length;i++){ + var dependentTo = this.searchFields.DEPENDENT_FIELDS[this.refineParameters[i]]; + + //if filter is not marked as hidden OR it is hidden but it is dependent to a field that it IS selected + if(this.searchFields.HIDDEN_FIELDS.indexOf(this.refineParameters[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) ){ + + fields.push(this.refineParameters[i]); + } + + } + return fields; + } + public getRefineFieldsQuery():string{ + + console.log("Refine parames::"+this.refineParameters.length+this.searchFields.HIDDEN_FIELDS.length); + var fields:string[] = this.getFields(); + + var fieldsStr = "" + for(var i =0 ; i < fields.length ;i++){ + fieldsStr+="&fields="+fields[i]; + } + return fieldsStr; + } + } diff --git a/portal-2/src/app/searchPages/searchUtils/searchPaging.component.ts b/portal-2/src/app/searchPages/searchUtils/searchPaging.component.ts index 1dcddaf3..f5adc39a 100644 --- a/portal-2/src/app/searchPages/searchUtils/searchPaging.component.ts +++ b/portal-2/src/app/searchPages/searchUtils/searchPaging.component.ts @@ -5,10 +5,10 @@ import {Observable} from 'rxjs/Observable'; selector: 'search-paging', template: `
-
+
-
+
{{totalResults}} documents, page {{page}} of {{(currentPage())}}
diff --git a/portal-2/src/app/services/searchOrganizations.service.ts b/portal-2/src/app/services/searchOrganizations.service.ts index 38152057..0467c11e 100644 --- a/portal-2/src/app/services/searchOrganizations.service.ts +++ b/portal-2/src/app/services/searchOrganizations.service.ts @@ -37,7 +37,8 @@ export class SearchOrganizationsService { let length = Array.isArray(data) ? data.length : 1; for(let i=0; i 1 ? data[i]['result']['metadata']['oaf:entity']['oaf:organization'] : data['result']['metadata']['oaf:entity']['oaf:organization']; + console.log("Organizations size::: "+length+ " is array::"+Array.isArray(data) ); + let resData = Array.isArray(data) ? data[i]['result']['metadata']['oaf:entity']['oaf:organization'] : data['result']['metadata']['oaf:entity']['oaf:organization']; var result: SearchResult = new SearchResult(); @@ -49,7 +50,7 @@ export class SearchOrganizationsService { } result['title'].url = OpenaireProperties.getsearchLinkToOrganization(); - result['title'].url += length > 1 ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier']; + result['title'].url += Array.isArray(data) ? data[i]['result']['header']['dri:objIdentifier'] : data['result']['header']['dri:objIdentifier']; if(resData['rels'].hasOwnProperty("rel")) { let relLength = Array.isArray(resData['rels']['rel']) ? resData['rels']['rel'].length : 1; diff --git a/portal-2/src/app/services/searchProjects.service.ts b/portal-2/src/app/services/searchProjects.service.ts index 78656702..b0b63862 100644 --- a/portal-2/src/app/services/searchProjects.service.ts +++ b/portal-2/src/app/services/searchProjects.service.ts @@ -3,6 +3,7 @@ import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {OpenaireProperties} from '../utils/properties/openaireProperties'; import {SearchResult} from '../utils/entities/searchResult'; +// import {RefineParsingUtils} from './services-utils/refineResults.class'; @Injectable() export class SearchProjectsService { diff --git a/portal-2/src/app/services/services.module.ts b/portal-2/src/app/services/services.module.ts index 71683364..f88c8393 100644 --- a/portal-2/src/app/services/services.module.ts +++ b/portal-2/src/app/services/services.module.ts @@ -20,8 +20,9 @@ import {SearchDataprovidersService} from './searchDataproviders.service'; import {SearchDatasetsService} from './searchDatasets.service'; import {SearchOrganizationsService} from './searchOrganizations.service'; import {SearchPeopleService} from './searchPeople.service'; - import {SearchProjectsService} from './searchProjects.service'; +import {RefineResultsService} from './servicesUtils/refineResuts.service'; + @NgModule({ @@ -36,7 +37,7 @@ import {SearchProjectsService} from './searchProjects.service'; SearchCrossrefService, SearchDataciteService, SearchOrcidService, SearchPublicationsService, SearchDataprovidersService, DataProviderService, SearchProjectsService, SearchDatasetsService, SearchOrganizationsService, - SearchPeopleService + SearchPeopleService,RefineResultsService ], exports: [ ] diff --git a/portal-2/src/app/services/servicesUtils/refineResults.class.ts b/portal-2/src/app/services/servicesUtils/refineResults.class.ts new file mode 100644 index 00000000..ed0a4e2c --- /dev/null +++ b/portal-2/src/app/services/servicesUtils/refineResults.class.ts @@ -0,0 +1,17 @@ + + + + class RefineParsingUtils { + + + public static parse (data) { + // let results: SearchResult[] = []; + // + // let length = Array.isArray(data) ? data.length : 1; + // + // for(let i=0; i 1 ? data[i]['result']['metadata']['oaf:entity']['oaf:project'] : data['result']['metadata']['oaf:entity']['oaf:project']; + // + // var result: SearchResult = new SearchResult(); + } + } diff --git a/portal-2/src/app/services/servicesUtils/refineResuts.service.ts b/portal-2/src/app/services/servicesUtils/refineResuts.service.ts new file mode 100644 index 00000000..889db63d --- /dev/null +++ b/portal-2/src/app/services/servicesUtils/refineResuts.service.ts @@ -0,0 +1,48 @@ +import {Injectable} from '@angular/core'; +import {Http, Response} from '@angular/http'; +import {Observable} from 'rxjs/Observable'; + // import {RefineParsingUtils} from './services-utils/refineResults.class'; + import { Filter, Value} from '../../searchPages/searchUtils/searchHelperClasses.class'; + +@Injectable() +export class RefineResultsService { + + constructor(private http: Http) {} + + getRefineResults(fields:string[]):any { + + console.info("In get RefineResults:"); + + + return this.http.get('./refineResults.json') + .map(res => res.json()) + .do(res => console.log(res)) + .map(res => this.parseRefineResults(res['refineResults'],fields)) + ; + } + public parseRefineResults (data, fields:string[]):Filter[] { + // var data = this.json.refineReuslts; + var filters:Filter[] = []; + for(let j=0; j {