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 {SearchDataprovidersService} from '../../services/searchDataproviders.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
|
|
14
|
@Component({
|
15
|
selector: 'advanced-search-dataprovider',
|
16
|
template: `
|
17
|
<advanced-search-page pageTitle="Advanced Search Data Providers" entityType="dataprovider"
|
18
|
type = "datasources"
|
19
|
[(results)] = "results"
|
20
|
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
|
21
|
[(searchUtils)] = "searchUtils"
|
22
|
(queryChange)="queryChanged($event)" [resourcesQuery]="resourcesQuery">
|
23
|
</advanced-search-page>
|
24
|
|
25
|
`
|
26
|
})
|
27
|
|
28
|
export class AdvancedSearchDataProvidersComponent {
|
29
|
public results =[];
|
30
|
public filters =[];
|
31
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
32
|
public searchFields:SearchFields = new SearchFields();
|
33
|
|
34
|
public fieldIds: string[] = this.searchFields.DATASOURCE_ADVANCED_FIELDS;
|
35
|
public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
|
36
|
public selectedFields:AdvancedField[] = [];
|
37
|
|
38
|
@ViewChild (AdvancedSearchPageComponent) searchPage : AdvancedSearchPageComponent ;
|
39
|
public resourcesQuery = "query=(oaftype exact datasource)";
|
40
|
|
41
|
|
42
|
constructor (private route: ActivatedRoute, private _searchDataProvidersService: SearchDataprovidersService ) {
|
43
|
|
44
|
this.results =[];
|
45
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
46
|
this.searchUtils.status =errorCodes.LOADING;
|
47
|
this.searchUtils.baseUrl = OpenaireProperties.searchLinkToAdvancedDataProviders;
|
48
|
console.info("Con -base url:"+this.searchUtils.baseUrl );
|
49
|
|
50
|
}
|
51
|
ngOnInit() {
|
52
|
this.sub = this.route.queryParams.subscribe(params => {
|
53
|
let page = (params['page']=== undefined)?0:+params['page'];
|
54
|
this.searchUtils.page = ( page < 1 ) ? 1 : page;
|
55
|
this.searchPage.fieldIds = this.fieldIds;
|
56
|
this.searchPage.selectedFields = this.selectedFields;
|
57
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
58
|
this.searchPage.getSelectedFiltersFromUrl(params);
|
59
|
this.getResults(this.searchPage.createQueryParameters(), this.searchUtils.page, this.searchUtils.size);
|
60
|
|
61
|
});
|
62
|
}
|
63
|
ngOnDestroy() {
|
64
|
this.sub.unsubscribe();
|
65
|
}
|
66
|
sub: any;
|
67
|
public getResults(parameters:string, page: number, size: number){
|
68
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
69
|
this.searchUtils.status = errorCodes.LOADING;
|
70
|
this.searchPage.openLoading();
|
71
|
|
72
|
console.info("Advanced Search Publications: Execute search query "+parameters);
|
73
|
this._searchDataProvidersService.advancedSearchDataproviders(parameters, page, size).subscribe(
|
74
|
data => {
|
75
|
this.searchUtils.totalResults = data[0];
|
76
|
console.info("Adv Search Data providers 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
|
this.searchPage.closeLoading();
|
85
|
|
86
|
},
|
87
|
err => {
|
88
|
console.log(err);
|
89
|
console.info("error");
|
90
|
//TODO check erros (service not available, bad request)
|
91
|
// if( ){
|
92
|
// this.searchUtils.status = errorCodes.ERROR;
|
93
|
// }
|
94
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
95
|
this.searchUtils.status = errorCodes.NOT_AVAILABLE;
|
96
|
this.searchPage.closeLoading();
|
97
|
|
98
|
}
|
99
|
);
|
100
|
}
|
101
|
|
102
|
public queryChanged($event) {
|
103
|
var parameters = $event.value;
|
104
|
this.getResults(parameters, this.searchUtils.page,this.searchUtils.size);
|
105
|
console.info("queryChanged: Execute search query "+parameters);
|
106
|
|
107
|
}
|
108
|
|
109
|
|
110
|
}
|