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
|
import {ExportCSVComponent} from '../../utils/exportCSV.class';
|
13
|
|
14
|
@Component({
|
15
|
selector: 'search-entity-registries',
|
16
|
template: `
|
17
|
|
18
|
<search-page pageTitle="Entity Registries"
|
19
|
type="datasources" entityType="dataprovider" [(filters)] = "filters"
|
20
|
[(results)] = "results" [(searchUtils)] = "searchUtils"
|
21
|
[baseUrl] = "baseUrl" [showResultCount]=false
|
22
|
(queryChange)="queryChanged($event)"
|
23
|
(downloadClick)="downloadClicked($event)"
|
24
|
[csvParams]="csvParams" csvPath="resources">
|
25
|
</search-page>
|
26
|
|
27
|
`
|
28
|
|
29
|
})
|
30
|
export class SearchEntityRegistriesComponent {
|
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 fieldIdsMap= this.searchFields.DATASOURCE_FIELDS;
|
40
|
public _prefixQueryFields: {field:string,opName:string,opValue:string,values:string[]}[] =[
|
41
|
{field:"type",opName:"tp",opValue:"and",values: ["other"]}];
|
42
|
// ["entityregistry","entityregistry::projects","entityregistry::repositories"]}];
|
43
|
public _prefixQuery: string = "";
|
44
|
|
45
|
public CSV: any = { "columnNames": [ "Title", "Type", "Coutries", "Compatibility" ],
|
46
|
"export":[]
|
47
|
};
|
48
|
public CSVDownloaded = false;
|
49
|
|
50
|
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
51
|
public resourcesQuery = "&query=((oaftype exact datasource) and(datasourcetypeuiid = other))";
|
52
|
public csvParams: string;
|
53
|
|
54
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
|
55
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
56
|
this.searchUtils.status =errorCodes.LOADING;
|
57
|
this.baseUrl = OpenaireProperties.getLinkToSearchEntityRegistries();
|
58
|
for(var i = 0; i < this._prefixQueryFields.length; i++ ){
|
59
|
for(var j =0; j < this._prefixQueryFields[i].values.length; j++){
|
60
|
this._prefixQuery+="&" + this._prefixQueryFields[i].field + "="
|
61
|
+ this._prefixQueryFields[i].values[j] + "&" +
|
62
|
this._prefixQueryFields[i].opName + "=" + this._prefixQueryFields[i].opValue;
|
63
|
}
|
64
|
}
|
65
|
this._prefixQuery+="&";
|
66
|
}
|
67
|
|
68
|
public ngOnInit() {
|
69
|
this.searchPage.refineFields = this.refineFields;
|
70
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
71
|
this.sub = this.route.queryParams.subscribe(params => {
|
72
|
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
73
|
this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
|
74
|
this.filters = this.createFilters();
|
75
|
|
76
|
var queryParameters = this.searchPage.getIndexQueryParametersFromUrl(params);
|
77
|
this._getResults(queryParameters, false, this.searchUtils.page, this.searchUtils.size);
|
78
|
});
|
79
|
}
|
80
|
|
81
|
public ngOnDestroy() {
|
82
|
if(this.sub){
|
83
|
this.sub.unsubscribe();
|
84
|
}
|
85
|
if(this.subResults){
|
86
|
this.subResults.unsubscribe();
|
87
|
} }
|
88
|
private _getResults(parameters:string,refine:boolean, page: number, size: number){
|
89
|
this.csvParams = parameters+this.resourcesQuery+"&type=datasources";
|
90
|
|
91
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
92
|
this.searchUtils.status = errorCodes.LOADING;
|
93
|
this.searchPage.openLoading();
|
94
|
|
95
|
this.subResults = this._searchDataprovidersService.searchEntityRegistries(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, []).subscribe(
|
96
|
data => {
|
97
|
this.searchUtils.totalResults = data[0];
|
98
|
console.info("search Entity Registries: [Parameters:"+parameters+" ] [total results:"+this.searchUtils.totalResults+"]");
|
99
|
this.results = data[1];
|
100
|
this.searchPage.checkSelectedFilters(this.filters);
|
101
|
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
102
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
103
|
this.searchUtils.status = errorCodes.DONE;
|
104
|
if(this.searchUtils.totalResults == 0 ){
|
105
|
this.searchUtils.status = errorCodes.NONE;
|
106
|
}
|
107
|
this.searchPage.closeLoading();
|
108
|
|
109
|
},
|
110
|
err => {
|
111
|
console.log(err);
|
112
|
//TODO check erros (service not available, bad request)
|
113
|
// if( ){
|
114
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
115
|
// }
|
116
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
117
|
this.searchUtils.status = errorCodes.ERROR;
|
118
|
this.searchPage.closeLoading();
|
119
|
|
120
|
}
|
121
|
);
|
122
|
}
|
123
|
private setFilters(){
|
124
|
//TODO set filters from
|
125
|
}
|
126
|
|
127
|
public queryChanged($event) {
|
128
|
var parameters = $event.index;
|
129
|
console.info("queryChanged: Execute search query "+parameters);
|
130
|
this._getResults(parameters, false, this.searchUtils.page, this.searchUtils.size);
|
131
|
}
|
132
|
private createFilters():Filter[] {
|
133
|
var filter_names=["Type","Compatibility Level"];
|
134
|
var filter_ids=["datasourcetypename","datasourcecompatibilityname"];
|
135
|
var searchFields = new SearchFields();
|
136
|
var filter_original_ids = searchFields.ENTITY_REGISTRIES_FIELDS;
|
137
|
var value_names=[
|
138
|
["Funder database","Registry of repositories","Scholarly Comm. Infrastructure","Registry","Information Space","Web Source"],
|
139
|
|
140
|
["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)"]];
|
141
|
|
142
|
var value_original_ids=[
|
143
|
["Funder database","Registry of repositories","Scholarly Comm. Infrastructure","Registry","Information Space","Web Source"],
|
144
|
//["entityregistry::projects","entityregistry::repositories","scholarcomminfra","entityregistry","infospace","websource"],
|
145
|
//["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]
|
146
|
["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)"]];
|
147
|
|
148
|
var filters: Filter[] =[];
|
149
|
for(var i =0 ; i < filter_names.length;i++){
|
150
|
var values:Value[] = [];
|
151
|
for(var j =0 ; j < value_names[i].length;j++){
|
152
|
var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
|
153
|
values.push(value);
|
154
|
}
|
155
|
var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or' };
|
156
|
filters.push(filter);
|
157
|
}
|
158
|
return filters;
|
159
|
}
|
160
|
|
161
|
|
162
|
|
163
|
public downloadClicked($event) {
|
164
|
if(!this.CSVDownloaded) {
|
165
|
this.CSVDownloaded = false;
|
166
|
|
167
|
var parameters = $event.value;
|
168
|
|
169
|
//this.getResultsCSV(parameters, false, 1, 1000);
|
170
|
|
171
|
this._searchDataprovidersService.searchEntityRegistriesCSV(parameters, this.searchPage.getRefineFieldsQuery(), 1, 1000).subscribe(
|
172
|
data => {
|
173
|
this.CSV.export = data;
|
174
|
ExportCSVComponent.downloadCSV(this.CSV, "etityRegistries.csv");
|
175
|
|
176
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
177
|
this.searchUtils.status = errorCodes.DONE;
|
178
|
},
|
179
|
err => {
|
180
|
console.log(err);
|
181
|
//TODO check erros (service not available, bad request)
|
182
|
// if( ){
|
183
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
184
|
// }
|
185
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
186
|
this.searchUtils.status = errorCodes.ERROR;
|
187
|
}
|
188
|
);
|
189
|
}
|
190
|
}
|
191
|
}
|