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 {SearchPublicationsService} from '../../services/searchPublications.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-publications',
|
15
|
template: `
|
16
|
<advanced-search-page pageTitle="Advanced Search Publications" entityType="publication"
|
17
|
[(results)] = "results"
|
18
|
[(searchUtils)] = "searchUtils"
|
19
|
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
|
20
|
(queryChange)="queryChanged($event)">
|
21
|
</advanced-search-page>
|
22
|
|
23
|
`
|
24
|
})
|
25
|
|
26
|
export class AdvancedSearchPublicationsComponent {
|
27
|
public results =[];
|
28
|
public filters =[];
|
29
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
30
|
|
31
|
public searchFields:SearchFields = new SearchFields();
|
32
|
|
33
|
public fieldIds: string[] = this.searchFields.RESULT_ADVANCED_FIELDS;
|
34
|
public fieldIdsMap= this.searchFields.RESULT_FIELDS;
|
35
|
public selectedFields:AdvancedField[] = [];
|
36
|
|
37
|
@ViewChild (AdvancedSearchPageComponent) searchPage : AdvancedSearchPageComponent ;
|
38
|
|
39
|
|
40
|
constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) {
|
41
|
|
42
|
this.results =[];
|
43
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
44
|
this.searchUtils.status =errorCodes.LOADING;
|
45
|
this.searchUtils.baseUrl = OpenaireProperties.searchLinkToAdvancedPublications;
|
46
|
|
47
|
|
48
|
|
49
|
}
|
50
|
ngOnInit() {
|
51
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
52
|
this.searchUtils.status =errorCodes.LOADING;
|
53
|
this.sub = this.route.queryParams.subscribe(params => {
|
54
|
let page = (params['page']=== undefined)?1:+params['page'];
|
55
|
this.searchUtils.page = ( page <= 0 ) ? 1 : page;
|
56
|
this.searchPage.fieldIds = this.fieldIds;
|
57
|
this.searchPage.selectedFields = this.selectedFields;
|
58
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
59
|
|
60
|
this.searchPage.getSelectedFiltersFromUrl(params);
|
61
|
this.getResults(this.searchPage.createQueryParameters(), this.searchUtils.page, this.searchUtils.size);
|
62
|
|
63
|
});
|
64
|
}
|
65
|
ngOnDestroy() {
|
66
|
this.sub.unsubscribe();
|
67
|
}
|
68
|
sub: any;
|
69
|
public getResults(parameters:string, page: number, size: number){
|
70
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
71
|
this.searchUtils.status = errorCodes.LOADING;
|
72
|
console.info("Advanced Search Publications: Execute search query "+parameters);
|
73
|
this._searchPublicationsService.advancedSearchPublications(parameters, page, size).subscribe(
|
74
|
data => {
|
75
|
this.searchUtils.totalResults = data[0];
|
76
|
console.info("searchPubl total="+this.searchUtils.totalResults);
|
77
|
this.results = data[1];
|
78
|
this.searchPage.updateBaseUrlWithParameters();
|
79
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
80
|
this.searchUtils.status = errorCodes.DONE;
|
81
|
if(this.searchUtils.totalResults == 0 ){
|
82
|
this.searchUtils.status = errorCodes.NONE;
|
83
|
}
|
84
|
},
|
85
|
err => {
|
86
|
console.log(err);
|
87
|
console.info("error");
|
88
|
//TODO check erros (service not available, bad request)
|
89
|
// if( ){
|
90
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
91
|
// }
|
92
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
93
|
this.searchUtils.status = errorCodes.NOT_AVAILABLE;
|
94
|
}
|
95
|
);
|
96
|
}
|
97
|
|
98
|
public queryChanged($event) {
|
99
|
var parameters = $event.value;
|
100
|
this.getResults(parameters, this.searchUtils.page,this.searchUtils.size);
|
101
|
console.info("queryChanged: Execute search query "+parameters);
|
102
|
|
103
|
}
|
104
|
|
105
|
|
106
|
}
|