Skip to content
Snippets Groups Projects
Unverified Commit b1aaaf30 authored by xgui3783's avatar xgui3783 Committed by GitHub
Browse files

Merge pull request #1384 from FZJ-INM1-BDA/fix_miniSearchBar

fix: min tray filtering
parents 75962d85 45a1c57e
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import { UntypedFormControl } from "@angular/forms";
import { debounceTime, distinctUntilChanged, map, startWith } from "rxjs/operators";
import { MatAutocompleteSelectedEvent } from "@angular/material/autocomplete";
import { SapiViewsCoreRichRegionListTemplateDirective } from "./regionListSearchTmpl.directive";
import { BehaviorSubject, combineLatest } from "rxjs";
const filterRegionViaSearch = (searchTerm: string) => (region:SxplrRegion) => {
return region.name.toLocaleLowerCase().includes(searchTerm.toLocaleLowerCase())
......@@ -25,13 +26,16 @@ export class SapiViewsCoreRichRegionListSearch {
showNOptions = 4
private _regions: SxplrRegion[] = []
get regions(){
return this._regions
}
#regions = new BehaviorSubject<SxplrRegion[]>([])
@Input('sxplr-sapiviews-core-rich-regionlistsearch-regions')
set regions(reg: SxplrRegion[]) {
this._regions = reg.filter(r => !reg.some(c => c.parentIds.includes(r.id)))
this.#regions.next(reg)
}
#mappedRegionNames = new BehaviorSubject<string[]>([])
@Input('sxplr-sapiviews-core-rich-regionlistsearch-mapped-region-names')
set mappedRegions(regNames: string[]) {
this.#mappedRegionNames.next(regNames)
}
@ContentChild(SapiViewsCoreRichRegionListTemplateDirective)
......@@ -51,13 +55,18 @@ export class SapiViewsCoreRichRegionListSearch {
public searchFormControl = new UntypedFormControl()
public searchedList$ = this.searchFormControl.valueChanges.pipe(
startWith(''),
distinctUntilChanged(),
debounceTime(160),
map((searchTerm: string | SxplrRegion) => {
public searchedList$ = combineLatest([
this.searchFormControl.valueChanges.pipe(
startWith(''),
distinctUntilChanged(),
debounceTime(160),
),
this.#regions,
this.#mappedRegionNames
]).pipe(
map(([searchTerm, regions, mappedRegionNames]) => {
if (typeof searchTerm === "string") {
return this.regions.filter(filterRegionViaSearch(searchTerm))
return regions.filter(r => mappedRegionNames.includes(r.name)).filter(filterRegionViaSearch(searchTerm))
}
return []
})
......
......@@ -562,6 +562,7 @@
<sxplr-sapiviews-core-rich-regionlistsearch
[sxplr-sapiviews-core-rich-regionlistsearch-regions]="allAvailableRegions$ | async"
[sxplr-sapiviews-core-rich-regionlistsearch-mapped-region-names]="view.labelMappedRegionNames"
[sxplr-sapiviews-core-rich-regionlistsearch-current-search]="view.selectedRegions.length === 1 ? view.selectedRegions[0].name : null"
(sxplr-sapiviews-core-rich-regionlistsearch-region-select)="selectRoi($event)"
(sxplr-sapiviews-core-rich-regionlistsearch-region-toggle)="toggleRoi($event)">
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment