1
|
import {Component, ViewChild} from '@angular/core';
|
2
|
import { ActivatedRoute} from '@angular/router';
|
3
|
|
4
|
import {ErrorCodes} from '../../openaireLibrary/utils/properties/errorCodes';
|
5
|
import {ErrorMessagesComponent} from '../../openaireLibrary/utils/errorMessages.component';
|
6
|
import {SearchFields} from '../../openaireLibrary/utils/properties/searchFields';
|
7
|
import {SearchPageTableViewComponent } from '../../openaireLibrary/searchPages/searchUtils/searchPageTableView.component';
|
8
|
import {SearchCustomFilter, SearchUtilsClass} from '../../openaireLibrary/searchPages/searchUtils/searchUtils.class';
|
9
|
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
|
10
|
import {SearchCommunityDataprovidersService} from '../../openaireLibrary/connect/contentProviders/searchDataproviders.service';
|
11
|
import {ConnectHelper} from '../../openaireLibrary/connect/connectHelper';
|
12
|
import {PiwikHelper} from '../../utils/piwikHelper';
|
13
|
|
14
|
@Component({
|
15
|
selector: 'openaire-search-dataproviders',
|
16
|
template: `
|
17
|
|
18
|
<search-page-table pageTitle="Search Content Providers"
|
19
|
type="content providers" entityType="dataprovider"
|
20
|
[results] = "results" [searchUtils] = "searchUtils"
|
21
|
[columnNames]="columnNames"
|
22
|
[showResultCount]=false
|
23
|
openaireLink="https://beta.explore.openaire.eu/search/find/dataproviders"
|
24
|
[disableForms]="disableForms"
|
25
|
[enableSearchView]="enableSearchView"
|
26
|
searchFormClass="datasourcesTableSearchForm"
|
27
|
formPlaceholderText="Search by name..."
|
28
|
[piwikSiteId]="piwikSiteId" [hasPrefix]="false" [customFilter]="customFilter" [enableEntitySelection]="true"
|
29
|
[includeOnlyResultsAndFilter]="false" [showBreadcrumb]="true">
|
30
|
</search-page-table>
|
31
|
`
|
32
|
|
33
|
})
|
34
|
export class OpenaireSearchDataprovidersComponent {
|
35
|
private errorCodes: ErrorCodes;
|
36
|
private errorMessages: ErrorMessagesComponent;
|
37
|
public columnNames = ['Name', 'Official Name'];
|
38
|
public results =[];
|
39
|
public filters =[];
|
40
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
41
|
public sub: any; public subResults: any;
|
42
|
public _location:Location;
|
43
|
public searchFields:SearchFields = new SearchFields();
|
44
|
public refineFields: string[] = [];// = this.searchFields.JOURNAL_FIELDS;
|
45
|
properties:EnvProperties;
|
46
|
|
47
|
public disableForms: boolean = false;
|
48
|
public enableSearchView: boolean = true;
|
49
|
|
50
|
private communityId: string = '';
|
51
|
|
52
|
@ViewChild (SearchPageTableViewComponent) searchPage : SearchPageTableViewComponent ;
|
53
|
piwikSiteId = null;
|
54
|
customFilter: SearchCustomFilter = null;
|
55
|
initialLoad = true;
|
56
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchCommunityDataprovidersService) {
|
57
|
this.errorCodes = new ErrorCodes();
|
58
|
this.errorMessages = new ErrorMessagesComponent();
|
59
|
this.searchUtils.status = this.errorCodes.LOADING;
|
60
|
|
61
|
}
|
62
|
|
63
|
public ngOnInit() {
|
64
|
this.route.data
|
65
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
66
|
this.properties = data.envSpecific;
|
67
|
|
68
|
//this.searchPage.refineFields = this.refineFields;
|
69
|
this.sub = this.route.queryParams.subscribe(params => {
|
70
|
this.communityId = ConnectHelper.getCommunityFromDomain(this.properties.domain);
|
71
|
if(!this.communityId) {
|
72
|
this.communityId = params['communityId'];
|
73
|
}
|
74
|
this.customFilter = new SearchCustomFilter("Community", "communityId", this.communityId, "");
|
75
|
this.piwikSiteId = PiwikHelper.getSiteId(this.communityId,this.properties.environment);
|
76
|
this.searchUtils.keyword = (params['fv0']?params['fv0']:(params['keyword']?params['keyword']:''));
|
77
|
//this.filters = this.createFilters();
|
78
|
//this.searchPage.getParametersFromUrl(params);
|
79
|
if(this.initialLoad) {
|
80
|
this.initialLoad = false;
|
81
|
console.log("Init get results")
|
82
|
this._getResults(params);
|
83
|
}else{
|
84
|
// this.searchPage.transform(this.results);
|
85
|
this.searchPage.goTo(1);
|
86
|
console.log("Init transfrm " + this.searchUtils.keyword)
|
87
|
}
|
88
|
});
|
89
|
});
|
90
|
}
|
91
|
|
92
|
public ngOnDestroy() {
|
93
|
if(this.sub){
|
94
|
this.sub.unsubscribe();
|
95
|
}
|
96
|
if(this.subResults){
|
97
|
this.subResults.unsubscribe();
|
98
|
}
|
99
|
}
|
100
|
private _getResults(params){
|
101
|
this.searchUtils.status = this.errorCodes.LOADING;
|
102
|
this.disableForms = true;
|
103
|
this.enableSearchView = false;
|
104
|
this.results = [];
|
105
|
this.searchUtils.totalResults = 0;
|
106
|
|
107
|
let size: number = 0;
|
108
|
|
109
|
this.subResults = this._searchDataprovidersService.searchDataproviders(this.properties, this.communityId).subscribe(
|
110
|
data => {
|
111
|
//this.filters = this.createFilters(data, params);
|
112
|
this.searchUtils.totalResults = data.length;
|
113
|
//console.info("search Content Providers [total results:"+this.searchUtils.totalResults+"]");
|
114
|
this.results = data;
|
115
|
|
116
|
//this.searchPage.checkSelectedFilters(this.filters);
|
117
|
|
118
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
119
|
this.searchUtils.status = this.errorCodes.DONE;
|
120
|
if(this.searchUtils.totalResults == 0 ){
|
121
|
this.searchUtils.status = this.errorCodes.NONE;
|
122
|
} else {
|
123
|
this.searchPage.triggerInitialLoad();
|
124
|
this.searchPage.transform(this.results);
|
125
|
this.disableForms = false;
|
126
|
}
|
127
|
this.enableSearchView = true;
|
128
|
},
|
129
|
err => {
|
130
|
/*
|
131
|
console.log(err);
|
132
|
//TODO check erros (service not available, bad request)
|
133
|
|
134
|
if(err.status == '404') {
|
135
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
136
|
} else if(err.status == '500') {
|
137
|
this.searchUtils.status = this.errorCodes.ERROR;
|
138
|
} else {
|
139
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
140
|
}
|
141
|
*/
|
142
|
this.handleError("Error getting content providers for community with id: "+this.communityId, err);
|
143
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
144
|
|
145
|
this.enableSearchView = true;
|
146
|
}
|
147
|
);
|
148
|
}
|
149
|
private setFilters(){
|
150
|
//TODO set filters from
|
151
|
}
|
152
|
/*
|
153
|
private createFilters(data, params):Filter[] {
|
154
|
let length = Array.isArray(data) ? data.length : 1;
|
155
|
|
156
|
var filter_names=[];
|
157
|
var filter_ids=[];
|
158
|
var searchFields = new SearchFields();
|
159
|
var filter_original_ids = [];//searchFields.JOURNAL_FIELDS;
|
160
|
|
161
|
this.refineFields = ["relfunder"];
|
162
|
this.searchPage.refineFields = this.refineFields;
|
163
|
this.searchPage.getParametersFromUrl(params);
|
164
|
|
165
|
var value_names=[];
|
166
|
var value_original_ids=[];
|
167
|
|
168
|
var funders = new Set<String>();
|
169
|
var value_name = [];
|
170
|
var value_original_id = [];
|
171
|
let i;
|
172
|
for(i=0; i<length; i++) {
|
173
|
let resData = Array.isArray(data) ? data[i] : data;
|
174
|
if(resData.funder && !funders.has(resData.funder)) {
|
175
|
funders.add(resData.funder);
|
176
|
value_name.push(resData.funder);
|
177
|
value_original_id.push(resData.funder.trim());
|
178
|
}
|
179
|
}
|
180
|
value_names.push(value_name);
|
181
|
value_original_ids.push(value_original_id);
|
182
|
|
183
|
var filters: Filter[] =[];
|
184
|
for(i =0 ; i < filter_names.length;i++){
|
185
|
var values:Value[] = [];
|
186
|
for(var j =0 ; j < value_names[i].length;j++){
|
187
|
var value:Value = {name: value_names[i][j], id: value_original_ids[i][j], number:j, selected:false}
|
188
|
values.push(value);
|
189
|
}
|
190
|
var filter:Filter = {title: filter_names[i], filterId: filter_ids[i], originalFilterId: filter_original_ids[i], values : values, countSelectedValues:0, "filterOperator": 'or' };
|
191
|
filters.push(filter);
|
192
|
}
|
193
|
console.info(filters);
|
194
|
|
195
|
return filters;
|
196
|
}
|
197
|
*/
|
198
|
|
199
|
private handleError(message: string, error) {
|
200
|
console.error("Content Providers simple Search Page: "+message, error);
|
201
|
}
|
202
|
}
|