Skip to content

Commit

Permalink
Add dropdown values in resultlist
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbet committed Jul 16, 2018
1 parent be45e7b commit 8dd743e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
33 changes: 28 additions & 5 deletions src/contributors/ResultListContributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { getElementFromJsonObject, isArray, download } from '../utils/utils';
import { Action, ElementIdentifier, triggerType, SortEnum, FieldsConfiguration, Column, Detail, Field } from '../models/models';
import * as jsonpath from 'jsonpath';
import * as jsonSchema from '../jsonSchemas/resultlistContributorConf.schema.json';
import { AggregationResponse } from 'arlas-api';

/**
* Interface define in Arlas-web-components
Expand Down Expand Up @@ -157,6 +158,10 @@ export class ResultListContributor extends Contributor {
*/
public fieldsList: Array<{ columnName: string, fieldName: string, dataType: string }> = [];
/**
* List of column of the table, @Input() fieldsList of ResultListComponent.
*/
public dropDownMapValues: Map<string, Observable<Array<string>>> = new Map<string, Observable<Array<string>>>();
/**
* Instance of DetailedDataRetriever class, @Input() detailedDataRetriever of ResultListComponent.
*/
public detailedDataRetriever = new ResultListDetailedDataRetriever();
Expand All @@ -167,6 +172,8 @@ export class ResultListContributor extends Contributor {


public filtersMap: Map<string, string | number | Date> = new Map<string, string | number | Date>();
public fieldsConfiguration = this.getConfigValue('fieldsConfiguration');

/**
* Sort parameter of the list.
*/
Expand All @@ -175,11 +182,7 @@ export class ResultListContributor extends Contributor {
* geoSort parameter of the list.
*/
private geoOrderSort: Sort = {};

private includesvalues = new Array<string>();


public fieldsConfiguration = this.getConfigValue('fieldsConfiguration');
private columns: Array<Column> = (this.getConfigValue('columns') !== undefined) ? (this.getConfigValue('columns')) : ([]);
private columnsProcess = {};
/**
Expand All @@ -202,6 +205,15 @@ export class ResultListContributor extends Contributor {
this.columnsProcess[column.columnName] = column.process;
this.fieldsList.push(column);
this.includesvalues.push(column.fieldName);
if (column.dropdown) {
let size = 10;
if (column.dropdownsize) {
size = column.dropdownsize;
}
this.dropDownMapValues.set(column.fieldName, this.getDropDownValues(column.fieldName, size.toString()));
} else {
this.dropDownMapValues.set(column.fieldName, Observable.from([[]]));
}
});
this.includesvalues.push(this.fieldsConfiguration.idFieldName);
if (this.fieldsConfiguration.titleFieldNames) {
Expand Down Expand Up @@ -541,7 +553,7 @@ export class ResultListContributor extends Contributor {
});
}

private setProcessFieldData(h: Hit, field: Field, map: Map<string, string | number | Date>, dataType: string) {
private setProcessFieldData(h: Hit, field: Field, map: Map<string, string | number | Date>, dataType: string): void {
const result: string = getElementFromJsonObject(h.data, field.fieldPath);
const process: string = field.process;
let resultValue = result;
Expand All @@ -552,4 +564,15 @@ export class ResultListContributor extends Contributor {
}
map.set(field.fieldPath + '_' + dataType, resultValue);
}

private getDropDownValues(field: string, size: string): Observable<Array<string>> {
const aggregations: Aggregation[] = new Array<Aggregation>();
aggregations.push({
type: Aggregation.TypeEnum.Term,
field: field,
size: size
});
const result = this.collaborativeSearcheService.resolveAggregation([projType.aggregate, aggregations]);
return result.map(aggResponse => aggResponse.elements.map(element => (<any>element).key_as_string));
}
}
10 changes: 9 additions & 1 deletion src/jsonSchemas/resultlistContributorConf.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"type": "string"
},
"iconCssClass": {
"description": "Field path of field to customize css class",
"description": "Field path of field to customize css",
"type": "string"
}
}
Expand All @@ -99,6 +99,14 @@
"process": {
"description": "Process transformation to display (ex : result.trim())",
"type": "string"
},
"dropdown": {
"description": "Whether the filter column search has a dropdown list",
"type": "boolean"
},
"dropdownsize": {
"description": "Size of dropdown list, 10 by default",
"type": "number"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export interface Column {
fieldName: string;
dataType: string;
process: string;
dropdown: boolean;
dropdownsize: number;
}

export interface Detail {
Expand Down

0 comments on commit 8dd743e

Please sign in to comment.