Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien Délèze committed Mar 31, 2020
1 parent 9b036e3 commit ca5b48c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->
<ul *ngIf="buckets" class="list-unstyled m-0">
<li class="form-check" *ngFor="let bucket of buckets|slice:0:bucketSize">
<input class="form-check-input" type="checkbox" [checked]="isSelected(bucket.key)"
<input class="form-check-input" type="checkbox" [checked]="isSelected(getFullValue(bucket.key))"
(click)="updateFilter(bucket.key)">
<label class="form-check-label">
<span *ngIf="bucket.name">{{ bucket.name }}</span>
Expand All @@ -27,7 +27,7 @@
*ngFor="let aggregation of bucketChildren(bucket)"
[buckets]="aggregation.buckets"
[aggregationKey]="aggregation.key"
[size]="size"
[size]="aggregation.bucketSize"
[parents]="getParentsWithValue(bucket.key)"
></ng-core-record-search-aggregation-buckets>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ export class BucketsComponent implements OnInit {
});
}

/**
* Prefix of the value containing all parents values.
*/
get parentPrefix() {
return `${this.parents.join('-')}-`;
}

/**
* Return an array containing all the parents values (with the current value, too).
* This array is given to children for constructing their values.
Expand All @@ -87,6 +80,15 @@ export class BucketsComponent implements OnInit {
return parents;
}

/**
* Return full value for the given bucket value.
* @param value Current bucket value
* @return string
*/
getFullValue(value: string): string {
return this.getParentsWithValue(value).join('-');
}

/**
* Get current language
* @return Current language
Expand Down Expand Up @@ -115,7 +117,7 @@ export class BucketsComponent implements OnInit {
* @return Boolean
*/
isSelected(value: string): boolean {
return this.aggregationFilters.includes(this.parentPrefix + value);
return this.aggregationFilters.includes(value);
}

/**
Expand All @@ -125,12 +127,12 @@ export class BucketsComponent implements OnInit {
*/
updateFilter(value: string) {
// Add parent values
value = this.parentPrefix + value;
const fullValue = this.getFullValue(value);

if (this.isSelected(value)) {
this.aggregationFilters = this.aggregationFilters.filter(selectedValue => selectedValue !== value);
if (this.isSelected(fullValue)) {
this.aggregationFilters = this.aggregationFilters.filter(selectedValue => selectedValue !== fullValue);
} else {
this.aggregationFilters.push(value);
this.aggregationFilters.push(fullValue);
}

this._recordSearchService.updateAggregationFilter(this.aggregationKey, this.aggregationFilters);
Expand Down

0 comments on commit ca5b48c

Please sign in to comment.