import {Component, Input, ViewChild} from '@angular/core'; import { ActivatedRoute} from '@angular/router'; import {Location} from '@angular/common'; import { Filter, Value} from '../searchUtils/searchHelperClasses.class'; import {RefineFieldResultsService} from '../../services/refineFieldResults.service'; import {ErrorCodes} from '../../utils/properties/errorCodes'; import {SearchFields, FieldDetails} from '../../utils/properties/searchFields'; import {SearchPageComponent } from '../searchUtils/searchPage.component'; import {SearchUtilsClass} from '../searchUtils/searchUtils.class'; import{EnvProperties} from '../../utils/properties/env-properties'; @Component({ selector: 'browse-entities', template: `
` }) export class BrowseEntitiesComponent { public searchFields:SearchFields = new SearchFields(); public filters =[]; @Input() public baseUrl:string = ""; @Input() public entityName:string = ""; @Input() public refineFields: string[] ;//= this.searchFields.RESULT_REFINE_FIELDS; @Input() properties:EnvProperties; public sub: any; public errorCodes:ErrorCodes = new ErrorCodes(); public status = this.errorCodes.LOADING; public fieldIdsMap=this.searchFields.RESULT_REFINE_FIELDS; constructor ( private _refineFieldsService: RefineFieldResultsService ) { } public ngOnInit() { for(var i=0; i < this.searchFields.HIDDEN_FIELDS.length; i++){ var index = this.refineFields.indexOf(this.searchFields.HIDDEN_FIELDS[i]) ; if(index > -1){ this.refineFields.splice(index,1); } } this.getStats(); } public ngOnDestroy() { if(this.sub){ this.sub.unsubscribe(); } } private getStats(){ this.status = this.errorCodes.LOADING; this.sub = this._refineFieldsService.getRefineFieldsResultsByEntityName(this.refineFields,this.entityName, this.properties).subscribe( data => { console.info("Get Stats for "+this.entityName+ ": [Total:"+data[0]+" ] [fields: "+data[1].length+"]"); this.filters = data[1]; this.status = this.errorCodes.DONE; if(data[0] == 0 ){ this.status = this.errorCodes.NONE; } }, err => { console.log(err); //TODO check erros (service not available, bad request) // if( ){ // this.searchUtils.status = ErrorCodes.ERROR; // } //this.status = this.errorCodes.ERROR; if(err.status == '404') { this.status = this.errorCodes.NOT_FOUND; } else if(err.status == '500') { this.status = this.errorCodes.ERROR; } else { this.status = this.errorCodes.NOT_AVAILABLE; } } ); } }