1
|
import {Component, Input, ViewChild} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import { Router, ActivatedRoute} from '@angular/router';
|
4
|
import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class';
|
5
|
import {SearchPeopleService} from '../../services/searchPeople.service';
|
6
|
import {SearchResult} from '../../utils/entities/searchResult';
|
7
|
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
|
8
|
import {AdvancedSearchPageComponent} from '../searchUtils/advancedSearchPage.component';
|
9
|
import {SearchFields} from '../../utils/properties/searchFields';
|
10
|
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
|
11
|
|
12
|
|
13
|
@Component({
|
14
|
selector: 'advanced-search-organizations',
|
15
|
template: `
|
16
|
<advanced-search-page pageTitle="Advanced Search People" entityType="person"
|
17
|
type = "people"
|
18
|
[(results)] = "results"
|
19
|
[(searchUtils)] = "searchUtils"
|
20
|
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
|
21
|
(queryChange)="queryChanged($event)" [resourcesQuery]="resourcesQuery">
|
22
|
</advanced-search-page>
|
23
|
|
24
|
`
|
25
|
})
|
26
|
|
27
|
export class AdvancedSearchPeopleComponent {
|
28
|
public results =[];
|
29
|
public filters =[];
|
30
|
|
31
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
32
|
|
33
|
public searchFields:SearchFields = new SearchFields();
|
34
|
|
35
|
public fieldIds: string[] = this.searchFields.PERSON_ADVANCED_FIELDS;
|
36
|
public fieldIdsMap = this.searchFields.PERSON_FIELDS;
|
37
|
public selectedFields:AdvancedField[] = [];
|
38
|
|
39
|
@ViewChild (AdvancedSearchPageComponent) searchPage : AdvancedSearchPageComponent ;
|
40
|
public resourcesQuery = "query=(oaftype exact person)";
|
41
|
|
42
|
|
43
|
constructor (private route: ActivatedRoute, private _searchPeopleService: SearchPeopleService ) {
|
44
|
|
45
|
this.results =[];
|
46
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
47
|
this.searchUtils.status =errorCodes.LOADING;
|
48
|
this.searchUtils.baseUrl = OpenaireProperties.searchLinkToAdvancedPeople;
|
49
|
|
50
|
|
51
|
|
52
|
}
|
53
|
ngOnInit() {
|
54
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
55
|
this.searchUtils.status =errorCodes.LOADING;
|
56
|
this.sub = this.route.queryParams.subscribe(params => {
|
57
|
let page = (params['page']=== undefined)?1:+params['page'];
|
58
|
this.searchUtils.page = ( page <= 0 ) ? 1 : page;
|
59
|
this.searchPage.fieldIds = this.fieldIds;
|
60
|
this.searchPage.selectedFields = this.selectedFields;
|
61
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
62
|
this.searchPage.getSelectedFiltersFromUrl(params);
|
63
|
this.getResults(this.searchPage.createQueryParameters(), this.searchUtils.page, this.searchUtils.size);
|
64
|
|
65
|
});
|
66
|
}
|
67
|
ngOnDestroy() {
|
68
|
this.sub.unsubscribe();
|
69
|
}
|
70
|
sub: any;
|
71
|
public getResults(parameters:string, page: number, size: number){
|
72
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
73
|
this.searchUtils.status = errorCodes.LOADING;
|
74
|
this.searchPage.openLoading();
|
75
|
|
76
|
console.info("Advanced Search People: Execute search query "+parameters);
|
77
|
this._searchPeopleService.advancedSearchPeople(parameters, page, size).subscribe(
|
78
|
data => {
|
79
|
this.searchUtils.totalResults = data[0];
|
80
|
console.info("search People total="+this.searchUtils.totalResults);
|
81
|
this.results = data[1];
|
82
|
this.searchPage.updateBaseUrlWithParameters();
|
83
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
84
|
this.searchUtils.status = errorCodes.DONE;
|
85
|
if(this.searchUtils.totalResults == 0 ){
|
86
|
this.searchUtils.status = errorCodes.NONE;
|
87
|
}
|
88
|
this.searchPage.closeLoading();
|
89
|
|
90
|
},
|
91
|
err => {
|
92
|
console.log(err);
|
93
|
console.info("error");
|
94
|
//TODO check erros (service not available, bad request)
|
95
|
// if( ){
|
96
|
// this.searchUtils.status = errorCodes.ERROR;
|
97
|
// }
|
98
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
99
|
this.searchUtils.status = errorCodes.NOT_AVAILABLE;
|
100
|
this.searchPage.closeLoading();
|
101
|
|
102
|
}
|
103
|
);
|
104
|
}
|
105
|
private setFilters(){
|
106
|
//TODO set filters from
|
107
|
}
|
108
|
|
109
|
public queryChanged($event) {
|
110
|
var parameters = $event.value;
|
111
|
this.getResults(parameters, this.searchUtils.page,this.searchUtils.size);
|
112
|
console.info("queryChanged: Execute search query "+parameters);
|
113
|
|
114
|
}
|
115
|
|
116
|
|
117
|
}
|