From a3d93c97dd4d52f36334b8b4986b33d311ef28f4 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Thu, 6 Oct 2016 14:49:19 +0000 Subject: [PATCH] adding search page for projects git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@43957 d315682c-612b-4755-9ff5-7f18f6832af3 --- portal-2/src/app/app.routing.ts | 19 +-- portal-2/src/app/searchPages/search.module.ts | 5 +- .../searchDataproviders.component.ts | 2 +- .../searchPages/searchProjects.component.ts | 147 ++++++++++++++++++ .../searchUtils/searchResult.component.ts | 11 ++ .../app/services/searchProjects.service.ts | 119 ++++++++++++++ .../services/searchPublications.service.ts | 8 +- portal-2/src/app/services/services.module.ts | 4 +- .../navigationBar.component.ts | 7 +- .../src/app/utils/entities/searchResult.ts | 6 +- .../utils/properties/openaireProperties.ts | 9 ++ portal-2/src/server.ts | 1 + 12 files changed, 318 insertions(+), 20 deletions(-) create mode 100644 portal-2/src/app/searchPages/searchProjects.component.ts create mode 100644 portal-2/src/app/services/searchProjects.service.ts diff --git a/portal-2/src/app/app.routing.ts b/portal-2/src/app/app.routing.ts index faf55d75..a3a2be16 100644 --- a/portal-2/src/app/app.routing.ts +++ b/portal-2/src/app/app.routing.ts @@ -14,8 +14,9 @@ import { PublicationComponent } from './landingPages/publication/publication.com import { DataProviderComponent } from './landingPages/dataProvider/dataProvider.component' import { SearchComponent } from './searchPages/find/search.component'; import { SearchPublicationsComponent } from './searchPages/searchPublications.component'; -import { AdvancedSearchPublicationsComponent } from './searchPages/advancedSearchPublications.component'; import { SearchDataprovidersComponent } from './searchPages/searchDataproviders.component'; +import { SearchProjectsComponent } from './searchPages/searchProjects.component'; +import { AdvancedSearchPublicationsComponent } from './searchPages/advancedSearchPublications.component'; import { DepositComponent } from './deposit/deposit.component'; import { DepositResultComponent } from './deposit/depositResult.component'; import { ErrorPageComponent } from './error/errorPage.component'; @@ -26,9 +27,9 @@ import { SearchAllComponent } from './searchAll/searchAll.component'; const appRoutes: Routes = [ { path: '', component: SearchComponent, pathMatch: 'full' }, { path: 'claims', component: ClaimsAdminComponent }, - { path: 'home', component: HomeComponent }, - { path: 'claim', component: ClaimComponent }, - { path: 'myclaims', component: MyClaimsComponent }, + { path: 'home', component: HomeComponent }, + { path: 'claim', component: ClaimComponent }, + { path: 'myclaims', component: MyClaimsComponent }, { path: 'search/person', component: PersonComponent }, { path: 'search/project', component: ProjectComponent }, { path: 'search/organization', component: OrganizationComponent }, @@ -39,15 +40,15 @@ const appRoutes: Routes = [ { path: 'linking', component: LinkingComponent }, { path: 'bulk-linking', component: BulkLinkingComponent}, { path: 'search/find/publications', component: SearchPublicationsComponent }, - { path: 'search/advanced/publications', component: AdvancedSearchPublicationsComponent }, { path: 'search/find/dataproviders', component: SearchDataprovidersComponent }, + { path: 'search/find/projects', component: SearchProjectsComponent }, + { path: 'search/advanced/publications', component: AdvancedSearchPublicationsComponent }, { path: 'deposit', component: DepositComponent}, - { path: 'deposit-results', component: DepositResultComponent}, + { path: 'deposit-results', component: DepositResultComponent}, { path: 'test', component: TestComponent}, { path: 'search', component: SearchAllComponent }, - { path: 'error', component: ErrorPageComponent}, - - { path: '**', component: ErrorPageComponent } // it has to be the last one - otherwise the next declaration are ignored + { path: 'error', component: ErrorPageComponent}, + { path: '**', component: ErrorPageComponent } // it has to be the last one - otherwise the next declaration are ignored ]; diff --git a/portal-2/src/app/searchPages/search.module.ts b/portal-2/src/app/searchPages/search.module.ts index 67723ecb..43753c1e 100644 --- a/portal-2/src/app/searchPages/search.module.ts +++ b/portal-2/src/app/searchPages/search.module.ts @@ -21,6 +21,7 @@ import {AdvancedSearchFormComponent} from './searchUtils/advancedSearchForm.comp import { SearchPublicationsComponent } from './searchPublications.component'; import { AdvancedSearchPublicationsComponent } from './advancedSearchPublications.component'; import { SearchDataprovidersComponent } from './searchDataproviders.component'; +import { SearchProjectsComponent } from './searchProjects.component'; import {SearchComponent} from './find/search.component'; @@ -44,7 +45,8 @@ import {SearchComponent} from './find/search.component'; SearchPublicationsComponent, AdvancedSearchPublicationsComponent, SearchDataprovidersComponent, - SearchComponent + SearchComponent, + SearchProjectsComponent ], providers:[ @@ -54,6 +56,7 @@ import {SearchComponent} from './find/search.component'; SearchAllComponent, AdvancedSearchPublicationsComponent, SearchPublicationsComponent, + SearchProjectsComponent, SearchDataprovidersComponent, SearchComponent ] diff --git a/portal-2/src/app/searchPages/searchDataproviders.component.ts b/portal-2/src/app/searchPages/searchDataproviders.component.ts index feb5b382..656c79ad 100644 --- a/portal-2/src/app/searchPages/searchDataproviders.component.ts +++ b/portal-2/src/app/searchPages/searchDataproviders.component.ts @@ -35,7 +35,7 @@ export class SearchDataprovidersComponent { //this.filters =[]; var errorCodes:ErrorCodes = new ErrorCodes(); this.status =errorCodes.LOADING; - this.baseUrl = OpenaireProperties.getLinkToSearchPublications(); + this.baseUrl = OpenaireProperties.getLinkToSearchDataProviders(); } private ngOnInit() { diff --git a/portal-2/src/app/searchPages/searchProjects.component.ts b/portal-2/src/app/searchPages/searchProjects.component.ts new file mode 100644 index 00000000..f5c22344 --- /dev/null +++ b/portal-2/src/app/searchPages/searchProjects.component.ts @@ -0,0 +1,147 @@ +import {Component, Input, ViewChild} from '@angular/core'; +import { ActivatedRoute} from '@angular/router'; + +import { Filter, Value} from './searchUtils/searchHelperClasses.class'; + +import {SearchProjectsService} from '../services/searchProjects.service'; +import {SearchResult} from '../utils/entities/searchResult'; +import {OpenaireProperties, ErrorCodes} from '../utils/properties/openaireProperties'; + +@Component({ + selector: 'search-projects', + template: ` + + + + + ` + +}) +export class SearchProjectsComponent { + public results =[]; + private filters =[]; + public totalResults:number = 0 ; + public status:number; + private baseUrl:string; + private keyword = ''; + private page :number = 1; + private size :number = 10; + private sub: any; + + constructor (private route: ActivatedRoute, private _searchProjectsService: SearchProjectsService ) { + //this.results =[]; + //this.filters =[]; + var errorCodes:ErrorCodes = new ErrorCodes(); + this.status =errorCodes.LOADING; + this.baseUrl = OpenaireProperties.getLinkToSearchProjects(); + } + + 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); + + } + + + + 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++; + } + } + } + } + } + + }); + } + + private ngOnDestroy() { + this.sub.unsubscribe(); + } + + public getResults(parameters:string, page: number, size: number){ + console.info("getResults: Execute search query "+parameters); + + this._searchProjectsService.searchProjects(parameters, page, size).subscribe( + data => { + this.totalResults = data[0]; + console.info("search Projects total="+this.totalResults); + this.results = data[1]; + var errorCodes:ErrorCodes = new ErrorCodes(); + this.status = errorCodes.DONE; + if(this.totalResults == 0 ){ + this.status = errorCodes.NONE; + } + }, + err => { + console.error(err); + console.info("error"); + //TODO check erros (service not available, bad request) + // if( ){ + // this.status = ErrorCodes.ERROR; + // } + var errorCodes:ErrorCodes = new ErrorCodes(); + this.status = errorCodes.NOT_AVAILABLE; + } + ); + } + + private setFilters(){ + //TODO set filters from + } + + private queryChanged($event) { + var parameters = $event.value; + console.info("queryChanged: Execute search query "+parameters); + this.getResults(parameters, this.page, this.size); + } + + +} diff --git a/portal-2/src/app/searchPages/searchUtils/searchResult.component.ts b/portal-2/src/app/searchPages/searchUtils/searchResult.component.ts index 8f9fe369..dae0d0de 100644 --- a/portal-2/src/app/searchPages/searchUtils/searchResult.component.ts +++ b/portal-2/src/app/searchPages/searchUtils/searchResult.component.ts @@ -59,6 +59,17 @@ import { ErrorCodes} from '../../utils/properties/openaireProperties'; Embargo End Date: {{result.embargoEndDate}} +
+ Funders: + + + + {{funder.funderShortname}} + + , + +
+ ({{result.startYear}} - {{result.endYear}})
Organizations: diff --git a/portal-2/src/app/services/searchProjects.service.ts b/portal-2/src/app/services/searchProjects.service.ts new file mode 100644 index 00000000..78656702 --- /dev/null +++ b/portal-2/src/app/services/searchProjects.service.ts @@ -0,0 +1,119 @@ +import {Injectable} from '@angular/core'; +import {Http, Response} from '@angular/http'; +import {Observable} from 'rxjs/Observable'; +import {OpenaireProperties} from '../utils/properties/openaireProperties'; +import {SearchResult} from '../utils/entities/searchResult'; + +@Injectable() +export class SearchProjectsService { + private sizeOfDescription: number = 497; + + constructor(private http: Http) {} + + searchProjects (params: string, page: number, size: number):any { + + console.info("In searchProjects"); + + let link = OpenaireProperties.getSearchAPIURL()+"projects"; + + let url = link+"?"; + if(params != '') { + url += "q="+params+"&page="+page+"&size="+size; + } else { + url += "page="+page+"&size="+size; + } + + return this.http.get(url) + .map(res => res.json()) + //.do(res => console.info(res)) + .map(res => [res['meta'].total, this.parseResults(res['results'])]) + ; + } + + + parseResults(data: any): SearchResult[] { + 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(); + + result['title'] = {"name": '', "url": '', "accessMode": ''}; + if(Array.isArray(resData['title'])) { + // resData['title'][0].hasOwnProperty("content") { + result['title'].name = resData['title'][0]; + // } + } else { + // resData['title'].hasOwnProperty("content") { + result['title'].name = resData['title']; + // } + } + + // if(resData['title'].hasOwnProperty("content")) { + // result['title'].name = resData['title'].content; + // } + result['title'].url = OpenaireProperties.getsearchLinkToProject(); + result['title'].url += length > 1 ? 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; + + for(let j=0; j 1 ? resData['rels']['rel'][j] : resData['rels']['rel']; + + if(relation.hasOwnProperty("to")) { + if(relation['to'].class == "hasParticipant") { + if(result['organizations'] == undefined) { + result['organizations'] = new Array< + { "name": string, "url": string}>(); + } + + let countOrganizations = result['organizations'].length; + + result['organizations'][countOrganizations] = { "name": "", "url": "" } + + result['organizations'][countOrganizations]['url'] = + OpenaireProperties.getsearchLinkToOrganization() + relation['to'].content; + result['organizations'][countOrganizations]['name'] = relation.legalname; + + + + + } + } + } + } + if(resData.hasOwnProperty("fundingtree")) { + if(result['funders'] == undefined) { + result['funders'] = new Array< + {"funderShortname": string, "funderName": string}>(); + } + + let fundingLength = Array.isArray(resData['fundingtree']) ? resData['fundingtree'].length : 1; + + for(let z=0; z 1 ? resData['fundingtree'][z] : resData['fundingtree']; + let countFunders = result['funders'].length; + if(fundingData.hasOwnProperty("funder")) { + result['funders'][countFunders] = {"funderShortname": "", "funderName": ""}; + result['funders'][countFunders]['funderShortname'] = fundingData['funder'].shortname; + result['funders'][countFunders]['funderName'] = fundingData['funder'].name; + } + } + } + if(resData.hasOwnProperty("startdate")) { + result.startYear = resData.startdate.split('-')[0]; + } + if(resData.hasOwnProperty("enddate")) { + result.endYear = resData.enddate.split('-')[0]; + } + + results.push(result); + } + + return results; + } +} diff --git a/portal-2/src/app/services/searchPublications.service.ts b/portal-2/src/app/services/searchPublications.service.ts index 10e444c4..a302cb1f 100644 --- a/portal-2/src/app/services/searchPublications.service.ts +++ b/portal-2/src/app/services/searchPublications.service.ts @@ -44,13 +44,13 @@ export class SearchPublicationsService { result['title'] = {"name": '', "url": '', "accessMode": ''}; if(Array.isArray(resData['title'])) { - resData['title'][0].hasOwnProperty("content") { + // resData['title'][0].hasOwnProperty("content") { result['title'].name = resData['title'][0].content; - } + // } } else { - resData['title'].hasOwnProperty("content") { + // resData['title'].hasOwnProperty("content") { result['title'].name = resData['title'].content; - } + // } } result['title'].url = OpenaireProperties.getsearchLinkToPublication(); diff --git a/portal-2/src/app/services/services.module.ts b/portal-2/src/app/services/services.module.ts index ae22c69a..74e958d8 100644 --- a/portal-2/src/app/services/services.module.ts +++ b/portal-2/src/app/services/services.module.ts @@ -18,6 +18,7 @@ import {SearchPublicationsService} from './searchPublications.service'; import {DataProviderService} from './dataProvider.service'; import {SearchDataprovidersService} from './searchDataproviders.service'; +import {SearchProjectsService} from './searchProjects.service'; @NgModule({ @@ -30,7 +31,8 @@ import {SearchDataprovidersService} from './searchDataproviders.service'; ContextsService, DatasetService, OpenaireProjectsService,OrganizationService, PersonService, ProjectService, PublicationService, SearchCrossrefService, SearchCrossrefService, SearchDataciteService, SearchOrcidService, - SearchPublicationsService, SearchDataprovidersService, DataProviderService + SearchPublicationsService, SearchDataprovidersService, DataProviderService, + SearchProjectsService ], exports: [ diff --git a/portal-2/src/app/sharedComponents/navigationBar.component.ts b/portal-2/src/app/sharedComponents/navigationBar.component.ts index bb657d39..948a57e9 100644 --- a/portal-2/src/app/sharedComponents/navigationBar.component.ts +++ b/portal-2/src/app/sharedComponents/navigationBar.component.ts @@ -25,8 +25,11 @@ import 'rxjs/Rx';