1 |
61381
|
k.triantaf
|
import {Component, Input, } from '@angular/core';
|
2 |
|
|
import {RefineFieldResultsService} from '../../services/refineFieldResults.service';
|
3 |
|
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
4 |
|
|
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
|
5 |
|
|
import {SearchFields} from '../../utils/properties/searchFields';
|
6 |
|
|
import {SearchCustomFilter} from '../searchUtils/searchUtils.class';
|
7 |
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
8 |
|
|
import {StringUtils} from '../../utils/string-utils.class';
|
9 |
|
|
|
10 |
|
|
@Component({
|
11 |
|
|
selector: 'browse-entities',
|
12 |
|
|
template: `
|
13 |
|
|
<div>
|
14 |
|
|
|
15 |
|
|
<errorMessages [status]="[status]" [type]="'results'"></errorMessages>
|
16 |
|
|
|
17 |
|
|
<div class ="uk-grid" *ngIf="status ===errorCodes.DONE">
|
18 |
|
|
<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">
|
19 |
|
|
<browse-statistic [baseUrl]=baseUrl [filter]=filter ></browse-statistic>
|
20 |
|
|
</div>
|
21 |
|
|
</div>
|
22 |
|
|
</div>
|
23 |
|
|
`
|
24 |
|
|
|
25 |
|
|
})
|
26 |
|
|
export class BrowseEntitiesComponent {
|
27 |
|
|
public searchFields:SearchFields = new SearchFields();
|
28 |
|
|
public filters =[];
|
29 |
|
|
@Input() public baseUrl:string = "";
|
30 |
|
|
@Input() public entityName:string = "";
|
31 |
|
|
@Input() public refineFields: string[] ;//= this.searchFields.RESULT_REFINE_FIELDS;
|
32 |
|
|
@Input() properties:EnvProperties;
|
33 |
|
|
@Input() customFilter:SearchCustomFilter= null;
|
34 |
|
|
|
35 |
|
|
public sub: any;
|
36 |
|
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
37 |
|
|
private errorMessages: ErrorMessagesComponent;
|
38 |
|
|
public status = this.errorCodes.LOADING;
|
39 |
|
|
public fieldIdsMap=this.searchFields.RESULT_REFINE_FIELDS;
|
40 |
|
|
|
41 |
|
|
constructor ( private _refineFieldsService: RefineFieldResultsService ) {
|
42 |
|
|
this.errorMessages = new ErrorMessagesComponent();
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
public ngOnInit() {
|
46 |
|
|
for(var i=0; i < this.searchFields.HIDDEN_FIELDS.length; i++){
|
47 |
|
|
var index = this.refineFields.indexOf(this.searchFields.HIDDEN_FIELDS[i]) ;
|
48 |
|
|
if(index > -1){
|
49 |
|
|
this.refineFields.splice(index,1);
|
50 |
|
|
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
this.getStats();
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
public ngOnDestroy() {
|
57 |
|
|
if(this.sub){
|
58 |
|
|
this.sub.unsubscribe();
|
59 |
|
|
}
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
private getStats(){
|
64 |
|
|
|
65 |
|
|
this.status = this.errorCodes.LOADING;
|
66 |
|
|
var refineParams = null;
|
67 |
|
|
if(this.customFilter){
|
68 |
|
|
refineParams = (refineParams?(refineParams+'&'):'')+"&fq="+StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId )));
|
69 |
|
|
}
|
70 |
|
|
this.sub = this._refineFieldsService.getRefineFieldsResultsByEntityName(this.refineFields,this.entityName, this.properties,refineParams).subscribe(
|
71 |
|
|
data => {
|
72 |
|
|
//console.info("Get Stats for "+this.entityName+ ": [Total:"+data[0]+" ] [fields: "+data[1].length+"]");
|
73 |
|
|
this.filters = data[1];
|
74 |
|
|
this.status = this.errorCodes.DONE;
|
75 |
|
|
if(data[0] == 0 ){
|
76 |
|
|
this.status = this.errorCodes.NONE;
|
77 |
|
|
}
|
78 |
|
|
},
|
79 |
|
|
err => {
|
80 |
|
|
//console.log(err);
|
81 |
|
|
this.handleError("Error getting refine fields results (stats) by entity: "+this.entityName, err);
|
82 |
|
|
this.status = this.errorMessages.getErrorCode(err.status);
|
83 |
|
|
|
84 |
|
|
//TODO check erros (service not available, bad request)
|
85 |
|
|
// if( ){
|
86 |
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
87 |
|
|
// }
|
88 |
|
|
//this.status = this.errorCodes.ERROR;
|
89 |
|
|
/*if(err.status == '404') {
|
90 |
|
|
this.status = this.errorCodes.NOT_FOUND;
|
91 |
|
|
} else if(err.status == '500') {
|
92 |
|
|
this.status = this.errorCodes.ERROR;
|
93 |
|
|
} else {
|
94 |
|
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
95 |
|
|
}*/
|
96 |
|
|
}
|
97 |
|
|
);
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
private handleError(message: string, error) {
|
101 |
|
|
console.error("Browse Entities (Search): "+message, error);
|
102 |
|
|
}
|
103 |
|
|
}
|