1 |
58326
|
konstantin
|
import {Component, ElementRef, Input, Output, ViewChild} from '@angular/core';
|
2 |
56649
|
k.triantaf
|
import {Location} from '@angular/common';
|
3 |
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
4 |
|
|
import {Meta, Title} from '@angular/platform-browser';
|
5 |
50169
|
argiro.kok
|
|
6 |
58045
|
argiro.kok
|
import {AdvancedField, Filter, Value} from './searchHelperClasses.class';
|
7 |
56059
|
argiro.kok
|
import {SearchCustomFilter, SearchUtilsClass} from './searchUtils.class';
|
8 |
56649
|
k.triantaf
|
import {ModalLoading} from '../../utils/modal/loading.component';
|
9 |
58391
|
argiro.kok
|
import {Dates, Identifier, StringUtils} from '../../utils/string-utils.class';
|
10 |
56649
|
k.triantaf
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
11 |
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
12 |
51835
|
sofia.balt
|
|
13 |
56649
|
k.triantaf
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
14 |
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
15 |
|
|
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
|
16 |
|
|
import {HelperService} from "../../utils/helper/helper.service";
|
17 |
58045
|
argiro.kok
|
import {SearchFields} from "../../utils/properties/searchFields";
|
18 |
58052
|
argiro.kok
|
import {RefineResultsUtils} from "../../services/servicesUtils/refineResults.class";
|
19 |
58105
|
konstantin
|
import {RangeFilter} from "../../utils/rangeFilter/rangeFilterHelperClasses.class";
|
20 |
58244
|
argiro.kok
|
import {ZenodoInformationClass} from "../../deposit/utils/zenodoInformation.class";
|
21 |
59180
|
konstantin
|
import {Breadcrumb} from "../../utils/breadcrumbs/breadcrumbs.component";
|
22 |
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
23 |
|
|
import {properties} from "../../../../environments/environment";
|
24 |
59303
|
konstantin
|
import {AlertModal} from "../../utils/modal/alert";
|
25 |
51835
|
sofia.balt
|
|
26 |
58326
|
konstantin
|
declare var UIkit: any;
|
27 |
|
|
|
28 |
50169
|
argiro.kok
|
@Component({
|
29 |
58045
|
argiro.kok
|
selector: 'new-search-page',
|
30 |
|
|
templateUrl: 'newSearchPage.component.html'
|
31 |
50169
|
argiro.kok
|
})
|
32 |
58045
|
argiro.kok
|
export class NewSearchPageComponent {
|
33 |
58326
|
konstantin
|
@ViewChild('offcanvas_element') offcanvasElement: ElementRef;
|
34 |
51746
|
argiro.kok
|
@Input() piwikSiteId = null;
|
35 |
56840
|
konstantin
|
@Input() hasPrefix: boolean = true;
|
36 |
50169
|
argiro.kok
|
@Input() pageTitle = "";
|
37 |
|
|
@Input() results = [];
|
38 |
|
|
@Input() type;
|
39 |
|
|
@Input() entityType;
|
40 |
56649
|
k.triantaf
|
@Input() searchUtils: SearchUtilsClass = new SearchUtilsClass();
|
41 |
|
|
@Input() fieldIds: string[];
|
42 |
50169
|
argiro.kok
|
@Input() fieldIdsMap;//:{ [key:string]:{ name:string, operator:string, type:string, indexField:string, equalityOperator:string }} ;
|
43 |
56649
|
k.triantaf
|
@Input() selectedFields: AdvancedField[];
|
44 |
|
|
@ViewChild(ModalLoading) loading: ModalLoading;
|
45 |
50169
|
argiro.kok
|
@Input() csvParams: string;
|
46 |
|
|
@Input() csvPath: string;
|
47 |
|
|
@Input() simpleSearchLink: string = "";
|
48 |
58045
|
argiro.kok
|
@Input() advancedSearchLink: string = "";
|
49 |
56649
|
k.triantaf
|
@Input() disableForms: boolean = false;
|
50 |
59180
|
konstantin
|
@Input() disableRefineForms: boolean = false;
|
51 |
50169
|
argiro.kok
|
@Input() loadPaging: boolean = true;
|
52 |
|
|
@Input() oldTotalResults: number = 0;
|
53 |
50586
|
argiro.kok
|
@Input() openaireLink: string;
|
54 |
58391
|
argiro.kok
|
@Input() customFilter: SearchCustomFilter;
|
55 |
59180
|
konstantin
|
@Input() sort: boolean = true;
|
56 |
|
|
@Input() sortedByChanged: string = "";
|
57 |
|
|
@Input() resultsPerPageChanged: number;
|
58 |
53353
|
argiro.kok
|
@Input() searchFormClass: string = "searchForm";
|
59 |
58045
|
argiro.kok
|
//From simple:
|
60 |
58105
|
konstantin
|
@Input() rangeFilters: RangeFilter[] = [];
|
61 |
|
|
@Input() rangeFields: string[][] = [];
|
62 |
58045
|
argiro.kok
|
@Input() refineFields = [];
|
63 |
59180
|
konstantin
|
@Input() filters:Filter[] = [];
|
64 |
58072
|
argiro.kok
|
selectedFilters: number = 0;
|
65 |
58105
|
konstantin
|
selectedRangeFilters: number = 0;
|
66 |
58045
|
argiro.kok
|
private searchFieldsHelper: SearchFields = new SearchFields();
|
67 |
|
|
@Input() newQueryButton: boolean = true;
|
68 |
|
|
public showUnknownFilters: boolean = false; // when a filter exists in query but has no results, so no filters returned from the query
|
69 |
58055
|
argiro.kok
|
URLCreatedFilters: Filter[] = [];
|
70 |
58105
|
konstantin
|
URLCreatedRangeFilters: RangeFilter[] = [];
|
71 |
58045
|
argiro.kok
|
@Input() showRefine: boolean = true;
|
72 |
|
|
@Input() tableViewLink: string;
|
73 |
|
|
@Input() usedBy: string = "search";
|
74 |
58244
|
argiro.kok
|
@Input() public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
|
75 |
|
|
@Input() showLastIndex: boolean = true;
|
76 |
58045
|
argiro.kok
|
@Input() showResultCount: boolean = true;
|
77 |
58105
|
konstantin
|
@Input() showMoreFilterValuesInline: boolean = true;
|
78 |
58132
|
konstantin
|
@Input() filterValuesNum: number = 6;
|
79 |
58045
|
argiro.kok
|
@Input() keywordFields = [];
|
80 |
|
|
@Input() simpleView: boolean = true;
|
81 |
|
|
@Input() formPlaceholderText = "Type Keywords...";
|
82 |
58115
|
argiro.kok
|
@Input() resultTypes = null;
|
83 |
59180
|
konstantin
|
resultTypeOptions = [{"id":"publication", "name":"Publications"},{"id":"dataset", "name":"Research data"},
|
84 |
|
|
{"id":"software", "name":"Software"},{"id":"other", "name":" Other research products"}];
|
85 |
|
|
selectedTypesNum = 0;
|
86 |
58115
|
argiro.kok
|
@Input() quickFilter: { filter: Filter, selected: boolean, filterId: string, value: string };
|
87 |
|
|
@Input() includeOnlyResultsAndFilter:boolean = false;
|
88 |
59180
|
konstantin
|
@Input() showBreadcrumb:boolean = false;
|
89 |
58268
|
konstantin
|
@Input() lastIndex: boolean = true;
|
90 |
59180
|
konstantin
|
public dashboard: boolean = properties.isDashboard;
|
91 |
58268
|
konstantin
|
|
92 |
50169
|
argiro.kok
|
piwiksub: any;
|
93 |
56649
|
k.triantaf
|
public parameterNames: string[] = [];
|
94 |
|
|
public parameterValues: string[] = [];
|
95 |
50169
|
argiro.kok
|
|
96 |
50586
|
argiro.kok
|
public csvLimit: number = 0;
|
97 |
|
|
public pagingLimit: number = 0;
|
98 |
|
|
public resultsPerPage: number = 0;
|
99 |
|
|
isPiwikEnabled = false;
|
100 |
56649
|
k.triantaf
|
properties: EnvProperties;
|
101 |
|
|
public pageContents = null;
|
102 |
|
|
public divContents = null;
|
103 |
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
104 |
|
|
public errorCodes: ErrorCodes = new ErrorCodes();
|
105 |
59180
|
konstantin
|
breadcrumbs:Breadcrumb[] = [];
|
106 |
53740
|
argiro.kok
|
url = null;
|
107 |
59180
|
konstantin
|
metaDescription = "";
|
108 |
59303
|
konstantin
|
@Input() basicMetaDescription = [];
|
109 |
|
|
|
110 |
58093
|
argiro.kok
|
@Input() entitiesSelection:boolean = true;
|
111 |
59303
|
konstantin
|
@Input() showSwitchSearchLink:boolean = true;
|
112 |
59180
|
konstantin
|
|
113 |
|
|
// on 1st load, do not show filters until results query returns.
|
114 |
|
|
public hideFilters: boolean = true;
|
115 |
|
|
|
116 |
|
|
//Dashboard
|
117 |
|
|
filterToggle = false;
|
118 |
|
|
customFilterEnabled:boolean = false;
|
119 |
59303
|
konstantin
|
//stickyform
|
120 |
|
|
@Input() stickyForm:boolean = false;
|
121 |
|
|
|
122 |
|
|
@ViewChild('removeCustomFilter') removeCustomFilter: AlertModal;
|
123 |
|
|
currentValueToRemove;
|
124 |
|
|
currentFilterToRemove;
|
125 |
|
|
isCustomFilterSelected:boolean = true;
|
126 |
56649
|
k.triantaf
|
constructor(private route: ActivatedRoute,
|
127 |
|
|
private location: Location,
|
128 |
|
|
private _meta: Meta,
|
129 |
|
|
private _title: Title,
|
130 |
|
|
private _piwikService: PiwikService,
|
131 |
|
|
private router: Router,
|
132 |
|
|
private seoService: SEOService,
|
133 |
|
|
private helper: HelperService) {
|
134 |
|
|
}
|
135 |
|
|
|
136 |
50169
|
argiro.kok
|
ngOnInit() {
|
137 |
50586
|
argiro.kok
|
this.route.data
|
138 |
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
139 |
|
|
this.properties = data.envSpecific;
|
140 |
56649
|
k.triantaf
|
//this.getDivContents();
|
141 |
|
|
this.getPageContents();
|
142 |
50586
|
argiro.kok
|
this.pagingLimit = data.envSpecific.pagingLimit;
|
143 |
56649
|
k.triantaf
|
this.resultsPerPage = data.envSpecific.resultsPerPage;
|
144 |
50586
|
argiro.kok
|
this.csvLimit = data.envSpecific.csvLimit;
|
145 |
|
|
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
|
146 |
59303
|
konstantin
|
this.updateUrl(data.envSpecific.baseLink + this.router.url);
|
147 |
59180
|
konstantin
|
this.url = data.envSpecific.baseLink + this.router.url;
|
148 |
59303
|
konstantin
|
if (typeof document !== 'undefined' && this.isPiwikEnabled && !this.includeOnlyResultsAndFilter) {
|
149 |
51746
|
argiro.kok
|
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
|
150 |
50586
|
argiro.kok
|
}
|
151 |
|
|
});
|
152 |
59180
|
konstantin
|
this.route.queryParams.subscribe(params => {
|
153 |
59303
|
konstantin
|
if (params['page'] && params['page'] != 1) {
|
154 |
59180
|
konstantin
|
HelperFunctions.scrollToId("searchForm");
|
155 |
|
|
}
|
156 |
|
|
this.customFilterEnabled = params['cf'] && params['cf'] == "true";
|
157 |
|
|
});
|
158 |
59303
|
konstantin
|
if (!this.includeOnlyResultsAndFilter) {
|
159 |
|
|
if(this.basicMetaDescription.length == 0 ){
|
160 |
|
|
if (this.entityType == "result") {
|
161 |
|
|
this.basicMetaDescription = ["Discover" + (this.properties.adminToolsCommunity == 'openaire'?"over 100 million of":"")+" research outcomes ", "categorized by research type, year range, funder, languages, community and content providers."];
|
162 |
|
|
} else if (this.entityType == "project") {
|
163 |
|
|
this.basicMetaDescription = ["Discover research projects and correlated research categorized by Funder and active year. ", "Statistics data about produced research outcomes per year available."];
|
164 |
|
|
} else if (this.entityType == "organization") {
|
165 |
|
|
this.basicMetaDescription = ["Discover worldwide research organizations from over 100 countries and correlated research. ", "Funding, content providers, research pubblications and research data available."];
|
166 |
|
|
}else{
|
167 |
|
|
this.basicMetaDescription.push(this.pageTitle)
|
168 |
|
|
}
|
169 |
|
|
}
|
170 |
|
|
this.metaDescription = this.basicMetaDescription.join(" ");
|
171 |
|
|
this.updateTitle(this.pageTitle);
|
172 |
|
|
this.updateDescription();
|
173 |
|
|
}
|
174 |
50586
|
argiro.kok
|
|
175 |
51835
|
sofia.balt
|
this.searchUtils.baseUrl = "/" + this.searchUtils.baseUrl;
|
176 |
56649
|
k.triantaf
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.router.url, false);
|
177 |
59180
|
konstantin
|
this.breadcrumbs.push({name: 'home', route: '/'});
|
178 |
|
|
if(this.simpleView) {
|
179 |
|
|
this.breadcrumbs.push( {name: "Search", route: null});
|
180 |
|
|
}else if(!this.simpleView && this.advancedSearchLink) {
|
181 |
|
|
this.breadcrumbs.push({name: "Advanced Search", route: null});
|
182 |
|
|
}
|
183 |
|
|
//console.log(this.filters)
|
184 |
50169
|
argiro.kok
|
}
|
185 |
|
|
|
186 |
56649
|
k.triantaf
|
private getPageContents() {
|
187 |
59180
|
konstantin
|
if((this.customFilter && this.customFilter.queryFieldName == "communityId") && this.properties.adminToolsCommunity !== "monitor") {
|
188 |
|
|
this.helper.getPageHelpContents(this.properties, (this.customFilter) ? this.customFilter.valueId : this.properties.adminToolsCommunity, this.router.url).subscribe(contents => {
|
189 |
|
|
this.pageContents = contents;
|
190 |
|
|
});
|
191 |
|
|
}
|
192 |
56649
|
k.triantaf
|
}
|
193 |
|
|
|
194 |
|
|
private getDivContents() {
|
195 |
59180
|
konstantin
|
if((this.customFilter && this.customFilter.queryFieldName == "communityId") && this.properties.adminToolsCommunity !== "monitor") {
|
196 |
|
|
this.helper.getDivHelpContents(this.properties, (this.customFilter) ? this.customFilter.valueId : this.properties.adminToolsCommunity, this.router.url).subscribe(contents => {
|
197 |
|
|
this.divContents = contents;
|
198 |
|
|
});
|
199 |
|
|
}
|
200 |
56649
|
k.triantaf
|
}
|
201 |
|
|
|
202 |
50169
|
argiro.kok
|
ngOnDestroy() {
|
203 |
56649
|
k.triantaf
|
if (this.piwiksub) {
|
204 |
51835
|
sofia.balt
|
this.piwiksub.unsubscribe();
|
205 |
|
|
}
|
206 |
50169
|
argiro.kok
|
}
|
207 |
56649
|
k.triantaf
|
|
208 |
59180
|
konstantin
|
updateDescription() {
|
209 |
59303
|
konstantin
|
// this.metaDescription2 = "";
|
210 |
|
|
/*if(this.resultTypes){
|
211 |
59180
|
konstantin
|
let array = [];
|
212 |
|
|
for(let type of this.resultTypeOptions){
|
213 |
|
|
if(this.resultTypes[type.id]== true){
|
214 |
|
|
array.push(type.name);
|
215 |
|
|
}
|
216 |
|
|
}
|
217 |
|
|
if(array.length == 0){
|
218 |
|
|
this.metaDescription += "research outcomes ";
|
219 |
|
|
}else{
|
220 |
|
|
this.metaDescription += array.join(", ") + " ";
|
221 |
|
|
}
|
222 |
|
|
}else{
|
223 |
|
|
this.metaDescription = this.pageTitle + " ";
|
224 |
59303
|
konstantin
|
}*/
|
225 |
59180
|
konstantin
|
let filterArray = [];
|
226 |
|
|
for(let filter of this.filters){
|
227 |
|
|
if(filter.countSelectedValues> 0){
|
228 |
|
|
for(let value of filter.values){
|
229 |
|
|
if(value.selected) {
|
230 |
|
|
filterArray.push(value.name);
|
231 |
|
|
}
|
232 |
|
|
}
|
233 |
|
|
}
|
234 |
|
|
}
|
235 |
|
|
for(let field of this.selectedFields){
|
236 |
|
|
if((field.type == "entity" || field.type == "refine") && field.valueLabel.length > 0 && filterArray.indexOf(field.valueLabel)==-1){
|
237 |
|
|
filterArray.push(field.valueLabel)
|
238 |
|
|
}else if(!(field.type == "entity" || field.type == "refine") && field.value.length > 0 && filterArray.indexOf(field.value)==-1) {
|
239 |
|
|
filterArray.push(field.value);
|
240 |
|
|
}
|
241 |
|
|
}
|
242 |
59303
|
konstantin
|
this.metaDescription= (filterArray.length > 0?( this.basicMetaDescription[0] + " Filtered by: " + filterArray.join(", ") + " ")
|
243 |
|
|
:this.basicMetaDescription.join(" "));
|
244 |
59180
|
konstantin
|
this._meta.updateTag({content: this.metaDescription}, "name='description'");
|
245 |
|
|
this._meta.updateTag({content: this.metaDescription}, "property='og:description'");
|
246 |
50169
|
argiro.kok
|
}
|
247 |
56649
|
k.triantaf
|
|
248 |
|
|
updateTitle(title: string) {
|
249 |
56840
|
konstantin
|
var _prefix = "";
|
250 |
58045
|
argiro.kok
|
if (this.hasPrefix) {
|
251 |
56840
|
konstantin
|
_prefix = "OpenAIRE | ";
|
252 |
|
|
}
|
253 |
56649
|
k.triantaf
|
var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
|
254 |
51835
|
sofia.balt
|
this._title.setTitle(_title);
|
255 |
56649
|
k.triantaf
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
256 |
50169
|
argiro.kok
|
}
|
257 |
56649
|
k.triantaf
|
|
258 |
|
|
updateUrl(url: string) {
|
259 |
|
|
this._meta.updateTag({content: url}, "property='og:url'");
|
260 |
50169
|
argiro.kok
|
}
|
261 |
|
|
|
262 |
58045
|
argiro.kok
|
|
263 |
|
|
clearFilters() {
|
264 |
|
|
for (var i = 0; i < this.filters.length; i++) {
|
265 |
|
|
for (var j = 0; j < this.filters[i].countSelectedValues; j++) {
|
266 |
|
|
if (this.filters[i].values[j].selected) {
|
267 |
|
|
this.filters[i].values[j].selected = false;
|
268 |
|
|
}
|
269 |
|
|
this.filters[i].countSelectedValues = 0;
|
270 |
59180
|
konstantin
|
this.filters[i].radioValue = "";
|
271 |
58045
|
argiro.kok
|
}
|
272 |
|
|
}
|
273 |
58052
|
argiro.kok
|
this.selectedFilters = 0;
|
274 |
58105
|
konstantin
|
for(let i = 0; i < this.rangeFilters.length; i++) {
|
275 |
|
|
this.rangeFilters[i].selectedFromValue = null;
|
276 |
|
|
this.rangeFilters[i].selectedToValue = null;
|
277 |
|
|
}
|
278 |
|
|
this.selectedRangeFilters = 0;
|
279 |
58072
|
argiro.kok
|
if (this.quickFilter) {
|
280 |
|
|
this.removeValueFromQuickFilter();
|
281 |
|
|
}
|
282 |
59180
|
konstantin
|
this.resultTypes = {};
|
283 |
|
|
for(let type of this.resultTypeOptions){
|
284 |
|
|
this.resultTypes[type.id]=false;
|
285 |
|
|
}
|
286 |
58045
|
argiro.kok
|
this.goTo(1);
|
287 |
|
|
// this.clearKeywords();
|
288 |
|
|
}
|
289 |
|
|
|
290 |
59180
|
konstantin
|
goTo(page: number = 1, scroll:boolean = true) {
|
291 |
58326
|
konstantin
|
if(this.offcanvasElement) {
|
292 |
|
|
UIkit.offcanvas(this.offcanvasElement.nativeElement).hide();
|
293 |
|
|
}
|
294 |
|
|
|
295 |
58045
|
argiro.kok
|
this.searchUtils.page = page;
|
296 |
58105
|
konstantin
|
this.buildPageURLParameters(this.filters, this.rangeFilters, true);
|
297 |
58045
|
argiro.kok
|
this.router.navigate([this.searchUtils.baseUrl], {queryParams: this.routerHelper.createQueryParams(this.parameterNames, this.parameterValues)});
|
298 |
59180
|
konstantin
|
if(scroll) {
|
299 |
|
|
HelperFunctions.scrollToId("searchForm");
|
300 |
|
|
}
|
301 |
58045
|
argiro.kok
|
/* Code For Piwik*/
|
302 |
|
|
if (typeof localStorage !== 'undefined') {
|
303 |
|
|
//console.log("In PreviousRouteRecorder : "+this.router.url );
|
304 |
|
|
localStorage.setItem('previousRoute', this.router.url);
|
305 |
|
|
}
|
306 |
|
|
if (this.isPiwikEnabled && (typeof document !== 'undefined')) {
|
307 |
|
|
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe();
|
308 |
|
|
}
|
309 |
|
|
/* End Piwik Code */
|
310 |
|
|
}
|
311 |
|
|
|
312 |
58072
|
argiro.kok
|
queryChanged() {
|
313 |
58045
|
argiro.kok
|
|
314 |
59180
|
konstantin
|
this.goTo(1, false);
|
315 |
58045
|
argiro.kok
|
}
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
sizeChanged($event) {
|
319 |
59180
|
konstantin
|
//this.searchUtils.size = $event.value;
|
320 |
|
|
this.resultsPerPageChanged = $event;
|
321 |
|
|
|
322 |
58045
|
argiro.kok
|
this.goTo(1);
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
sortByChanged($event) {
|
326 |
59180
|
konstantin
|
//this.searchUtils.sortBy = $event.value;
|
327 |
|
|
this.sortedByChanged = $event;
|
328 |
58045
|
argiro.kok
|
this.goTo(1);
|
329 |
|
|
}
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
getOperatorParameter(parameter: string): string {
|
333 |
|
|
for (let id of this.fieldIds) {
|
334 |
|
|
if (this.fieldIdsMap[id]["param"] == parameter) {
|
335 |
|
|
return this.fieldIdsMap[id]["operator"];
|
336 |
|
|
}
|
337 |
|
|
}
|
338 |
|
|
}
|
339 |
|
|
|
340 |
|
|
/*
|
341 |
|
|
* Get A sub-array of this.refineFields array, which contains the ids of the selected filters
|
342 |
|
|
*/
|
343 |
|
|
public getSelectedFilters(): string[] {
|
344 |
|
|
var selected: string[] = [];
|
345 |
59180
|
konstantin
|
var filters= (this.filters.length > 0)?this.filters:this.URLCreatedFilters;
|
346 |
|
|
for (var i = 0; i < filters.length; i++) {
|
347 |
|
|
var filter: Filter = filters[i];
|
348 |
58045
|
argiro.kok
|
if (filter.countSelectedValues > 0) {
|
349 |
|
|
selected.push(filter.filterId);
|
350 |
|
|
}
|
351 |
|
|
}
|
352 |
|
|
return selected;
|
353 |
|
|
}
|
354 |
|
|
|
355 |
|
|
/*
|
356 |
|
|
* Get A sub-array of this.refineFields array, which contains the ids of the selected parameters
|
357 |
|
|
*/
|
358 |
|
|
private getSelectedParameters(): string[] {
|
359 |
|
|
var selected: string[] = [];
|
360 |
|
|
for (var i = 0; i < this.refineFields.length; i++) {
|
361 |
58055
|
argiro.kok
|
if (this.parameterNames.indexOf(this.refineFields[i]) != -1) {
|
362 |
58045
|
argiro.kok
|
selected.push(this.refineFields[i]);
|
363 |
|
|
}
|
364 |
|
|
}
|
365 |
|
|
return selected;
|
366 |
|
|
}
|
367 |
|
|
|
368 |
|
|
/*
|
369 |
|
|
* 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 )
|
370 |
|
|
*/
|
371 |
|
|
public getFields(): string[] {
|
372 |
|
|
var selected_filters: string[] = this.getSelectedFilters();
|
373 |
|
|
if (selected_filters.length == 0) {
|
374 |
|
|
selected_filters = this.getSelectedParameters();
|
375 |
|
|
}
|
376 |
|
|
var fields: string[] = [];
|
377 |
|
|
for (var i = 0; i < this.refineFields.length; i++) {
|
378 |
|
|
var dependentTo = this.searchFieldsHelper.DEPENDENT_FIELDS[this.refineFields[i]];
|
379 |
|
|
|
380 |
|
|
//if filter is not marked as hidden OR it is hidden but it is dependent to a field that it IS selected
|
381 |
|
|
if (this.searchFieldsHelper.HIDDEN_FIELDS.indexOf(this.refineFields[i]) == -1 || (selected_filters.indexOf(dependentTo) != -1) || (selected_filters.indexOf(this.refineFields[i]) != -1)) {
|
382 |
|
|
fields.push(this.refineFields[i]);
|
383 |
|
|
}
|
384 |
|
|
}
|
385 |
|
|
return fields;
|
386 |
|
|
}
|
387 |
|
|
|
388 |
|
|
/*
|
389 |
|
|
* Get a query string of all fields, that want to get from search (e.g. &fields=funderid&fields=projectstartyear&...))
|
390 |
|
|
*/
|
391 |
|
|
public getRefineFieldsQuery(): string {
|
392 |
|
|
|
393 |
|
|
var fields: string[] = this.getFields();
|
394 |
|
|
var fieldsStr = ""
|
395 |
|
|
for (var i = 0; i < fields.length; i++) {
|
396 |
|
|
fieldsStr += "&fields=" + fields[i];
|
397 |
|
|
}
|
398 |
|
|
return "&refine=true" + fieldsStr;
|
399 |
|
|
}
|
400 |
|
|
|
401 |
|
|
|
402 |
|
|
/*
|
403 |
|
|
* Mark as check the new filters that are selected, when you get them from search
|
404 |
|
|
*/
|
405 |
|
|
public checkSelectedFilters(filters: Filter[]) {
|
406 |
|
|
this.filters = filters;
|
407 |
59303
|
konstantin
|
if(this.customFilter && !this.customFilter.isHiddenFilter) {
|
408 |
|
|
this.customFilter.selected = null;
|
409 |
|
|
}
|
410 |
58045
|
argiro.kok
|
for (var i = 0; i < filters.length; i++) {
|
411 |
|
|
var filter: Filter = filters[i];
|
412 |
|
|
filter.countSelectedValues = 0;
|
413 |
58055
|
argiro.kok
|
if (this.parameterNames.indexOf(filter.filterId) != -1) {
|
414 |
|
|
let values = (decodeURIComponent(this.parameterValues[this.parameterNames.indexOf(filter.filterId)])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
415 |
58045
|
argiro.kok
|
for (let filterValue of filter.values) {
|
416 |
|
|
if (values.indexOf(StringUtils.quote(filterValue.id)) > -1) {
|
417 |
|
|
filterValue.selected = true;
|
418 |
|
|
filter.countSelectedValues++;
|
419 |
|
|
} else {
|
420 |
|
|
filterValue.selected = false;
|
421 |
|
|
|
422 |
|
|
}
|
423 |
|
|
}
|
424 |
59303
|
konstantin
|
if(this.customFilter){
|
425 |
|
|
this.customFilter.selected = this.customFilter.queryFieldName == filter.filterId && values.indexOf(StringUtils.quote(this.customFilter.valueId)) != -1;
|
426 |
|
|
}
|
427 |
58073
|
argiro.kok
|
} else if (this.quickFilter && this.quickFilter.filterId == filter.filterId && this.quickFilter.selected) {
|
428 |
58072
|
argiro.kok
|
for (let filterValue of filter.values) {
|
429 |
|
|
if (filterValue.id == this.quickFilter.value) {
|
430 |
|
|
filterValue.selected = true;
|
431 |
|
|
filter.countSelectedValues++;
|
432 |
|
|
} else {
|
433 |
|
|
filterValue.selected = false;
|
434 |
|
|
}
|
435 |
|
|
}
|
436 |
58045
|
argiro.kok
|
} else {
|
437 |
|
|
for (let filterValue of filter.values) {
|
438 |
|
|
filterValue.selected = false;
|
439 |
|
|
}
|
440 |
|
|
}
|
441 |
58073
|
argiro.kok
|
if (this.quickFilter && filter.filterId == this.quickFilter.filterId) {
|
442 |
58072
|
argiro.kok
|
this.quickFilter.filter = filter;
|
443 |
|
|
}
|
444 |
58045
|
argiro.kok
|
}
|
445 |
59303
|
konstantin
|
if (this.parameterNames.indexOf("cf") != -1 && this.parameterValues[this.parameterNames.indexOf("cf")] == "true") {
|
446 |
|
|
this.customFilter.selected = true;
|
447 |
|
|
}else if(this.customFilter && this.customFilter.selected == null){
|
448 |
|
|
this.customFilter.selected = false;
|
449 |
|
|
}
|
450 |
58045
|
argiro.kok
|
this.filterFilterValues(this.filters);
|
451 |
59303
|
konstantin
|
if(!this.includeOnlyResultsAndFilter) {
|
452 |
|
|
this.updateDescription();
|
453 |
|
|
}
|
454 |
58045
|
argiro.kok
|
return filters;
|
455 |
|
|
}
|
456 |
|
|
|
457 |
|
|
/*
|
458 |
58105
|
konstantin
|
* Mark as check the new range filters that are selected
|
459 |
|
|
*/
|
460 |
|
|
public checkSelectedRangeFilters(filters: RangeFilter[]) {
|
461 |
|
|
//console.log("checkSelectedRangeFilters: parameterNames.length: "+this.parameterNames.length);
|
462 |
|
|
|
463 |
|
|
this.rangeFilters = filters;
|
464 |
|
|
for (let i = 0; i < filters.length; i++) {
|
465 |
|
|
let filter: RangeFilter = filters[i];
|
466 |
|
|
|
467 |
|
|
if (this.parameterNames.indexOf(filter.filterId) != -1) {
|
468 |
|
|
//console.log(filter.filterId + " "+this.parameterNames.indexOf(filter.filterId) );
|
469 |
|
|
let values = (decodeURIComponent(this.parameterValues[this.parameterNames.indexOf(filter.filterId)])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
470 |
|
|
let operators: string [] = (StringUtils.URIDecode(this.parameterValues[this.parameterNames.indexOf(filter.filterId)])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
471 |
|
|
if (values.length == operators.length) {
|
472 |
|
|
for (let j = 0; j < values.length; j++) {
|
473 |
|
|
if (this.fieldIdsMap[filter.originalFilterIdFrom+"-range-"+filter.originalFilterIdTo].filterType == "range") {
|
474 |
|
|
let value: string = StringUtils.unquote(values[j]);
|
475 |
|
|
let validDates: boolean = true;
|
476 |
|
|
|
477 |
|
|
let years: string[] = (value.substring(5)).split(":");
|
478 |
|
|
let yearFrom: string = (Dates.isValidYear(years[0]) ? years[0] : null);
|
479 |
|
|
let yearTo: string = (Dates.isValidYear(years[1]) ? years[1] : null);
|
480 |
|
|
//console.log("checkSelectedRangeFilters: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
|
481 |
|
|
if(yearFrom) {
|
482 |
|
|
filter.selectedFromValue = yearFrom;
|
483 |
|
|
}
|
484 |
|
|
if(yearTo) {
|
485 |
|
|
filter.selectedToValue = yearTo;
|
486 |
|
|
}
|
487 |
58135
|
konstantin
|
if(yearFrom && yearTo) {
|
488 |
|
|
filter.selectedFromAndToValues = yearFrom + "-" + yearTo;
|
489 |
|
|
} else if(yearFrom) {
|
490 |
58148
|
konstantin
|
filter.selectedFromAndToValues = "From " + yearFrom;
|
491 |
58135
|
konstantin
|
} else if(yearTo) {
|
492 |
58148
|
konstantin
|
filter.selectedFromAndToValues = "Until " + yearTo;
|
493 |
58135
|
konstantin
|
}
|
494 |
|
|
|
495 |
58105
|
konstantin
|
if(!yearFrom && !yearTo) {
|
496 |
|
|
validDates = false;
|
497 |
|
|
}
|
498 |
|
|
|
499 |
|
|
// if (value.length < 14) {
|
500 |
|
|
// validDates = false;
|
501 |
|
|
// console.log("not valid (length<14)");
|
502 |
|
|
// } else {
|
503 |
|
|
// if (!Dates.isValidYear(value.substring(5, 9)) || !Dates.isValidYear(value.substring(10, 14))) {
|
504 |
|
|
// validDates = false;
|
505 |
|
|
// console.log("not valid years");
|
506 |
|
|
// } else {
|
507 |
|
|
// filter.selectedFromValue = value.substring(5, 9);
|
508 |
|
|
// filter.selectedToValue = value.substring(10, 14);
|
509 |
|
|
// console.log(filter);
|
510 |
|
|
// }
|
511 |
|
|
// }
|
512 |
|
|
}
|
513 |
|
|
}
|
514 |
|
|
}
|
515 |
|
|
} else {
|
516 |
|
|
filter.selectedFromValue = null;
|
517 |
|
|
filter.selectedToValue = null;
|
518 |
|
|
}
|
519 |
|
|
}
|
520 |
|
|
return this.rangeFilters;
|
521 |
|
|
}
|
522 |
|
|
|
523 |
59180
|
konstantin
|
get existingFiltersWithValues() {
|
524 |
|
|
if(this.filters.length == 0) {
|
525 |
|
|
return 0;
|
526 |
|
|
}
|
527 |
|
|
return this.filters.some(filter => (filter.values && filter.values.length > 0));
|
528 |
|
|
}
|
529 |
|
|
|
530 |
58105
|
konstantin
|
/*
|
531 |
58045
|
argiro.kok
|
* For Funder filters - if funder selected
|
532 |
|
|
*/
|
533 |
|
|
public filterFilterValues(filters: Filter[]) {
|
534 |
|
|
var funders = [];
|
535 |
|
|
var funder_prefix = [];
|
536 |
|
|
for (var i = 0; i < filters.length; i++) {
|
537 |
|
|
|
538 |
|
|
var filter: Filter = filters[i];
|
539 |
|
|
// console.log(filter.filterId);
|
540 |
58055
|
argiro.kok
|
if (filter.filterId.indexOf("funder") != -1 && this.parameterNames.indexOf(filter.filterId) != -1) {
|
541 |
|
|
let funders = (decodeURIComponent(this.parameterValues[this.parameterNames.indexOf(filter.filterId)])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
542 |
58045
|
argiro.kok
|
for (let funder of funders) {
|
543 |
|
|
funder_prefix.push(StringUtils.unquote(funder).split("____")[0]);
|
544 |
|
|
}
|
545 |
|
|
// console.log(funder_prefix );
|
546 |
|
|
} else if (filter.filterId.indexOf("funding") != -1) {
|
547 |
|
|
// console.log(" funding: "+filter.filterId );
|
548 |
|
|
var filteredValues = []
|
549 |
|
|
for (let filterValue of filter.values) {
|
550 |
|
|
var value_prefix = filterValue.id.split("____")[0];
|
551 |
|
|
// console.log("Value prefix: "+value_prefix );
|
552 |
|
|
if (funder_prefix.indexOf(value_prefix) != -1) {
|
553 |
|
|
// console.log("here" + value_prefix);
|
554 |
|
|
filteredValues.push(filterValue);
|
555 |
|
|
}
|
556 |
|
|
|
557 |
|
|
}
|
558 |
|
|
if (filteredValues.length > 0) {
|
559 |
|
|
filter.values = filteredValues;
|
560 |
|
|
}
|
561 |
|
|
}
|
562 |
|
|
|
563 |
|
|
}
|
564 |
|
|
|
565 |
|
|
return filters;
|
566 |
|
|
}
|
567 |
|
|
|
568 |
58072
|
argiro.kok
|
public countSelectedFilters(filters: Filter[]): number {
|
569 |
58052
|
argiro.kok
|
this.selectedFilters = 0;
|
570 |
|
|
for (let filter of filters) {
|
571 |
58045
|
argiro.kok
|
if (filter.countSelectedValues > 0) {
|
572 |
58052
|
argiro.kok
|
this.selectedFilters += filter.countSelectedValues;
|
573 |
58045
|
argiro.kok
|
}
|
574 |
|
|
}
|
575 |
58052
|
argiro.kok
|
return this.selectedFilters;
|
576 |
58045
|
argiro.kok
|
}
|
577 |
|
|
|
578 |
58105
|
konstantin
|
public countSelectedRangeFilters(rangeFilters: RangeFilter[]) : number {
|
579 |
|
|
this.selectedRangeFilters = 0;
|
580 |
|
|
for(let filter of rangeFilters) {
|
581 |
|
|
if(filter.selectedFromValue || filter.selectedToValue) {
|
582 |
|
|
this.selectedRangeFilters++;
|
583 |
|
|
}
|
584 |
|
|
}
|
585 |
|
|
return this.selectedRangeFilters;
|
586 |
|
|
}
|
587 |
|
|
|
588 |
58045
|
argiro.kok
|
private clearKeywords() {
|
589 |
|
|
if (this.searchUtils.keyword.length > 0) {
|
590 |
|
|
this.searchUtils.keyword = '';
|
591 |
|
|
}
|
592 |
|
|
this.goTo(1);
|
593 |
|
|
}
|
594 |
|
|
|
595 |
59303
|
konstantin
|
public removeFilter(value: Value, filter: Filter, forceRemove:boolean = false) {
|
596 |
|
|
this.currentValueToRemove = value;
|
597 |
|
|
this.currentFilterToRemove = filter;
|
598 |
|
|
if(!forceRemove && this.customFilter && this.customFilter.queryFieldName ==filter.filterId && this.customFilter.valueId == value.id && this.customFilter.promptToAddFilter ){
|
599 |
|
|
this.openRemoveCustomFilterModal();
|
600 |
|
|
return;
|
601 |
|
|
}
|
602 |
58045
|
argiro.kok
|
filter.countSelectedValues--;
|
603 |
58052
|
argiro.kok
|
this.selectedFilters--;
|
604 |
58045
|
argiro.kok
|
if (value.selected == true) {
|
605 |
|
|
value.selected = false;
|
606 |
|
|
}
|
607 |
59180
|
konstantin
|
if(filter.filterType == "radio"){
|
608 |
|
|
filter.radioValue = "";
|
609 |
|
|
}
|
610 |
58072
|
argiro.kok
|
if (this.quickFilter && this.quickFilter.filterId == filter.filterId) {
|
611 |
|
|
this.removeValueFromQuickFilter();
|
612 |
|
|
}
|
613 |
58045
|
argiro.kok
|
this.goTo(1);
|
614 |
58105
|
konstantin
|
}
|
615 |
59303
|
konstantin
|
public openRemoveCustomFilterModal() {
|
616 |
|
|
this.removeCustomFilter.alertTitle = 'Remove filter';
|
617 |
|
|
this.removeCustomFilter.message = 'You are about to see results that are not related to '+ this.customFilter.valueName + '. Do you want to proceed?';
|
618 |
|
|
this.removeCustomFilter.okButtonText = 'Yes';
|
619 |
|
|
this.removeCustomFilter.cancelButtonText = 'No';
|
620 |
|
|
this.removeCustomFilter.open();
|
621 |
|
|
}
|
622 |
58045
|
argiro.kok
|
|
623 |
59303
|
konstantin
|
closeCustomFilterModal() {
|
624 |
|
|
this.removeFilter(this.currentValueToRemove, this.currentFilterToRemove, true);
|
625 |
|
|
this.isCustomFilterSelected = false;
|
626 |
|
|
}
|
627 |
|
|
|
628 |
58105
|
konstantin
|
public removeRangeFilter(filter: RangeFilter) {
|
629 |
|
|
filter.selectedFromValue = null;
|
630 |
|
|
filter.selectedToValue = null;
|
631 |
|
|
this.goTo(1);
|
632 |
58045
|
argiro.kok
|
}
|
633 |
|
|
|
634 |
|
|
getSelectedValues(filter): any {
|
635 |
|
|
var selected = [];
|
636 |
|
|
if (filter.countSelectedValues > 0) {
|
637 |
|
|
for (var i = 0; i < filter.values.length; i++) {
|
638 |
|
|
if (filter.values[i].selected) {
|
639 |
|
|
selected.push(filter.values[i]);
|
640 |
|
|
}
|
641 |
|
|
}
|
642 |
|
|
}
|
643 |
|
|
return selected;
|
644 |
|
|
|
645 |
|
|
}
|
646 |
|
|
|
647 |
|
|
filterChanged($event) {
|
648 |
58105
|
konstantin
|
if (this.quickFilter && this.quickFilter.filter) {
|
649 |
58072
|
argiro.kok
|
this.removeValueFromQuickFilter();
|
650 |
|
|
}
|
651 |
58045
|
argiro.kok
|
this.goTo(1);
|
652 |
58072
|
argiro.kok
|
|
653 |
58045
|
argiro.kok
|
}
|
654 |
|
|
|
655 |
58072
|
argiro.kok
|
/**
|
656 |
|
|
* if there is a change in the values of the quick filter, this function has to be run, to also update the quickFilter
|
657 |
|
|
*/
|
658 |
|
|
removeValueFromQuickFilter() {
|
659 |
|
|
if (this.quickFilter.filter.countSelectedValues == 0) {
|
660 |
|
|
this.quickFilter.selected = false;
|
661 |
|
|
} else {
|
662 |
|
|
let isQuickEnabled = false;
|
663 |
|
|
for (let filterValue of this.quickFilter.filter.values) {
|
664 |
|
|
isQuickEnabled = (filterValue.name == this.quickFilter.value)
|
665 |
|
|
}
|
666 |
|
|
this.quickFilter.selected = (isQuickEnabled && this.quickFilter.filter.countSelectedValues == 1);
|
667 |
|
|
}
|
668 |
|
|
}
|
669 |
|
|
|
670 |
59303
|
konstantin
|
/**
|
671 |
|
|
* Set selected the value of the custom filter.
|
672 |
|
|
*/
|
673 |
|
|
addCustomFilter() {
|
674 |
|
|
this.customFilter.selected = true;
|
675 |
|
|
if(this.refineFields.indexOf(this.customFilter.queryFieldName) == -1 ){
|
676 |
|
|
this.customFilterEnabled = true;
|
677 |
|
|
}else {
|
678 |
|
|
for (let filter of this.filters) {
|
679 |
|
|
if (this.customFilter.queryFieldName == filter.filterId) {
|
680 |
|
|
for (let value of filter.values) {
|
681 |
|
|
if (value.id == this.customFilter.valueId) {
|
682 |
|
|
value.selected = true;
|
683 |
|
|
filter.countSelectedValues++;
|
684 |
|
|
}
|
685 |
|
|
}
|
686 |
|
|
}
|
687 |
|
|
}
|
688 |
|
|
}
|
689 |
|
|
this.filterChanged(null);
|
690 |
|
|
|
691 |
|
|
}
|
692 |
58045
|
argiro.kok
|
// for loading
|
693 |
|
|
public openLoading() {
|
694 |
|
|
this.loading.open();
|
695 |
|
|
}
|
696 |
|
|
|
697 |
|
|
public closeLoading() {
|
698 |
|
|
this.loading.close();
|
699 |
|
|
}
|
700 |
|
|
|
701 |
|
|
/**
|
702 |
|
|
* Build advanced search Filters based on the URL parameters
|
703 |
|
|
* @param params
|
704 |
|
|
*/
|
705 |
58173
|
argiro.kok
|
createAdvancedSearchSelectedFiltersFromNewURLParameters(params) {
|
706 |
|
|
for (let i = 0; i < Object.keys(params).length; i++) {
|
707 |
|
|
if(params["f"+i] && params["fv"+i] ) {
|
708 |
|
|
let fieldId = params["f" + i].split(",")[0];
|
709 |
|
|
let operator = (params["f" + i].split(",").length >1 )?params["f" + i].split(",")[1]:"and";
|
710 |
|
|
let fieldparam = (this.fieldIdsMap[fieldId]) ? this.fieldIdsMap[fieldId].param : "";
|
711 |
|
|
|
712 |
|
|
if (!this.fieldIdsMap[fieldId]) {
|
713 |
|
|
console.error("Field: " + fieldId + " not found in fieldIds map");
|
714 |
|
|
continue;
|
715 |
|
|
}
|
716 |
|
|
let value: string = StringUtils.URIDecode(params["fv"+i]);
|
717 |
|
|
if (this.fieldIdsMap[fieldId].type == "date") {
|
718 |
|
|
let validDates: boolean = true;
|
719 |
|
|
let dateField: AdvancedField = new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type, value, operator);
|
720 |
|
|
if (value.indexOf("range") != -1) {
|
721 |
|
|
dateField.dateValue.type = "range";
|
722 |
|
|
if (value.length < 26) {
|
723 |
|
|
validDates = false;
|
724 |
|
|
} else {
|
725 |
|
|
if (!Dates.isValidDate(value.substring(5, 15)) || !Dates.isValidDate(value.substring(16, 26))) {
|
726 |
|
|
validDates = false;
|
727 |
|
|
} else {
|
728 |
|
|
dateField.dateValue.from = Dates.getDateFromString(value.substring(5, 15));
|
729 |
|
|
dateField.dateValue.to = Dates.getDateFromString(value.substring(16, 26));
|
730 |
|
|
}
|
731 |
|
|
}
|
732 |
|
|
// "rangeYYYY-MM-DD:YYYY-MM-DD"
|
733 |
|
|
} else {
|
734 |
|
|
dateField.dateValue.setDatesByType(value);
|
735 |
|
|
}
|
736 |
|
|
if (validDates) {
|
737 |
|
|
this.selectedFields.push(dateField);
|
738 |
|
|
}
|
739 |
|
|
|
740 |
|
|
} else {
|
741 |
|
|
this.selectedFields.push(new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type,value, operator));
|
742 |
|
|
}
|
743 |
|
|
|
744 |
|
|
}
|
745 |
|
|
}
|
746 |
|
|
}
|
747 |
|
|
/**
|
748 |
|
|
* Build advanced search Filters based on the URL parameters
|
749 |
|
|
* @param params
|
750 |
|
|
*/
|
751 |
58045
|
argiro.kok
|
createAdvancedSearchSelectedFiltersFromURLParameters(params) {
|
752 |
58173
|
argiro.kok
|
this.createAdvancedSearchSelectedFiltersFromNewURLParameters(params);
|
753 |
56649
|
k.triantaf
|
for (var i = 0; i < this.fieldIds.length; i++) {
|
754 |
|
|
var fieldId = this.fieldIds[i];
|
755 |
|
|
var fieldparam = (this.fieldIdsMap[fieldId]) ? this.fieldIdsMap[fieldId].param : "";
|
756 |
|
|
if (!this.fieldIdsMap[fieldId]) {
|
757 |
|
|
console.error("Field: " + fieldId + " not found in fieldIds map");
|
758 |
58173
|
argiro.kok
|
continue;
|
759 |
56649
|
k.triantaf
|
}
|
760 |
50169
|
argiro.kok
|
|
761 |
56649
|
k.triantaf
|
var operatorId = this.getOperatorParameter(fieldparam);
|
762 |
|
|
if (params[fieldparam] != undefined && params[operatorId] != undefined) {
|
763 |
|
|
var values: string [] = StringUtils.URIDecode(params[fieldparam]).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
764 |
|
|
var operators: string [] = (StringUtils.URIDecode(params[operatorId])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
765 |
|
|
if (values.length == operators.length) {
|
766 |
|
|
for (var j = 0; j < values.length; j++) {
|
767 |
|
|
if (this.fieldIdsMap[fieldId].type == "date") {
|
768 |
|
|
var value: string = StringUtils.unquote(values[j]);
|
769 |
|
|
var validDates: boolean = true;
|
770 |
|
|
var dateField: AdvancedField = new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type, value, operators[j]);
|
771 |
|
|
if (value.indexOf("range") != -1) {
|
772 |
|
|
dateField.dateValue.type = "range";
|
773 |
|
|
if (value.length < 26) {
|
774 |
|
|
validDates = false;
|
775 |
|
|
} else {
|
776 |
|
|
if (!Dates.isValidDate(value.substring(5, 15)) || !Dates.isValidDate(value.substring(16, 26))) {
|
777 |
|
|
validDates = false;
|
778 |
|
|
} else {
|
779 |
|
|
dateField.dateValue.from = Dates.getDateFromString(value.substring(5, 15));
|
780 |
|
|
dateField.dateValue.to = Dates.getDateFromString(value.substring(16, 26));
|
781 |
|
|
}
|
782 |
|
|
}
|
783 |
|
|
// "rangeYYYY-MM-DD:YYYY-MM-DD"
|
784 |
|
|
} else {
|
785 |
|
|
dateField.dateValue.setDatesByType(value);
|
786 |
|
|
}
|
787 |
|
|
if (validDates) {
|
788 |
|
|
this.selectedFields.push(dateField);
|
789 |
|
|
}
|
790 |
50169
|
argiro.kok
|
|
791 |
56649
|
k.triantaf
|
} else {
|
792 |
58173
|
argiro.kok
|
this.selectedFields.push(new AdvancedField(fieldId, fieldparam, this.fieldIdsMap[fieldId].name, this.fieldIdsMap[fieldId].type, values[j], operators[j]));
|
793 |
56649
|
k.triantaf
|
}
|
794 |
|
|
}
|
795 |
|
|
}
|
796 |
|
|
}
|
797 |
|
|
}
|
798 |
58045
|
argiro.kok
|
if (params['keyword'] && params['keyword'].length > 0) {
|
799 |
|
|
this.selectedFields.push(new AdvancedField(this.fieldIds[0], this.fieldIdsMap[this.fieldIds[0]].param, this.fieldIdsMap[this.fieldIds[0]].name, this.fieldIdsMap[this.fieldIds[0]].type, params['keyword'], "and"));
|
800 |
|
|
}
|
801 |
56649
|
k.triantaf
|
if (this.selectedFields.length == 0) {
|
802 |
58045
|
argiro.kok
|
this.selectedFields.push(new AdvancedField(this.fieldIds[0], this.fieldIdsMap[this.fieldIds[0]].param, this.fieldIdsMap[this.fieldIds[0]].name, this.fieldIdsMap[this.fieldIds[0]].type, "", "and"));
|
803 |
56649
|
k.triantaf
|
}
|
804 |
50169
|
argiro.kok
|
}
|
805 |
56649
|
k.triantaf
|
|
806 |
58045
|
argiro.kok
|
/**
|
807 |
|
|
* Create Search API query based on the selected fields of the advanced form
|
808 |
|
|
*/
|
809 |
|
|
getSearchAPIQueryForAdvancedSearhFields() {
|
810 |
|
|
|
811 |
56649
|
k.triantaf
|
var params = "";
|
812 |
58045
|
argiro.kok
|
var countParams = 0;
|
813 |
|
|
for (var i = 0; i < this.selectedFields.length; i++) {
|
814 |
|
|
if (this.fieldIdsMap[this.selectedFields[i].id] != undefined && (this.selectedFields[i].value != "" || this.selectedFields[i].type == "date")) {
|
815 |
|
|
//console.log("createQueryParameters::"+this.selectedFields[i].type);
|
816 |
|
|
if (this.selectedFields[i].type == "date") {
|
817 |
|
|
if (this.selectedFields[i].dateValue.type != "any") {
|
818 |
|
|
params += (countParams == 0 ? "" : this.selectedFields[i].operatorId) + " " + this.selectedFields[i].id + this.fieldIdsMap[this.selectedFields[i].id].equalityOperator + '"' + StringUtils.URIEncode(Dates.getDateToString(this.selectedFields[i].dateValue.from)) + " "
|
819 |
|
|
+ StringUtils.URIEncode(Dates.getDateToString(this.selectedFields[i].dateValue.to)) + '"' + " ";
|
820 |
|
|
}
|
821 |
|
|
} else {
|
822 |
|
|
if (this.selectedFields[i].id == "q") {
|
823 |
58348
|
argiro.kok
|
// console.log(this.selectedFields[i].value)
|
824 |
59180
|
konstantin
|
/* var op = "";
|
825 |
58045
|
argiro.kok
|
var doisParams = "";
|
826 |
58164
|
argiro.kok
|
if ((this.entityType == 'publication' || this.entityType == 'dataset' || this.entityType == 'software' || this.entityType == 'other' || this.entityType == "result")) {
|
827 |
|
|
var DOIs: Identifier[] = Identifier.getIdentifiersFromString(this.selectedFields[i].value);
|
828 |
|
|
for (let identifier of DOIs) {
|
829 |
58348
|
argiro.kok
|
// console.log(identifier)
|
830 |
58164
|
argiro.kok
|
// pidclassid exact \"doi\" and pid exact \"10.1016/j.nima.2015.11.134\"
|
831 |
|
|
//and (authorid exact \"0000-0001-7291-3210 \" )"
|
832 |
|
|
if(identifier.class == "ORCID"){
|
833 |
|
|
doisParams += (doisParams.length > 0 ? " or " : "") +'(authorid="' + identifier.id + '")';
|
834 |
|
|
}else{
|
835 |
|
|
doisParams += (doisParams.length > 0 ? " or " : "") +'(pidclassid exact "' + identifier.class + '" and pid="' + identifier.id + '")';
|
836 |
|
|
}
|
837 |
58045
|
argiro.kok
|
}
|
838 |
|
|
}
|
839 |
|
|
if (doisParams.length > 0) {
|
840 |
58244
|
argiro.kok
|
params += this.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId ,countParams,true, true) + " or " + doisParams;
|
841 |
58045
|
argiro.kok
|
} else {
|
842 |
58244
|
argiro.kok
|
params += this.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId,countParams,true);
|
843 |
59180
|
konstantin
|
}*/
|
844 |
|
|
params += NewSearchPageComponent.createKeywordQuery(this.entityType,this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams);
|
845 |
58244
|
argiro.kok
|
//TODO deposit case
|
846 |
58348
|
argiro.kok
|
// console.log(this.usedBy)
|
847 |
|
|
// console.log(this.keywordFields)
|
848 |
58244
|
argiro.kok
|
|
849 |
|
|
if(this.usedBy == "deposit") {
|
850 |
|
|
|
851 |
|
|
if(this.keywordFields.length > 0) {
|
852 |
|
|
params += " or ("
|
853 |
|
|
}
|
854 |
|
|
for(let j=0; j< this.keywordFields.length ; j++) {
|
855 |
|
|
if(j > 0) {
|
856 |
|
|
params += " or "
|
857 |
|
|
}
|
858 |
59180
|
konstantin
|
params += NewSearchPageComponent.createQuotedKeywordQuery(this.selectedFields[i].value, this.keywordFields[j].name, " or ", countParams,false);
|
859 |
58244
|
argiro.kok
|
// let field = this.keywordFields[i];
|
860 |
|
|
//keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(keyword);
|
861 |
|
|
// params += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(keyword));
|
862 |
|
|
}
|
863 |
|
|
if(this.keywordFields.length > 0) {
|
864 |
|
|
params += " ) "
|
865 |
|
|
}
|
866 |
|
|
}
|
867 |
|
|
|
868 |
58138
|
argiro.kok
|
} else if (countParams == 0 && this.selectedFields[i].operatorId == "not" && this.fieldIdsMap[this.selectedFields[i].id].equalityOperator != "=") {
|
869 |
58045
|
argiro.kok
|
params += " " + this.selectedFields[i].id + " <> " + '"' + StringUtils.URIEncode(this.selectedFields[i].value) + '"' + " ";
|
870 |
58138
|
argiro.kok
|
} else if(this.fieldIdsMap[this.selectedFields[i].id].equalityOperator == "=") {
|
871 |
59180
|
konstantin
|
params+=NewSearchPageComponent.createQuotedKeywordQuery(this.selectedFields[i].value, this.selectedFields[i].id, this.selectedFields[i].operatorId, countParams, false);
|
872 |
58138
|
argiro.kok
|
}else{
|
873 |
59180
|
konstantin
|
params += (countParams == 0 ? "" : " " + this.selectedFields[i].operatorId + " ") + this.selectedFields[i].id + this.fieldIdsMap[this.selectedFields[i].id].equalityOperator + '"' + encodeURIComponent(this.selectedFields[i].value) + '"' + " ";
|
874 |
58045
|
argiro.kok
|
|
875 |
|
|
}
|
876 |
|
|
}
|
877 |
|
|
countParams++;
|
878 |
|
|
}
|
879 |
|
|
}
|
880 |
|
|
|
881 |
58348
|
argiro.kok
|
// console.log("ParameterS:")
|
882 |
|
|
// console.log(params)
|
883 |
58045
|
argiro.kok
|
return params;
|
884 |
|
|
}
|
885 |
59180
|
konstantin
|
public static createKeywordQuery(entityType:string, value:string, id, operatorId, countParams=0){
|
886 |
|
|
let params = "";
|
887 |
|
|
let doisParams = "";
|
888 |
|
|
var DOIs: Identifier[] = Identifier.getIdentifiersFromString(value);
|
889 |
|
|
if ((entityType == 'publication' || entityType == 'dataset' || entityType == 'software' || entityType == 'other' || entityType == "result")) {
|
890 |
|
|
for (let identifier of DOIs) {
|
891 |
|
|
// console.log(identifier)
|
892 |
|
|
// pidclassid exact \"doi\" and pid exact \"10.1016/j.nima.2015.11.134\"
|
893 |
|
|
//and (authorid exact \"0000-0001-7291-3210 \" )"
|
894 |
|
|
if(identifier.class == "ORCID"){
|
895 |
|
|
doisParams += (doisParams.length > 0 ? " or " : "") +'(authorid="' + identifier.id + '")';
|
896 |
|
|
}else{
|
897 |
|
|
doisParams += (doisParams.length > 0 ? " or " : "") +'(pidclassid exact "' + identifier.class + '" and pid="' + identifier.id + '")';
|
898 |
|
|
}
|
899 |
|
|
}
|
900 |
|
|
}
|
901 |
|
|
if (doisParams.length > 0) {
|
902 |
|
|
params += "(" + this.createQuotedKeywordQuery(value, id, operatorId ,countParams,true, true) + " or " + doisParams+")";
|
903 |
|
|
} else {
|
904 |
|
|
//if it is PIDs but no doisquery produced, forced to use quotes as the query will fail due to special characters
|
905 |
|
|
params += this.createQuotedKeywordQuery(value, id, operatorId,countParams,true,
|
906 |
|
|
(DOIs.length > 0 && doisParams.length == 0) );
|
907 |
|
|
}
|
908 |
|
|
return params;
|
909 |
58045
|
argiro.kok
|
|
910 |
59180
|
konstantin
|
}
|
911 |
|
|
private static createQuotedKeywordQuery(fieldValue, fieldId, fieldOperator, countParams:number, isSearchAll:boolean, forceQuotted:boolean=false){
|
912 |
58138
|
argiro.kok
|
let params = "";
|
913 |
59180
|
konstantin
|
let countQuote = (fieldValue.match(/'/g) || []).length;
|
914 |
|
|
let countDoubleQuote = (fieldValue.match(/"/g) || []).length;
|
915 |
|
|
let quotedParts = [];
|
916 |
|
|
if(countQuote % 2 == 0 && countDoubleQuote % 2 ==0){
|
917 |
|
|
quotedParts = (fieldValue)?fieldValue.match(/(["'])(.*?)*?\1/g):[];
|
918 |
|
|
}
|
919 |
|
|
params+= (countParams == 0 ? "" : fieldOperator);
|
920 |
|
|
params+= " (";
|
921 |
58164
|
argiro.kok
|
if(forceQuotted){
|
922 |
59180
|
konstantin
|
return (countParams == 0 ? "" : " "+fieldOperator+" ") + this.getQuotedQueryPart(fieldId, '"'+ fieldValue+'"',isSearchAll);
|
923 |
58164
|
argiro.kok
|
}
|
924 |
58244
|
argiro.kok
|
if(quotedParts && quotedParts.length == 1 && quotedParts[0] == fieldValue ){
|
925 |
|
|
params+=this.getQuotedQueryPart(fieldId, fieldValue,isSearchAll);
|
926 |
58138
|
argiro.kok
|
}else if( quotedParts && quotedParts.length > 0){
|
927 |
|
|
for(let i=0; i< quotedParts.length; i++){
|
928 |
|
|
params+=(i>0)?" and ":"";
|
929 |
58244
|
argiro.kok
|
params+=this.getQuotedQueryPart(fieldId, quotedParts[i],isSearchAll);
|
930 |
58138
|
argiro.kok
|
}
|
931 |
|
|
let startPoint = 0;
|
932 |
|
|
let endPoint = 0;
|
933 |
|
|
for(let i=0; i< quotedParts.length; i++){
|
934 |
58244
|
argiro.kok
|
let index = fieldValue.indexOf(quotedParts[i]);
|
935 |
|
|
endPoint = (i+1<quotedParts.length)? fieldValue.indexOf(quotedParts[i+1]):fieldValue.length;
|
936 |
|
|
// console.log(fieldValue.indexOf(quotedParts[i+1]) +" - "+fieldValue.length);
|
937 |
58138
|
argiro.kok
|
// console.log(" SP "+ startPoint+" EP: "+endPoint);
|
938 |
|
|
if(index==startPoint){
|
939 |
|
|
startPoint +=quotedParts[i].length;
|
940 |
|
|
}else if(startPoint < index){
|
941 |
|
|
endPoint = index;
|
942 |
|
|
}
|
943 |
|
|
// console.log(" SP "+ startPoint+" EP: "+endPoint);
|
944 |
58244
|
argiro.kok
|
if(decodeURIComponent(fieldValue.substring(startPoint,endPoint)).split(" ").join("").length > 0) {
|
945 |
|
|
params += " and " + this.getNoQuotedQueryPart(fieldId, fieldValue.substring(startPoint, endPoint), isSearchAll);
|
946 |
58138
|
argiro.kok
|
}
|
947 |
|
|
// console.log("For "+i+" " +params+" SP "+ startPoint+" EP: "+endPoint);
|
948 |
58244
|
argiro.kok
|
// startPoint = (i+1<quotedParts.length)? fieldValue.indexOf(quotedParts[i+i]):fieldValue.length;//(startPoint<index )?(index + quotedParts[i].length):fieldValue.length;
|
949 |
|
|
startPoint = ((i+1<quotedParts.length)?(fieldValue.indexOf(quotedParts[i+1])+quotedParts[i+1].length):(endPoint== index?(index+quotedParts[i].length):endPoint));
|
950 |
58138
|
argiro.kok
|
}
|
951 |
58244
|
argiro.kok
|
if(startPoint !=fieldValue.length && decodeURIComponent(fieldValue.substring(startPoint,fieldValue.length)).split(" ").join("").length > 0){
|
952 |
|
|
params+=" and " + this.getNoQuotedQueryPart(fieldId, fieldValue.substring(startPoint,fieldValue.length),isSearchAll);
|
953 |
58138
|
argiro.kok
|
}
|
954 |
|
|
}else{
|
955 |
58244
|
argiro.kok
|
params+=this.getNoQuotedQueryPart(fieldId, fieldValue,isSearchAll);
|
956 |
58138
|
argiro.kok
|
}
|
957 |
59180
|
konstantin
|
params += ")";
|
958 |
58138
|
argiro.kok
|
return params;
|
959 |
|
|
}
|
960 |
|
|
|
961 |
59180
|
konstantin
|
private static getQuotedQueryPart(fieldId:string, value:string, isSearchAll:boolean){
|
962 |
58244
|
argiro.kok
|
return (isSearchAll?"__all":fieldId)+" exact "+StringUtils.URIEncode(value);
|
963 |
58138
|
argiro.kok
|
}
|
964 |
59180
|
konstantin
|
private static getNoQuotedQueryPart(fieldId:string, value:string, isSearchAll:boolean){
|
965 |
|
|
//split the keywords of the vlaue and query seperately for each keyword using quotes to allow characters like .@
|
966 |
|
|
let valueKeywords= value.split(" ");
|
967 |
|
|
let query = "";
|
968 |
|
|
let i=0;
|
969 |
|
|
for(let keyword of valueKeywords ){
|
970 |
|
|
if(keyword.length > 0){
|
971 |
|
|
query+= (i!=0?" and ":"")+(isSearchAll?"(":fieldId+"=")+"\""+StringUtils.URIEncode(keyword) +"\""+ (isSearchAll?")":"");
|
972 |
|
|
i++;
|
973 |
|
|
}
|
974 |
58138
|
argiro.kok
|
}
|
975 |
59180
|
konstantin
|
return query
|
976 |
58138
|
argiro.kok
|
}
|
977 |
|
|
|
978 |
58045
|
argiro.kok
|
/**
|
979 |
|
|
* Create Search API query based on the filters of refine fields
|
980 |
|
|
* @param URLparams
|
981 |
58073
|
argiro.kok
|
* @param firstLoad
|
982 |
58045
|
argiro.kok
|
*/
|
983 |
58072
|
argiro.kok
|
getSearchAPIQueryForRefineFields(URLparams, firstLoad: boolean) {
|
984 |
58045
|
argiro.kok
|
|
985 |
|
|
var allFqs = "";
|
986 |
58348
|
argiro.kok
|
// console.log(this.refineFields)
|
987 |
58045
|
argiro.kok
|
for (var i = 0; i < this.refineFields.length; i++) {
|
988 |
|
|
var filterId = this.refineFields[i];
|
989 |
|
|
|
990 |
|
|
if (URLparams[filterId] != undefined) {
|
991 |
58055
|
argiro.kok
|
let values = (StringUtils.URIDecode(StringUtils.URIDecode(URLparams[filterId]))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
992 |
58045
|
argiro.kok
|
var countvalues = 0;
|
993 |
|
|
var fq = "";
|
994 |
|
|
let filterOp: string = this.searchFieldsHelper.getFieldOperator(filterId);
|
995 |
58052
|
argiro.kok
|
// console.info(filterId, filterOp);
|
996 |
58045
|
argiro.kok
|
for (let value of values) {
|
997 |
|
|
countvalues++;
|
998 |
|
|
var paramId = this.fieldIdsMap[filterId].param;
|
999 |
|
|
// parameters+='&' + paramId+ '='+ value;//+"&" + this.fieldIdsMap[paramId].operator + "="+((countvalues == 1)?"and":"or");
|
1000 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + filterId + " exact " + (value);
|
1001 |
|
|
}
|
1002 |
|
|
if (countvalues > 0) {
|
1003 |
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
1004 |
|
|
}
|
1005 |
|
|
allFqs += fq;
|
1006 |
|
|
}
|
1007 |
|
|
}
|
1008 |
59180
|
konstantin
|
this.customFilterEnabled = URLparams["cf"] == "true";
|
1009 |
|
|
if(this.customFilter && (this.customFilter.isHiddenFilter || (this.refineFields.indexOf(this.customFilter.queryFieldName) == -1 && this.customFilterEnabled))){
|
1010 |
58045
|
argiro.kok
|
allFqs += "&fq=" + StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId)));
|
1011 |
|
|
}
|
1012 |
|
|
|
1013 |
58156
|
argiro.kok
|
if (this.quickFilter && this.entityType == "result") {
|
1014 |
|
|
if((firstLoad && URLparams[this.quickFilter.filterId] == undefined && URLparams["qf"] == undefined) || URLparams["qf"] == "true"
|
1015 |
|
|
|| ((URLparams[this.quickFilter.filterId] != undefined && StringUtils.URIDecode(URLparams[this.quickFilter.filterId]).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1).indexOf(StringUtils.quote(this.quickFilter.value)) != -1))) {
|
1016 |
58072
|
argiro.kok
|
this.quickFilter.selected = true;
|
1017 |
|
|
} else {
|
1018 |
|
|
this.quickFilter.selected = false;
|
1019 |
|
|
}
|
1020 |
58156
|
argiro.kok
|
if ((firstLoad && URLparams[this.quickFilter.filterId] == undefined && URLparams["qf"] == undefined)
|
1021 |
|
|
||( URLparams[this.quickFilter.filterId] == undefined && URLparams["qf"] == "true")) {
|
1022 |
58072
|
argiro.kok
|
allFqs += "&fq=resultbestaccessright exact " + StringUtils.quote(this.quickFilter.value);
|
1023 |
|
|
}
|
1024 |
|
|
}
|
1025 |
|
|
|
1026 |
|
|
if (this.entityType == "result") {
|
1027 |
|
|
if (URLparams["type"]) {
|
1028 |
58354
|
argiro.kok
|
let types = URLparams["type"].split(",");
|
1029 |
|
|
if(types.indexOf("publications")!=-1 && types.indexOf("datasets")!=-1 && types.indexOf("software")!=-1 && types.indexOf("other")!=-1 ){
|
1030 |
|
|
allFqs += "&type=results";
|
1031 |
|
|
}else{
|
1032 |
|
|
for (let type of types) {
|
1033 |
|
|
allFqs += "&type=" + type;
|
1034 |
|
|
}
|
1035 |
58072
|
argiro.kok
|
}
|
1036 |
58093
|
argiro.kok
|
}else{
|
1037 |
58354
|
argiro.kok
|
allFqs += "&type=results";
|
1038 |
58072
|
argiro.kok
|
}
|
1039 |
|
|
} else if (this.entityType == "publication") {
|
1040 |
|
|
allFqs += "&type=publications";
|
1041 |
|
|
} else if (this.entityType == "dataset") {
|
1042 |
|
|
allFqs += "&type=datasets";
|
1043 |
|
|
} else if (this.entityType == "software") {
|
1044 |
|
|
allFqs += "&type=software";
|
1045 |
|
|
} else if (this.entityType == "other") {
|
1046 |
|
|
allFqs += "&type=other";
|
1047 |
58132
|
konstantin
|
} else if(this.entityType == "project") {
|
1048 |
|
|
allFqs += "&type=projects";
|
1049 |
|
|
} else if(this.entityType == "organization") {
|
1050 |
|
|
allFqs += "&type=organizations";
|
1051 |
|
|
} else if(this.entityType == "dataprovider") {
|
1052 |
|
|
allFqs += "&type=datasources";
|
1053 |
58072
|
argiro.kok
|
}
|
1054 |
58348
|
argiro.kok
|
// console.log("AllFqs (check type): "+allFqs);
|
1055 |
|
|
// console.log("type: "+this.entityType);
|
1056 |
58045
|
argiro.kok
|
// var keyword = URLparams['keyword'];
|
1057 |
|
|
// var doiQuery = "";
|
1058 |
|
|
// var keywordQuery = "";
|
1059 |
|
|
// if((keyword && keyword.length > 0)){
|
1060 |
|
|
// if((this.type == 'publications' ||this.type == 'research data' || this.type == 'software' || this.type == 'other research products')){
|
1061 |
|
|
// var DOIs:string[] = DOI.getDOIsFromString(keyword);
|
1062 |
|
|
// var doisParams = "";
|
1063 |
|
|
//
|
1064 |
|
|
// for(var i =0 ;i < DOIs.length; i++){
|
1065 |
|
|
// doisParams+=(doisParams.length > 0?"&":"")+'doi="'+ DOIs[i]+'"';
|
1066 |
|
|
// }
|
1067 |
|
|
// if(doisParams.length > 0){
|
1068 |
|
|
// doiQuery += "&"+doisParams;
|
1069 |
|
|
// }else {
|
1070 |
|
|
// keywordQuery += "&q="+StringUtils.URIEncode(keyword);
|
1071 |
|
|
// }
|
1072 |
|
|
// }else{
|
1073 |
|
|
// if(this.usedBy == "deposit") {
|
1074 |
|
|
// if(this.keywordFields.length > 0) {
|
1075 |
|
|
// keywordQuery = "&fq=";
|
1076 |
|
|
// }
|
1077 |
|
|
//
|
1078 |
|
|
// for(let i=0; i< this.keywordFields.length ; i++) {
|
1079 |
|
|
// if(i > 0) {
|
1080 |
|
|
// keywordQuery += " or ";
|
1081 |
|
|
// }
|
1082 |
|
|
// let field = this.keywordFields[i];
|
1083 |
|
|
// //keywordQuery += field.name+field.equalityOperator+StringUtils.URIEncode(keyword);
|
1084 |
|
|
// keywordQuery += field.name+field.equalityOperator+StringUtils.quote(StringUtils.URIEncode(keyword));
|
1085 |
|
|
// }
|
1086 |
|
|
// } else {
|
1087 |
|
|
// keywordQuery += "&q=" + StringUtils.URIEncode(keyword);
|
1088 |
|
|
// }
|
1089 |
|
|
//
|
1090 |
|
|
// }
|
1091 |
|
|
// }
|
1092 |
|
|
//TODO add DOI?
|
1093 |
58072
|
argiro.kok
|
return allFqs;
|
1094 |
58045
|
argiro.kok
|
|
1095 |
|
|
}
|
1096 |
|
|
|
1097 |
|
|
/**
|
1098 |
58105
|
konstantin
|
* Create Search API query based on the filters of refine fields
|
1099 |
|
|
* @param URLparams
|
1100 |
|
|
*/
|
1101 |
|
|
getSearchAPIQueryForRangeFields(URLparams) {
|
1102 |
|
|
let allFqs = "";
|
1103 |
|
|
for (let i = 0; i < this.rangeFields.length; i++) {
|
1104 |
|
|
let filterId = this.rangeFields[i][0]+"-range-"+this.rangeFields[i][1];
|
1105 |
|
|
let filterParam = this.searchFieldsHelper.getFieldParam(filterId, this.entityType);
|
1106 |
|
|
|
1107 |
|
|
if (URLparams[filterParam] != undefined) {
|
1108 |
|
|
let values = (StringUtils.URIDecode(StringUtils.URIDecode(URLparams[filterParam]))).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
1109 |
|
|
var countvalues = 0;
|
1110 |
|
|
var fq = "";
|
1111 |
|
|
var fqFrom = "";
|
1112 |
|
|
var fqTo = "";
|
1113 |
|
|
let filterOp: string = this.searchFieldsHelper.getFieldOperator(filterId);
|
1114 |
|
|
|
1115 |
|
|
for (let value of values) {
|
1116 |
|
|
if (this.fieldIdsMap[filterId].filterType == "range") {
|
1117 |
|
|
|
1118 |
|
|
let selectedFromValue;
|
1119 |
|
|
let selectedToValue;
|
1120 |
|
|
|
1121 |
|
|
let years: string[] = (value.substring(5)).split(":");
|
1122 |
|
|
let yearFrom: string = (Dates.isValidYear(years[0]) ? years[0] : null);
|
1123 |
|
|
//(Number.isInteger(parseInt(years[0], 10)) ? years[0] : null);
|
1124 |
|
|
let yearTo: string = (Dates.isValidYear(years[1]) ? years[1] : null);
|
1125 |
|
|
//console.log("getSearchAPIQueryForRangeFields: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
|
1126 |
|
|
if(yearFrom) {
|
1127 |
|
|
selectedFromValue = yearFrom;
|
1128 |
|
|
}
|
1129 |
|
|
if(yearTo) {
|
1130 |
|
|
selectedToValue = yearTo;
|
1131 |
|
|
}
|
1132 |
|
|
if(yearFrom || yearTo) {
|
1133 |
|
|
|
1134 |
|
|
// if (value.length <= 14) {
|
1135 |
|
|
// if(Dates.isValidYear(value.substring(5, 9))) {
|
1136 |
|
|
// selectedFromValue = value.substring(5, 9);
|
1137 |
|
|
// }
|
1138 |
|
|
// if(Dates.isValidYear(value.substring(10, 14))) {
|
1139 |
|
|
// selectedToValue = value.substring(10, 14);
|
1140 |
|
|
// }
|
1141 |
|
|
|
1142 |
59180
|
konstantin
|
/*if(this.rangeFields[i][0] == this.rangeFields[i][1]) {
|
1143 |
58105
|
konstantin
|
//console.log(selectedFromValue + " - "+selectedToValue);
|
1144 |
|
|
if (selectedFromValue && selectedToValue) {
|
1145 |
|
|
let equalityOp = this.fieldIdsMap[filterId].equalityOperator;
|
1146 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOp + "\"" + selectedFromValue + " " + selectedToValue + "\"";
|
1147 |
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
1148 |
|
|
} else if (selectedFromValue) {
|
1149 |
|
|
let equalityOp = this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator;
|
1150 |
|
|
if(equalityOp == " = ") {
|
1151 |
|
|
equalityOp = " >= ";
|
1152 |
|
|
}
|
1153 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOp + "\"" + selectedFromValue + "\"";
|
1154 |
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
1155 |
|
|
} else if (selectedToValue) {
|
1156 |
|
|
let equalityOp = this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator;
|
1157 |
|
|
if(equalityOp == " = ") {
|
1158 |
|
|
equalityOp = " <= ";
|
1159 |
|
|
}
|
1160 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOp + "\"" + selectedToValue + "\"";
|
1161 |
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
1162 |
|
|
}
|
1163 |
|
|
} else {
|
1164 |
|
|
let equalityOpFrom = this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator;
|
1165 |
|
|
let equalityOpTo = this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator;
|
1166 |
|
|
|
1167 |
|
|
if (selectedFromValue) {
|
1168 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][0] + equalityOpFrom + "\"" + selectedFromValue + "\"";
|
1169 |
|
|
// fq = "&fq=" + StringUtils.URIEncode(fq);
|
1170 |
|
|
}
|
1171 |
|
|
if (selectedToValue) {
|
1172 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + this.rangeFields[i][1] + equalityOpTo + "\"" + selectedToValue + "\"";
|
1173 |
|
|
// fq = "&fq=" + StringUtils.URIEncode(fq);
|
1174 |
|
|
}
|
1175 |
|
|
if(selectedFromValue || selectedToValue) {
|
1176 |
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
1177 |
|
|
}
|
1178 |
59180
|
konstantin
|
}*/
|
1179 |
|
|
fq = NewSearchPageComponent.createRangeFilterQuery(this.rangeFields[i], selectedFromValue, selectedToValue, this.fieldIdsMap[filterId].equalityOperator, this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator, this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator, filterOp );
|
1180 |
58105
|
konstantin
|
}
|
1181 |
|
|
}
|
1182 |
|
|
}
|
1183 |
|
|
allFqs += fq +fqFrom + fqTo;
|
1184 |
|
|
}
|
1185 |
|
|
}
|
1186 |
|
|
|
1187 |
|
|
return allFqs;
|
1188 |
|
|
|
1189 |
|
|
}
|
1190 |
59180
|
konstantin
|
// createRangeFilterQuery(this.rangeFields[i], selectedFromValue, selectedToValue, this.fieldIdsMap[this.rangeFields[i][0]].equalityOperator, this.fieldIdsMap[this.rangeFields[i][1]].equalityOperator; filterOp )
|
1191 |
|
|
public static createRangeFilterQuery(rangeField,selectedFromValue, selectedToValue, equalityOp, equalityOpFrom, equalityOpTo, filterOp ){
|
1192 |
|
|
let fq="";
|
1193 |
|
|
if(rangeField[0] == rangeField[1]) {
|
1194 |
|
|
//console.log(selectedFromValue + " - "+selectedToValue);
|
1195 |
|
|
if (selectedFromValue && selectedToValue) {
|
1196 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOp + "\"" + selectedFromValue + " " + selectedToValue + "\"";
|
1197 |
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
1198 |
|
|
} else if (selectedFromValue) {
|
1199 |
|
|
if(equalityOpFrom == " = ") {
|
1200 |
|
|
equalityOpFrom = " >= ";
|
1201 |
|
|
}
|
1202 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOpFrom + "\"" + selectedFromValue + "\"";
|
1203 |
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
1204 |
|
|
} else if (selectedToValue) {
|
1205 |
|
|
if(equalityOpTo == " = ") {
|
1206 |
|
|
equalityOpTo = " <= ";
|
1207 |
|
|
}
|
1208 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOpTo + "\"" + selectedToValue + "\"";
|
1209 |
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
1210 |
|
|
}
|
1211 |
|
|
} else {
|
1212 |
58105
|
konstantin
|
|
1213 |
59180
|
konstantin
|
if (selectedFromValue) {
|
1214 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[0] + equalityOpFrom + "\"" + selectedFromValue + "\"";
|
1215 |
|
|
// fq = "&fq=" + StringUtils.URIEncode(fq);
|
1216 |
|
|
}
|
1217 |
|
|
if (selectedToValue) {
|
1218 |
|
|
fq += (fq.length > 0 ? " " + filterOp + " " : "") + rangeField[1] + equalityOpTo + "\"" + selectedToValue + "\"";
|
1219 |
|
|
// fq = "&fq=" + StringUtils.URIEncode(fq);
|
1220 |
|
|
}
|
1221 |
|
|
if(selectedFromValue || selectedToValue) {
|
1222 |
|
|
fq = "&fq=" + StringUtils.URIEncode(fq);
|
1223 |
|
|
}
|
1224 |
|
|
|
1225 |
|
|
}
|
1226 |
|
|
return fq;
|
1227 |
|
|
}
|
1228 |
58105
|
konstantin
|
/**
|
1229 |
58055
|
argiro.kok
|
* Sets parameterNames and parameterValues arrays
|
1230 |
|
|
* used in paging, advanced search link, Goto()
|
1231 |
|
|
* @param filters either query filters or filters defined by the URL parameters
|
1232 |
58105
|
konstantin
|
* @param rangeFilters defined by the URL parameters
|
1233 |
58055
|
argiro.kok
|
* @param includePage
|
1234 |
58045
|
argiro.kok
|
*/
|
1235 |
58105
|
konstantin
|
buildPageURLParameters(filters:Filter[], rangeFilters: RangeFilter[], includePage: boolean) {
|
1236 |
56649
|
k.triantaf
|
this.parameterNames.splice(0, this.parameterNames.length);
|
1237 |
|
|
this.parameterValues.splice(0, this.parameterValues.length);
|
1238 |
|
|
for (var i = 0; i < this.selectedFields.length; i++) {
|
1239 |
58173
|
argiro.kok
|
//default operator is and
|
1240 |
|
|
this.parameterNames.push("f"+i);
|
1241 |
|
|
this.parameterValues.push(this.selectedFields[i].id + (this.selectedFields[i].operatorId!='and'?(","+this.selectedFields[i].operatorId):''));
|
1242 |
|
|
this.parameterNames.push("fv"+i);
|
1243 |
|
|
if (this.selectedFields[i].type == "date") {
|
1244 |
|
|
|
1245 |
|
|
if (this.selectedFields[i].dateValue.type == "range") {
|
1246 |
|
|
this.parameterValues.push(StringUtils.URIEncode("range" + Dates.getDateToString(this.selectedFields[i].dateValue.from) + ":" + Dates.getDateToString(this.selectedFields[i].dateValue.to)));
|
1247 |
56649
|
k.triantaf
|
} else {
|
1248 |
58173
|
argiro.kok
|
this.parameterValues.push(StringUtils.URIEncode(this.selectedFields[i].dateValue.type));
|
1249 |
50169
|
argiro.kok
|
}
|
1250 |
|
|
|
1251 |
58173
|
argiro.kok
|
} else {
|
1252 |
58348
|
argiro.kok
|
// console.log(this.selectedFields[i].value +" " + StringUtils.URIEncode(this.selectedFields[i].value))
|
1253 |
58173
|
argiro.kok
|
this.parameterValues.push(StringUtils.URIEncode(this.selectedFields[i].value));
|
1254 |
50169
|
argiro.kok
|
}
|
1255 |
|
|
}
|
1256 |
59180
|
konstantin
|
if (includePage) {
|
1257 |
58055
|
argiro.kok
|
this.parameterNames.push("page");
|
1258 |
|
|
this.parameterValues.push("" + this.searchUtils.page);
|
1259 |
50169
|
argiro.kok
|
}
|
1260 |
53919
|
konstantin
|
|
1261 |
59180
|
konstantin
|
//if (this.searchUtils.size != this.resultsPerPage) {
|
1262 |
|
|
if (this.resultsPerPageChanged) {
|
1263 |
53919
|
konstantin
|
this.parameterNames.push("size");
|
1264 |
59180
|
konstantin
|
//this.parameterValues.push("" + this.searchUtils.size);
|
1265 |
|
|
this.parameterValues.push("" + this.resultsPerPageChanged);
|
1266 |
53919
|
konstantin
|
}
|
1267 |
|
|
|
1268 |
59180
|
konstantin
|
//if (this.sort && this.searchUtils.sortBy) {
|
1269 |
|
|
if (this.sort && this.sortByChanged) {
|
1270 |
53937
|
konstantin
|
this.parameterNames.push("sortBy");
|
1271 |
59180
|
konstantin
|
//this.parameterValues.push(this.searchUtils.sortBy);
|
1272 |
|
|
this.parameterValues.push(this.sortedByChanged);
|
1273 |
53937
|
konstantin
|
}
|
1274 |
58055
|
argiro.kok
|
for (let filter of filters) {
|
1275 |
58045
|
argiro.kok
|
var filterLimits = "";
|
1276 |
|
|
if (filter.countSelectedValues > 0) {
|
1277 |
|
|
for (let value of filter.values) {
|
1278 |
|
|
if (value.selected == true) {
|
1279 |
|
|
filterLimits += ((filterLimits.length == 0) ? '' : ',') + '"' + (value.id) + '"';
|
1280 |
50169
|
argiro.kok
|
}
|
1281 |
56649
|
k.triantaf
|
}
|
1282 |
58045
|
argiro.kok
|
if (filterLimits.length > 0) {
|
1283 |
|
|
this.parameterNames.push(filter.filterId);
|
1284 |
|
|
this.parameterValues.push(filterLimits);
|
1285 |
|
|
}
|
1286 |
50169
|
argiro.kok
|
}
|
1287 |
|
|
}
|
1288 |
58105
|
konstantin
|
for (let filter of rangeFilters) {
|
1289 |
|
|
var filterLimits = "";
|
1290 |
|
|
let yearFrom: string = (Dates.isValidYear(filter.selectedFromValue) ? filter.selectedFromValue : null);
|
1291 |
|
|
let yearTo: string = (Dates.isValidYear(filter.selectedToValue) ? filter.selectedToValue : null);
|
1292 |
|
|
if(yearFrom || yearTo) {
|
1293 |
|
|
this.parameterNames.push(filter.filterId);
|
1294 |
|
|
this.parameterValues.push("range" + (yearFrom ? yearFrom : "") + ":" + (yearTo ? yearTo : ""));
|
1295 |
|
|
}
|
1296 |
|
|
// if (filter.countSelectedValues > 0) {
|
1297 |
|
|
// for (let value of filter.values) {
|
1298 |
|
|
// if (value.selected == true) {
|
1299 |
|
|
// filterLimits += ((filterLimits.length == 0) ? '' : ',') + '"' + (value.id) + '"';
|
1300 |
|
|
// }
|
1301 |
|
|
// }
|
1302 |
|
|
// if (filterLimits.length > 0) {
|
1303 |
|
|
// this.parameterNames.push(filter.filterId);
|
1304 |
|
|
// this.parameterValues.push(filterLimits);
|
1305 |
|
|
// }
|
1306 |
|
|
// }
|
1307 |
|
|
}
|
1308 |
58045
|
argiro.kok
|
if (this.searchUtils.keyword.length > 0) {
|
1309 |
|
|
this.parameterNames.push("keyword");
|
1310 |
|
|
this.parameterValues.push(this.searchUtils.keyword);
|
1311 |
56059
|
argiro.kok
|
}
|
1312 |
50169
|
argiro.kok
|
|
1313 |
58072
|
argiro.kok
|
if (this.resultTypes && this.entityType == "result") {
|
1314 |
|
|
let values = [];
|
1315 |
|
|
if (this.resultTypes.publication) {
|
1316 |
|
|
values.push("publications");
|
1317 |
|
|
}
|
1318 |
|
|
if (this.resultTypes.dataset) {
|
1319 |
|
|
values.push("datasets");
|
1320 |
|
|
}
|
1321 |
|
|
if (this.resultTypes.software) {
|
1322 |
|
|
values.push("software");
|
1323 |
|
|
}
|
1324 |
|
|
if (this.resultTypes.other) {
|
1325 |
|
|
values.push("other");
|
1326 |
|
|
}
|
1327 |
59180
|
konstantin
|
this.selectedTypesNum = 0;
|
1328 |
|
|
if (values.length > 0 && values.length != 4) {
|
1329 |
58072
|
argiro.kok
|
this.parameterNames.push("type");
|
1330 |
|
|
this.parameterValues.push(values.join(","));
|
1331 |
59180
|
konstantin
|
this.selectedTypesNum = values.length;
|
1332 |
58072
|
argiro.kok
|
}
|
1333 |
|
|
if(this.quickFilter) {
|
1334 |
|
|
this.parameterNames.push("qf");
|
1335 |
|
|
this.parameterValues.push("" + this.quickFilter.selected);
|
1336 |
|
|
}
|
1337 |
|
|
}
|
1338 |
59180
|
konstantin
|
if(this.customFilterEnabled){
|
1339 |
|
|
this.parameterNames.push("cf");
|
1340 |
|
|
this.parameterValues.push("true");
|
1341 |
|
|
}
|
1342 |
58055
|
argiro.kok
|
// if (this.searchUtils.size != this.resultsPerPage) {
|
1343 |
|
|
// // allLimits += ((allLimits.length == 0) ? '?' : '&') + 'size=' + this.searchUtils.size;
|
1344 |
|
|
// this.parameterNames.push("size");
|
1345 |
|
|
// this.parameterValues.push("" + this.searchUtils.size);
|
1346 |
|
|
// }
|
1347 |
|
|
// if (this.sort && this.searchUtils.sortBy) {
|
1348 |
|
|
// // allLimits += ((allLimits.length == 0) ? '?' : '&') + 'sortBy=' + this.searchUtils.sortBy;
|
1349 |
|
|
// this.parameterNames.push("sortBy");
|
1350 |
|
|
// this.parameterValues.push(this.searchUtils.sortBy);
|
1351 |
|
|
// }
|
1352 |
58156
|
argiro.kok
|
// console.log(this.parameterNames)
|
1353 |
|
|
// console.log(this.parameterValues)
|
1354 |
50169
|
argiro.kok
|
}
|
1355 |
58055
|
argiro.kok
|
|
1356 |
|
|
/**
|
1357 |
|
|
* create filters based on URL params
|
1358 |
|
|
* @param URLparams
|
1359 |
|
|
*/
|
1360 |
|
|
getRefineFiltersFromURL(URLparams) {
|
1361 |
58052
|
argiro.kok
|
let fields = new SearchFields();
|
1362 |
|
|
let filters: Filter[] = [];
|
1363 |
|
|
for (let i = 0; i < this.refineFields.length; i++) {
|
1364 |
|
|
let filterId = this.refineFields[i];
|
1365 |
|
|
if (URLparams[filterId] != undefined) {
|
1366 |
|
|
let filter = new Filter();
|
1367 |
58073
|
argiro.kok
|
filter.title = fields.getFieldName(filterId, this.entityType);
|
1368 |
58052
|
argiro.kok
|
filter.filterId = filterId;
|
1369 |
|
|
filter.originalFilterId = filterId;
|
1370 |
|
|
filter.values = [];
|
1371 |
|
|
let values = StringUtils.URIDecode(URLparams[filterId]).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
1372 |
|
|
for (let value of values) {
|
1373 |
56649
|
k.triantaf
|
|
1374 |
58052
|
argiro.kok
|
let v: Value = new Value();
|
1375 |
|
|
v.name = RefineResultsUtils.keepPartAfterCharacters(StringUtils.unquote(value), "||");
|
1376 |
59180
|
konstantin
|
v.name = (v.name.indexOf("::")!=-1)?v.name.substring(v.name.indexOf("::")+2).split("::").join("|"):v.name; // for funding streams
|
1377 |
58052
|
argiro.kok
|
v.id = StringUtils.unquote(value);
|
1378 |
|
|
v.selected = true;
|
1379 |
|
|
filter.values.push(v);
|
1380 |
|
|
// console.log(v)
|
1381 |
|
|
filter.countSelectedValues++;
|
1382 |
|
|
}
|
1383 |
|
|
filters.push(filter)
|
1384 |
|
|
}
|
1385 |
|
|
}
|
1386 |
58072
|
argiro.kok
|
|
1387 |
|
|
if (this.quickFilter) {
|
1388 |
|
|
if (this.entityType == "result" && (URLparams[this.quickFilter.filterId] == undefined) && (URLparams["qf"] == undefined || URLparams["qf"] == "true")) {
|
1389 |
|
|
let filter = new Filter();
|
1390 |
58105
|
konstantin
|
filter.title = fields.getFieldName(this.quickFilter.filterId, this.entityType);
|
1391 |
58072
|
argiro.kok
|
filter.filterId = this.quickFilter.filterId;
|
1392 |
|
|
filter.originalFilterId = this.quickFilter.filterId;
|
1393 |
|
|
filter.values = [];
|
1394 |
|
|
let v: Value = new Value();
|
1395 |
|
|
v.name = this.quickFilter.value;
|
1396 |
|
|
v.id = this.quickFilter.value;
|
1397 |
|
|
v.selected = true;
|
1398 |
|
|
filter.values.push(v);
|
1399 |
|
|
filter.countSelectedValues = 1;
|
1400 |
|
|
filters.push(filter)
|
1401 |
|
|
}
|
1402 |
|
|
}
|
1403 |
|
|
if (this.entityType == "result") {
|
1404 |
|
|
this.resultTypes = null;
|
1405 |
|
|
this.resultTypes = {
|
1406 |
|
|
|
1407 |
|
|
};
|
1408 |
|
|
|
1409 |
|
|
if (URLparams["type"]) {
|
1410 |
|
|
|
1411 |
|
|
this.resultTypes['publication'] = (URLparams["type"].split(",").indexOf("publications") != -1);
|
1412 |
|
|
this.resultTypes['dataset'] = (URLparams["type"].split(",").indexOf("datasets") != -1);
|
1413 |
|
|
this.resultTypes['software'] = (URLparams["type"].split(",").indexOf("software") != -1);
|
1414 |
|
|
this.resultTypes['other'] = (URLparams["type"].split(",").indexOf("other") != -1);
|
1415 |
|
|
|
1416 |
|
|
} else {
|
1417 |
59180
|
konstantin
|
this.resultTypes['publication'] = false;
|
1418 |
|
|
this.resultTypes['dataset'] = false;
|
1419 |
|
|
this.resultTypes['software'] = false;
|
1420 |
|
|
this.resultTypes['other'] = false;
|
1421 |
58072
|
argiro.kok
|
}
|
1422 |
|
|
|
1423 |
|
|
}
|
1424 |
|
|
|
1425 |
58055
|
argiro.kok
|
this.URLCreatedFilters = filters;
|
1426 |
58052
|
argiro.kok
|
}
|
1427 |
|
|
|
1428 |
|
|
/**
|
1429 |
58105
|
konstantin
|
* create range filters based on URL params
|
1430 |
|
|
* @param URLparams
|
1431 |
|
|
*/
|
1432 |
|
|
getRangeFiltersFromURL(URLparams) {
|
1433 |
|
|
let fields = new SearchFields();
|
1434 |
|
|
let filters: RangeFilter[] = [];
|
1435 |
|
|
for (let i = 0; i < this.rangeFields.length; i++) {
|
1436 |
|
|
let filterId = this.rangeFields[i][0]+"-range-"+this.rangeFields[i][1];
|
1437 |
|
|
let filterParam = fields.getFieldParam(filterId, this.entityType);
|
1438 |
|
|
//console.log("rangeFilter (from url): filterId - filterParam");
|
1439 |
|
|
//console.log(filterId + " - "+ filterParam);
|
1440 |
|
|
if (URLparams[filterParam] != undefined) {
|
1441 |
|
|
let filter = new RangeFilter();
|
1442 |
|
|
filter.title = fields.getFieldName(filterId, this.entityType);
|
1443 |
|
|
filter.filterId = filterParam;
|
1444 |
|
|
filter.originalFilterIdFrom = this.rangeFields[i][0];
|
1445 |
|
|
filter.originalFilterIdTo = this.rangeFields[i][1];
|
1446 |
|
|
|
1447 |
|
|
|
1448 |
|
|
let values = (decodeURIComponent(URLparams[filterParam])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, -1);
|
1449 |
|
|
for (let j = 0; j < values.length; j++) {
|
1450 |
|
|
if (this.fieldIdsMap[filterId].filterType == "range") {
|
1451 |
|
|
let value: string = StringUtils.unquote(values[j]);
|
1452 |
|
|
let validDates: boolean = true;
|
1453 |
|
|
// if (value.length < 14) {
|
1454 |
|
|
// validDates = false;
|
1455 |
|
|
// } else {
|
1456 |
|
|
// if (!Dates.isValidYear(value.substring(5, 9)) || !Dates.isValidYear(value.substring(10, 14))) {
|
1457 |
|
|
// validDates = false;
|
1458 |
|
|
// } else {
|
1459 |
|
|
// filter.selectedFromValue = value.substring(5, 9);
|
1460 |
|
|
// filter.selectedToValue = value.substring(10, 14);
|
1461 |
|
|
// }
|
1462 |
|
|
// }
|
1463 |
|
|
let years: string[] = (value.substring(5)).split(":");
|
1464 |
|
|
let yearFrom: string = (Dates.isValidYear(years[0]) ? years[0] : null);
|
1465 |
|
|
let yearTo: string = (Dates.isValidYear(years[1]) ? years[1] : null);
|
1466 |
|
|
//console.log("getRangeFiltersFromURL: yearFrom: " + yearFrom + " - yearTo: "+yearTo);
|
1467 |
|
|
if(yearFrom) {
|
1468 |
|
|
filter.selectedFromValue = yearFrom;
|
1469 |
|
|
//filter.selectedFromAndToValues = yearFrom;
|
1470 |
|
|
}
|
1471 |
|
|
/*if(yearFrom && yearTo) {
|
1472 |
|
|
filter.selectedFromAndToValues += "-";
|
1473 |
|
|
}*/
|
1474 |
|
|
if(yearTo) {
|
1475 |
|
|
filter.selectedToValue = yearTo;
|
1476 |
|
|
//filter.selectedFromAndToValues += yearTo;
|
1477 |
|
|
}
|
1478 |
|
|
//console.log("filter.selectedFromAndToValues: "+filter.selectedFromAndToValues);
|
1479 |
|
|
if(!yearFrom && !yearTo) {
|
1480 |
|
|
validDates = false;
|
1481 |
|
|
}
|
1482 |
|
|
|
1483 |
|
|
}
|
1484 |
|
|
}
|
1485 |
|
|
//console.log(filters);
|
1486 |
|
|
filters.push(filter)
|
1487 |
|
|
}
|
1488 |
|
|
}
|
1489 |
|
|
// console.log("Empty Filters");
|
1490 |
|
|
// console.log(filters);
|
1491 |
|
|
this.URLCreatedRangeFilters = filters;
|
1492 |
|
|
// return filters;
|
1493 |
|
|
|
1494 |
|
|
}
|
1495 |
|
|
|
1496 |
|
|
/**
|
1497 |
58052
|
argiro.kok
|
* Checks if query has no results, display Filters from URL parameters
|
1498 |
|
|
* Mark checked the selected filters
|
1499 |
|
|
* Count the checked
|
1500 |
|
|
* @param filters
|
1501 |
|
|
*/
|
1502 |
58354
|
argiro.kok
|
public prepareFiltersToShow(filters: Filter[], totalResults): Filter[] {
|
1503 |
|
|
if (this.URLCreatedFilters.length > 0 && totalResults == 0) {
|
1504 |
58052
|
argiro.kok
|
this.showUnknownFilters = true;
|
1505 |
58055
|
argiro.kok
|
this.filters = this.URLCreatedFilters;
|
1506 |
58354
|
argiro.kok
|
} else if (totalResults != 0) {
|
1507 |
58052
|
argiro.kok
|
this.showUnknownFilters = false;
|
1508 |
|
|
this.filters = filters;
|
1509 |
59180
|
konstantin
|
}else if((this.URLCreatedFilters.length == 0 && totalResults == 0)){
|
1510 |
|
|
this.showUnknownFilters = true;
|
1511 |
|
|
this.filters = filters;
|
1512 |
58052
|
argiro.kok
|
}
|
1513 |
59180
|
konstantin
|
|
1514 |
58105
|
konstantin
|
this.buildPageURLParameters(this.URLCreatedFilters, this.URLCreatedRangeFilters, true);
|
1515 |
|
|
//this.checkSelectedRangeFilters(this.rangeFilters);
|
1516 |
|
|
|
1517 |
58052
|
argiro.kok
|
this.checkSelectedFilters(this.filters);
|
1518 |
|
|
this.countSelectedFilters(this.filters);
|
1519 |
|
|
return this.filters;
|
1520 |
|
|
}
|
1521 |
|
|
|
1522 |
58055
|
argiro.kok
|
/**
|
1523 |
58105
|
konstantin
|
* Mark checked the selected range filters
|
1524 |
|
|
*/
|
1525 |
|
|
public prepareRangeFiltersToShow() {
|
1526 |
|
|
this.rangeFilters = RangeFilter.parse(this.rangeFields, this.entityType); // OK
|
1527 |
|
|
|
1528 |
|
|
//this.buildPageURLRangeParameters(this.rangeFilters, true);
|
1529 |
|
|
this.checkSelectedRangeFilters(this.rangeFilters);
|
1530 |
|
|
this.countSelectedRangeFilters(this.rangeFilters);
|
1531 |
|
|
return this.rangeFilters;
|
1532 |
|
|
}
|
1533 |
|
|
|
1534 |
|
|
/**
|
1535 |
58055
|
argiro.kok
|
* Used to set the variables and search page, and prepare it before the getResults query
|
1536 |
|
|
* @param fieldIds
|
1537 |
|
|
* @param selectedFields
|
1538 |
|
|
* @param refineFields
|
1539 |
58244
|
argiro.kok
|
* @param rangeFields
|
1540 |
58055
|
argiro.kok
|
* @param fieldIdsMap
|
1541 |
|
|
* @param customFilter
|
1542 |
|
|
* @param params
|
1543 |
58244
|
argiro.kok
|
* @param entityType
|
1544 |
|
|
* @param quickFilter
|
1545 |
58055
|
argiro.kok
|
*/
|
1546 |
58105
|
konstantin
|
prepareSearchPage(fieldIds, selectedFields, refineFields, rangeFields, fieldIdsMap, customFilter, params, entityType, quickFilter=null){
|
1547 |
58348
|
argiro.kok
|
// console.log(this.refineFields);
|
1548 |
58072
|
argiro.kok
|
this.entityType = entityType;
|
1549 |
|
|
this.fieldIds = fieldIds;
|
1550 |
|
|
this.selectedFields = selectedFields;
|
1551 |
|
|
this.refineFields = refineFields;
|
1552 |
58105
|
konstantin
|
this.rangeFields = rangeFields;
|
1553 |
58072
|
argiro.kok
|
this.fieldIdsMap = fieldIdsMap;
|
1554 |
|
|
this.customFilter = customFilter;
|
1555 |
58093
|
argiro.kok
|
this.quickFilter = quickFilter;
|
1556 |
58105
|
konstantin
|
this.getRangeFiltersFromURL(params);
|
1557 |
58072
|
argiro.kok
|
this.getRefineFiltersFromURL(params);
|
1558 |
|
|
this.createAdvancedSearchSelectedFiltersFromURLParameters(params);
|
1559 |
|
|
}
|
1560 |
59180
|
konstantin
|
|
1561 |
|
|
removeResultType(type){
|
1562 |
|
|
if(this.resultTypes && this.resultTypes[type]){
|
1563 |
|
|
this.resultTypes[type]=false;
|
1564 |
|
|
this.goTo(1);
|
1565 |
|
|
}
|
1566 |
|
|
}
|
1567 |
50169
|
argiro.kok
|
}
|