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