1 |
50169
|
argiro.kok
|
import {Component, Input, ViewChild} from '@angular/core';
|
2 |
55964
|
argiro.kok
|
import {Observable} from 'rxjs';
|
3 |
50169
|
argiro.kok
|
import { Router, ActivatedRoute} from '@angular/router';
|
4 |
|
|
import {Filter, Value,AdvancedField} from '../searchUtils/searchHelperClasses.class';
|
5 |
|
|
import {SearchPublicationsService} from '../../services/searchPublications.service';
|
6 |
|
|
import {SearchResult} from '../../utils/entities/searchResult';
|
7 |
50761
|
argiro.kok
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
8 |
54825
|
konstantin
|
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
|
9 |
50169
|
argiro.kok
|
import {AdvancedSearchPageComponent} from '../searchUtils/advancedSearchPage.component';
|
10 |
|
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
11 |
56059
|
argiro.kok
|
import {SearchCustomFilter, SearchUtilsClass} from '../searchUtils/searchUtils.class';
|
12 |
50586
|
argiro.kok
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
13 |
50169
|
argiro.kok
|
|
14 |
|
|
|
15 |
|
|
@Component({
|
16 |
|
|
selector: 'advanced-search-publications',
|
17 |
|
|
template: `
|
18 |
|
|
<advanced-search-page pageTitle="Advanced Search for Publications" entityType="publication"
|
19 |
|
|
type="publications"
|
20 |
|
|
[(results)] = "results"
|
21 |
|
|
[(searchUtils)] = "searchUtils"
|
22 |
|
|
[(fieldIds)]="fieldIds" [(fieldIdsMap)]="fieldIdsMap" [(selectedFields)]="selectedFields"
|
23 |
|
|
(queryChange)="queryChanged($event)"
|
24 |
50586
|
argiro.kok
|
[csvParams]="csvParams" csvPath="publications" simpleSearchLink="/search/find/publications"
|
25 |
50169
|
argiro.kok
|
[disableForms]="disableForms"
|
26 |
|
|
[loadPaging]="loadPaging"
|
27 |
50586
|
argiro.kok
|
[oldTotalResults]="oldTotalResults"
|
28 |
|
|
[(openaireLink)]=openaireLink
|
29 |
53353
|
argiro.kok
|
[(connectCommunityId)]=connectCommunityId [piwikSiteId]=piwikSiteId
|
30 |
53937
|
konstantin
|
searchFormClass="publicationsSearchForm"
|
31 |
|
|
[(sort)]=sort >
|
32 |
50169
|
argiro.kok
|
</advanced-search-page>
|
33 |
|
|
`
|
34 |
|
|
})
|
35 |
|
|
|
36 |
|
|
export class AdvancedSearchPublicationsComponent {
|
37 |
|
|
private errorCodes: ErrorCodes;
|
38 |
54825
|
konstantin
|
private errorMessages: ErrorMessagesComponent;
|
39 |
51746
|
argiro.kok
|
@Input() piwikSiteId = null;
|
40 |
50169
|
argiro.kok
|
public results =[];
|
41 |
|
|
public filters =[];
|
42 |
|
|
|
43 |
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
44 |
|
|
public searchFields:SearchFields = new SearchFields();
|
45 |
|
|
|
46 |
|
|
public fieldIds: string[] = this.searchFields.RESULT_ADVANCED_FIELDS;
|
47 |
|
|
public fieldIdsMap= this.searchFields.RESULT_FIELDS;
|
48 |
|
|
public selectedFields:AdvancedField[] = [];
|
49 |
|
|
public resourcesQuery = "((oaftype exact result) and (resulttypeid exact publication))";
|
50 |
|
|
public csvParams: string;
|
51 |
|
|
public disableForms: boolean = false;
|
52 |
|
|
public loadPaging: boolean = true;
|
53 |
|
|
public oldTotalResults: number = 0;
|
54 |
50586
|
argiro.kok
|
@Input() openaireLink: string ;
|
55 |
52027
|
argiro.kok
|
@Input() connectCommunityId: string;
|
56 |
56059
|
argiro.kok
|
@Input() customFilter:SearchCustomFilter= null;
|
57 |
50586
|
argiro.kok
|
public pagingLimit: number = 0;
|
58 |
|
|
public isPiwikEnabled;
|
59 |
53937
|
konstantin
|
public sort: boolean = true;
|
60 |
50586
|
argiro.kok
|
properties:EnvProperties;
|
61 |
50169
|
argiro.kok
|
|
62 |
|
|
@ViewChild (AdvancedSearchPageComponent) searchPage : AdvancedSearchPageComponent ;
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
constructor (private route: ActivatedRoute, private _searchPublicationsService: SearchPublicationsService ) {
|
66 |
|
|
|
67 |
|
|
this.results =[];
|
68 |
|
|
this.errorCodes = new ErrorCodes();
|
69 |
54825
|
konstantin
|
this.errorMessages = new ErrorMessagesComponent();
|
70 |
50169
|
argiro.kok
|
this.searchUtils.status = this.errorCodes.LOADING;
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
}
|
75 |
|
|
ngOnInit() {
|
76 |
50586
|
argiro.kok
|
this.route.data
|
77 |
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
78 |
|
|
this.properties= data.envSpecific;
|
79 |
50761
|
argiro.kok
|
this.searchUtils.baseUrl = data.envSpecific.searchLinkToAdvancedPublications;
|
80 |
50586
|
argiro.kok
|
this.pagingLimit = data.envSpecific.pagingLimit;
|
81 |
|
|
this.isPiwikEnabled = data.envSpecific.enablePiwikTrack;
|
82 |
|
|
|
83 |
|
|
});
|
84 |
50169
|
argiro.kok
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
85 |
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
86 |
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
87 |
|
|
if(params['page'] && this.searchUtils.page != params['page']) {
|
88 |
|
|
this.loadPaging = false;
|
89 |
|
|
this.oldTotalResults = this.searchUtils.totalResults;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
let page = (params['page']=== undefined)?1:+params['page'];
|
93 |
|
|
this.searchUtils.page = ( page <= 0 ) ? 1 : page;
|
94 |
53919
|
konstantin
|
|
95 |
|
|
this.searchUtils.size = (params['size']=== undefined)?10:+params['size'];
|
96 |
|
|
if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
|
97 |
|
|
this.searchUtils.size = 10;
|
98 |
|
|
}
|
99 |
53937
|
konstantin
|
this.searchUtils.sortBy = (params['sortBy'])?params['sortBy']:'';
|
100 |
54075
|
konstantin
|
if(this.searchUtils.sortBy && this.searchUtils.sortBy != "resultdateofacceptance,descending" && this.searchUtils.sortBy != "resultdateofacceptance,ascending") {
|
101 |
53937
|
konstantin
|
this.searchUtils.sortBy = "";
|
102 |
|
|
}
|
103 |
|
|
|
104 |
50169
|
argiro.kok
|
this.searchPage.fieldIds = this.fieldIds;
|
105 |
|
|
this.selectedFields =[];
|
106 |
|
|
this.searchPage.selectedFields = this.selectedFields;
|
107 |
|
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
108 |
52027
|
argiro.kok
|
this.searchPage.connectCommunityId = this.connectCommunityId;
|
109 |
56059
|
argiro.kok
|
this.searchPage.customFilter = this.customFilter;
|
110 |
50169
|
argiro.kok
|
this.searchPage.getSelectedFiltersFromUrl(params);
|
111 |
53937
|
konstantin
|
this.getResults(this.searchPage.createQueryParameters(), this.searchUtils.page, this.searchUtils.size, this.searchUtils.sortBy);
|
112 |
50169
|
argiro.kok
|
});
|
113 |
|
|
}
|
114 |
|
|
ngOnDestroy() {
|
115 |
|
|
this.sub.unsubscribe();
|
116 |
|
|
}
|
117 |
|
|
sub: any;
|
118 |
53937
|
konstantin
|
public getResults(parameters:string, page: number, size: number, sortBy: string){
|
119 |
50586
|
argiro.kok
|
if(page > this.pagingLimit) {
|
120 |
|
|
size=0;
|
121 |
|
|
}
|
122 |
|
|
if(page <= this.pagingLimit || this.searchUtils.status == this.errorCodes.LOADING) {
|
123 |
50169
|
argiro.kok
|
if(parameters!= null && parameters != '' ) {
|
124 |
50586
|
argiro.kok
|
this.csvParams ="&fq=("+this.resourcesQuery +" and (" + parameters + "))";
|
125 |
50169
|
argiro.kok
|
}else{
|
126 |
50586
|
argiro.kok
|
this.csvParams ="&fq="+this.resourcesQuery;
|
127 |
50169
|
argiro.kok
|
}
|
128 |
|
|
|
129 |
50586
|
argiro.kok
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
130 |
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
131 |
|
|
//this.searchPage.openLoading();
|
132 |
|
|
this.disableForms = true;
|
133 |
|
|
this.results = [];
|
134 |
|
|
this.searchUtils.totalResults = 0;
|
135 |
50169
|
argiro.kok
|
|
136 |
54775
|
konstantin
|
//console.info("Advanced Search for Publications: Execute search query "+parameters);
|
137 |
53937
|
konstantin
|
this._searchPublicationsService.advancedSearchPublications(parameters, page, size, sortBy, this.properties).subscribe(
|
138 |
50586
|
argiro.kok
|
data => {
|
139 |
|
|
this.searchUtils.totalResults = data[0];
|
140 |
|
|
this.results = data[1];
|
141 |
|
|
this.searchPage.updateBaseUrlWithParameters();
|
142 |
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
143 |
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
144 |
|
|
if(this.searchUtils.totalResults == 0 ){
|
145 |
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
146 |
|
|
}
|
147 |
|
|
//this.searchPage.closeLoading();
|
148 |
|
|
this.disableForms = false;
|
149 |
50169
|
argiro.kok
|
|
150 |
50586
|
argiro.kok
|
if(this.searchUtils.status == this.errorCodes.DONE) {
|
151 |
|
|
// Page out of limit!!!
|
152 |
|
|
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
|
153 |
|
|
if(!(Number.isInteger(totalPages))) {
|
154 |
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
155 |
|
|
}
|
156 |
|
|
if(totalPages < page) {
|
157 |
|
|
this.searchUtils.totalResults = 0;
|
158 |
|
|
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
|
159 |
|
|
}
|
160 |
50169
|
argiro.kok
|
}
|
161 |
50586
|
argiro.kok
|
},
|
162 |
|
|
err => {
|
163 |
54825
|
konstantin
|
//console.log(err);
|
164 |
|
|
this.handleError("Error getting publications", err);
|
165 |
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
166 |
|
|
|
167 |
50586
|
argiro.kok
|
//TODO check erros (service not available, bad request)
|
168 |
|
|
// if( ){
|
169 |
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
170 |
|
|
// }
|
171 |
|
|
//var errorCodes:ErrorCodes = new ErrorCodes();
|
172 |
|
|
//this.searchUtils.status = errorCodes.NOT_AVAILABLE;
|
173 |
54825
|
konstantin
|
/*if(err.status == '404') {
|
174 |
50586
|
argiro.kok
|
this.searchUtils.status = this.errorCodes.NOT_FOUND;
|
175 |
|
|
} else if(err.status == '500') {
|
176 |
|
|
this.searchUtils.status = this.errorCodes.ERROR;
|
177 |
|
|
} else {
|
178 |
|
|
this.searchUtils.status = this.errorCodes.NOT_AVAILABLE;
|
179 |
54825
|
konstantin
|
}*/
|
180 |
50169
|
argiro.kok
|
|
181 |
50586
|
argiro.kok
|
//this.searchPage.closeLoading();
|
182 |
|
|
this.disableForms = false;
|
183 |
50169
|
argiro.kok
|
|
184 |
50586
|
argiro.kok
|
}
|
185 |
|
|
);
|
186 |
|
|
}
|
187 |
50169
|
argiro.kok
|
}
|
188 |
|
|
|
189 |
|
|
public queryChanged($event) {
|
190 |
|
|
this.loadPaging = true;
|
191 |
|
|
|
192 |
|
|
var parameters = $event.value;
|
193 |
55371
|
konstantin
|
//this.getResults(parameters, this.searchUtils.page,this.searchUtils.size, this.searchUtils.sortBy);
|
194 |
54775
|
konstantin
|
//console.info("queryChanged: Execute search query "+parameters);
|
195 |
50169
|
argiro.kok
|
|
196 |
|
|
}
|
197 |
|
|
|
198 |
54825
|
konstantin
|
private handleError(message: string, error) {
|
199 |
|
|
console.error("Publications advanced Search Page: "+message, error);
|
200 |
|
|
}
|
201 |
50169
|
argiro.kok
|
}
|