Revision 55570
Added by Argiro Kokogiannaki almost 5 years ago
searchPage.component.ts | ||
---|---|---|
1 | 1 |
import {Component, Input} from '@angular/core'; |
2 | 2 |
import {ViewChild, Output} from '@angular/core'; |
3 |
import {EventEmitter,ElementRef} from '@angular/core';
|
|
3 |
import {EventEmitter} from '@angular/core'; |
|
4 | 4 |
import {Location} from '@angular/common'; |
5 | 5 |
import {Router, ActivatedRoute} from '@angular/router'; |
6 | 6 |
import {Title, Meta} from '@angular/platform-browser'; |
7 | 7 |
|
8 |
import {Observable} from 'rxjs/Observable'; |
|
9 |
|
|
10 | 8 |
import {Filter, Value} from './searchHelperClasses.class'; |
11 |
import {SearchResult} from '../../utils/entities/searchResult'; |
|
12 |
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields'; |
|
9 |
import {SearchFields} from '../../utils/properties/searchFields'; |
|
13 | 10 |
import {SearchUtilsClass} from './searchUtils.class'; |
14 | 11 |
import {DOI, StringUtils} from '../../utils/string-utils.class'; |
12 |
import {RouterHelper} from '../../utils/routerHelper.class'; |
|
15 | 13 |
import {ModalLoading} from '../../utils/modal/loading.component'; |
16 |
import {SearchFilterComponent} from './searchFilter.component'; |
|
17 |
import {SearchFilterModalComponent} from './searchFilterModal.component'; |
|
18 | 14 |
import {ErrorCodes} from '../../utils/properties/errorCodes'; |
19 | 15 |
import {PiwikService} from '../../utils/piwik/piwik.service'; |
20 | 16 |
import {EnvProperties} from '../../utils/properties/env-properties'; |
21 |
import { SEOService } from '../../sharedComponents/SEO/SEO.service'; |
|
17 |
import { SEOService } from '../../sharedComponents/SEO/SEO.service'; |
|
18 |
import {HelperFunctions} from "../../utils/HelperFunctions.class"; |
|
22 | 19 |
|
23 | 20 |
@Component({ |
24 | 21 |
selector: 'search-page', |
... | ... | |
55 | 52 |
@Input() mapUrl: string = ""; |
56 | 53 |
@Input() mapTooltipType: string ="content providers"; |
57 | 54 |
@Input() newQueryButton: boolean = true; |
55 |
@Input() lastIndex: boolean = true; |
|
56 |
@Input() hasPrefix: boolean = true; |
|
58 | 57 |
//@Input() sortBy: string = ""; |
59 | 58 |
@ViewChild (ModalLoading) loading : ModalLoading ; |
60 | 59 |
public fieldIdsMap;//: { [key:string]:{ name:string, operator:string, type:string, indexField:string, equalityOperator:string }}; |
... | ... | |
70 | 69 |
// public currentFilter: Filter; |
71 | 70 |
public csvLimit: number = 0; |
72 | 71 |
public pagingLimit: number = 0; |
73 |
public resultsPerPage: number = 0; |
|
72 |
public resultsPerPage: number = 10;
|
|
74 | 73 |
public isPiwikEnabled; |
75 | 74 |
properties:EnvProperties; |
75 |
public routerHelper:RouterHelper = new RouterHelper(); |
|
76 | 76 |
public errorCodes:ErrorCodes = new ErrorCodes(); |
77 | 77 |
|
78 | 78 |
constructor (private route: ActivatedRoute, |
79 | 79 |
private location: Location, |
80 | 80 |
private _meta: Meta, |
81 | 81 |
private _title: Title, |
82 |
private element: ElementRef, |
|
83 | 82 |
private _piwikService:PiwikService, |
84 | 83 |
private router: Router, |
85 | 84 |
private seoService: SEOService) { |
... | ... | |
91 | 90 |
.subscribe((data: { envSpecific: EnvProperties }) => { |
92 | 91 |
this.properties = data.envSpecific; |
93 | 92 |
this.pagingLimit = data.envSpecific.pagingLimit; |
94 |
this.resultsPerPage =data.envSpecific.resultsPerPage; |
|
95 | 93 |
this.csvLimit = data.envSpecific.csvLimit; |
96 | 94 |
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack; |
97 | 95 |
if(typeof window !== 'undefined') { |
... | ... | |
101 | 99 |
this.piwiksub = this._piwikService.trackView(this.properties, this.pageTitle, this.piwikSiteId).subscribe(); |
102 | 100 |
} |
103 | 101 |
}); |
104 |
if (typeof document !== 'undefined') { |
|
105 |
this.element.nativeElement.scrollIntoView(); |
|
106 |
} |
|
102 |
HelperFunctions.scroll(); |
|
103 |
|
|
107 | 104 |
// this.updateBaseUrlWithParameters(this.filters); |
108 | 105 |
this.updateTitle(this.pageTitle); |
109 | 106 |
var description = "Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle; |
110 | 107 |
this.updateDescription(description); |
111 | 108 |
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this.router.url,false); |
112 | 109 |
} |
113 |
ngAfterViewChecked(){ |
|
114 | 110 |
|
115 |
} |
|
116 | 111 |
ngOnDestroy() { |
117 | 112 |
if(this.piwiksub){ |
118 | 113 |
this.piwiksub.unsubscribe(); |
119 | 114 |
} |
120 | 115 |
} |
121 |
// toggleModal($event) { |
|
122 |
// this.currentFilter = $event.value; |
|
123 |
// //this.searchFilterModal.open(); |
|
124 |
// } |
|
125 | 116 |
|
117 |
|
|
126 | 118 |
updateDescription(description:string) { |
127 | 119 |
this._meta.updateTag({content:description},"name='description'"); |
128 | 120 |
this._meta.updateTag({content:description},"property='og:description'"); |
129 | 121 |
} |
122 |
|
|
130 | 123 |
updateTitle(title:string) { |
131 |
var _prefix ="OpenAIRE | "; |
|
132 |
var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title); |
|
124 |
let _title: string; |
|
125 |
if(this.hasPrefix) { |
|
126 |
let _prefix ="OpenAIRE | "; |
|
127 |
_title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title); |
|
128 |
} else { |
|
129 |
_title = ((title.length > 50) ? title.substring(0, 50) : title); |
|
130 |
} |
|
133 | 131 |
this._title.setTitle(_title); |
134 | 132 |
this._meta.updateTag({content:_title},"property='og:title'"); |
135 | 133 |
} |
134 |
|
|
136 | 135 |
updateUrl(url:string) { |
137 | 136 |
this._meta.updateTag({content:url},"property='og:url'"); |
138 | 137 |
} |
139 | 138 |
|
139 |
public getQueryParamsFromUrl(params) { |
|
140 |
this.queryParameters = new Map<string,string>(); |
|
141 |
for(let i=0; i< this.refineFields.length ; i++) { |
|
142 |
let filterId = this.refineFields[i]; |
|
143 |
if (params[filterId] != undefined) { |
|
144 |
this.queryParameters.set(filterId, StringUtils.URIDecode(params[filterId])); |
|
145 |
} |
|
146 |
} |
|
147 |
return this.queryParameters; |
|
148 |
} |
|
149 |
|
|
140 | 150 |
public getQueryParametersFromUrl(params){ // called by ngOnInit function of search find pages |
141 | 151 |
// var parameters = ""; |
142 | 152 |
var allFqs = ""; |
... | ... | |
359 | 369 |
if(this.searchUtils.page != 1 && includePage){ |
360 | 370 |
allLimits+=((allLimits.length == 0)?'?':'&') + 'page=' + this.searchUtils.page; |
361 | 371 |
} |
362 |
if(this.searchUtils.size != 10) {
|
|
372 |
if(this.searchUtils.size != this.resultsPerPage) {
|
|
363 | 373 |
allLimits+=((allLimits.length == 0)?'?':'&') + 'size=' + this.searchUtils.size; |
364 | 374 |
this.parameterNames.push("size"); |
365 | 375 |
this.parameterValues.push(""+this.searchUtils.size); |
... | ... | |
523 | 533 |
//console.info("queryParams : "+queryParameters); |
524 | 534 |
var indexQuery = this.createIndexQueryParameters(this.filters); |
525 | 535 |
|
526 |
this.location.go(location.pathname,urlParameters); |
|
536 |
//this.location.go(location.pathname,urlParameters); |
|
537 |
this.router.navigate( [this.baseUrl], { queryParams: this.routerHelper.createQueryParams(this.parameterNames, this.parameterValues) } ); |
|
538 |
|
|
527 | 539 |
/* Code For Piwik*/ |
528 | 540 |
if (typeof localStorage !== 'undefined') { |
529 | 541 |
localStorage.setItem('previousRoute', this.router.url); |
... | ... | |
534 | 546 |
/* End Piwik Code */ |
535 | 547 |
this.queryChange.emit({ |
536 | 548 |
value: queryParameters, |
537 |
index:indexQuery |
|
538 |
|
|
549 |
index:indexQuery,
|
|
550 |
params: this.queryParameters |
|
539 | 551 |
}); |
540 |
if (typeof document !== 'undefined') { |
|
541 |
this.element.nativeElement.scrollIntoView(); |
|
542 |
} |
|
552 |
HelperFunctions.scroll(); |
|
543 | 553 |
} |
544 | 554 |
filterChanged($event){ |
545 | 555 |
this.goTo(1); |
Also available in: Unified diff
[Library|newlinking]
Merging trunk|library into branch newlinking 55132:55568