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, FieldDetails} from '../../utils/properties/searchFields';
|
10
|
import {SearchPageTableViewComponent } from '../searchUtils/searchPageTableView.component';
|
11
|
import {SearchUtilsClass } from '../searchUtils/searchUtils.class';
|
12
|
|
13
|
@Component({
|
14
|
selector: 'search-journals-table',
|
15
|
template: `
|
16
|
|
17
|
<search-page-table pageTitle="OpenAIRE Journals Table"
|
18
|
type="content providers" entityType="dataprovider" [(filters)] = "filters"
|
19
|
[(results)] = "results" [(searchUtils)] = "searchUtils"
|
20
|
[showResultCount]=false
|
21
|
[disableForms]="disableForms"
|
22
|
[searchViewLink]="'/search/journals'"
|
23
|
searchFormClass="journalsTableSearchForm"
|
24
|
formPlaceholderText="Search for Journals">
|
25
|
</search-page-table>
|
26
|
`
|
27
|
|
28
|
})
|
29
|
export class SearchJournalsTableComponent {
|
30
|
private errorCodes: ErrorCodes;
|
31
|
|
32
|
public results =[];
|
33
|
public filters =[];
|
34
|
public baseUrl:string;
|
35
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
36
|
public sub: any; public subResults: any;
|
37
|
public _location:Location;
|
38
|
public searchFields:SearchFields = new SearchFields();
|
39
|
public refineFields: string[] = this.searchFields.JOURNAL_FIELDS;
|
40
|
|
41
|
/*public CSV: any = { "columnNames": [ "Title", "Type", "Coutries", "Compatibility" ],
|
42
|
"export":[]
|
43
|
};
|
44
|
public CSVDownloaded = false;
|
45
|
public csvParams: string;
|
46
|
public resourcesQuery = "&query=((oaftype exact datasource) not(datasourcecompatibilityid = UNKNOWN) not(datasourcecompatibilityid = notCompatible) not(datasourcetypeuiid = other))";*/
|
47
|
|
48
|
public disableForms: boolean = false;
|
49
|
|
50
|
@ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ;
|
51
|
|
52
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService ) {
|
53
|
this.errorCodes = new ErrorCodes();
|
54
|
this.searchUtils.status = this.errorCodes.LOADING;
|
55
|
this.baseUrl = OpenaireProperties.getLinkToSearchJournalsTable();
|
56
|
}
|
57
|
|
58
|
public ngOnInit() {
|
59
|
this.searchPage.refineFields = this.refineFields;
|
60
|
this.sub = this.route.queryParams.subscribe(params => {
|
61
|
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
62
|
//this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
|
63
|
this.filters = this.createFilters();
|
64
|
this.searchPage.getParametersFromUrl(params);
|
65
|
this._getResults();
|
66
|
});
|
67
|
}
|
68
|
|
69
|
public ngOnDestroy() {
|
70
|
if(this.sub){
|
71
|
this.sub.unsubscribe();
|
72
|
}
|
73
|
if(this.subResults){
|
74
|
this.subResults.unsubscribe();
|
75
|
} }
|
76
|
private _getResults(){
|
77
|
//this.csvParams = this.resourcesQuery+"&type=datasources";
|
78
|
|
79
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
80
|
this.searchUtils.status = this.errorCodes.LOADING;
|
81
|
this.disableForms = true;
|
82
|
this.results = [];
|
83
|
this.searchUtils.totalResults = 0;
|
84
|
|
85
|
let size: number = 0;
|
86
|
this.subResults = this._searchDataprovidersService.searchJournalsTable().subscribe(
|
87
|
data => {
|
88
|
size = data;
|
89
|
if(size > 0) {
|
90
|
this.subResults = this._searchDataprovidersService.searchJournals("", null, 1, size, []).subscribe(
|
91
|
data => {
|
92
|
this.searchUtils.totalResults = data[0];
|
93
|
console.info("search Journals [total results:"+this.searchUtils.totalResults+"]");
|
94
|
this.results = data[1];
|
95
|
|
96
|
this.searchPage.checkSelectedFilters(this.filters);
|
97
|
|
98
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
99
|
this.searchUtils.status = this.errorCodes.DONE;
|
100
|
if(this.searchUtils.totalResults == 0 ){
|
101
|
this.searchUtils.status = this.errorCodes.NONE;
|
102
|
}
|
103
|
this.disableForms = false;
|
104
|
},
|
105
|
err => {
|
106
|
console.log(err);
|
107
|
//TODO check erros (service not available, bad request)
|
108
|
// if( ){
|
109
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
110
|
// }
|
111
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
112
|
//this.searchUtils.status = errorCodes.ERROR;
|
113
|
if(err.status == '404') {
|
114
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
115
|
} else if(err.status == '500') {
|
116
|
this.searchUtils.status = this.errorCodes.ERROR;
|
117
|
} else {
|
118
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
119
|
}
|
120
|
|
121
|
this.disableForms = false;
|
122
|
|
123
|
}
|
124
|
);
|
125
|
} else {
|
126
|
this.searchPage.checkSelectedFilters(this.filters);
|
127
|
|
128
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
129
|
this.searchUtils.status = this.errorCodes.NONE;
|
130
|
this.disableForms = false;
|
131
|
}
|
132
|
},
|
133
|
err => {
|
134
|
console.log(err);
|
135
|
//TODO check erros (service not available, bad request)
|
136
|
// if( ){
|
137
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
138
|
// }
|
139
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
140
|
//this.searchUtils.status = errorCodes.ERROR;
|
141
|
if(err.status == '404') {
|
142
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
143
|
} else if(err.status == '500') {
|
144
|
this.searchUtils.status = this.errorCodes.ERROR;
|
145
|
} else {
|
146
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
147
|
}
|
148
|
}
|
149
|
);
|
150
|
|
151
|
}
|
152
|
private setFilters(){
|
153
|
//TODO set filters from
|
154
|
}
|
155
|
|
156
|
private createFilters():Filter[] {
|
157
|
var filter_names=["Type","Compatibility Level"];
|
158
|
var filter_ids=["datasourcetypeuiid","datasourcecompatibilityname"];
|
159
|
var searchFields = new SearchFields();
|
160
|
var filter_original_ids = searchFields.JOURNAL_FIELDS;
|
161
|
var value_names=[
|
162
|
/*[
|
163
|
"Institutional Publication Repository","Thematic Publication Repository", "Other Publication Repository",
|
164
|
"Institutional Repositories Aggregators",
|
165
|
"Thematic Repositories Aggregators", "Other Repositories Aggregators",
|
166
|
"Data Repositories", "Data Repositories Aggregators", "Journals", "Journals Aggregators", "CRIS Systems", "Publication Catalogues"],
|
167
|
*/
|
168
|
["Journal", "Journal Aggregator\/Publisher"],
|
169
|
|
170
|
|
171
|
|
172
|
|
173
|
["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)"]];
|
174
|
|
175
|
var value_original_ids=[
|
176
|
["pubsrepository::journal", "aggregator::pubsrepository::journals"],
|
177
|
//["driver","openaire2.0", "driver-openaire2.0", "openaire3.0","openaire2.0_data"]
|
178
|
["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)"]];
|
179
|
var filters: Filter[] =[];
|
180
|
for(var i =0 ; i < filter_names.length;i++){
|
181
|
var values:Value[] = [];
|
182
|
for(var j =0 ; j < value_names[i].length;j++){
|
183
|
var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
|
184
|
values.push(value);
|
185
|
}
|
186
|
var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or' };
|
187
|
filters.push(filter);
|
188
|
}
|
189
|
return filters;
|
190
|
}
|
191
|
}
|