1 |
50169
|
argiro.kok
|
import {Component, Input, ViewChild} from '@angular/core';
|
2 |
|
|
import { ActivatedRoute} from '@angular/router';
|
3 |
|
|
import {Location} from '@angular/common';
|
4 |
|
|
|
5 |
|
|
import { Filter, Value} from '../searchUtils/searchHelperClasses.class';
|
6 |
|
|
|
7 |
|
|
import {RefineFieldResultsService} from '../../services/refineFieldResults.service';
|
8 |
50761
|
argiro.kok
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
9 |
54825
|
konstantin
|
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
|
10 |
50169
|
argiro.kok
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
11 |
|
|
import {SearchPageComponent } from '../searchUtils/searchPage.component';
|
12 |
56059
|
argiro.kok
|
import {SearchCustomFilter, SearchUtilsClass} from '../searchUtils/searchUtils.class';
|
13 |
50586
|
argiro.kok
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
14 |
53860
|
argiro.kok
|
import {StringUtils} from '../../utils/string-utils.class';
|
15 |
50169
|
argiro.kok
|
|
16 |
|
|
@Component({
|
17 |
|
|
selector: 'browse-entities',
|
18 |
|
|
template: `
|
19 |
|
|
<div>
|
20 |
53379
|
argiro.kok
|
<!--div *ngIf="status == errorCodes.LOADING" class="uk-animation-fade uk-margin-large-top uk-width-1-1" role="alert"><span class="loading-gif uk-align-center" ></span></div>
|
21 |
50169
|
argiro.kok
|
<div *ngIf="status == errorCodes.NONE" class="uk-alert uk-alert-primary uk-animation-fade" role="alert">No Results found</div>
|
22 |
|
|
<div *ngIf="status == errorCodes.ERROR" class="uk-alert uk-alert-warning uk-animation-fade" role="alert">An Error Occured</div>
|
23 |
|
|
<div *ngIf="status == errorCodes.NOT_AVAILABLE" class="uk-alert uk-alert-danger" role="alert">Service temprorarily unavailable. Please try again later.</div>
|
24 |
|
|
<div *ngIf="status == errorCodes.NOT_FOUND" class="uk-alert uk-alert-danger" role="alert">No filters found</div-->
|
25 |
|
|
<errorMessages [status]="[status]" [type]="'results'"></errorMessages>
|
26 |
|
|
|
27 |
56059
|
argiro.kok
|
<div class ="uk-grid" *ngIf="status ===errorCodes.DONE">
|
28 |
52309
|
argiro.kok
|
<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">
|
29 |
50169
|
argiro.kok
|
<browse-statistic [baseUrl]=baseUrl [filter]=filter ></browse-statistic>
|
30 |
|
|
</div>
|
31 |
|
|
</div>
|
32 |
|
|
</div>
|
33 |
|
|
`
|
34 |
|
|
|
35 |
|
|
})
|
36 |
|
|
export class BrowseEntitiesComponent {
|
37 |
|
|
public searchFields:SearchFields = new SearchFields();
|
38 |
|
|
public filters =[];
|
39 |
|
|
@Input() public baseUrl:string = "";
|
40 |
|
|
@Input() public entityName:string = "";
|
41 |
|
|
@Input() public refineFields: string[] ;//= this.searchFields.RESULT_REFINE_FIELDS;
|
42 |
50586
|
argiro.kok
|
@Input() properties:EnvProperties;
|
43 |
56059
|
argiro.kok
|
@Input() customFilter:SearchCustomFilter= null;
|
44 |
53860
|
argiro.kok
|
|
45 |
50169
|
argiro.kok
|
public sub: any;
|
46 |
|
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
47 |
54825
|
konstantin
|
private errorMessages: ErrorMessagesComponent;
|
48 |
50169
|
argiro.kok
|
public status = this.errorCodes.LOADING;
|
49 |
|
|
public fieldIdsMap=this.searchFields.RESULT_REFINE_FIELDS;
|
50 |
|
|
|
51 |
|
|
constructor ( private _refineFieldsService: RefineFieldResultsService ) {
|
52 |
54825
|
konstantin
|
this.errorMessages = new ErrorMessagesComponent();
|
53 |
50169
|
argiro.kok
|
}
|
54 |
|
|
|
55 |
|
|
public ngOnInit() {
|
56 |
|
|
for(var i=0; i < this.searchFields.HIDDEN_FIELDS.length; i++){
|
57 |
|
|
var index = this.refineFields.indexOf(this.searchFields.HIDDEN_FIELDS[i]) ;
|
58 |
|
|
if(index > -1){
|
59 |
|
|
this.refineFields.splice(index,1);
|
60 |
|
|
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
this.getStats();
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
public ngOnDestroy() {
|
67 |
|
|
if(this.sub){
|
68 |
|
|
this.sub.unsubscribe();
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
private getStats(){
|
74 |
|
|
|
75 |
|
|
this.status = this.errorCodes.LOADING;
|
76 |
56070
|
argiro.kok
|
var refineParams = null;
|
77 |
56059
|
argiro.kok
|
if(this.customFilter){
|
78 |
|
|
refineParams = (refineParams?(refineParams+'&'):'')+"&fq="+StringUtils.URIEncode(this.customFilter.queryFieldName + " exact " + StringUtils.quote((this.customFilter.valueId )));
|
79 |
|
|
}
|
80 |
53860
|
argiro.kok
|
this.sub = this._refineFieldsService.getRefineFieldsResultsByEntityName(this.refineFields,this.entityName, this.properties,refineParams).subscribe(
|
81 |
50169
|
argiro.kok
|
data => {
|
82 |
54775
|
konstantin
|
//console.info("Get Stats for "+this.entityName+ ": [Total:"+data[0]+" ] [fields: "+data[1].length+"]");
|
83 |
50169
|
argiro.kok
|
this.filters = data[1];
|
84 |
|
|
this.status = this.errorCodes.DONE;
|
85 |
|
|
if(data[0] == 0 ){
|
86 |
|
|
this.status = this.errorCodes.NONE;
|
87 |
|
|
}
|
88 |
|
|
},
|
89 |
|
|
err => {
|
90 |
54825
|
konstantin
|
//console.log(err);
|
91 |
|
|
this.handleError("Error getting refine fields results (stats) by entity: "+this.entityName, err);
|
92 |
|
|
this.status = this.errorMessages.getErrorCode(err.status);
|
93 |
|
|
|
94 |
50169
|
argiro.kok
|
//TODO check erros (service not available, bad request)
|
95 |
|
|
// if( ){
|
96 |
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
97 |
|
|
// }
|
98 |
|
|
//this.status = this.errorCodes.ERROR;
|
99 |
54825
|
konstantin
|
/*if(err.status == '404') {
|
100 |
50169
|
argiro.kok
|
this.status = this.errorCodes.NOT_FOUND;
|
101 |
|
|
} else if(err.status == '500') {
|
102 |
|
|
this.status = this.errorCodes.ERROR;
|
103 |
|
|
} else {
|
104 |
|
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
105 |
54825
|
konstantin
|
}*/
|
106 |
50169
|
argiro.kok
|
}
|
107 |
|
|
);
|
108 |
54825
|
konstantin
|
}
|
109 |
|
|
|
110 |
|
|
private handleError(message: string, error) {
|
111 |
|
|
console.error("Browse Entities (Search): "+message, error);
|
112 |
|
|
}
|
113 |
50169
|
argiro.kok
|
}
|