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 {SearchPageTableViewComponent } from '../searchUtils/searchPageTableView.component';
|
11
|
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
|
12
|
|
13
|
@Component({
|
14
|
selector: 'search-entity-registries-table',
|
15
|
template: `
|
16
|
|
17
|
<search-page-table pageTitle="Registries/ Databases"
|
18
|
type="content providers" entityType="dataprovider" [(filters)] = "filters"
|
19
|
[(results)] = "results" [(searchUtils)] = "searchUtils"
|
20
|
[showResultCount]=false
|
21
|
[disableForms]="disableForms"
|
22
|
[searchViewLink]="'/search/entity-registries'"
|
23
|
searchFormClass="entityRegistriesTableSearchForm"
|
24
|
formPlaceholderText="Search for Registries/ Databases">
|
25
|
</search-page-table>
|
26
|
|
27
|
`
|
28
|
|
29
|
})
|
30
|
export class SearchEntityRegistriesTableComponent {
|
31
|
private errorCodes: ErrorCodes;
|
32
|
|
33
|
public results =[];
|
34
|
public filters =[];
|
35
|
public baseUrl:string;
|
36
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
37
|
public sub: any; public subResults: any;
|
38
|
public _location:Location;
|
39
|
public searchFields:SearchFields = new SearchFields();
|
40
|
public refineFields: string[] = this.searchFields.ENTITY_REGISTRIES_FIELDS;
|
41
|
public disableForms: boolean = false;
|
42
|
|
43
|
@ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ;
|
44
|
|
45
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
|
46
|
this.errorCodes = new ErrorCodes();
|
47
|
this.searchUtils.status = this.errorCodes.LOADING;
|
48
|
}
|
49
|
|
50
|
public ngOnInit() {
|
51
|
this.searchPage.refineFields = this.refineFields;
|
52
|
this.sub = this.route.queryParams.subscribe(params => {
|
53
|
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
54
|
//this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
|
55
|
this.filters = this.createFilters();
|
56
|
|
57
|
this.searchPage.getParametersFromUrl(params);
|
58
|
this._getResults("", false, this.searchUtils.page);
|
59
|
});
|
60
|
}
|
61
|
|
62
|
public ngOnDestroy() {
|
63
|
if(this.sub){
|
64
|
this.sub.unsubscribe();
|
65
|
}
|
66
|
if(this.subResults){
|
67
|
this.subResults.unsubscribe();
|
68
|
} }
|
69
|
private _getResults(parameters:string,refine:boolean, page: number){
|
70
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
71
|
this.searchUtils.status = this.errorCodes.LOADING;
|
72
|
this.disableForms = true;
|
73
|
this.results = [];
|
74
|
this.searchUtils.totalResults = 0;
|
75
|
|
76
|
let size: number = 0;
|
77
|
this.subResults = this._searchDataprovidersService.searchEntityRegistriesTable().subscribe(
|
78
|
data => {
|
79
|
size = data;
|
80
|
if(size > 0) {
|
81
|
this.subResults = this._searchDataprovidersService.searchEntityRegistries("",null, page, size, []).subscribe(
|
82
|
data => {
|
83
|
this.searchUtils.totalResults = data[0];
|
84
|
console.info("search Entity Registries [total results:"+this.searchUtils.totalResults+"]");
|
85
|
this.results = data[1];
|
86
|
this.searchPage.checkSelectedFilters(this.filters);
|
87
|
|
88
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
89
|
this.searchUtils.status = this.errorCodes.DONE;
|
90
|
if(this.searchUtils.totalResults == 0 ){
|
91
|
this.searchUtils.status = this.errorCodes.NONE;
|
92
|
}
|
93
|
this.disableForms = false;
|
94
|
|
95
|
},
|
96
|
err => {
|
97
|
console.log(err);
|
98
|
//TODO check erros (service not available, bad request)
|
99
|
// if( ){
|
100
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
101
|
// }
|
102
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
103
|
//this.searchUtils.status = errorCodes.ERROR;
|
104
|
if(err.status == '404') {
|
105
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
106
|
} else if(err.status == '500') {
|
107
|
this.searchUtils.status = this.errorCodes.ERROR;
|
108
|
} else {
|
109
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
110
|
}
|
111
|
|
112
|
this.disableForms = false;
|
113
|
|
114
|
}
|
115
|
);
|
116
|
} else {
|
117
|
this.searchPage.checkSelectedFilters(this.filters);
|
118
|
|
119
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
120
|
this.searchUtils.status = this.errorCodes.NONE;
|
121
|
this.disableForms = false;
|
122
|
}
|
123
|
},
|
124
|
err => {
|
125
|
console.log(err);
|
126
|
//TODO check erros (service not available, bad request)
|
127
|
// if( ){
|
128
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
129
|
// }
|
130
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
131
|
//this.searchUtils.status = errorCodes.ERROR;
|
132
|
if(err.status == '404') {
|
133
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
134
|
} else if(err.status == '500') {
|
135
|
this.searchUtils.status = this.errorCodes.ERROR;
|
136
|
} else {
|
137
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
138
|
}
|
139
|
}
|
140
|
);
|
141
|
/*
|
142
|
this.subResults = this._searchDataprovidersService.searchEntityRegistries(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, []).subscribe(
|
143
|
data => {
|
144
|
this.searchUtils.totalResults = data[0];
|
145
|
console.info("search Entity Registries: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
146
|
this.results = data[1];
|
147
|
this.searchPage.checkSelectedFilters(this.filters);
|
148
|
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
149
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
150
|
this.searchUtils.status = errorCodes.DONE;
|
151
|
if(this.searchUtils.totalResults == 0 ){
|
152
|
this.searchUtils.status = errorCodes.NONE;
|
153
|
}
|
154
|
//this.searchPage.closeLoading();
|
155
|
this.disableForms = false;
|
156
|
|
157
|
},
|
158
|
err => {
|
159
|
console.log(err);
|
160
|
//TODO check erros (service not available, bad request)
|
161
|
// if( ){
|
162
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
163
|
// }
|
164
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
165
|
this.searchUtils.status = errorCodes.ERROR;
|
166
|
//this.searchPage.closeLoading();
|
167
|
this.disableForms = false;
|
168
|
|
169
|
}
|
170
|
);
|
171
|
*/
|
172
|
}
|
173
|
private setFilters(){
|
174
|
//TODO set filters from
|
175
|
}
|
176
|
|
177
|
|
178
|
private createFilters():Filter[] {
|
179
|
var filter_names=["Type","Compatibility Level"];
|
180
|
var filter_ids=["datasourcetypename","datasourcecompatibilityname"];
|
181
|
var searchFields = new SearchFields();
|
182
|
var filter_original_ids = searchFields.ENTITY_REGISTRIES_FIELDS;
|
183
|
var value_names=[
|
184
|
["Funder database","Registry of repositories","Scholarly Comm. Infrastructure","Registry","Information Space","Web Source"],
|
185
|
|
186
|
["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)"]];
|
187
|
|
188
|
var value_original_ids=[
|
189
|
["Funder database","Registry of repositories","Scholarly Comm. Infrastructure","Registry","Information Space","Web Source"],
|
190
|
//["entityregistry::projects","entityregistry::repositories","scholarcomminfra","entityregistry","infospace","websource"],
|
191
|
//["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]
|
192
|
["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)"]];
|
193
|
|
194
|
var filters: Filter[] =[];
|
195
|
for(var i =0 ; i < filter_names.length;i++){
|
196
|
var values:Value[] = [];
|
197
|
for(var j =0 ; j < value_names[i].length;j++){
|
198
|
var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
|
199
|
values.push(value);
|
200
|
}
|
201
|
var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or' };
|
202
|
filters.push(filter);
|
203
|
}
|
204
|
return filters;
|
205
|
}
|
206
|
}
|