1
|
import {Component, Input, ViewChild} from '@angular/core';
|
2
|
import { ActivatedRoute} from '@angular/router';
|
3
|
|
4
|
import { Filter, Value} from '../searchUtils/searchHelperClasses.class';
|
5
|
|
6
|
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
|
7
|
import {SearchResult} from '../../utils/entities/searchResult';
|
8
|
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
|
9
|
import {SearchFields} from '../../utils/properties/searchFields';
|
10
|
import {SearchPageComponent } from '../searchUtils/searchPage.component';
|
11
|
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
|
12
|
|
13
|
|
14
|
@Component({
|
15
|
selector: 'search-entity-registries',
|
16
|
template: `
|
17
|
|
18
|
<search-page pageTitle="Entity Registries" type="datasource" [(filters)] = "filters"
|
19
|
[(results)] = "results" [(searchUtils)] = "searchUtils"
|
20
|
[baseUrl] = "baseUrl" [showResultCount]=false (queryChange)="queryChanged($event)" >
|
21
|
</search-page>
|
22
|
|
23
|
`
|
24
|
|
25
|
})
|
26
|
export class SearchEntityRegistriesComponent {
|
27
|
public results =[];
|
28
|
private filters =[];
|
29
|
private baseUrl:string;
|
30
|
private searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
31
|
private sub: any; private subResults: any;
|
32
|
private _location:Location;
|
33
|
private searchFields:SearchFields = new SearchFields();
|
34
|
private refineFields: string[] = this.searchFields.DATAPROVIDER_INDEX;
|
35
|
private indexIdsMap: { [key:string]:string } = this.searchFields.DATAPROVIDER_INDEX_PARAM_MAP;
|
36
|
private fieldIdsMap: { [key:string]:{ name:string, operator:string, type:string, indexField:string, equalityOperator:string }} = this.searchFields.DATAPROVIDER_FIELDS_MAP;
|
37
|
private _prefixQueryFields: {field:string,opName:string,opValue:string,values:string[]}[] =[
|
38
|
{field:"type",opName:"tp",opValue:"and",values: ["other"]}];
|
39
|
// ["entityregistry","entityregistry::projects","entityregistry::repositories"]}];
|
40
|
private _prefixQuery: string = "";
|
41
|
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
42
|
|
43
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
|
44
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
45
|
this.searchUtils.status =errorCodes.LOADING;
|
46
|
this.baseUrl = OpenaireProperties.getLinkToSearchDataProviders();
|
47
|
for(var i = 0; i < this._prefixQueryFields.length; i++ ){
|
48
|
for(var j =0; j < this._prefixQueryFields[i].values.length; j++){
|
49
|
this._prefixQuery+="&" + this._prefixQueryFields[i].field + "="
|
50
|
+ this._prefixQueryFields[i].values[j] + "&" +
|
51
|
this._prefixQueryFields[i].opName + "=" + this._prefixQueryFields[i].opValue;
|
52
|
}
|
53
|
}
|
54
|
this._prefixQuery+="&";
|
55
|
}
|
56
|
|
57
|
private ngOnInit() {
|
58
|
this.searchPage.refineFields = this.refineFields;
|
59
|
this.searchPage.indexIdsMap = this.indexIdsMap;
|
60
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
61
|
this.sub = this.route.queryParams.subscribe(params => {
|
62
|
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
63
|
this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
|
64
|
this.filters = this.createFilters();
|
65
|
|
66
|
var queryParameters = this.searchPage.getIndexQueryParametersFromUrl(params);
|
67
|
this._getResults(queryParameters, false, this.searchUtils.page, this.searchUtils.size);
|
68
|
});
|
69
|
}
|
70
|
|
71
|
private ngOnDestroy() {
|
72
|
if(this.sub){
|
73
|
this.sub.unsubscribe();
|
74
|
}
|
75
|
if(this.subResults){
|
76
|
this.subResults.unsubscribe();
|
77
|
} }
|
78
|
private _getResults(parameters:string,refine:boolean, page: number, size: number){
|
79
|
this.subResults = this._searchDataprovidersService.searchEntityRegistries(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, []).subscribe(
|
80
|
data => {
|
81
|
this.searchUtils.totalResults = data[0];
|
82
|
console.info("search Entity Registries: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
83
|
this.results = data[1];
|
84
|
this.searchPage.checkSelectedFilters(this.filters);
|
85
|
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
86
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
87
|
this.searchUtils.status = errorCodes.DONE;
|
88
|
if(this.searchUtils.totalResults == 0 ){
|
89
|
this.searchUtils.status = errorCodes.NONE;
|
90
|
}
|
91
|
},
|
92
|
err => {
|
93
|
console.error(err);
|
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.ERROR;
|
100
|
}
|
101
|
);
|
102
|
}
|
103
|
private setFilters(){
|
104
|
//TODO set filters from
|
105
|
}
|
106
|
|
107
|
private queryChanged($event) {
|
108
|
var parameters = $event.index;
|
109
|
console.info("queryChanged: Execute search query "+parameters);
|
110
|
this._getResults(parameters, false, this.searchUtils.page, this.searchUtils.size);
|
111
|
}
|
112
|
private createFilters():Filter[] {
|
113
|
var filter_names=["Type","Compatibility Level"];
|
114
|
var filter_ids=["datasourcetypeid","datasourcecompatibilityid"];
|
115
|
var searchFields = new SearchFields();
|
116
|
var filter_original_ids = searchFields.ENTITY_REGISTRIES_FIELDS;
|
117
|
var value_names=[
|
118
|
["Funder database","Registry of repositories","Scholarly Comm. Infrastructure","Registry","Information Space","Web Source"],
|
119
|
|
120
|
["OpenAIRE Basic (DRIVER OA)","OpenAIRE 2.0 (EC funding)", "OpenAIRE 2.0+ (DRIVER OA, EC funding)", "OpenAIRE 3.0 (OA, funding)","OpenAIRE Data (funded, referenced datasets)"]];
|
121
|
|
122
|
var value_original_ids=[
|
123
|
["entityregistry::projects","entityregistry::repositories","scholarcomminfra","entityregistry","infospace","websource"],
|
124
|
["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]];
|
125
|
|
126
|
var filters: Filter[] =[];
|
127
|
for(var i =0 ; i < filter_names.length;i++){
|
128
|
var values:Value[] = [];
|
129
|
for(var j =0 ; j < value_names[i].length;j++){
|
130
|
var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
|
131
|
values.push(value);
|
132
|
}
|
133
|
var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or'}
|
134
|
filters.push(filter);
|
135
|
}
|
136
|
return filters;
|
137
|
}
|
138
|
|
139
|
}
|