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 |
|
|
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
|
9 |
|
|
import {SearchFields, FieldDetails} 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-animation-fade uk-margin-large-top uk-width-1-1" role="alert"><img src="./assets/loading.gif" class="uk-align-center" alt="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" role="alert">Service temprorarily unavailable. Please try again later.</div>
|
21 |
|
|
<div *ngIf="status == errorCodes.NOT_FOUND" class="uk-alert uk-alert-danger" role="alert">No filters found</div-->
|
22 |
|
|
<errorMessages [status]="[status]" [type]="'results'"></errorMessages>
|
23 |
|
|
|
24 |
|
|
<div class ="uk-grid">
|
25 |
|
|
<div *ngFor= "let filter of filters" class = "uk-margin-bottom uk-width-1-4@l uk-width-1-3@m uk-width-1-2@s">
|
26 |
|
|
<browse-statistic [baseUrl]=baseUrl [filter]=filter ></browse-statistic>
|
27 |
|
|
</div>
|
28 |
|
|
</div>
|
29 |
|
|
</div>
|
30 |
|
|
`
|
31 |
|
|
|
32 |
|
|
})
|
33 |
|
|
export class BrowseEntitiesComponent {
|
34 |
|
|
public searchFields:SearchFields = new SearchFields();
|
35 |
|
|
public filters =[];
|
36 |
|
|
@Input() public baseUrl:string = "";
|
37 |
|
|
@Input() public entityName:string = "";
|
38 |
|
|
@Input() public refineFields: string[] ;//= this.searchFields.RESULT_REFINE_FIELDS;
|
39 |
|
|
public sub: any;
|
40 |
|
|
public errorCodes:ErrorCodes = new ErrorCodes();
|
41 |
|
|
public status = this.errorCodes.LOADING;
|
42 |
|
|
public fieldIdsMap=this.searchFields.RESULT_REFINE_FIELDS;
|
43 |
|
|
|
44 |
|
|
constructor ( private _refineFieldsService: RefineFieldResultsService ) {
|
45 |
|
|
// this.baseUrl = OpenaireProperties.getLinkToSearchPublications();
|
46 |
|
|
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
public ngOnInit() {
|
50 |
|
|
for(var i=0; i < this.searchFields.HIDDEN_FIELDS.length; i++){
|
51 |
|
|
var index = this.refineFields.indexOf(this.searchFields.HIDDEN_FIELDS[i]) ;
|
52 |
|
|
if(index > -1){
|
53 |
|
|
this.refineFields.splice(index,1);
|
54 |
|
|
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
this.getStats();
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
public ngOnDestroy() {
|
61 |
|
|
if(this.sub){
|
62 |
|
|
this.sub.unsubscribe();
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
private getStats(){
|
68 |
|
|
|
69 |
|
|
this.status = this.errorCodes.LOADING;
|
70 |
|
|
this.sub = this._refineFieldsService.getRefineFieldsResultsByEntityName(this.refineFields,this.entityName).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 |
|
|
//TODO check erros (service not available, bad request)
|
82 |
|
|
// if( ){
|
83 |
|
|
// this.searchUtils.status = ErrorCodes.ERROR;
|
84 |
|
|
// }
|
85 |
|
|
//this.status = this.errorCodes.ERROR;
|
86 |
|
|
if(err.status == '404') {
|
87 |
|
|
this.status = this.errorCodes.NOT_FOUND;
|
88 |
|
|
} else if(err.status == '500') {
|
89 |
|
|
this.status = this.errorCodes.ERROR;
|
90 |
|
|
} else {
|
91 |
|
|
this.status = this.errorCodes.NOT_AVAILABLE;
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
);
|
95 |
|
|
}
|
96 |
|
|
}
|