1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ViewChild, Output} from '@angular/core';
|
3
|
import { Location} from '@angular/common';
|
4
|
import {Router, ActivatedRoute} from '@angular/router';
|
5
|
import {Title, Meta} from '@angular/platform-browser';
|
6
|
|
7
|
import {Filter, Value} from './searchHelperClasses.class';
|
8
|
import {SearchFields} from '../../utils/properties/searchFields';
|
9
|
import {SearchCustomFilter, SearchUtilsClass} from './searchUtils.class';
|
10
|
import {DOI, StringUtils} from '../../utils/string-utils.class';
|
11
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
12
|
import {ModalLoading} from '../../utils/modal/loading.component';
|
13
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
14
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
15
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
16
|
import { SEOService } from '../../sharedComponents/SEO/SEO.service';
|
17
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
18
|
import {ZenodoInformationClass} from "../../deposit/utils/zenodoInformation.class";
|
19
|
import {HelperService} from "../../utils/helper/helper.service";
|
20
|
|
21
|
@Component({
|
22
|
selector: 'search-page',
|
23
|
templateUrl: 'searchPage.component.html'
|
24
|
|
25
|
})
|
26
|
export class SearchPageComponent {
|
27
|
@Input() piwikSiteId = null;
|
28
|
@Input() pageTitle = "";
|
29
|
@Input() formPlaceholderText = "Type Keywords...";
|
30
|
@Input() results = [];
|
31
|
@Input() filters = [];
|
32
|
@Input() type:string = "";
|
33
|
@Input() entityType: string = "";
|
34
|
@Input() usedBy: string = "search";
|
35
|
@Input() showMoreFilterValuesInline: boolean = false;
|
36
|
@Input() filterValuesNum: number = 5;
|
37
|
@Input() public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
|
38
|
@Input() searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
39
|
@Input() baseUrl:string = '';
|
40
|
@Input() showResultCount:boolean = true;
|
41
|
@Input() showRefine:boolean = true;
|
42
|
@Input() refineFields = [];
|
43
|
@Input() csvParams: string;
|
44
|
@Input() csvPath: string;
|
45
|
@Input() advancedSearchLink: string = "";
|
46
|
@Input() advancedSearchParameters;
|
47
|
@Input() tableViewLink: string;
|
48
|
@Input() disableForms: boolean = false;
|
49
|
@Input() loadPaging: boolean = true;
|
50
|
@Input() oldTotalResults: number = 0;
|
51
|
@Input() tableView: boolean = false;
|
52
|
@Input() searchFormClass: string = "searchForm";
|
53
|
@Input() openaireLink: string;
|
54
|
@Input() customFilter:SearchCustomFilter= null;
|
55
|
@Input() sort: boolean = false;
|
56
|
@Input() mapUrl: string = "";
|
57
|
@Input() mapTooltipType: string ="content providers";
|
58
|
@Input() newQueryButton: boolean = true;
|
59
|
@Input() lastIndex: boolean = true;
|
60
|
@Input() hasPrefix: boolean = true;
|
61
|
@Input() showType = false;
|
62
|
//@Input() sortBy: string = "";
|
63
|
@ViewChild (ModalLoading) loading : ModalLoading ;
|
64
|
public fieldIdsMap;//: { [key:string]:{ name:string, operator:string, type:string, indexField:string, equalityOperator:string }};
|
65
|
@Input() keywordFields = [];
|
66
|
private searchFieldsHelper:SearchFields = new SearchFields();
|
67
|
private queryParameters: Map<string, string> = new Map<string,string>();
|
68
|
private baseURLWithParameters:string = '';
|
69
|
private sub: any; piwiksub: any;
|
70
|
// public countFilters= 0;
|
71
|
public parameterNames:string[] =[];
|
72
|
public parameterValues:string[] =[];
|
73
|
public showUnknownFilters:boolean = false; // when a filter exists in query but has no results, so no filters returned from the query
|
74
|
//@ViewChild (SearchFilterModalComponent) searchFilterModal : SearchFilterModalComponent ;
|
75
|
// public currentFilter: Filter;
|
76
|
public csvLimit: number = 0;
|
77
|
public pagingLimit: number = 0;
|
78
|
public resultsPerPage: number = 10;
|
79
|
public isPiwikEnabled;
|
80
|
public pageContents = null;
|
81
|
public divContents = null;
|
82
|
properties:EnvProperties;
|
83
|
public routerHelper:RouterHelper = new RouterHelper();
|
84
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
85
|
|
86
|
constructor (private route: ActivatedRoute,
|
87
|
private location: Location,
|
88
|
private _meta: Meta,
|
89
|
private _title: Title,
|
90
|
private _piwikService:PiwikService,
|
91
|
private router: Router,
|
92
|
private seoService: SEOService,
|
93
|
private helper: HelperService) {
|
94
|
}
|
95
|
|
96
|
ngOnInit() {
|
97
|
this.route.data
|
98
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
99
|
this.properties = data.envSpecific;
|
100
|
//this.getDivContents();
|
101
|
this.getPageContents();
|
102
|
this.pagingLimit = data.envSpecific.pagingLimit;
|
103
|
HelperFunctions.scroll();
|
104
|
this.csvLimit = data.envSpecific.csvLimit;
|
105
|
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
|
106
|
if(typeof window !== 'undefined') {
|
107
|
this.updateUrl(data.envSpecific.baseLink+location.pathname);
|
108
|
}
|
109
|
if(typeof document !== 'undefined' && this.isPiwikEnabled){
|
110
|
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
|
111
|
}
|
112
|
});
|
113
|
|
114
|
// this.updateBaseUrlWithParameters(this.filters);
|
115
|
this.updateTitle(this.pageTitle);
|
116
|
var description = "Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle;
|
117
|
this.updateDescription(description);
|
118
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this.router.url,false);
|
119
|
}
|
120
|
|
121
|
private getPageContents() {
|
122
|
this.helper.getPageHelpContents(this.properties, (this.customFilter)?this.customFilter.valueId:null, this.router.url).subscribe(contents => {
|
123
|
|
124
|
this.pageContents = contents;
|
125
|
})
|
126
|
}
|
127
|
|
128
|
private getDivContents() {
|
129
|
this.helper.getDivHelpContents(this.properties, (this.customFilter)?this.customFilter.valueId:null, this.router.url).subscribe(contents => {
|
130
|
this.divContents = contents;
|
131
|
})
|
132
|
}
|
133
|
|
134
|
ngOnDestroy() {
|
135
|
if(this.piwiksub){
|
136
|
this.piwiksub.unsubscribe();
|
137
|
}
|
138
|
}
|
139
|
|
140
|
|
141
|
updateDescription(description:string) {
|
142
|
this._meta.updateTag({content:description},"name='description'");
|
143
|
this._meta.updateTag({content:description},"property='og:description'");
|
144
|
}
|
145
|
|
146
|
updateTitle(title:string) {
|
147
|
let _title: string;
|
148
|
if(this.hasPrefix && !this.customFilter) {
|
149
|
let _prefix ="OpenAIRE | ";
|
150
|
_title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
|
151
|
} else {
|
152
|
_title = ((title.length > 50) ? title.substring(0, 50) : title);
|
153
|
}
|
154
|
this._title.setTitle(_title);
|
155
|
this._meta.updateTag({content:_title},"property='og:title'");
|
156
|
}
|
157
|
|
158
|
updateUrl(url:string) {
|
159
|
this._meta.updateTag({content:url},"property='og:url'");
|
160
|
}
|
161
|
|
162
|
public getQueryParamsFromUrl(params) {
|
163
|
this.queryParameters = new Map<string,string>();
|
164
|
for(let i=0; i< this.refineFields.length ; i++) {
|
165
|
let filterId = this.refineFields[i];
|
166
|
if (params[filterId] != undefined) {
|
167
|
this.queryParameters.set(filterId, StringUtils.URIDecode(params[filterId]));
|
168
|
}
|
169
|
}
|
170
|
return this.queryParameters;
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* Create Search API query based on the page URL parameters
|
175
|
* @param params page URL parameters
|
176
|
*/
|
177
|
public getQueryParametersFromUrl(params){ // called by ngOnInit function of search find pages
|
178
|
// var parameters = "";
|
179
|
var allFqs = "";
|
180
|
|
181
|
this.queryParameters = new Map<string,string>();
|
182
|
for(var i=0; i< this.refineFields.length ; i++){
|
183
|
var filterId = this.refineFields[i];
|
184
|
|
185
|
if(params[filterId] != undefined) {
|
186
|
this.queryParameters.set(filterId, StringUtils.URIDecode(params[filterId]));
|
187
|
let values = (StringUtils.URIDecode(this.queryParameters.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
|
188
|
var countvalues = 0;
|
189
|
var fq = "";
|
190
|
let filterOp: string = this.searchFieldsHelper.getFieldOperator(filterId);
|
191
|
console.info(filterId, filterOp);
|
192
|
for(let value of values) {
|
193
|
countvalues++;
|
194
|
var paramId = this.fieldIdsMap[filterId].param;
|
195
|
// parameters+='&' + paramId+ '='+ value;//+"&" + this.fieldIdsMap[paramId].operator + "="+((countvalues == 1)?"and":"or");
|
196
|
fq+=(fq.length > 0 ? " " + filterOp + " ":"" ) + filterId +" exact " +(value);
|
197
|
}
|
198
|
if(countvalues > 0){
|
199
|
fq="&fq="+StringUtils.URIEncode(fq);
|
200
|
}
|
201
|
allFqs += fq;
|
202
|
}
|
203
|
}
|
204
|
if(this.customFilter){
|
205
|
allFqs+= "&fq="+StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId )));
|
206
|
}
|
207
|
var keyword = params['keyword'];
|
208
|
var doiQuery = "";
|
209
|
var keywordQuery = "";
|
210
|
if((keyword && keyword.length > 0)){
|
211
|
if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
|
212
|
var DOIs:string[] = DOI.getDOIsFromString(keyword);
|
213
|
var doisParams = "";
|
214
|
|
215
|
for(var i =0 ;i < DOIs.length; i++){
|
216
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
217
|
}
|
218
|
if(doisParams.length > 0){
|
219
|
doiQuery += "&"+doisParams;
|
220
|
}else {
|
221
|
keywordQuery += "&q="+StringUtils.URIEncode(keyword);
|
222
|
}
|
223
|
}else{
|
224
|
if(this.usedBy == "deposit") {
|
225
|
if(this.keywordFields.length > 0) {
|
226
|
keywordQuery = "&fq=";
|
227
|
}
|
228
|
|
229
|
for(let i=0; i< this.keywordFields.length ; i++) {
|
230
|
if(i > 0) {
|
231
|
keywordQuery += " or ";
|
232
|
}
|
233
|
let field = this.keywordFields[i];
|
234
|
//keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(keyword);
|
235
|
keywordQuery += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(keyword));
|
236
|
}
|
237
|
} else {
|
238
|
keywordQuery += "&q=" + StringUtils.URIEncode(keyword);
|
239
|
}
|
240
|
|
241
|
}
|
242
|
}
|
243
|
return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs;
|
244
|
}
|
245
|
public getIndexQueryParametersFromUrl(params){ // called by ngOnInit function of search pages that request 'resources'
|
246
|
// var parameters = "";
|
247
|
var allFqs = "";
|
248
|
|
249
|
for(var i=0; i< this.refineFields.length ; i++){
|
250
|
var filterId = this.refineFields[i];
|
251
|
var fq = "";
|
252
|
if(params[filterId] != undefined) {
|
253
|
this.queryParameters.set(filterId,decodeURIComponent(params[filterId]));
|
254
|
let values = (decodeURIComponent(this.queryParameters.get(filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
|
255
|
var countvalues = 0;
|
256
|
let filterOp: string = this.searchFieldsHelper.getFieldOperator(filterId);
|
257
|
console.info(filterId, filterOp);
|
258
|
for(let value of values) {
|
259
|
countvalues++;
|
260
|
// parameters+= ((countvalues == 1)?" and (":" or ")+ filterId+ '='+ value;
|
261
|
fq+=(fq.length > 0 ? " " + filterOp + " ":"" ) + filterId + " exact " + value;//StringUtils.quote(value);
|
262
|
}
|
263
|
// parameters+= " ) ";
|
264
|
if(countvalues > 0){
|
265
|
fq="&fq="+StringUtils.URIEncode(fq);
|
266
|
}
|
267
|
allFqs += fq;
|
268
|
}
|
269
|
|
270
|
}
|
271
|
var keyword = params['keyword'];
|
272
|
var doiQuery = "";
|
273
|
var keywordQuery = "";
|
274
|
if((keyword && keyword.length > 0)){
|
275
|
if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
|
276
|
var DOIs:string[] = DOI.getDOIsFromString(keyword);
|
277
|
var doisParams = "";
|
278
|
|
279
|
for(var i =0 ;i < DOIs.length; i++){
|
280
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
281
|
}
|
282
|
if(doisParams.length > 0){
|
283
|
doiQuery += "&"+doisParams;
|
284
|
}
|
285
|
}else{
|
286
|
keywordQuery += "and ("+StringUtils.quote(StringUtils.URIEncode(keyword)) +")";
|
287
|
|
288
|
}
|
289
|
}
|
290
|
return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs;
|
291
|
|
292
|
}
|
293
|
/*
|
294
|
* Mark as check the new filters that are selected, when you get them from search
|
295
|
*/
|
296
|
public checkSelectedFilters(filters:Filter[]){
|
297
|
this.filters = filters;
|
298
|
for(var i=0; i< filters.length ; i++){
|
299
|
var filter:Filter = filters[i];
|
300
|
filter.countSelectedValues = 0;
|
301
|
if(this.queryParameters.get(filter.filterId) != undefined) {
|
302
|
let values = (decodeURIComponent(this.queryParameters.get(filter.filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
|
303
|
for(let filterValue of filter.values) {
|
304
|
if(values.indexOf(StringUtils.quote(filterValue.id)) > -1) {
|
305
|
filterValue.selected = true;
|
306
|
filter.countSelectedValues++;
|
307
|
}else{
|
308
|
filterValue.selected = false;
|
309
|
|
310
|
}
|
311
|
}
|
312
|
}else{
|
313
|
for(let filterValue of filter.values) {
|
314
|
filterValue.selected = false;
|
315
|
}
|
316
|
}
|
317
|
}
|
318
|
this.filterFilterValues(this.filters);
|
319
|
return filters;
|
320
|
}
|
321
|
/*
|
322
|
* For Funder filters - if funder selected
|
323
|
*/
|
324
|
public filterFilterValues(filters:Filter[]){
|
325
|
var funders = [];
|
326
|
var funder_prefix = [];
|
327
|
for(var i=0; i< filters.length ; i++){
|
328
|
|
329
|
var filter:Filter = filters[i];
|
330
|
// console.log(filter.filterId);
|
331
|
if(filter.filterId.indexOf("funder")!=-1 && this.queryParameters.get(filter.filterId) != undefined) {
|
332
|
let funders = (decodeURIComponent(this.queryParameters.get(filter.filterId))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
|
333
|
for(let funder of funders) {
|
334
|
funder_prefix.push(StringUtils.unquote(funder).split("____")[0]);
|
335
|
}
|
336
|
// console.log(funder_prefix );
|
337
|
}else if(filter.filterId.indexOf("funding")!=-1){
|
338
|
// console.log(" funding: "+filter.filterId );
|
339
|
var filteredValues = []
|
340
|
for(let filterValue of filter.values) {
|
341
|
var value_prefix = filterValue.id.split("____")[0];
|
342
|
// console.log("Value prefix: "+value_prefix );
|
343
|
if(funder_prefix.indexOf(value_prefix)!=-1){
|
344
|
// console.log("here" + value_prefix);
|
345
|
filteredValues.push(filterValue);
|
346
|
}
|
347
|
|
348
|
}
|
349
|
if(filteredValues.length > 0){
|
350
|
filter.values = filteredValues;
|
351
|
}
|
352
|
}
|
353
|
|
354
|
}
|
355
|
|
356
|
return filters;
|
357
|
}
|
358
|
/*
|
359
|
* Update the url with proper parameters. This is used as base url in Paging Component
|
360
|
*/
|
361
|
public updateBaseUrlWithParameters(filters:Filter[]){
|
362
|
this.baseURLWithParameters = this.baseUrl + this.createUrlParameters(filters,false);
|
363
|
|
364
|
}
|
365
|
|
366
|
/**
|
367
|
* Get The filters and create page URL parameters
|
368
|
* @param filters
|
369
|
* @param includePage
|
370
|
*/
|
371
|
private createUrlParameters(filters:Filter[], includePage:boolean){
|
372
|
var allLimits="";//location.search.slice(1);
|
373
|
this.queryParameters = new Map<string,string>();
|
374
|
this.parameterNames.splice(0,this.parameterNames.length);
|
375
|
this.parameterValues.splice(0,this.parameterValues.length);
|
376
|
|
377
|
for (let filter of filters){
|
378
|
var filterLimits="";
|
379
|
if(filter.countSelectedValues > 0 ){
|
380
|
for (let value of filter.values){
|
381
|
if(value.selected == true){
|
382
|
filterLimits+=((filterLimits.length == 0)?'':',') +'"'+ (value.id)+'"';
|
383
|
}
|
384
|
}
|
385
|
this.queryParameters.set(filter.filterId,filterLimits);
|
386
|
if(filterLimits.length > 0){
|
387
|
this.parameterNames.push(filter.filterId);
|
388
|
this.parameterValues.push(filterLimits);
|
389
|
}
|
390
|
allLimits+=(allLimits.length==0?"?":"&")+((filterLimits.length == 0 )?'':filter.filterId + '='+ filterLimits) ;
|
391
|
}
|
392
|
}
|
393
|
if(this.searchUtils.keyword.length > 0 ){
|
394
|
allLimits+=(allLimits.length==0?"?":"&")+'keyword=' + this.searchUtils.keyword;
|
395
|
this.parameterNames.push("keyword");
|
396
|
this.parameterValues.push(this.searchUtils.keyword);
|
397
|
//this.parameterValues.push(StringUtils.quote(this.searchUtils.keyword));
|
398
|
}
|
399
|
if(this.searchUtils.page != 1 && includePage){
|
400
|
allLimits+=((allLimits.length == 0)?'?':'&') + 'page=' + this.searchUtils.page;
|
401
|
}
|
402
|
if(this.searchUtils.size != this.resultsPerPage) {
|
403
|
allLimits+=((allLimits.length == 0)?'?':'&') + 'size=' + this.searchUtils.size;
|
404
|
this.parameterNames.push("size");
|
405
|
this.parameterValues.push(""+this.searchUtils.size);
|
406
|
}
|
407
|
if(this.sort && this.searchUtils.sortBy) {
|
408
|
allLimits+=((allLimits.length == 0)?'?':'&') + 'sortBy=' + this.searchUtils.sortBy;
|
409
|
this.parameterNames.push("sortBy");
|
410
|
this.parameterValues.push(this.searchUtils.sortBy);
|
411
|
} /*else {
|
412
|
let index: number = this.parameterNames.findIndex(function(element) {
|
413
|
return element == "sortBy";
|
414
|
});
|
415
|
console.info("index of sortby: "+index);
|
416
|
if(index >= 0) {
|
417
|
console.info("------remove sortBy------");
|
418
|
this.parameterNames.splice(index, 1);
|
419
|
this.parameterValues.splice(index, 1);
|
420
|
}
|
421
|
}*/
|
422
|
|
423
|
return allLimits;
|
424
|
}
|
425
|
/*
|
426
|
*
|
427
|
*/
|
428
|
private createSearchQueryParameters(filters:Filter[]){ // called by goTo, result emited to and used by search find pages
|
429
|
var allFqs = "";
|
430
|
for (let filter of filters){
|
431
|
if(filter.countSelectedValues > 0 ){
|
432
|
var fq = "";
|
433
|
var count_selected=0;
|
434
|
for (let value of filter.values){
|
435
|
if(value.selected == true){
|
436
|
count_selected++;
|
437
|
fq+=(fq.length > 0 ? " " + filter.filterOperator + " ":"" ) + filter.filterId + " exact " + StringUtils.quote((value.id));
|
438
|
}
|
439
|
}
|
440
|
|
441
|
fq="&fq="+StringUtils.URIEncode(fq);
|
442
|
allFqs += fq;
|
443
|
}
|
444
|
}
|
445
|
|
446
|
var doiQuery = "";
|
447
|
var keywordQuery = "";
|
448
|
if((this.searchUtils.keyword && this.searchUtils.keyword.length > 0)){
|
449
|
if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
|
450
|
var DOIs:string[] = DOI.getDOIsFromString(this.searchUtils.keyword);
|
451
|
var doisParams = "";
|
452
|
|
453
|
for(var i =0 ;i < DOIs.length; i++){
|
454
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
455
|
}
|
456
|
if(doisParams.length > 0){
|
457
|
doiQuery += "&"+doisParams;
|
458
|
}else{
|
459
|
keywordQuery += "&q="+StringUtils.URIEncode(this.searchUtils.keyword);
|
460
|
}
|
461
|
}else{
|
462
|
if(this.usedBy == "deposit") {
|
463
|
if(this.keywordFields.length > 0) {
|
464
|
keywordQuery = "&fq=";
|
465
|
}
|
466
|
|
467
|
for(let i=0; i< this.keywordFields.length ; i++) {
|
468
|
if(i > 0) {
|
469
|
keywordQuery += " or ";
|
470
|
}
|
471
|
let field = this.keywordFields[i];
|
472
|
//keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(this.searchUtils.keyword);
|
473
|
keywordQuery += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(this.searchUtils.keyword));
|
474
|
}
|
475
|
} else {
|
476
|
keywordQuery += "&q=" + StringUtils.URIEncode(this.searchUtils.keyword);
|
477
|
}
|
478
|
}
|
479
|
}
|
480
|
return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs;
|
481
|
|
482
|
}
|
483
|
private createIndexQueryParameters(filters:Filter[]){ // called by goTo, result emited to and used by search pages that request 'resources'
|
484
|
var allFqs = "";
|
485
|
for (let filter of filters){
|
486
|
if(filter.countSelectedValues > 0){
|
487
|
var count_selected=0;
|
488
|
var fq = "";
|
489
|
for (let value of filter.values){
|
490
|
if(value.selected == true){
|
491
|
count_selected++;
|
492
|
fq+=(fq.length > 0 ? " " + filter.filterOperator + " ":"" ) + filter.filterId + " exact " + (StringUtils.quote(value.id));
|
493
|
}
|
494
|
}
|
495
|
if(count_selected > 0){
|
496
|
fq="&fq="+StringUtils.URIEncode(fq);
|
497
|
allFqs += fq;
|
498
|
}
|
499
|
}
|
500
|
}
|
501
|
var doiQuery = "";
|
502
|
var keywordQuery = "";
|
503
|
if((this.searchUtils.keyword && this.searchUtils.keyword.length > 0)){
|
504
|
if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
|
505
|
var DOIs:string[] = DOI.getDOIsFromString(this.searchUtils.keyword);
|
506
|
var doisParams = "";
|
507
|
for(var i =0 ;i < DOIs.length; i++){
|
508
|
doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
509
|
}
|
510
|
if(doisParams.length > 0){
|
511
|
doiQuery += "&"+doisParams;
|
512
|
}
|
513
|
}else{
|
514
|
keywordQuery += " and ("+StringUtils.quote(StringUtils.URIEncode(this.searchUtils.keyword)) +")"
|
515
|
|
516
|
}
|
517
|
}
|
518
|
return (doiQuery.length > 0 ? doiQuery:keywordQuery) + allFqs;
|
519
|
|
520
|
}
|
521
|
public countFilters():number{
|
522
|
var filters=0;
|
523
|
this.showUnknownFilters = false;
|
524
|
for (let filter of this.filters){
|
525
|
if(filter.countSelectedValues > 0){
|
526
|
filters+=filter.countSelectedValues;
|
527
|
}
|
528
|
}
|
529
|
if(this.searchUtils.keyword.length > 0 ){
|
530
|
filters++;
|
531
|
}
|
532
|
var errorCodes:ErrorCodes = new ErrorCodes();
|
533
|
if(this.queryParameters.keys() && this.searchUtils.totalResults == 0 && this.searchUtils.status !=errorCodes.LOADING ){
|
534
|
if(this.newQueryButton) {
|
535
|
this.showUnknownFilters = true;
|
536
|
}
|
537
|
}
|
538
|
return filters;
|
539
|
}
|
540
|
private clearKeywords(){
|
541
|
if(this.searchUtils.keyword.length > 0 ){
|
542
|
this.searchUtils.keyword ='';
|
543
|
}
|
544
|
this.goTo(1);
|
545
|
}
|
546
|
private clearFilters(){
|
547
|
for (var i =0 ; i < this.filters.length; i++){
|
548
|
for (var j=0; j < this.filters[i].countSelectedValues; j++){
|
549
|
if(this.filters[i].values[j].selected){
|
550
|
this.filters[i].values[j].selected = false;
|
551
|
}
|
552
|
this.filters[i].countSelectedValues = 0;
|
553
|
}
|
554
|
}
|
555
|
this.clearKeywords();
|
556
|
|
557
|
}
|
558
|
private removeFilter(value:Value,filter:Filter){
|
559
|
filter.countSelectedValues--;
|
560
|
if(value.selected == true){
|
561
|
value.selected = false;
|
562
|
}
|
563
|
this.goTo(1);
|
564
|
|
565
|
}
|
566
|
goTo(page:number = 1){
|
567
|
this.searchUtils.page = page;
|
568
|
this.createUrlParameters(this.filters,true);
|
569
|
this.router.navigate( [this.baseUrl], { queryParams: this.routerHelper.createQueryParams(this.parameterNames, this.parameterValues) } );
|
570
|
|
571
|
/* Code For Piwik*/
|
572
|
if (typeof localStorage !== 'undefined') {
|
573
|
localStorage.setItem('previousRoute', this.router.url);
|
574
|
}
|
575
|
if(this.isPiwikEnabled && (typeof document !== 'undefined')){
|
576
|
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
|
577
|
}
|
578
|
HelperFunctions.scroll();
|
579
|
}
|
580
|
filterChanged($event){
|
581
|
this.goTo(1);
|
582
|
}
|
583
|
keywordChanged($event) {
|
584
|
this.searchUtils.keyword = $event.value;
|
585
|
this.goTo(1);
|
586
|
}
|
587
|
|
588
|
sizeChanged($event) {
|
589
|
this.searchUtils.size = $event.value;
|
590
|
this.goTo(1);
|
591
|
}
|
592
|
|
593
|
sortByChanged($event) {
|
594
|
this.searchUtils.sortBy = $event.value;
|
595
|
this.goTo(1);
|
596
|
}
|
597
|
|
598
|
/*
|
599
|
* Get A sub-array of this.refineFields array, which contains the ids of the selected filters
|
600
|
*/
|
601
|
public getSelectedFilters():string[] {
|
602
|
var selected:string[] = [];
|
603
|
for(var i=0; i < this.filters.length; i++){
|
604
|
var filter:Filter = this.filters[i];
|
605
|
if(filter.countSelectedValues > 0){
|
606
|
selected.push(filter.filterId);
|
607
|
}
|
608
|
}
|
609
|
return selected;
|
610
|
}
|
611
|
/*
|
612
|
* Get A sub-array of this.refineFields array, which contains the ids of the selected parameters
|
613
|
*/
|
614
|
private getSelectedParameters():string[] {
|
615
|
var selected:string[] = [];
|
616
|
var params:string[] = Object.keys(this.queryParameters);
|
617
|
|
618
|
for(var i=0; i < this.refineFields.length; i++){
|
619
|
if(this.queryParameters.get(this.refineFields[i])!= undefined ){
|
620
|
selected.push(this.refineFields[i]);
|
621
|
}
|
622
|
}
|
623
|
return selected;
|
624
|
}
|
625
|
/*
|
626
|
* Get A sub-array of this.refineFields array, which hides hidden fields (e.g Funding level 0,1,2,..), and contains those that depend on another fields (e.g Funding level 0 if Funder is selected )
|
627
|
*/
|
628
|
public getFields():string[] {
|
629
|
var selected_filters:string[] = this.getSelectedFilters();
|
630
|
if(selected_filters.length == 0){
|
631
|
selected_filters = this.getSelectedParameters();
|
632
|
}
|
633
|
var fields:string[] = [];
|
634
|
for(var i =0 ; i < this.refineFields.length;i++){
|
635
|
var dependentTo = this.searchFieldsHelper.DEPENDENT_FIELDS[this.refineFields[i]];
|
636
|
|
637
|
//if filter is not marked as hidden OR it is hidden but it is dependent to a field that it IS selected
|
638
|
if(this.searchFieldsHelper.HIDDEN_FIELDS.indexOf(this.refineFields[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) || (selected_filters.indexOf(this.refineFields[i]) != -1) ){
|
639
|
fields.push(this.refineFields[i]);
|
640
|
}
|
641
|
}
|
642
|
return fields;
|
643
|
}
|
644
|
/*
|
645
|
* Get a query string of all fields, that want to get from search (e.g. &fields=funderid&fields=projectstartyear&...))
|
646
|
*/
|
647
|
public getRefineFieldsQuery():string{
|
648
|
|
649
|
var fields:string[] = this.getFields();
|
650
|
var fieldsStr = ""
|
651
|
for(var i =0 ; i < fields.length ;i++){
|
652
|
fieldsStr+="&fields="+fields[i];
|
653
|
}
|
654
|
return "&refine=true"+fieldsStr;
|
655
|
}
|
656
|
|
657
|
// for loading
|
658
|
public openLoading(){
|
659
|
if(this.loading){
|
660
|
this.loading.open();
|
661
|
}
|
662
|
}
|
663
|
public closeLoading(){
|
664
|
if(this.loading){
|
665
|
this.loading.close();
|
666
|
}
|
667
|
}
|
668
|
getSelectedValues(filter):any{
|
669
|
var selected = [];
|
670
|
if(filter.countSelectedValues >0){
|
671
|
for (var i=0; i < filter.values.length; i++){
|
672
|
if(filter.values[i].selected){
|
673
|
selected.push(filter.values[i]);
|
674
|
}
|
675
|
}
|
676
|
}
|
677
|
return selected;
|
678
|
|
679
|
}
|
680
|
}
|