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 = "data providers"
|
19
|
[(results)] = "results"
|
20
|
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
|
21
|
[(searchUtils)] = "searchUtils"
|
22
|
(queryChange)="queryChanged($event)"
|
23
|
[csvParams]="csvParams" csvPath="resources" simpleSearchLink="/search/find/dataproviders"
|
24
|
[disableForms]="disableForms">
|
25
|
</advanced-search-page>
|
26
|
|
27
|
`
|
28
|
})
|
29
|
|
30
|
export class AdvancedSearchDataProvidersComponent {
|
31
|
public results =[];
|
32
|
public filters =[];
|
33
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
34
|
public searchFields:SearchFields = new SearchFields();
|
35
|
|
36
|
public fieldIds: string[] = this.searchFields.DATASOURCE_ADVANCED_FIELDS;
|
37
|
public fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
|
38
|
public selectedFields:AdvancedField[] = [];
|
39
|
|
40
|
@ViewChild (AdvancedSearchPageComponent) searchPage : AdvancedSearchPageComponent ;
|
41
|
public resourcesQuery = "(oaftype exact datasource)";
|
42
|
public csvParams: string;
|
43
|
public disableForms: boolean = false;
|
44
|
|
45
|
constructor (private route: ActivatedRoute, private _searchDataProvidersService: SearchDataprovidersService ) {
|
46
|
|
47
|
this.results =[];
|
48
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
49
|
this.searchUtils.status =errorCodes.LOADING;
|
50
|
this.searchUtils.baseUrl = OpenaireProperties.searchLinkToAdvancedDataProviders;
|
51
|
console.info("Con -base url:"+this.searchUtils.baseUrl );
|
52
|
|
53
|
}
|
54
|
ngOnInit() {
|
55
|
this.sub = this.route.queryParams.subscribe(params => {
|
56
|
let page = (params['page']=== undefined)?0:+params['page'];
|
57
|
this.searchUtils.page = ( page < 1 ) ? 1 : page;
|
58
|
this.searchPage.fieldIds = this.fieldIds;
|
59
|
this.selectedFields =[];
|
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
|
if(parameters!= null && parameters != '' ) {
|
73
|
this.csvParams ="&type=datasources&query=( "+this.resourcesQuery + "and (" + parameters + "))";
|
74
|
}else{
|
75
|
this.csvParams ="&type=datasources&query="+this.resourcesQuery;
|
76
|
}
|
77
|
|
78
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
79
|
this.searchUtils.status = errorCodes.LOADING;
|
80
|
//this.searchPage.openLoading();
|
81
|
this.disableForms = true;
|
82
|
this.results = [];
|
83
|
this.searchUtils.totalResults = 0;
|
84
|
|
85
|
console.info("Advanced Search Publications: Execute search query "+parameters);
|
86
|
this._searchDataProvidersService.advancedSearchDataproviders(parameters, page, size).subscribe(
|
87
|
data => {
|
88
|
this.searchUtils.totalResults = data[0];
|
89
|
console.info("Adv Search Data providers total="+this.searchUtils.totalResults);
|
90
|
this.results = data[1];
|
91
|
this.searchPage.updateBaseUrlWithParameters();
|
92
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
93
|
this.searchUtils.status = errorCodes.DONE;
|
94
|
if(this.searchUtils.totalResults == 0 ){
|
95
|
this.searchUtils.status = errorCodes.NONE;
|
96
|
}
|
97
|
//this.searchPage.closeLoading();
|
98
|
this.disableForms = false;
|
99
|
|
100
|
if(this.searchUtils.status == errorCodes.DONE) {
|
101
|
// Page out of limit!!!
|
102
|
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
|
103
|
if(!(Number.isInteger(totalPages))) {
|
104
|
totalPages = (parseInt(totalPages, 10) + 1);
|
105
|
}
|
106
|
if(totalPages < page) {
|
107
|
this.searchUtils.totalResults = 0;
|
108
|
this.searchUtils.status = errorCodes.OUT_OF_BOUND;
|
109
|
}
|
110
|
}
|
111
|
},
|
112
|
err => {
|
113
|
console.log(err);
|
114
|
console.info("error");
|
115
|
//TODO check erros (service not available, bad request)
|
116
|
// if( ){
|
117
|
// this.searchUtils.status = errorCodes.ERROR;
|
118
|
// }
|
119
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
120
|
this.searchUtils.status = errorCodes.NOT_AVAILABLE;
|
121
|
//this.searchPage.closeLoading();
|
122
|
this.disableForms = false;
|
123
|
}
|
124
|
);
|
125
|
}
|
126
|
|
127
|
public queryChanged($event) {
|
128
|
var parameters = $event.value;
|
129
|
this.getResults(parameters, this.searchUtils.page,this.searchUtils.size);
|
130
|
console.info("queryChanged: Execute search query "+parameters);
|
131
|
|
132
|
}
|
133
|
|
134
|
|
135
|
}
|