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