1
|
import {Component, Input, ViewChild, Output, EventEmitter, ChangeDetectorRef} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import {Location} from '@angular/common';
|
4
|
import { Filter, Value} from './searchHelperClasses.class';
|
5
|
import {SearchResult} from '../../utils/entities/searchResult';
|
6
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
7
|
import {SearchUtilsClass} from './searchUtils.class';
|
8
|
import {DOI, StringUtils} from '../../utils/string-utils.class';
|
9
|
import {ModalLoading} from '../../utils/modal/loading.component';
|
10
|
import { Meta} from '../../../angular2-meta';
|
11
|
import{SearchFilterComponent} from './searchFilter.component';
|
12
|
import {SearchFilterModalComponent} from './searchFilterModal.component';
|
13
|
import { ErrorCodes} from '../../utils/properties/openaireProperties';
|
14
|
import {OpenaireProperties} from '../../utils/properties/openaireProperties';
|
15
|
import {ContentProvidersDatatablePipe} from '../../utils/pipes/contentProvidersDatatable.pipe';
|
16
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
17
|
|
18
|
@Component({
|
19
|
selector: 'search-page-table',
|
20
|
templateUrl:'searchPageTableView.component.html'
|
21
|
})
|
22
|
export class SearchPageTableViewComponent {
|
23
|
@Input() pageTitle = "";
|
24
|
@Input() results;
|
25
|
@Input() filters = [];
|
26
|
@Input() type:string = "";
|
27
|
@Input() entityType: string = "";
|
28
|
@Input() searchUtils:SearchUtilsClass;// = new SearchUtilsClass();
|
29
|
//@Output() downloadClick = new EventEmitter();
|
30
|
@Input() showResultCount:boolean = true;
|
31
|
@Input() showRefine:boolean = true;
|
32
|
@Input() refineFields = [];
|
33
|
//@Input() csvParams: string;
|
34
|
//@Input() csvPath: string;
|
35
|
@Input() searchViewLink: string;
|
36
|
@Input() disableForms: boolean = false;
|
37
|
@Input() searchFormClass: string = "searchForm";
|
38
|
@Input() formPlaceholderText = "Type Keywords...";
|
39
|
@ViewChild (ModalLoading) loading : ModalLoading ;
|
40
|
private searchFieldsHelper:SearchFields = new SearchFields();
|
41
|
private queryParameters: Map<string, string> = new Map<string,string>();
|
42
|
private sub: any;
|
43
|
public countFilters= 0;
|
44
|
public parameterNames:string[] =[];
|
45
|
public parameterValues:string[] =[];
|
46
|
|
47
|
public triggerPipe: boolean = false;
|
48
|
|
49
|
public rowsOnPage:number = 10;
|
50
|
@ViewChild('mf') table: any;//DataTable;
|
51
|
|
52
|
@ViewChild (SearchFilterModalComponent) searchFilterModal : SearchFilterModalComponent ;
|
53
|
public currentFilter: Filter;
|
54
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
55
|
piwiksub: any;
|
56
|
|
57
|
constructor (private location: Location , private _meta: Meta, private _piwikService:PiwikService, public cd: ChangeDetectorRef) { }
|
58
|
|
59
|
ngOnInit() {
|
60
|
this.updateTitle(this.pageTitle);
|
61
|
this.updateDescription("Openaire, search, repositories, open access, type, content provider, funder, project, " + this.type + "," +this.pageTitle);
|
62
|
if(typeof window !== 'undefined') {
|
63
|
this.updateUrl(OpenaireProperties.getBaseLink()+location.pathname);
|
64
|
}
|
65
|
if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
|
66
|
this.piwiksub = this._piwikService.trackView(this.pageTitle).subscribe();
|
67
|
}
|
68
|
}
|
69
|
ngOnDestroy() {
|
70
|
if(this.piwiksub){
|
71
|
this.piwiksub.unsubscribe();
|
72
|
}
|
73
|
}
|
74
|
public sortByOrganization = (dataprovider: any) => {
|
75
|
if(dataprovider.organizations && dataprovider.organizations.length > 0) {
|
76
|
return dataprovider.organizations[0].name.toUpperCase();
|
77
|
}
|
78
|
return "-";
|
79
|
}
|
80
|
|
81
|
totalPages(): number {
|
82
|
let totalPages:any = this.searchUtils.totalResults/(this.rowsOnPage);
|
83
|
if(!(Number.isInteger(totalPages))) {
|
84
|
totalPages = (parseInt(totalPages, 10) + 1);
|
85
|
}
|
86
|
return totalPages;
|
87
|
}
|
88
|
|
89
|
refreshTable(page:number) {
|
90
|
this.searchUtils.page=page;
|
91
|
//this.table.mfActivePage=$event.value;
|
92
|
this.table.setPage(this.searchUtils.page, this.rowsOnPage);
|
93
|
}
|
94
|
|
95
|
toggleModal($event) {
|
96
|
this.currentFilter = $event.value;
|
97
|
this.searchFilterModal.open();
|
98
|
}
|
99
|
|
100
|
updateDescription(description:string){
|
101
|
this._meta.updateMeta("description", description);
|
102
|
this._meta.updateProperty("og:description", description);
|
103
|
}
|
104
|
updateTitle(title:string){
|
105
|
var _prefix ="OpenAIRE | ";
|
106
|
var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
|
107
|
this._meta.setTitle(_title );
|
108
|
this._meta.updateProperty("og:title",_title);
|
109
|
}
|
110
|
updateUrl(url:string){
|
111
|
this._meta.updateProperty("og:url", url);
|
112
|
}
|
113
|
|
114
|
public getParametersFromUrl(params) {
|
115
|
for(var i=0; i< this.refineFields.length ; i++) {
|
116
|
var filterId = this.refineFields[i];
|
117
|
if(params[filterId] != undefined) {
|
118
|
if(this.queryParameters == undefined){
|
119
|
this.queryParameters = new Map<string,string>();
|
120
|
}
|
121
|
this.queryParameters[filterId]=decodeURIComponent(params[filterId]);
|
122
|
}
|
123
|
}
|
124
|
}
|
125
|
/*
|
126
|
* Mark as check the new filters that are selected, when you get them from search
|
127
|
*/
|
128
|
public checkSelectedFilters(filters:Filter[]){
|
129
|
|
130
|
this.filters = filters;
|
131
|
for(var i=0; i< filters.length ; i++){
|
132
|
var filter:Filter = filters[i];
|
133
|
filter.countSelectedValues = 0;
|
134
|
|
135
|
if(this.queryParameters[filter.filterId] != undefined) {
|
136
|
let values = (decodeURIComponent(this.queryParameters[filter.filterId])).split(/,(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,-1);
|
137
|
for(let filterValue of filter.values) {
|
138
|
if(values.indexOf(StringUtils.quote(filterValue.id)) > -1) {
|
139
|
filterValue.selected = true;
|
140
|
filter.countSelectedValues++;
|
141
|
}else{
|
142
|
filterValue.selected = false;
|
143
|
}
|
144
|
}
|
145
|
}else{
|
146
|
for(let filterValue of filter.values) {
|
147
|
filterValue.selected = false;
|
148
|
}
|
149
|
}
|
150
|
}
|
151
|
|
152
|
return filters;
|
153
|
}
|
154
|
|
155
|
/*
|
156
|
*
|
157
|
*/
|
158
|
private createUrlParameters(filters:Filter[], includePage:boolean){
|
159
|
var allLimits="";//location.search.slice(1);
|
160
|
this.parameterNames.splice(0,this.parameterNames.length);
|
161
|
this.parameterValues.splice(0,this.parameterValues.length);
|
162
|
|
163
|
for (let filter of filters){
|
164
|
var filterLimits="";
|
165
|
if(filter.countSelectedValues > 0){
|
166
|
for (let value of filter.values){
|
167
|
if(value.selected == true){
|
168
|
filterLimits+=((filterLimits.length == 0)?'':',') +'"'+ StringUtils.URIEncode(value.id)+'"';
|
169
|
}
|
170
|
}
|
171
|
this.queryParameters[filter.filterId]=filterLimits;
|
172
|
if(filterLimits.length > 0){
|
173
|
this.parameterNames.push(filter.filterId);
|
174
|
this.parameterValues.push(filterLimits);
|
175
|
}
|
176
|
allLimits+=(allLimits.length==0?"?":"&")+((filterLimits.length == 0 )?'':filter.filterId + '='+ filterLimits) ;
|
177
|
}
|
178
|
}
|
179
|
if(this.searchUtils.keyword.length > 0 ){
|
180
|
allLimits+=(allLimits.length==0?"?":"&")+'keyword=' + this.searchUtils.keyword;
|
181
|
this.parameterNames.push("keyword");
|
182
|
this.parameterValues.push(this.searchUtils.keyword);
|
183
|
}
|
184
|
|
185
|
//if(this.searchUtils.page != 1 && includePage){
|
186
|
// allLimits+=((allLimits.length == 0)?'?':'&') + 'page=' + this.searchUtils.page;
|
187
|
//}
|
188
|
|
189
|
return allLimits;
|
190
|
}
|
191
|
|
192
|
public isFiltered(){
|
193
|
var filtered=false;
|
194
|
for (let filter of this.filters){
|
195
|
if(filter.countSelectedValues > 0){
|
196
|
filtered = true;
|
197
|
break;
|
198
|
}
|
199
|
}
|
200
|
if(this.searchUtils.keyword.length > 0 ){
|
201
|
filtered = true;
|
202
|
}
|
203
|
return filtered;
|
204
|
}
|
205
|
private clearKeywords(){
|
206
|
if(this.searchUtils.keyword.length > 0 ){
|
207
|
this.searchUtils.keyword ='';
|
208
|
}
|
209
|
this.goTo(1, true);
|
210
|
}
|
211
|
private clearFilters(){
|
212
|
for (var i =0 ; i < this.filters.length; i++) {
|
213
|
for (var j=0; j < this.filters[i].values.length; j++) {
|
214
|
if(this.filters[i].values[j].selected) {
|
215
|
this.filters[i].values[j].selected = false;
|
216
|
}
|
217
|
}
|
218
|
this.filters[i].countSelectedValues = 0;
|
219
|
}
|
220
|
this.clearKeywords();
|
221
|
}
|
222
|
|
223
|
private removeFilter(value:Value,filter:Filter){
|
224
|
filter.countSelectedValues--;
|
225
|
if(value.selected == true){
|
226
|
value.selected = false;
|
227
|
}
|
228
|
this.goTo(1, true);
|
229
|
}
|
230
|
goTo(page:number = 1, triggerPipe:boolean = true){
|
231
|
this.refreshTable(page);
|
232
|
|
233
|
var urlParameters = this.createUrlParameters(this.filters,true);
|
234
|
this.location.go(location.pathname,urlParameters);
|
235
|
if(triggerPipe) {
|
236
|
this.triggerPipe = !this.triggerPipe;
|
237
|
}
|
238
|
}
|
239
|
|
240
|
filterChanged($event){
|
241
|
this.goTo(1, true);
|
242
|
}
|
243
|
keywordChanged($event) {
|
244
|
this.searchUtils.keyword = $event.value;
|
245
|
this.goTo(1, true);
|
246
|
}
|
247
|
/*
|
248
|
downloadClicked($event) {
|
249
|
if($event.value == true) {
|
250
|
var queryParameters = this.createSearchQueryParameters(this.filters);
|
251
|
|
252
|
this.downloadClick.emit({
|
253
|
value: queryParameters
|
254
|
});
|
255
|
}
|
256
|
}
|
257
|
*/
|
258
|
|
259
|
|
260
|
getSelectedValues(filter):any{
|
261
|
var selected = [];
|
262
|
if(filter.countSelectedValues >0){
|
263
|
for (var i=0; i < filter.values.length; i++){
|
264
|
if(filter.values[i].selected){
|
265
|
selected.push(filter.values[i]);
|
266
|
}
|
267
|
}
|
268
|
}
|
269
|
return selected;
|
270
|
|
271
|
}
|
272
|
}
|