2020-11-11 15:43:13 +01:00
|
|
|
import {Component, Input, } from '@angular/core';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {RefineFieldResultsService} from '../../services/refineFieldResults.service';
|
2018-02-15 11:36:12 +01:00
|
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
2019-02-15 13:50:24 +01:00
|
|
|
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
|
2020-11-11 15:43:13 +01:00
|
|
|
import {SearchFields} from '../../utils/properties/searchFields';
|
|
|
|
import {SearchCustomFilter} from '../searchUtils/searchUtils.class';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
2018-11-19 11:15:13 +01:00
|
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'browse-entities',
|
|
|
|
template: `
|
|
|
|
<div>
|
2020-11-11 15:43:13 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
<errorMessages [status]="[status]" [type]="'results'"></errorMessages>
|
|
|
|
|
2019-06-12 16:13:56 +02:00
|
|
|
<div class ="uk-grid" *ngIf="status ===errorCodes.DONE">
|
2018-06-01 14:28:49 +02:00
|
|
|
<div *ngFor= "let filter of filters" class = "uk-margin-bottom uk-width-1-3@l uk-width-1-3@m uk-width-1-2@s">
|
2017-12-19 13:53:46 +01:00
|
|
|
<browse-statistic [baseUrl]=baseUrl [filter]=filter ></browse-statistic>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
|
|
|
|
})
|
|
|
|
export class BrowseEntitiesComponent {
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
|
|
|
public filters =[];
|
|
|
|
@Input() public baseUrl:string = "";
|
|
|
|
@Input() public entityName:string = "";
|
|
|
|
@Input() public refineFields: string[] ;//= this.searchFields.RESULT_REFINE_FIELDS;
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() properties:EnvProperties;
|
2019-06-12 16:13:56 +02:00
|
|
|
@Input() customFilter:SearchCustomFilter= null;
|
2018-11-19 11:15:13 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
public sub: any;
|
|
|
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
2019-02-15 13:50:24 +01:00
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2017-12-19 13:53:46 +01:00
|
|
|
public status = this.errorCodes.LOADING;
|
|
|
|
public fieldIdsMap=this.searchFields.RESULT_REFINE_FIELDS;
|
|
|
|
|
|
|
|
constructor ( private _refineFieldsService: RefineFieldResultsService ) {
|
2019-02-15 13:50:24 +01:00
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
for(var i=0; i < this.searchFields.HIDDEN_FIELDS.length; i++){
|
|
|
|
var index = this.refineFields.indexOf(this.searchFields.HIDDEN_FIELDS[i]) ;
|
|
|
|
if(index > -1){
|
|
|
|
this.refineFields.splice(index,1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.getStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if(this.sub){
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private getStats(){
|
|
|
|
|
|
|
|
this.status = this.errorCodes.LOADING;
|
2019-06-13 14:31:39 +02:00
|
|
|
var refineParams = null;
|
2019-06-12 16:13:56 +02:00
|
|
|
if(this.customFilter){
|
|
|
|
refineParams = (refineParams?(refineParams+'&'):'')+"&fq="+StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId )));
|
|
|
|
}
|
2018-11-19 11:15:13 +01:00
|
|
|
this.sub = this._refineFieldsService.getRefineFieldsResultsByEntityName(this.refineFields,this.entityName, this.properties,refineParams).subscribe(
|
2017-12-19 13:53:46 +01:00
|
|
|
data => {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("Get Stats for "+this.entityName+ ": [Total:"+data[0]+" ] [fields: "+data[1].length+"]");
|
2017-12-19 13:53:46 +01:00
|
|
|
this.filters = data[1];
|
|
|
|
this.status = this.errorCodes.DONE;
|
|
|
|
if(data[0] == 0 ){
|
|
|
|
this.status = this.errorCodes.NONE;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
err => {
|
2019-02-15 13:50:24 +01:00
|
|
|
//console.log(err);
|
|
|
|
this.handleError("Error getting refine fields results (stats) by entity: "+this.entityName, err);
|
|
|
|
this.status = this.errorMessages.getErrorCode(err.status);
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
//TODO check erros (service not available, bad request)
|
|
|
|
// if( ){
|
|
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
|
|
|
// }
|
|
|
|
//this.status = this.errorCodes.ERROR;
|
2019-02-15 13:50:24 +01:00
|
|
|
/*if(err.status == '404') {
|
2017-12-19 13:53:46 +01:00
|
|
|
this.status = this.errorCodes.NOT_FOUND;
|
|
|
|
} else if(err.status == '500') {
|
|
|
|
this.status = this.errorCodes.ERROR;
|
|
|
|
} else {
|
|
|
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
2019-02-15 13:50:24 +01:00
|
|
|
}*/
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
);
|
2019-02-15 13:50:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private handleError(message: string, error) {
|
|
|
|
console.error("Browse Entities (Search): "+message, error);
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|