Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document: filter search by organisation #174

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
(typeaheadOnSelect)="typeaheadOnSelect($event)"
[typeaheadIsFirstItemActive]="false"
>
<input type="hidden" name="size" value="10">
<input type="hidden" name="page" value="1">
<input type="hidden" *ngFor="let queryParam of extraQueryParams | keyvalue"
[name]="queryParam.key"
[value]="queryParam.value">
<div class="input-group-append">
<button type="submit" (click)="doSearch($event)" [ngClass]="buttonCssClass">
<i *ngIf="!typeaheadLoading" class="fa fa-search"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export class AutocompleteComponent implements OnInit {
// The maximum length of options items list. The default value is 20.
@Input() typeaheadOptionsLimit = 10;

// Additional query parameters
@Input() extraQueryParams = { page: '1', size: '10' };

// The current selected suggestion.
asyncSelected = {
text: undefined,
Expand Down Expand Up @@ -134,7 +137,10 @@ export class AutocompleteComponent implements OnInit {
if (!this._redirect) {
if (this.internalRouting) {
this._router.navigate([this.action], {
queryParams: { q: this.asyncSelected.query, page: '1', size: '10' }
queryParams: {
...this.extraQueryParams,
q: this.asyncSelected.query
}
});
} else {
this.form.nativeElement.submit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
</label>
<ng-container *ngIf="isSelected(bucket.key)">
<ng-core-record-search-aggregation-buckets
*ngFor="let aggregation of bucketChildren(bucket)"
*ngFor="let aggregation of bucketChildren[bucket.key]"
[buckets]="aggregation.buckets"
[size]="aggregation.bucketSize"
[aggregationKey]="aggregation.key"
></ng-core-record-search-aggregation-buckets>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { TranslateLanguageService } from '../../../../translate/translate-language.service';
Expand All @@ -24,7 +24,7 @@ import { AggregationsFilter, RecordSearchService } from '../../record-search.ser
selector: 'ng-core-record-search-aggregation-buckets',
templateUrl: './buckets.component.html'
})
export class BucketsComponent implements OnInit, OnDestroy {
export class BucketsComponent implements OnInit, OnDestroy, OnChanges {
/**
* Buckets list for aggregation
*/
Expand Down Expand Up @@ -53,6 +53,11 @@ export class BucketsComponent implements OnInit, OnDestroy {
*/
aggregationsFilters: Array<AggregationsFilter> = [];

/**
* Children of current bucket
*/
bucketChildren: any = {};

/**
* Subscription to aggregationsFilters observable
*/
Expand All @@ -68,7 +73,7 @@ export class BucketsComponent implements OnInit, OnDestroy {
private _translateService: TranslateService,
private _recordSearchService: RecordSearchService,
private _translateLanguage: TranslateLanguageService
) { }
) {}

/**
* Component initialization method, which subscribe to the observable of
Expand All @@ -79,12 +84,25 @@ export class BucketsComponent implements OnInit, OnDestroy {
this._aggregationsFiltersSubscription = this._recordSearchService.aggregationsFilters.subscribe(
(aggregationsFilters: Array<AggregationsFilter>) => {
if (aggregationsFilters !== null) {
this.aggregationsFilters = aggregationsFilters;
}
this.aggregationsFilters = aggregationsFilters;
}
}
);
}

/**
* On changes hook, called each time an input property is modified.
* If buckets are changed, refresh children buckets.
* @param changes - bucket changes
*/
ngOnChanges(changes: SimpleChanges) {
if (changes.buckets) {
for (const bucket of this.buckets) {
this.bucketChildren[bucket.key] = this.getBucketChildren(bucket);
}
}
}

/**
* Component destruction.
* Unsubscribes from the observable of aggregations filters.
Expand All @@ -98,7 +116,9 @@ export class BucketsComponent implements OnInit, OnDestroy {
* @return List of selected filters
*/
get aggregationFilters(): Array<string> {
const aggregationFilters = this.aggregationsFilters.find((item: AggregationsFilter) => item.key === this.aggregationKey);
const aggregationFilters = this.aggregationsFilters.find(
(item: AggregationsFilter) => item.key === this.aggregationKey
);
if (aggregationFilters === undefined) {
return [];
}
Expand Down Expand Up @@ -148,15 +168,23 @@ export class BucketsComponent implements OnInit, OnDestroy {

if (index === -1) {
// No filters exist for the aggregation.
this._recordSearchService.updateAggregationFilter(this.aggregationKey, [bucket.key]);
this._recordSearchService.updateAggregationFilter(this.aggregationKey, [
bucket.key,
]);
} else {
if (!this.aggregationsFilters[index].values.includes(bucket.key)) {
// Bucket value is not yet selected, we add value to selected values.
this.aggregationsFilters[index].values.push(bucket.key);
this._recordSearchService.updateAggregationFilter(this.aggregationKey, this.aggregationsFilters[index].values);
this._recordSearchService.updateAggregationFilter(
this.aggregationKey,
this.aggregationsFilters[index].values
);
} else {
// Removes value from selected values and all children selected values.
this._recordSearchService.removeAggregationFilter(this.aggregationKey, bucket);
this._recordSearchService.removeAggregationFilter(
this.aggregationKey,
bucket
);
}
}
}
Expand All @@ -166,13 +194,14 @@ export class BucketsComponent implements OnInit, OnDestroy {
* @param bucket: parent bucket
* @return Bucket children list of given bucket
*/
bucketChildren(bucket: any): Array<any> {
getBucketChildren(bucket: any): Array<any> {
const children = [];
for (const k in bucket) {
if (bucket[k].buckets) {
children.push({
bucketSize: this.bucketSize,
key: k,
buckets: bucket[k].buckets
buckets: [...bucket[k].buckets],
});
}
}
Expand Down