1
|
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
|
import {ErrorCodes} from '../../utils/properties/errorCodes';
|
9
|
import {ErrorMessagesComponent} from '../../utils/errorMessages.component';
|
10
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
11
|
import {SearchPageComponent } from '../searchUtils/searchPage.component';
|
12
|
import {SearchUtilsClass} from '../searchUtils/searchUtils.class';
|
13
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
14
|
import {StringUtils} from '../../utils/string-utils.class';
|
15
|
|
16
|
@Component({
|
17
|
selector: 'browse-entities',
|
18
|
template: `
|
19
|
<div>
|
20
|
<!--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
|
<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
|
<div class ="uk-grid">
|
28
|
<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
|
<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
|
@Input() properties:EnvProperties;
|
43
|
@Input() connectCommunityId =null;
|
44
|
|
45
|
public sub: any;
|
46
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
47
|
private errorMessages: ErrorMessagesComponent;
|
48
|
public status = this.errorCodes.LOADING;
|
49
|
public fieldIdsMap=this.searchFields.RESULT_REFINE_FIELDS;
|
50
|
|
51
|
constructor ( private _refineFieldsService: RefineFieldResultsService ) {
|
52
|
this.errorMessages = new ErrorMessagesComponent();
|
53
|
}
|
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
|
var refineParams = this.connectCommunityId?("&fq="+StringUtils.URIEncode("communityId exact " + StringUtils.quote((this.connectCommunityId )))):null;
|
77
|
|
78
|
this.sub = this._refineFieldsService.getRefineFieldsResultsByEntityName(this.refineFields,this.entityName, this.properties,refineParams).subscribe(
|
79
|
data => {
|
80
|
//console.info("Get Stats for "+this.entityName+ ": [Total:"+data[0]+" ] [fields: "+data[1].length+"]");
|
81
|
this.filters = data[1];
|
82
|
this.status = this.errorCodes.DONE;
|
83
|
if(data[0] == 0 ){
|
84
|
this.status = this.errorCodes.NONE;
|
85
|
}
|
86
|
},
|
87
|
err => {
|
88
|
//console.log(err);
|
89
|
this.handleError("Error getting refine fields results (stats) by entity: "+this.entityName, err);
|
90
|
this.status = this.errorMessages.getErrorCode(err.status);
|
91
|
|
92
|
//TODO check erros (service not available, bad request)
|
93
|
// if( ){
|
94
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
95
|
// }
|
96
|
//this.status = this.errorCodes.ERROR;
|
97
|
/*if(err.status == '404') {
|
98
|
this.status = this.errorCodes.NOT_FOUND;
|
99
|
} else if(err.status == '500') {
|
100
|
this.status = this.errorCodes.ERROR;
|
101
|
} else {
|
102
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
103
|
}*/
|
104
|
}
|
105
|
);
|
106
|
}
|
107
|
|
108
|
private handleError(message: string, error) {
|
109
|
console.error("Browse Entities (Search): "+message, error);
|
110
|
}
|
111
|
}
|