From 8d530a01dedad04c1bca3646e9ac22f54d0cf784 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Mon, 31 Oct 2016 14:48:26 +0000 Subject: [PATCH] Search fields for publications and projects, change query creation for projects in order to work with the new API format, changes in Advanced search : select fieldtype only when adding new field git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@44372 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../advancedSearchPublications.component.ts | 6 +- .../advancedSearchPublications.component.ts | 168 ------------------ .../app/searchPages/find/search.component.ts | 14 +- .../searchPages/searchProjects.component.ts | 33 ++-- .../searchPublications.component.ts | 2 +- .../advancedSearchForm.component.ts | 23 +-- .../advancedSearchPage.component.ts | 21 ++- .../searchUtils/searchPage.component.ts | 31 +++- .../app/services/searchProjects.service.ts | 2 +- .../servicesUtils/refineResults.class.ts | 16 +- .../src/app/utils/properties/searchFields.ts | 68 +++++-- .../utils/staticAutoComplete2.component.ts | 83 ++++----- 12 files changed, 187 insertions(+), 280 deletions(-) delete mode 100644 portal-2/src/app/searchPages/advancedSearchPublications.component.ts diff --git a/portal-2/src/app/searchPages/advanced/advancedSearchPublications.component.ts b/portal-2/src/app/searchPages/advanced/advancedSearchPublications.component.ts index 713bcb10..535b1541 100644 --- a/portal-2/src/app/searchPages/advanced/advancedSearchPublications.component.ts +++ b/portal-2/src/app/searchPages/advanced/advancedSearchPublications.component.ts @@ -16,7 +16,7 @@ import {SearchFields} from '../../utils/properties/searchFields'; @@ -34,7 +34,8 @@ export class AdvancedSearchPublicationsComponent { private baseUrl: string; private searchFields:SearchFields = new SearchFields(); - private fieldIds: string[] = this.searchFields.ADVANCED_SEARCH_PUBLICATIONS_FIELDS; + private fieldIds: string[] = this.searchFields.ADVANCED_SEARCH_PUBLICATIONS_PARAM; + private fieldIdsMap: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.PUBLICATION_FIELDS_MAP; private selectedFields:AdvancedField[] = []; @ViewChild (AdvancedSearchPageComponent) searchPage : AdvancedSearchPageComponent ; @@ -58,6 +59,7 @@ export class AdvancedSearchPublicationsComponent { this.page = ( page <= 0 ) ? 1 : page; this.searchPage.fieldIds = this.fieldIds; this.searchPage.selectedFields = this.selectedFields; + this.searchPage.fieldIdsMap = this.fieldIdsMap; this.searchPage.getSelectedFiltersFromUrl(params); this.getResults(this.searchPage.createQueryParameters(), this.page, this.size); diff --git a/portal-2/src/app/searchPages/advancedSearchPublications.component.ts b/portal-2/src/app/searchPages/advancedSearchPublications.component.ts deleted file mode 100644 index 57251b83..00000000 --- a/portal-2/src/app/searchPages/advancedSearchPublications.component.ts +++ /dev/null @@ -1,168 +0,0 @@ -import {Component, Input, ViewChild} from '@angular/core'; -import {Observable} from 'rxjs/Observable'; -import { Router, ActivatedRoute} from '@angular/router'; -import {Filter, Value} from './searchUtils/searchHelperClasses.class'; -import {SearchPublicationsService} from '../services/searchPublications.service'; -import {SearchResult} from '../utils/entities/searchResult'; - import {OpenaireProperties} from '../utils/properties/openaireProperties'; - - -@Component({ - selector: 'advanced-search-publications', - template: ` - - - - ` - }) -export class AdvancedSearchPublicationsComponent { - private results =[]; - private filters =[]; - private totalResults:number = 0 ; - private page :number = 1; - private size :number = 1; - - private fields: {"name": string, "value": string}[] = [ - {"name": "all fields", "value": "all"}, - {"name": "Title", "value": "title"}, - {"name": "Author", "value": "author"}, - {"name": "Publisher", "value": "publisher"}, - {"name": "Subject", "value": "subject"} - ]; - private selectedFields: {"name": string, "value": string}[] = [this.fields[0]]; - - private quantifiers: {"name": string, "value": string}[] = [ - {"name": "all words", "value": "and"}, - {"name": "any words", "value": "or"}, - {"name": "none words", "value": "not"} - ]; - private selectedQuantifiers: {"name": string, "value": string}[] = [this.quantifiers[0]]; - - private keywords: string[] = ['']; - - constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) { - - this.results =[]; - this.filters =[]; - //SearchPublicationsComponent.filters = []; - /*this.totalResults = 123; - for(var i=0; i<15 ; i++){ - //var result = {title: "title"+i, id: "id"+i} - var result: SearchResult = new SearchResult(); - - result['title'] = {"name": "title"+i, "url": OpenaireProperties.getsearchLinkToPublication()+i, "accessMode": ""}; - - result['authors'] = new Array<{"name": string, "url": string}>(); - for(let j=0; j<=i+1; j++) { - result['authors'][j] = {"name": "author"+j+":"+i, "url": OpenaireProperties.getsearchLinkToPerson()+i}; - } - - result.year = "0000" - - result.description = "This is a description for publication "+i; - - result['projects'] = {"name": "EC | EPLANET (246806)", "url": "https://beta.openaire.eu/index.php?option=com_openaire&view=project&projectId=corda_______::9352bcbec0b5882278a21fdc0e83078c"}; - - this.results.push(result); - }*/ - - 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.sub = this.route.queryParams.subscribe(params => { - 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.push(filter); - - } - - - } - ngOnInit() { - this.sub = this.route.queryParams.subscribe(params => { - let page = (params['page']=== undefined)?1:+params['page']; - let size = (params['size']=== undefined)?10:+params['size']; - this.page = ( page <= 0 ) ? 1 : page; - this.size = ( size <= 0 ) ? 10 : size; - //this.keywords = (params['keyword']?params['keyword']:''); - - }); - - //TODO get the rest parameters to create query - } - ngOnDestroy() { - this.sub.unsubscribe(); - } - sub: any; - getResults(parameters:string){ - //http://rudie.di.uoa.gr:8080/dnet-functionality-services-1.2.0-SNAPSHOT/search?action=searchNrefine&sTransformer=results_openaire&rTransformer=results_openaire_browse&query=%28oaftype+exact+result%29+and+%28resulttypeid+exact+publication%29&page=5&size=10&fields=instancetypenameid&fields=resultlanguageid&fields=relfunderid&fields=relprojectid&fields=resultacceptanceyear&fields=resultbestlicense&fields=resulthostingdatasourceid&fields=communityid&locale=en_GB - console.info("getResults: Execute search query "+parameters); - } - private setFilters(){ - //TODO set filters from - } - - private queryChanged($event) { - var parameters = $event.value; - this.getResults(parameters); - console.info("queryChanged: Execute search query "+parameters); - - } - - -} diff --git a/portal-2/src/app/searchPages/find/search.component.ts b/portal-2/src/app/searchPages/find/search.component.ts index b2727072..af05aea0 100644 --- a/portal-2/src/app/searchPages/find/search.component.ts +++ b/portal-2/src/app/searchPages/find/search.component.ts @@ -183,7 +183,7 @@ export class SearchComponent { if(this.reloadPublications) { this.reloadPublications = false; this.searchPublicationsComponent.getResults(this.keyword, false, 1, 10); - this.linkToSearchPublications = OpenaireProperties.getLinkToSearchPublications() + this.keyword; + this.linkToSearchPublications = OpenaireProperties.getLinkToSearchPublications() + "?keyword=" + this.keyword; } } private searchDatasets() { @@ -191,7 +191,7 @@ export class SearchComponent { if(this.reloadDatasets) { this.reloadDatasets = false; this.searchDatasetsComponent.getResults(this.keyword, false, 1, 10); - this.linkToSearchDatasets = OpenaireProperties.getLinkToSearchDatasets() + this.keyword; + this.linkToSearchDatasets = OpenaireProperties.getLinkToSearchDatasets() + "?keyword=" + this.keyword; } } private searchProjects() { @@ -199,7 +199,7 @@ export class SearchComponent { if(this.reloadProjects) { this.reloadProjects = false; this.searchProjectsComponent.getResults(this.keyword, false, 1, 10); - this.linkToSearchProjects = OpenaireProperties.getLinkToSearchProjects() + this.keyword; + this.linkToSearchProjects = OpenaireProperties.getLinkToSearchProjects() + "?keyword=" + this.keyword; } } private searchDataProviders() { @@ -207,7 +207,7 @@ export class SearchComponent { if(this.reloadDataproviders) { this.reloadDataproviders = false; this.searchDataProvidersComponent.getResults(this.keyword, false, 1, 10); - this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders() + this.keyword; + this.linkToSearchDataproviders = OpenaireProperties.getLinkToSearchDataProviders() + "?keyword=" + this.keyword; } } private searchOrganizations() { @@ -215,7 +215,7 @@ export class SearchComponent { if(this.reloadOrganizations) { this.reloadOrganizations = false; this.searchOrganizationsComponent.getResults(this.keyword, false, 1, 10); - this.linkToSearchOrganizations = OpenaireProperties.getLinkToSearchOrganizations() + this.keyword; + this.linkToSearchOrganizations = OpenaireProperties.getLinkToSearchOrganizations() + "?keyword=" + this.keyword; } } private searchPeople() { @@ -223,13 +223,13 @@ export class SearchComponent { if(this.reloadPeople) { this.reloadPeople = false; this.searchPeopleComponent.getResults(this.keyword, false, 1, 10); - this.linkToSearchPeople = OpenaireProperties.getLinkToSearchPeople() + this.keyword; + this.linkToSearchPeople = OpenaireProperties.getLinkToSearchPeople() + "?keyword=" + this.keyword; } } private keywordChanged($event){ this.keyword = $event.value; - console.info("Search Find: search with keyword \"" + this.keyword + "\"" ); + console.info("Search Find: search with keyword \"" + this.keyword + "\"" ); //unsubscribeSearch(); diff --git a/portal-2/src/app/searchPages/searchProjects.component.ts b/portal-2/src/app/searchPages/searchProjects.component.ts index 85f10e82..f33d94ee 100644 --- a/portal-2/src/app/searchPages/searchProjects.component.ts +++ b/portal-2/src/app/searchPages/searchProjects.component.ts @@ -2,8 +2,6 @@ import {Component, Input, ViewChild} from '@angular/core'; import { ActivatedRoute} from '@angular/router'; import {Location} from '@angular/common'; 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'; @@ -30,26 +28,30 @@ export class SearchProjectsComponent { private page :number = 1; private size :number = 10; private sub: any; - private refineFields = []; private searchFields:SearchFields = new SearchFields(); - private urlParams : Map ; + private refineFields: string[] = this.searchFields.PROJECT_INDEX; + private indexIdsMap: { [key:string]:string } = this.searchFields.PROJECT_INDEX_PARAM_MAP; + private fieldIdsMap: { [key:string]:{ name:string, operator:string, type:string, indexField:string }} = this.searchFields.PROJECT_FIELDS_MAP; + private urlParams : Map; private _location:Location; @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ; constructor (private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService) { + console.info(" constructor SearchProjectsComponent "+this.refineFields.length); + var errorCodes:ErrorCodes = new ErrorCodes(); this.status =errorCodes.LOADING; this.baseUrl = OpenaireProperties.getLinkToSearchProjects(); - this.refineFields = this.searchFields.getPROJECT_FIELDS(); - if(!this.searchPage){ - this.searchPage = new SearchPageComponent(this._location); - } + this.refineFields = this.searchFields.PROJECT_INDEX; + } private ngOnInit() { this.searchPage.refineFields = this.refineFields; - console.info("Here:: init pr"+this.refineFields.length); + this.searchPage.indexIdsMap = this.indexIdsMap; + this.searchPage.fieldIdsMap = this.fieldIdsMap; + console.info(" ngOnInit SearchProjectsComponent "+this.refineFields.length); //get refine field filters from url parameters this.sub = this.route.queryParams.subscribe(params => { @@ -60,9 +62,8 @@ export class SearchProjectsComponent { //get page from url parameters this.page = (params['page']=== undefined)?1:+params['page']; - - this.searchPage.getSelectedFiltersFromUrl(params); - this.getResults(this.keyword, true, this.page, this.size); + var queryParameters = this.searchPage.getQueryParametersFromUrl(params); + this._getResults(queryParameters, true, this.page, this.size); }); } @@ -78,13 +79,17 @@ export class SearchProjectsComponent { this._getResults(parameters,refine,page,size); } private _getResults(parameters:string,refine:boolean, page: number, size: number){ - + if(!refine && !this.searchPage){ + this.searchPage = new SearchPageComponent(this._location); + } this._searchProjectsService.searchProjects(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields()).subscribe( data => { this.totalResults = data[0]; console.info("search Projects: [Parameters:"+parameters+" ] [total results:"+this.totalResults+"]"); this.results = data[1]; - this.filters = this.searchPage.checkSelectedFilters(data[2]); + this.filters = data[2]; + this.searchPage.checkSelectedFilters(this.filters); + // this.filters = this.searchPage.checkSelectedFilters(data[2]); this.searchPage.updateBaseUrlWithParameters(this.filters); var errorCodes:ErrorCodes = new ErrorCodes(); this.status = errorCodes.DONE; diff --git a/portal-2/src/app/searchPages/searchPublications.component.ts b/portal-2/src/app/searchPages/searchPublications.component.ts index 6dfcea61..4a10fc29 100644 --- a/portal-2/src/app/searchPages/searchPublications.component.ts +++ b/portal-2/src/app/searchPages/searchPublications.component.ts @@ -43,7 +43,7 @@ export class SearchPublicationsComponent { var errorCodes:ErrorCodes = new ErrorCodes(); this.status =errorCodes.LOADING; this.baseUrl = OpenaireProperties.getLinkToSearchPublications(); - this.refineFields = this.searchFields.getPROJECT_FIELDS(); + this.refineFields = this.searchFields.PUBLICATION_INDEX; //get refine field filters from url parameters if(!this.searchPage){ this.searchPage = new SearchPageComponent(this._location); diff --git a/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts b/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts index 15260185..ab4513e6 100644 --- a/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts +++ b/portal-2/src/app/searchPages/searchUtils/advancedSearchForm.component.ts @@ -30,18 +30,18 @@ import {SearchFields} from '../../utils/properties/searchFields';