63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
|
|
import { Filter, Value} from '../../searchPages/searchUtils/searchHelperClasses.class';
|
|
import { SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
|
|
|
|
|
export class RefineResultsUtils {
|
|
|
|
|
|
public static parse (data, fields:string[], entityType:string):Filter[] {
|
|
// var data = this.json.refineReuslts;
|
|
|
|
var searchFields:SearchFields = new SearchFields();
|
|
var filters:Filter[] = [];
|
|
if(data){
|
|
for(let j=0; j<fields.length; j++) {
|
|
|
|
var filter:Filter = new Filter();
|
|
filter.title = searchFields.getFieldName(fields[j],entityType);
|
|
filter.filterId = fields[j];
|
|
filter.originalFilterId = fields[j];
|
|
let field = data[fields[j]];
|
|
if(field){
|
|
for(let i=0; i<field.length; i++) {
|
|
var value:Value = new Value();
|
|
value.name = field[i].name;
|
|
value.name =this.removePartAfterCharacters(value,"||");
|
|
value.number = field[i].count;
|
|
value.id = field[i].id;
|
|
if(RefineResultsUtils.includeValue(value)){
|
|
filter.values.push(value);
|
|
}
|
|
|
|
|
|
}
|
|
filters.push(filter);
|
|
}
|
|
}
|
|
}
|
|
return filters;
|
|
}
|
|
private static includeValue (field):boolean {
|
|
if( field.name == "unidentified"){
|
|
return false;
|
|
|
|
}
|
|
return true;
|
|
}
|
|
private static removePartAfterCharacters(field, characters):string {
|
|
if( field.name.indexOf(characters) !=-1){
|
|
return field.name.split(characters)[0];
|
|
|
|
}
|
|
return field.name;
|
|
}
|
|
public static inParenthesisThePartAfterCharacters(field, characters):string {
|
|
if( field.name.indexOf(characters) !=-1){
|
|
return field.name.split(characters)[0]+" ("+field.name.split(characters)[1]+")";
|
|
|
|
}
|
|
return field.name;
|
|
}
|
|
}
|