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