1 |
61381
|
k.triantaf
|
import {Component, Input, ViewChild} from '@angular/core';
|
2 |
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
3 |
|
|
import {Location} from '@angular/common';
|
4 |
|
|
import {SearchDataprovidersService} from '../services/searchDataproviders.service';
|
5 |
|
|
import {ErrorCodes} from '../utils/properties/errorCodes';
|
6 |
|
|
import {ErrorMessagesComponent} from '../utils/errorMessages.component';
|
7 |
|
|
import {SearchFields} from '../utils/properties/searchFields';
|
8 |
|
|
|
9 |
|
|
import {SearchCustomFilter, SearchUtilsClass} from '../searchPages/searchUtils/searchUtils.class';
|
10 |
|
|
import {EnvProperties} from '../utils/properties/env-properties';
|
11 |
|
|
import {ZenodoInformationClass} from "./utils/zenodoInformation.class";
|
12 |
|
|
import {RouterHelper} from "../utils/routerHelper.class";
|
13 |
|
|
import {Breadcrumb} from "../utils/breadcrumbs/breadcrumbs.component";
|
14 |
|
|
import {properties} from "../../../environments/environment";
|
15 |
|
|
|
16 |
|
|
@Component({
|
17 |
|
|
selector: 'deposit-search-dataproviders',
|
18 |
|
|
template: `
|
19 |
|
|
|
20 |
|
|
<div class="uk-section uk-padding-remove-bottom uk-padding-remove-top">
|
21 |
|
|
<div class="explorePanelBackground communityPanelBackground uk-padding-small">
|
22 |
|
|
<div class="uk-container uk-container-large uk-margin-small-top uk-margin-small-bottom">
|
23 |
|
|
<!--<ul class="uk-breadcrumb">
|
24 |
|
|
<li><a class="breadcrumb" routerLinkActive="router-link-active" [routerLink]="depositLearnHowPage"
|
25 |
|
|
[queryParams]="properties.environment!='development'?{}:routerHelper.createQueryParam('communityId',communityId)">
|
26 |
|
|
Deposit
|
27 |
|
|
</a></li>
|
28 |
|
|
<li><span class="active uk-text-bold">Browse content providers</span></li>
|
29 |
|
|
</ul>-->
|
30 |
|
|
<breadcrumbs [light]="!!(this.communityId)" [breadcrumbs]="breadcrumbs"></breadcrumbs>
|
31 |
|
|
</div>
|
32 |
|
|
</div>
|
33 |
|
|
</div>
|
34 |
|
|
<div class="">
|
35 |
|
|
<div class="uk-container uk-container-large">
|
36 |
|
|
|
37 |
|
|
<form
|
38 |
|
|
class="uk-margin-top uk-grid uk-margin-small-left ng-untouched ng-pristine ng-valid uk-form-width-large uk-float-right">
|
39 |
|
|
|
40 |
|
|
<div class=" uk-padding-remove-left uk-margin-small-top uk-inline uk-width-expand">
|
41 |
|
|
<a *ngIf="keyword.length > 0" class="uk-form-icon uk-form-icon-flip"
|
42 |
|
|
(click)="keyword = ''"
|
43 |
|
|
uk-icon="icon: close"></a>
|
44 |
|
|
<input type="text" class="uk-input text-input-box uk-width-expand"
|
45 |
|
|
placeholder="Search by name, description, subject..." aria-describedby="sizing-addon2"
|
46 |
|
|
[(ngModel)]="keyword" name="keyword">
|
47 |
|
|
</div>
|
48 |
|
|
<!--<div class="uk-padding-remove-left uk-margin-small-top">
|
49 |
|
|
<button (click)="keywordChanged()" type="submit"
|
50 |
|
|
class=" uk-button portal-button uk-text-bold ">
|
51 |
|
|
Search
|
52 |
|
|
</button>
|
53 |
|
|
</div>-->
|
54 |
|
|
<div class="uk-padding-remove-left">
|
55 |
|
|
<button (click)="keywordChanged()" type="submit"
|
56 |
|
|
class="portal-button uk-margin-small-left uk-margin-small-top uk-button">Search
|
57 |
|
|
</button>
|
58 |
|
|
</div>
|
59 |
|
|
|
60 |
|
|
</form>
|
61 |
|
|
</div>
|
62 |
|
|
<search-dataproviders [simpleView]="true" type="deposit" simpleSearchLink="/participate/deposit/search" [includeOnlyResultsAndFilter]="true" >
|
63 |
|
|
</search-dataproviders>
|
64 |
|
|
</div>
|
65 |
|
|
`
|
66 |
|
|
})
|
67 |
|
|
export class SearchDataprovidersToDepositComponent {
|
68 |
|
|
private errorCodes: ErrorCodes;
|
69 |
|
|
private errorMessages: ErrorMessagesComponent;
|
70 |
|
|
@Input() piwikSiteId = null;
|
71 |
|
|
public results =[];
|
72 |
|
|
public filters =[];
|
73 |
|
|
public totalResults:number = 0 ;
|
74 |
|
|
public baseUrl:string;
|
75 |
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
76 |
|
|
public sub: any; public subResults: any;
|
77 |
|
|
public _location:Location;
|
78 |
|
|
public searchFields:SearchFields = new SearchFields();
|
79 |
|
|
public refineFields: string[] = this.searchFields.DEPOSIT_DATASOURCE_REFINE_FIELDS;
|
80 |
|
|
public fieldIdsMap= this.searchFields.DEPOSIT_DATASOURCE_FIELDS;
|
81 |
|
|
public keywordFields = this.searchFields.DEPOSIT_DATASOURCE_KEYWORD_FIELDS;
|
82 |
|
|
public csvParams: string;
|
83 |
|
|
|
84 |
|
|
public disableForms: boolean = false;
|
85 |
|
|
public loadPaging: boolean = true;
|
86 |
|
|
public oldTotalResults: number = 0;
|
87 |
|
|
pagingLimit = 0;
|
88 |
|
|
|
89 |
|
|
properties:EnvProperties = properties;
|
90 |
|
|
|
91 |
|
|
// @ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
92 |
|
|
|
93 |
|
|
@Input() public communityId: string = null;
|
94 |
|
|
@Input() public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
|
95 |
|
|
|
96 |
|
|
depositLearnHowPage: string = null;
|
97 |
|
|
public routerHelper:RouterHelper = new RouterHelper();
|
98 |
|
|
breadcrumbs:Breadcrumb[] = [];
|
99 |
|
|
parameters = {};
|
100 |
|
|
keyword = "";
|
101 |
|
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService, private router: Router) {
|
102 |
|
|
this.errorCodes = new ErrorCodes();
|
103 |
|
|
this.errorMessages = new ErrorMessagesComponent();
|
104 |
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
105 |
|
|
this.searchUtils.page =1;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
public ngOnInit() {
|
109 |
|
|
this.depositLearnHowPage = this.properties.depositLearnHowPage;
|
110 |
|
|
this.baseUrl = this.properties.depositSearchPage;
|
111 |
|
|
this.pagingLimit = this.properties.pagingLimit;
|
112 |
|
|
this.breadcrumbs.push({name: 'home', route: '/'}, {
|
113 |
|
|
name: "Deposit",
|
114 |
|
|
route: this.depositLearnHowPage
|
115 |
|
|
}, {name: "Browse repositories", route: null});
|
116 |
|
|
|
117 |
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
118 |
|
|
this.parameters = Object.assign({}, params);
|
119 |
|
|
this.keyword = params["fv0"]?params["fv0"]:'';
|
120 |
|
|
});
|
121 |
|
|
// this.searchPage.refineFields = this.refineFields;
|
122 |
|
|
// this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
123 |
|
|
// this.searchPage.keywordFields = this.keywordFields;
|
124 |
|
|
// var firstLoad =true;
|
125 |
|
|
//
|
126 |
|
|
// this.subscriptions = this.route.queryParams.subscribe(params => {
|
127 |
|
|
// this.loadPaging = true;
|
128 |
|
|
// if(params['page'] && this.searchUtils.page != params['page']) {
|
129 |
|
|
// this.loadPaging = false;
|
130 |
|
|
// this.oldTotalResults = this.searchUtils.totalResults;
|
131 |
|
|
// }
|
132 |
|
|
//
|
133 |
|
|
// this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
134 |
|
|
// var refine = true;
|
135 |
|
|
// if(this.searchUtils.page != ((params['page']=== undefined)?1:+params['page']) && this.filters && !firstLoad){
|
136 |
|
|
// refine = false;
|
137 |
|
|
//
|
138 |
|
|
// }
|
139 |
|
|
// firstLoad = false;
|
140 |
|
|
// this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
|
141 |
|
|
// this.searchUtils.size = (params['size']=== undefined)?5:+params['size'];
|
142 |
|
|
// if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
|
143 |
|
|
// this.searchUtils.size = 5;
|
144 |
|
|
// }
|
145 |
|
|
// this.searchPage.usedBy = "deposit";
|
146 |
|
|
// var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
|
147 |
|
|
// this._getResults(queryParameters, refine, this.searchUtils.page, this.searchUtils.size);
|
148 |
|
|
// });
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
public ngOnDestroy() {
|
152 |
|
|
if(this.sub){
|
153 |
|
|
this.sub.unsubscribe();
|
154 |
|
|
}
|
155 |
|
|
if(this.subResults){
|
156 |
|
|
this.subResults.unsubscribe();
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
|
|
keywordChanged(){
|
160 |
|
|
|
161 |
|
|
if ( this.keyword.length > 0) {
|
162 |
|
|
this.parameters["fv0"] = this.keyword;
|
163 |
|
|
this.parameters["f0"] = "q";
|
164 |
|
|
}else{
|
165 |
|
|
delete this.parameters['fv0'];
|
166 |
|
|
delete this.parameters['f0'];
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
if(this.parameters["page"]){
|
170 |
|
|
//GO to first page
|
171 |
|
|
delete this.parameters['page'];
|
172 |
|
|
}
|
173 |
|
|
|
174 |
|
|
|
175 |
|
|
this.router.navigate([this.properties.depositSearchPage], {queryParams: this.parameters} );
|
176 |
|
|
}
|
177 |
|
|
/*public getResults(keyword:string,refine:boolean, page: number, size: number){
|
178 |
|
|
var parameters = "";
|
179 |
|
|
if(keyword.length > 0){
|
180 |
|
|
//parameters = "q="+ keyword;
|
181 |
|
|
|
182 |
|
|
if(this.keywordFields.length > 0) {
|
183 |
|
|
parameters = "&fq=";
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
for(let i=0; i< this.keywordFields.length ; i++) {
|
187 |
|
|
if(i > 0) {
|
188 |
|
|
parameters += " or ";
|
189 |
|
|
}
|
190 |
|
|
let field = this.keywordFields[i];
|
191 |
|
|
parameters += field.name+field.equalityOperator+StringUtils.URIEncode(this.searchUtils.keyword);
|
192 |
|
|
}
|
193 |
|
|
}
|
194 |
|
|
this._getResults(parameters,refine,page, size);
|
195 |
|
|
}
|
196 |
|
|
private _getResults(parameters:string,refine:boolean, page: number, size: number){
|
197 |
|
|
if(page > this.pagingLimit) {
|
198 |
|
|
size=0;
|
199 |
|
|
}
|
200 |
|
|
if(page <= this.pagingLimit || this.searchUtils.status == this.errorCodes.LOADING) {
|
201 |
|
|
this.csvParams = parameters;
|
202 |
|
|
|
203 |
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
204 |
|
|
|
205 |
|
|
this.disableForms = true;
|
206 |
|
|
this.results = [];
|
207 |
|
|
this.searchUtils.totalResults = 0;
|
208 |
|
|
|
209 |
|
|
this.subResults = this._searchDataprovidersService.searchDataprovidersForDepositSearch(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields(),this.properties, "deposit").subscribe(
|
210 |
|
|
data => {
|
211 |
|
|
this.searchUtils.totalResults = data[0];
|
212 |
|
|
this.results = data[1];
|
213 |
|
|
if(refine){
|
214 |
|
|
this.filters = data[2];
|
215 |
|
|
}
|
216 |
|
|
this.searchPage.checkSelectedFilters(this.filters);
|
217 |
|
|
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
218 |
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
219 |
|
|
if(this.searchUtils.totalResults == 0 ){
|
220 |
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
221 |
|
|
}
|
222 |
|
|
this.disableForms = false;
|
223 |
|
|
|
224 |
|
|
if(this.searchUtils.status == this.errorCodes.DONE) {
|
225 |
|
|
// Page out of limit!!!
|
226 |
|
|
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
|
227 |
|
|
if(!(Number.isInteger(totalPages))) {
|
228 |
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
229 |
|
|
}
|
230 |
|
|
if(totalPages < page) {
|
231 |
|
|
this.searchUtils.totalResults = 0;
|
232 |
|
|
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
|
233 |
|
|
}
|
234 |
|
|
}
|
235 |
|
|
},
|
236 |
|
|
err => {
|
237 |
|
|
this.handleError("Error getting content providers", err);
|
238 |
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
239 |
|
|
|
240 |
|
|
this.disableForms = false;
|
241 |
|
|
}
|
242 |
|
|
);
|
243 |
|
|
}
|
244 |
|
|
}
|
245 |
|
|
*/
|
246 |
|
|
|
247 |
|
|
private handleError(message: string, error) {
|
248 |
|
|
console.error("Content Providers simple Search Page: "+message, error);
|
249 |
|
|
}
|
250 |
|
|
}
|