2019-07-15 18:14:27 +02:00
|
|
|
import {Component, Input, ViewChild} from '@angular/core';
|
|
|
|
import {ActivatedRoute} from '@angular/router';
|
|
|
|
import {Location} from '@angular/common';
|
|
|
|
import {SearchDataprovidersService} from '../services/searchDataproviders.service';
|
|
|
|
import {ErrorCodes} from '../utils/properties/errorCodes';
|
|
|
|
import {ErrorMessagesComponent} from '../utils/errorMessages.component';
|
|
|
|
import {SearchFields} from '../utils/properties/searchFields';
|
|
|
|
import {SearchPageComponent } from '../searchPages/searchUtils/searchPage.component';
|
2019-08-02 16:55:32 +02:00
|
|
|
import {SearchUtilsClass} from '../searchPages/searchUtils/searchUtils.class';
|
2019-07-15 18:14:27 +02:00
|
|
|
import {EnvProperties} from '../utils/properties/env-properties';
|
|
|
|
import {StringUtils} from "../utils/string-utils.class";
|
2019-07-16 13:24:13 +02:00
|
|
|
import {ZenodoInformationClass} from "./utils/zenodoInformation.class";
|
2019-07-31 12:41:06 +02:00
|
|
|
import {RouterHelper} from "../utils/routerHelper.class";
|
2019-07-15 18:14:27 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'search-dataproviders',
|
|
|
|
template: `
|
|
|
|
|
2019-07-22 16:15:23 +02:00
|
|
|
<div class="uk-section uk-padding-remove-bottom uk-padding-remove-top">
|
2019-10-17 15:32:31 +02:00
|
|
|
<div class="explorePanelBackground communityPanelBackground uk-margin-top uk-padding-small">
|
2019-07-15 18:14:27 +02:00
|
|
|
<div class="uk-container uk-container-large uk-margin-small-top uk-margin-small-bottom">
|
|
|
|
<ul class="uk-breadcrumb">
|
2019-07-31 12:41:06 +02:00
|
|
|
<li><a class="breadcrumb" routerLinkActive="router-link-active" [routerLink]="depositLearnHowPage"
|
|
|
|
[queryParams]="properties.environment!='development'?{}:routerHelper.createQueryParam('communityId',communityId)">
|
|
|
|
Deposit
|
|
|
|
</a></li>
|
2019-10-17 15:32:31 +02:00
|
|
|
<li><span class="active uk-text-bold">Browse content providers</span></li>
|
2019-07-15 18:14:27 +02:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-08-02 16:55:32 +02:00
|
|
|
<search-page pageTitle="Deposit Browse & Search repositories" [hasPrefix]=false
|
2019-07-15 18:14:27 +02:00
|
|
|
formPlaceholderText = "Search for Content Providers"
|
|
|
|
type="content providers" entityType="dataprovider" [(filters)] = "filters"
|
|
|
|
[(results)] = "results" [(searchUtils)] = "searchUtils" [baseUrl] = "baseUrl"
|
|
|
|
(queryChange)="queryChanged($event)"
|
|
|
|
[csvParams]="csvParams" csvPath="datasources"
|
|
|
|
[disableForms]="disableForms"
|
|
|
|
[loadPaging]="loadPaging"
|
|
|
|
[oldTotalResults]="oldTotalResults"
|
|
|
|
[piwikSiteId]=piwikSiteId
|
2019-07-16 18:23:33 +02:00
|
|
|
[searchFormClass]="''"
|
2019-07-15 18:14:27 +02:00
|
|
|
[usedBy]="'deposit'"
|
|
|
|
[showMoreFilterValuesInline]=true
|
|
|
|
[filterValuesNum]=4
|
2019-07-16 13:24:13 +02:00
|
|
|
[lastIndex]=false
|
|
|
|
[zenodoInformation]="zenodoInformation">
|
2019-07-15 18:14:27 +02:00
|
|
|
</search-page>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class SearchDataprovidersToDepositComponent {
|
|
|
|
private errorCodes: ErrorCodes;
|
|
|
|
private errorMessages: ErrorMessagesComponent;
|
|
|
|
@Input() piwikSiteId = null;
|
|
|
|
public results =[];
|
|
|
|
public filters =[];
|
|
|
|
public totalResults:number = 0 ;
|
|
|
|
public baseUrl:string;
|
|
|
|
public searchUtils:SearchUtilsClass = new SearchUtilsClass();
|
|
|
|
public sub: any; public subResults: any;
|
|
|
|
public _location:Location;
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
|
|
|
public refineFields: string[] = this.searchFields.DEPOSIT_DATASOURCE_REFINE_FIELDS;
|
|
|
|
public fieldIdsMap= this.searchFields.DEPOSIT_DATASOURCE_FIELDS;
|
|
|
|
public keywordFields = this.searchFields.DEPOSIT_DATASOURCE_KEYWORD_FIELDS;
|
|
|
|
public csvParams: string;
|
|
|
|
|
|
|
|
public disableForms: boolean = false;
|
|
|
|
public loadPaging: boolean = true;
|
|
|
|
public oldTotalResults: number = 0;
|
|
|
|
pagingLimit = 0;
|
|
|
|
|
|
|
|
properties:EnvProperties;
|
|
|
|
|
|
|
|
@ViewChild (SearchPageComponent) searchPage : SearchPageComponent ;
|
|
|
|
|
2019-07-31 12:41:06 +02:00
|
|
|
@Input() public communityId: string = null;
|
2019-07-16 13:24:13 +02:00
|
|
|
@Input() public zenodoInformation: ZenodoInformationClass = new ZenodoInformationClass();
|
|
|
|
|
2019-07-31 12:41:06 +02:00
|
|
|
depositLearnHowPage: string = null;
|
|
|
|
public routerHelper:RouterHelper = new RouterHelper();
|
|
|
|
|
2019-08-02 16:55:32 +02:00
|
|
|
constructor (private route: ActivatedRoute, private _searchDataprovidersService: SearchDataprovidersService) {
|
2019-07-15 18:14:27 +02:00
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
this.searchUtils.page =1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
2019-07-31 12:41:06 +02:00
|
|
|
this.depositLearnHowPage = this.properties.depositLearnHowPage;
|
|
|
|
this.baseUrl = this.properties.depositSearchPage;
|
|
|
|
this.pagingLimit = this.properties.pagingLimit;
|
2019-07-15 18:14:27 +02:00
|
|
|
});
|
|
|
|
this.searchPage.refineFields = this.refineFields;
|
|
|
|
this.searchPage.fieldIdsMap = this.fieldIdsMap;
|
|
|
|
this.searchPage.keywordFields = this.keywordFields;
|
|
|
|
var firstLoad =true;
|
|
|
|
|
|
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
|
|
|
if(params['page'] && this.searchUtils.page != params['page']) {
|
|
|
|
this.loadPaging = false;
|
|
|
|
this.oldTotalResults = this.searchUtils.totalResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.searchUtils.keyword = (params['keyword']?params['keyword']:'');
|
|
|
|
var refine = true;
|
|
|
|
if(this.searchUtils.page != ((params['page']=== undefined)?1:+params['page']) && this.filters && !firstLoad){
|
|
|
|
refine = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
firstLoad = false;
|
|
|
|
this.searchUtils.page = (params['page']=== undefined)?1:+params['page'];
|
|
|
|
this.searchUtils.size = (params['size']=== undefined)?5:+params['size'];
|
|
|
|
if(this.searchUtils.size != 5 && this.searchUtils.size != 10 && this.searchUtils.size != 20 && this.searchUtils.size != 50) {
|
|
|
|
this.searchUtils.size = 5;
|
|
|
|
}
|
|
|
|
this.searchPage.usedBy = "deposit";
|
|
|
|
var queryParameters = this.searchPage.getQueryParametersFromUrl(params);
|
|
|
|
this._getResults(queryParameters, refine, this.searchUtils.page, this.searchUtils.size);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if(this.sub){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
if(this.subResults){
|
|
|
|
this.subResults.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public getResults(keyword:string,refine:boolean, page: number, size: number){
|
|
|
|
var parameters = "";
|
|
|
|
if(keyword.length > 0){
|
|
|
|
//parameters = "q="+ keyword;
|
|
|
|
|
|
|
|
if(this.keywordFields.length > 0) {
|
|
|
|
parameters = "&fq=";
|
|
|
|
}
|
|
|
|
|
|
|
|
for(let i=0; i< this.keywordFields.length ; i++) {
|
|
|
|
if(i > 0) {
|
|
|
|
parameters += " or ";
|
|
|
|
}
|
|
|
|
let field = this.keywordFields[i];
|
|
|
|
parameters += field.name+field.equalityOperator+StringUtils.URIEncode(this.searchUtils.keyword);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._getResults(parameters,refine,page, size);
|
|
|
|
}
|
|
|
|
private _getResults(parameters:string,refine:boolean, page: number, size: number){
|
|
|
|
if(page > this.pagingLimit) {
|
|
|
|
size=0;
|
|
|
|
}
|
|
|
|
if(page <= this.pagingLimit || this.searchUtils.status == this.errorCodes.LOADING) {
|
|
|
|
this.csvParams = parameters;
|
|
|
|
|
|
|
|
this.searchUtils.status = this.errorCodes.LOADING;
|
|
|
|
|
|
|
|
this.disableForms = true;
|
|
|
|
this.results = [];
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
|
|
|
|
this.subResults = this._searchDataprovidersService.searchDataprovidersForDepositSearch(parameters,(refine)?this.searchPage.getRefineFieldsQuery():null, page, size, this.searchPage.getFields(),this.properties, "deposit").subscribe(
|
|
|
|
data => {
|
|
|
|
this.searchUtils.totalResults = data[0];
|
|
|
|
this.results = data[1];
|
|
|
|
if(refine){
|
|
|
|
this.filters = data[2];
|
|
|
|
}
|
|
|
|
this.searchPage.checkSelectedFilters(this.filters);
|
|
|
|
this.searchPage.updateBaseUrlWithParameters(this.filters);
|
|
|
|
this.searchUtils.status = this.errorCodes.DONE;
|
|
|
|
if(this.searchUtils.totalResults == 0 ){
|
|
|
|
this.searchUtils.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
this.disableForms = false;
|
|
|
|
|
|
|
|
if(this.searchUtils.status == this.errorCodes.DONE) {
|
|
|
|
// Page out of limit!!!
|
|
|
|
let totalPages:any = this.searchUtils.totalResults/(this.searchUtils.size);
|
|
|
|
if(!(Number.isInteger(totalPages))) {
|
|
|
|
totalPages = (parseInt(totalPages, 10) + 1);
|
|
|
|
}
|
|
|
|
if(totalPages < page) {
|
|
|
|
this.searchUtils.totalResults = 0;
|
|
|
|
this.searchUtils.status = this.errorCodes.OUT_OF_BOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
|
|
|
this.handleError("Error getting content providers", err);
|
|
|
|
this.searchUtils.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
|
|
|
|
this.disableForms = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public queryChanged($event) {
|
|
|
|
this.loadPaging = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error("Content Providers simple Search Page: "+message, error);
|
|
|
|
}
|
|
|
|
}
|