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 {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
|
9
|
import {SearchFields} from '../../utils/properties/searchFields';
|
10
|
import {SearchPageComponent } from '../searchUtils/searchPage.component';
|
11
|
import {SearchUtilsClass} from '../searchUtils/searchUtils.class';
|
12
|
|
13
|
@Component({
|
14
|
selector: 'browse-entities',
|
15
|
template: `
|
16
|
<div>
|
17
|
<div *ngIf="status == errorCodes.LOADING" class="uk-alert uk-alert-primary uk-animation-fade" role="alert">Loading...</div>
|
18
|
<div *ngIf="status == errorCodes.NONE" class="uk-alert uk-alert-primary uk-animation-fade" role="alert">No Results found</div>
|
19
|
<div *ngIf="status == errorCodes.ERROR" class="uk-alert uk-alert-warning uk-animation-fade" role="alert">An Error Occured</div>
|
20
|
<div *ngIf="status == errorCodes.NOT_AVAILABLE" class="uk-alert uk-alert-danger uk-animation-fade" role="alert">Service not available</div>
|
21
|
|
22
|
<div class ="uk-grid">
|
23
|
<div *ngFor= "let filter of filters" class = "uk-margin-top uk-width-1-4@l uk-width-1-3@m uk-width-1-2@s">
|
24
|
<browse-statistic [baseUrl]=baseUrl [filter]=filter ></browse-statistic>
|
25
|
</div>
|
26
|
</div>
|
27
|
</div>
|
28
|
`
|
29
|
|
30
|
})
|
31
|
export class BrowseEntitiesComponent {
|
32
|
public searchFields:SearchFields = new SearchFields();
|
33
|
public filters =[];
|
34
|
@Input() public baseUrl:string = "";
|
35
|
@Input() public entityName:string = "";
|
36
|
@Input() public refineFields: string[] ;//= this.searchFields.RESULT_REFINE_FIELDS;
|
37
|
public sub: any;
|
38
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
39
|
public status = this.errorCodes.LOADING;
|
40
|
public fieldIdsMap=this.searchFields.RESULT_REFINE_FIELDS;
|
41
|
|
42
|
constructor ( private _refineFieldsService: RefineFieldResultsService ) {
|
43
|
// this.baseUrl = OpenaireProperties.getLinkToSearchPublications();
|
44
|
|
45
|
}
|
46
|
|
47
|
public ngOnInit() {
|
48
|
for(var i=0; i < this.searchFields.HIDDEN_FIELDS.length; i++){
|
49
|
var index = this.refineFields.indexOf(this.searchFields.HIDDEN_FIELDS[i]) ;
|
50
|
if(index > -1){
|
51
|
this.refineFields.splice(index,1);
|
52
|
|
53
|
}
|
54
|
}
|
55
|
this.getStats();
|
56
|
}
|
57
|
|
58
|
public ngOnDestroy() {
|
59
|
if(this.sub){
|
60
|
this.sub.unsubscribe();
|
61
|
}
|
62
|
|
63
|
}
|
64
|
|
65
|
|
66
|
private getStats(){
|
67
|
|
68
|
this.status = this.errorCodes.LOADING;
|
69
|
this.sub = this._refineFieldsService.getRefineFieldsResultsByEntityName(this.refineFields,this.entityName).subscribe(
|
70
|
data => {
|
71
|
console.info("Get Stats for "+this.entityName+ ": [Total:"+data[0]+" ] [fields: "+data[1].length+"]");
|
72
|
this.filters = data[1];
|
73
|
this.status = this.errorCodes.DONE;
|
74
|
if(data[0] == 0 ){
|
75
|
this.status = this.errorCodes.NONE;
|
76
|
}
|
77
|
},
|
78
|
err => {
|
79
|
console.log(err);
|
80
|
//TODO check erros (service not available, bad request)
|
81
|
// if( ){
|
82
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
83
|
// }
|
84
|
this.status = this.errorCodes.ERROR;
|
85
|
}
|
86
|
);
|
87
|
}
|
88
|
}
|