-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from camptocamp/rework-filter-area
[Search] Rework filter area
- Loading branch information
Showing
16 changed files
with
395 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...ub/src/app/search/search-filters/dropdown-multiselect/dropdown-multiselect.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
apps/datahub/src/app/search/search-filters/filter-dropdown/filter-dropdown.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
@if (fieldName === 'qualityScore'){ | ||
<mel-datahub-dropdown-range | ||
class="w-full" | ||
[title]="title" | ||
[choices]="choices$ | async" | ||
(selectValues)="onSelectedValues($event)" | ||
[attr.data-cy-field]="fieldName" | ||
></mel-datahub-dropdown-range> | ||
} @else { | ||
<mel-datahub-dropdown-multiselect | ||
class="w-full" | ||
[title]="title" | ||
[maxRows]="6" | ||
[choices]="choices$ | async" | ||
[selected]="selected$ | async" | ||
[allowSearch]="true" | ||
(selectValues)="onSelectedValues($event)" | ||
[attr.data-cy-field]="fieldName" | ||
> | ||
</mel-datahub-dropdown-multiselect> | ||
} |
84 changes: 84 additions & 0 deletions
84
...earch/search-filters/mel-datahub-dropdown-range/mel-datahub-dropdown-range.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<button | ||
class="mel-primary-button gap-0 rounded-none w-52 justify-between" | ||
[attr.aria-owns]="id" | ||
(click)="openOverlay()" | ||
cdkOverlayOrigin | ||
#overlayOrigin="cdkOverlayOrigin" | ||
> | ||
<span>{{ title }}</span> | ||
<button class="h-6 w-6" data-cy="clearSelection"> | ||
@if(hasSelectedChoices && !overlayOpen){ | ||
<mat-icon | ||
class="material-symbols-outlined shrink-0 opacity-40 mr-1.5 hover:opacity-80 transition-colors clear-btn" | ||
(click)="clearSelection($event)" | ||
> | ||
close | ||
</mat-icon> | ||
} | ||
</button> | ||
<mat-icon class="material-symbols-outlined shrink-0"> | ||
@if(overlayOpen){ | ||
<ng-container>expand_less</ng-container> | ||
} @else { | ||
<ng-container>expand_more</ng-container> | ||
} | ||
</mat-icon> | ||
</button> | ||
|
||
<ng-template | ||
cdkConnectedOverlay | ||
cdkConnectedOverlayHasBackdrop | ||
cdkConnectedOverlayBackdropClass="cdk-overlay-transparent-backdrop" | ||
[cdkConnectedOverlayOrigin]="overlayOrigin" | ||
[cdkConnectedOverlayOpen]="overlayOpen" | ||
[cdkConnectedOverlayPositions]="overlayPositions" | ||
[cdkConnectedOverlayScrollStrategy]="scrollStrategy" | ||
[cdkConnectedOverlayFlexibleDimensions]="true" | ||
(overlayOutsideClick)="closeOverlay()" | ||
(detach)="closeOverlay()" | ||
> | ||
<div | ||
class="bg-white border border-gray-300 shadow-lg py-2 w-full overflow-x-hidden overflow-y-auto overlay-container" | ||
[style.max-height]="overlayMaxHeight" | ||
[style.width]="'300px'" | ||
role="listbox" | ||
tabindex="-1" | ||
[attr.id]="id" | ||
[attr.aria-multiselectable]="true" | ||
[attr.aria-label]="title" | ||
#overlayContainer | ||
> | ||
<div class="flex flex-col ml-3 gap-3"> | ||
<div class="mr-3"> | ||
<div class="text-primary" translate> | ||
mel.datahub.search.filters.range.from | ||
</div> | ||
<gn-ui-text-input | ||
class="w-64" | ||
(valueChange)="lowValue = $event" | ||
[value]="lowValue" | ||
[hint]="'mel.datahub.search.filters.minValue' | translate" | ||
></gn-ui-text-input> | ||
</div> | ||
<div class="mr-3"> | ||
<div class="text-primary" translate> | ||
mel.datahub.search.filters.range.to | ||
</div> | ||
<gn-ui-text-input | ||
class="w-64" | ||
(valueChange)="highValue = $event" | ||
[value]="highValue" | ||
[hint]="'mel.datahub.search.filters.maxValue' | translate" | ||
(keyup.enter)="onValidate()" | ||
></gn-ui-text-input> | ||
</div> | ||
<mel-datahub-button | ||
[disabled]="!lowValue || !highValue" | ||
class="self-end mr-3" | ||
[label]="'mel.datahub.search.filters.validate' | translate" | ||
[icon]="'arrow'" | ||
(click)="onValidate()" | ||
></mel-datahub-button> | ||
</div> | ||
</div> | ||
</ng-template> |
102 changes: 102 additions & 0 deletions
102
.../search/search-filters/mel-datahub-dropdown-range/mel-datahub-dropdown-range.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { | ||
CdkOverlayOrigin, | ||
ConnectedPosition, | ||
ScrollStrategyOptions, | ||
} from '@angular/cdk/overlay' | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
ElementRef, | ||
EventEmitter, | ||
Input, | ||
Output, | ||
ViewChild, | ||
} from '@angular/core' | ||
import { Choice, propagateToDocumentOnly } from 'geonetwork-ui' | ||
|
||
@Component({ | ||
selector: 'mel-datahub-dropdown-range', | ||
templateUrl: './mel-datahub-dropdown-range.component.html', | ||
styles: ``, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MelDatahubDropdownRangeComponent { | ||
lowValue = '' | ||
highValue = '' | ||
@Input() choices: Choice[] | ||
@Input() title: string | ||
@Input() selected: unknown[] = [] | ||
@Output() selectValues = new EventEmitter<unknown[]>() | ||
@ViewChild('overlayOrigin') overlayOrigin: CdkOverlayOrigin | ||
@ViewChild('overlayContainer', { read: ElementRef }) | ||
overlayContainer: ElementRef | ||
overlayPositions: ConnectedPosition[] = [ | ||
{ | ||
originX: 'start', | ||
originY: 'bottom', | ||
overlayX: 'start', | ||
overlayY: 'top', | ||
offsetY: 8, | ||
}, | ||
{ | ||
originX: 'start', | ||
originY: 'top', | ||
overlayX: 'start', | ||
overlayY: 'bottom', | ||
offsetY: -8, | ||
}, | ||
] | ||
scrollStrategy = this.scrollStrategies.reposition() | ||
overlayOpen = false | ||
overlayWidth = 'auto' | ||
overlayMaxHeight = 'none' | ||
id = `dropdown-range-${Math.floor(Math.random() * 10000)}` | ||
|
||
get hasSelectedChoices() { | ||
return this.selected.length > 0 | ||
} | ||
|
||
constructor(private scrollStrategies: ScrollStrategyOptions) {} | ||
|
||
openOverlay() { | ||
this.overlayWidth = | ||
this.overlayOrigin.elementRef.nativeElement.getBoundingClientRect() | ||
.width + 'px' | ||
this.overlayOpen = true | ||
} | ||
|
||
closeOverlay() { | ||
this.overlayOpen = false | ||
} | ||
|
||
clearSelection(event: Event) { | ||
this.selectValues.emit([]) | ||
this.highValue = '' | ||
this.lowValue = '' | ||
this.selected = [] | ||
propagateToDocumentOnly(event) | ||
} | ||
|
||
onValidate() { | ||
const lowValue = Number(this.lowValue) * 10 | ||
const highValue = Number(this.highValue) * 10 | ||
this.selected = this.choices | ||
.filter((choice) => { | ||
const choiceNb = Number(choice.value) | ||
if (lowValue && highValue) { | ||
return choiceNb >= lowValue && choiceNb <= highValue | ||
} else if (lowValue) { | ||
return choiceNb >= lowValue | ||
} else if (highValue) { | ||
return choiceNb <= highValue | ||
} | ||
return true | ||
}) | ||
.map((choice) => choice.value) | ||
if (this.selected.length === 0) { | ||
// If no value is selected, we keep the low and high values to display nothing | ||
this.selected.push(lowValue, highValue) | ||
} | ||
this.selectValues.emit(this.selected) | ||
} | ||
} |
Oops, something went wrong.