Skip to content
Snippets Groups Projects
Commit 23d68f16 authored by Xiao Gui's avatar Xiao Gui
Browse files

fix: region hierachy enter resets page

fix: mini region search now shows + n more
chore: fix mini region search style
parent 480b9542
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
## Features ## Features
- More detailed filter for connectivity - More detailed filter for connectivity
- Supports arbitrary layer based on URL parameter - Supports arbitrary layer based on URL parameter (#1252)
- Mini region search now shows prompt ... and {n} more (#1249)
- Minor update of mini region search UI
## Behind the scenes ## Behind the scenes
...@@ -13,3 +15,4 @@ ...@@ -13,3 +15,4 @@
## Bugfix ## Bugfix
- fixed open cheatsheet/quickstart in new window functionality - fixed open cheatsheet/quickstart in new window functionality
- fixed region hierarchy, on hit enter resetting the application (#1240)
...@@ -9,6 +9,7 @@ import { SapiViewsCoreRegionModule } from "../region"; ...@@ -9,6 +9,7 @@ import { SapiViewsCoreRegionModule } from "../region";
import { HighlightPipe } from "./regionsHierarchy/highlight.pipe"; import { HighlightPipe } from "./regionsHierarchy/highlight.pipe";
import { SapiViewsCoreRichRegionsHierarchy } from "./regionsHierarchy/regionsHierarchy.component"; import { SapiViewsCoreRichRegionsHierarchy } from "./regionsHierarchy/regionsHierarchy.component";
import { SapiViewsCoreRichRegionListSearch } from "./regionsListSearch/regionListSearch.component"; import { SapiViewsCoreRichRegionListSearch } from "./regionsListSearch/regionListSearch.component";
import { SapiViewsCoreRichRegionListTemplateDirective } from "./regionsListSearch/regionListSearchTmpl.directive";
@NgModule({ @NgModule({
imports: [ imports: [
...@@ -24,9 +25,11 @@ import { SapiViewsCoreRichRegionListSearch } from "./regionsListSearch/regionLis ...@@ -24,9 +25,11 @@ import { SapiViewsCoreRichRegionListSearch } from "./regionsListSearch/regionLis
SapiViewsCoreRichRegionListSearch, SapiViewsCoreRichRegionListSearch,
SapiViewsCoreRichRegionsHierarchy, SapiViewsCoreRichRegionsHierarchy,
HighlightPipe, HighlightPipe,
SapiViewsCoreRichRegionListTemplateDirective,
], ],
exports: [ exports: [
SapiViewsCoreRichRegionListSearch, SapiViewsCoreRichRegionListSearch,
SapiViewsCoreRichRegionListTemplateDirective,
SapiViewsCoreRichRegionsHierarchy, SapiViewsCoreRichRegionsHierarchy,
] ]
}) })
......
<form class="sxplr-custom-cmp text sxplr-w-100"> <mat-form-field class="sxplr-custom-cmp text sxplr-w-100">
<mat-form-field class="sxplr-w-100"> <input
<input [placeholder]="placeholderText"
[placeholder]="placeholderText" type="text"
type="text" matInput
matInput name="searchTerm"
name="searchTerm" [formControl]="searchFormControl"
[formControl]="searchFormControl" autocomplete="off">
autocomplete="off">
<!-- search input suffix --> <!-- search input suffix -->
<div matSuffix> <div matSuffix>
<ng-content select="[search-input-suffix]"></ng-content> <ng-content select="[search-input-suffix]"></ng-content>
</div> </div>
</mat-form-field> </mat-form-field>
</form>
<ng-template #tmplRef let-region> <ng-template #tmplRef let-region>
<div class="mat-body sxplr-d-flex sxplr-align-items-center sxplr-h-100 region-tmpl" <div class="mat-body sxplr-d-flex sxplr-align-items-center sxplr-h-100 region-tmpl"
......
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, TemplateRef } from "@angular/core"; import { ChangeDetectionStrategy, Component, ContentChild, EventEmitter, Input, Output, TemplateRef } from "@angular/core";
import { SapiRegionModel } from "src/atlasComponents/sapi/type"; import { SapiRegionModel } from "src/atlasComponents/sapi/type";
import { ARIA_LABELS } from "common/constants" import { ARIA_LABELS } from "common/constants"
import { UntypedFormControl } from "@angular/forms"; import { UntypedFormControl } from "@angular/forms";
import { debounceTime, distinctUntilChanged, map, startWith } from "rxjs/operators"; import { debounceTime, distinctUntilChanged, map, startWith } from "rxjs/operators";
import { MatAutocompleteSelectedEvent } from "@angular/material/autocomplete"; import { MatAutocompleteSelectedEvent } from "@angular/material/autocomplete";
import { SapiViewsCoreRichRegionListTemplateDirective } from "./regionListSearchTmpl.directive";
/** /**
* Filter function, which determines whether the region will be included in the list of autocompleted search. * Filter function, which determines whether the region will be included in the list of autocompleted search.
...@@ -34,6 +35,8 @@ export class SapiViewsCoreRichRegionListSearch { ...@@ -34,6 +35,8 @@ export class SapiViewsCoreRichRegionListSearch {
ARIA_LABELS = ARIA_LABELS ARIA_LABELS = ARIA_LABELS
showNOptions = 4
private _regions: SapiRegionModel[] = [] private _regions: SapiRegionModel[] = []
get regions(){ get regions(){
return this._regions return this._regions
...@@ -43,6 +46,9 @@ export class SapiViewsCoreRichRegionListSearch { ...@@ -43,6 +46,9 @@ export class SapiViewsCoreRichRegionListSearch {
this._regions = val.filter(filterRegionForListSearch) this._regions = val.filter(filterRegionForListSearch)
} }
@ContentChild(SapiViewsCoreRichRegionListTemplateDirective)
regionTmplDirective: SapiViewsCoreRichRegionListTemplateDirective
@Input('sxplr-sapiviews-core-rich-regionlistsearch-region-template-ref') @Input('sxplr-sapiviews-core-rich-regionlistsearch-region-template-ref')
regionTemplateRef: TemplateRef<any> regionTemplateRef: TemplateRef<any>
...@@ -54,18 +60,22 @@ export class SapiViewsCoreRichRegionListSearch { ...@@ -54,18 +60,22 @@ export class SapiViewsCoreRichRegionListSearch {
public searchFormControl = new UntypedFormControl() public searchFormControl = new UntypedFormControl()
public autocompleteList$ = this.searchFormControl.valueChanges.pipe( public searchedList$ = this.searchFormControl.valueChanges.pipe(
startWith(''), startWith(''),
distinctUntilChanged(), distinctUntilChanged(),
debounceTime(160), debounceTime(160),
map((searchTerm: string | SapiRegionModel) => { map((searchTerm: string | SapiRegionModel) => {
if (typeof searchTerm === "string") { if (typeof searchTerm === "string") {
return this.regions.filter(filterRegionViaSearch(searchTerm)).slice(0,5) return this.regions.filter(filterRegionViaSearch(searchTerm))
} }
return [] return []
}) })
) )
public autocompleteList$ = this.searchedList$.pipe(
map(list => list.slice(0, this.showNOptions))
)
displayFn(region: SapiRegionModel){ displayFn(region: SapiRegionModel){
return region?.name || '' return region?.name || ''
} }
......
...@@ -5,9 +5,10 @@ import { SAPI } from "src/atlasComponents/sapi" ...@@ -5,9 +5,10 @@ import { SAPI } from "src/atlasComponents/sapi"
import { atlasId, provideDarkTheme, getParcRegions, parcId, spaceId } from "src/atlasComponents/sapi/stories.base" import { atlasId, provideDarkTheme, getParcRegions, parcId, spaceId } from "src/atlasComponents/sapi/stories.base"
import { SapiViewsCoreRichModule } from "../module" import { SapiViewsCoreRichModule } from "../module"
import { SapiViewsCoreRichRegionListSearch } from "./regionListSearch.component" import { SapiViewsCoreRichRegionListSearch } from "./regionListSearch.component"
import { Pipe, PipeTransform, SecurityContext } from "@angular/core" import { Pipe, PipeTransform } from "@angular/core"
import { SapiRegionModel } from "src/atlasComponents/sapi/type" import { SapiRegionModel } from "src/atlasComponents/sapi/type"
import { DomSanitizer, SafeHtml } from "@angular/platform-browser" import { DomSanitizer } from "@angular/platform-browser"
import { SapiViewsCoreRegionModule } from "../../region"
@Pipe({ @Pipe({
name: 'regionTmplPipe', name: 'regionTmplPipe',
...@@ -38,6 +39,7 @@ export default { ...@@ -38,6 +39,7 @@ export default {
imports: [ imports: [
HttpClientModule, HttpClientModule,
SapiViewsCoreRichModule, SapiViewsCoreRichModule,
SapiViewsCoreRegionModule,
], ],
providers: [ providers: [
SAPI, SAPI,
...@@ -63,10 +65,8 @@ const Template: Story<SapiViewsCoreRichRegionListSearch> = (args: SapiViewsCoreR ...@@ -63,10 +65,8 @@ const Template: Story<SapiViewsCoreRichRegionListSearch> = (args: SapiViewsCoreR
tmplRef tmplRef
} = parameters } = parameters
const template = ` const template = `
${tmplRef ? ('<ng-template #tmplref let-region>' + tmplRef + '</ng-template>') : ''} <sxplr-sapiviews-core-rich-regionlistsearch>
<sxplr-sapiviews-core-rich-regionlistsearch ${tmplRef ? ('<ng-template regionTemplate let-region>' + tmplRef + '</ng-template>') : ''}
${tmplRef ? '[sxplr-sapiviews-core-rich-regionlistsearch-region-template-ref]="tmplref"' : ''}
>
${contentProjection || ''} ${contentProjection || ''}
</sxplr-sapiviews-core-rich-regionlistsearch> </sxplr-sapiviews-core-rich-regionlistsearch>
` `
...@@ -80,6 +80,9 @@ const Template: Story<SapiViewsCoreRichRegionListSearch> = (args: SapiViewsCoreR ...@@ -80,6 +80,9 @@ const Template: Story<SapiViewsCoreRichRegionListSearch> = (args: SapiViewsCoreR
}) })
} }
Template.loaders = [] Template.loaders = []
Template.parameters = {
tmplRef: `<span>{{ region.name }}</span>`
}
const asyncLoader = async (atlasId: string, parcId: string, spaceId: string) => { const asyncLoader = async (atlasId: string, parcId: string, spaceId: string) => {
const regions = await getParcRegions(atlasId, parcId, spaceId) const regions = await getParcRegions(atlasId, parcId, spaceId)
...@@ -97,6 +100,14 @@ const getContentProjection = ({ searchInputSuffix }) => { ...@@ -97,6 +100,14 @@ const getContentProjection = ({ searchInputSuffix }) => {
} }
export const Default = Template.bind({}) export const Default = Template.bind({})
Default.parameters = {
...Template.parameters,
tmplRef: `
<sxplr-sapiviews-core-region-region-list-item
[sxplr-sapiviews-core-region-region]="region">
</sxplr-sapiviews-core-region-region-list-item>
`
}
Default.loaders = [ Default.loaders = [
async () => { async () => {
const { regions } = await asyncLoader(atlasId.human, parcId.human.jba29, spaceId.human.mni152) const { regions } = await asyncLoader(atlasId.human, parcId.human.jba29, spaceId.human.mni152)
...@@ -112,6 +123,7 @@ InputSuffix.loaders = [ ...@@ -112,6 +123,7 @@ InputSuffix.loaders = [
} }
] ]
InputSuffix.parameters = { InputSuffix.parameters = {
...Template.parameters,
contentProjection: getContentProjection({ contentProjection: getContentProjection({
searchInputSuffix: `SUFFIX` searchInputSuffix: `SUFFIX`
}) })
...@@ -125,7 +137,8 @@ TemplatedRegionSuffix.loaders = [ ...@@ -125,7 +137,8 @@ TemplatedRegionSuffix.loaders = [
} }
] ]
TemplatedRegionSuffix.parameters = { TemplatedRegionSuffix.parameters = {
tmplRef: `<span [innerHTML]="region | regionTmplPipe"></span>` ...Template.parameters,
tmplRef: `<span [innerHTML]="region | regionTmplPipe"></span><span>{{ region.name }}</span>`
} }
......
...@@ -32,21 +32,33 @@ ...@@ -32,21 +32,33 @@
*ngFor="let region of autocompleteList$ | async" *ngFor="let region of autocompleteList$ | async"
[value]="region"> [value]="region">
<div class="sxplr-d-flex sxplr-justify-content-space-between"> <ng-template [ngIf]="regionTmplDirective">
<sxplr-sapiviews-core-region-region-list-item
[sxplr-sapiviews-core-region-region]="region">
</sxplr-sapiviews-core-region-region-list-item>
<ng-template <ng-template
[ngIf]="regionTemplateRef" [ngTemplateOutlet]="regionTmplDirective.tmplRef"
[ngTemplateOutlet]="regionTemplateRef"
[ngTemplateOutletContext]="{ [ngTemplateOutletContext]="{
$implicit: region $implicit: region
}"> }">
</ng-template> </ng-template>
</div> </ng-template>
</mat-option> </mat-option>
<ng-template [ngIf]="searchedList$ | async" let-searchedList>
<mat-option *ngIf="searchedList.length > showNOptions"
[disabled]="true">
<ng-template [ngIf]="regionTmplDirective">
<ng-template
[ngTemplateOutlet]="regionTmplDirective.tmplRef"
[ngTemplateOutletContext]="{
$implicit: {
name: '... and ' + (searchedList.length - showNOptions) + ' more'
}
}">
</ng-template>
</ng-template>
</mat-option>
</ng-template>
</mat-autocomplete> </mat-autocomplete>
\ No newline at end of file
import { Directive, TemplateRef } from "@angular/core";
import { SapiRegionModel } from "src/atlasComponents/sapi/type";
@Directive({
selector: 'ng-template[region-template],ng-template[regionTemplate]'
})
export class SapiViewsCoreRichRegionListTemplateDirective{
constructor(public tmplRef: TemplateRef<SapiRegionModel>){}
}
...@@ -515,28 +515,23 @@ ...@@ -515,28 +515,23 @@
<ng-template #autocompleteTmpl let-showTour="showTour"> <ng-template #autocompleteTmpl let-showTour="showTour">
<div class="sxplr-custom-cmp bg card ml-2 mr-2 mat-elevation-z8 pe-all auto-complete-container"> <div class="sxplr-custom-cmp bg card ml-2 mr-2 mat-elevation-z8 pe-all auto-complete-container">
<ng-template #selectedRegionCheckTmpl let-region>
<ng-template #fallbackTmpl>
<button mat-icon-button
class="sxplr-mt-a sxplr-mb-a">
<i class="far fa-square"></i>
</button>
</ng-template>
<button *ngIf="selectedRegions$ | async | includes : region; else fallbackTmpl"
mat-icon-button
color="primary"
class="sxplr-mt-a sxplr-mb-a">
<i class="far fa-check-square"></i>
</button>
</ng-template>
<sxplr-sapiviews-core-rich-regionlistsearch <sxplr-sapiviews-core-rich-regionlistsearch
[sxplr-sapiviews-core-rich-regionlistsearch-regions]="allAvailableRegions$ | async" [sxplr-sapiviews-core-rich-regionlistsearch-regions]="allAvailableRegions$ | async"
[sxplr-sapiviews-core-rich-regionlistsearch-current-search]="selectedRegions$ | async | getProperty : 0 | getProperty : 'name'" [sxplr-sapiviews-core-rich-regionlistsearch-current-search]="selectedRegions$ | async | getProperty : 0 | getProperty : 'name'"
[sxplr-sapiviews-core-rich-regionlistsearch-region-template-ref]="selectedRegionCheckTmpl"
(sxplr-sapiviews-core-rich-regionlistsearch-region-select)="selectRoi($event)"> (sxplr-sapiviews-core-rich-regionlistsearch-region-select)="selectRoi($event)">
<ng-template regionTemplate let-region>
<div class="sxplr-d-flex">
<button
mat-icon-button
class="sxplr-mt-a sxplr-mb-a">
<i [ngClass]="(selectedRegions$ | async | includes : region) ? 'fa-circle' : 'fa-none'" class="fas"></i>
</button>
<sxplr-sapiviews-core-region-region-list-item
[sxplr-sapiviews-core-region-region]="region">
</sxplr-sapiviews-core-region-region-list-item>
</div>
</ng-template>
<button mat-icon-button <button mat-icon-button
search-input-suffix search-input-suffix
*ngIf="selectedRegions$ | async | getProperty : 'length'" *ngIf="selectedRegions$ | async | getProperty : 'length'"
......
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