Add single select filter mode (#1671)
* Add single select filter mode * Update booklore-ui/src/app/features/book/components/book-browser/book-filter/book-filter.component.ts Co-authored-by: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com> --------- Co-authored-by: Aditya Chandel <8075870+adityachandelgit@users.noreply.github.com>
This commit is contained in:
co-authored by
Aditya Chandel
parent
5d79e06254
commit
7ff72a8916
+4
-3
@@ -1,7 +1,7 @@
|
|||||||
<div class="h-[calc(100dvh-6.1rem)] rounded-xl overflow-hidden bg-[var(--card-background)] flex flex-col border-[1px] border-solid border-[var(--p-content-border-color)]">
|
<div class="h-[calc(100dvh-6.1rem)] rounded-xl overflow-hidden bg-[var(--card-background)] flex flex-col border-[1px] border-solid border-[var(--p-content-border-color)]">
|
||||||
|
|
||||||
<div class="flex items-center justify-between px-4 py-4">
|
<div class="flex items-center justify-between px-4 py-4" style="border-bottom:1px solid var(--p-content-border-color)">
|
||||||
<span class="text font-semibold">Filter Mode</span>
|
<span class="text font-semibold">Filters</span>
|
||||||
<p-selectButton
|
<p-selectButton
|
||||||
[options]="filterModeOptions"
|
[options]="filterModeOptions"
|
||||||
[(ngModel)]="selectedFilterMode"
|
[(ngModel)]="selectedFilterMode"
|
||||||
@@ -9,7 +9,8 @@
|
|||||||
optionValue="value"
|
optionValue="value"
|
||||||
class="text-sm"
|
class="text-sm"
|
||||||
allowEmpty="false"
|
allowEmpty="false"
|
||||||
styleClass="h-8"></p-selectButton>
|
styleClass="h-8"
|
||||||
|
pTooltip="Filter selection mode: AND / OR / Single">></p-selectButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex-1 overflow-y-auto pb-4 pr-1" style="overscroll-behavior: contain;">
|
<div class="flex-1 overflow-y-auto pb-4 pr-1" style="overscroll-behavior: contain;">
|
||||||
|
|||||||
+21
-10
@@ -15,6 +15,7 @@ import {UserService} from '../../../../settings/user-management/user.service';
|
|||||||
import {MagicShelf} from '../../../../magic-shelf/service/magic-shelf.service';
|
import {MagicShelf} from '../../../../magic-shelf/service/magic-shelf.service';
|
||||||
import {BookRuleEvaluatorService} from '../../../../magic-shelf/service/book-rule-evaluator.service';
|
import {BookRuleEvaluatorService} from '../../../../magic-shelf/service/book-rule-evaluator.service';
|
||||||
import {GroupRule} from '../../../../magic-shelf/component/magic-shelf-component';
|
import {GroupRule} from '../../../../magic-shelf/component/magic-shelf-component';
|
||||||
|
import {Tooltip} from 'primeng/tooltip';
|
||||||
|
|
||||||
type Filter<T> = { value: T; bookCount: number };
|
type Filter<T> = { value: T; bookCount: number };
|
||||||
|
|
||||||
@@ -148,14 +149,15 @@ function getReadStatusName(status?: ReadStatus | null): string {
|
|||||||
AsyncPipe,
|
AsyncPipe,
|
||||||
TitleCasePipe,
|
TitleCasePipe,
|
||||||
FormsModule,
|
FormsModule,
|
||||||
SelectButton
|
SelectButton,
|
||||||
|
Tooltip,
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class BookFilterComponent implements OnInit, OnDestroy {
|
export class BookFilterComponent implements OnInit, OnDestroy {
|
||||||
private filterChangeSubject = new Subject<Record<string, any> | null>();
|
private filterChangeSubject = new Subject<Record<string, any> | null>();
|
||||||
|
|
||||||
@Output() filterSelected = new EventEmitter<Record<string, any> | null>();
|
@Output() filterSelected = new EventEmitter<Record<string, any> | null>();
|
||||||
@Output() filterModeChanged = new EventEmitter<'and' | 'or'>();
|
@Output() filterModeChanged = new EventEmitter<'and' | 'or' | 'single'>();
|
||||||
|
|
||||||
@Input() entity$!: Observable<Library | Shelf | MagicShelf | null> | undefined;
|
@Input() entity$!: Observable<Library | Shelf | MagicShelf | null> | undefined;
|
||||||
@Input() entityType$!: Observable<EntityType> | undefined;
|
@Input() entityType$!: Observable<EntityType> | undefined;
|
||||||
@@ -168,9 +170,11 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
filterTypes: string[] = [];
|
filterTypes: string[] = [];
|
||||||
filterModeOptions = [
|
filterModeOptions = [
|
||||||
{label: 'AND', value: 'and'},
|
{label: 'AND', value: 'and'},
|
||||||
{label: 'OR', value: 'or'}
|
{label: 'OR', value: 'or'},
|
||||||
|
{label: '1', value: 'single'},
|
||||||
];
|
];
|
||||||
private _selectedFilterMode: 'and' | 'or' = 'and';
|
singleSelect: boolean = false;
|
||||||
|
private _selectedFilterMode: 'and' | 'or' | 'single' = 'and';
|
||||||
expandedPanels: number = 0;
|
expandedPanels: number = 0;
|
||||||
readonly filterLabels: Record<string, string> = {
|
readonly filterLabels: Record<string, string> = {
|
||||||
author: 'Author',
|
author: 'Author',
|
||||||
@@ -319,11 +323,11 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get selectedFilterMode(): 'and' | 'or' {
|
get selectedFilterMode(): 'and' | 'or' | 'single' {
|
||||||
return this._selectedFilterMode;
|
return this._selectedFilterMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
set selectedFilterMode(mode: 'and' | 'or') {
|
set selectedFilterMode(mode: 'and' | 'or' | 'single') {
|
||||||
this._selectedFilterMode = mode;
|
this._selectedFilterMode = mode;
|
||||||
this.filterModeChanged.emit(mode);
|
this.filterModeChanged.emit(mode);
|
||||||
this.filterChangeSubject.next(
|
this.filterChangeSubject.next(
|
||||||
@@ -360,12 +364,19 @@ export class BookFilterComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
const index = this.activeFilters[filterType].indexOf(value);
|
const index = this.activeFilters[filterType].indexOf(value);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
this.activeFilters[filterType].splice(index, 1);
|
if (this._selectedFilterMode == 'single') {
|
||||||
if (this.activeFilters[filterType].length === 0) {
|
this.activeFilters = {};
|
||||||
delete this.activeFilters[filterType];
|
} else {
|
||||||
|
this.activeFilters[filterType].splice(index, 1);
|
||||||
|
if (this.activeFilters[filterType].length === 0) {
|
||||||
|
delete this.activeFilters[filterType];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.activeFilters[filterType].push(value);
|
if (this._selectedFilterMode == 'single') {
|
||||||
|
this.activeFilters = {[filterType]: []};
|
||||||
|
}
|
||||||
|
this.activeFilters[filterType].push(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.filterChangeSubject.next(Object.keys(this.activeFilters).length ? {...this.activeFilters} : null);
|
this.filterChangeSubject.next(Object.keys(this.activeFilters).length ? {...this.activeFilters} : null);
|
||||||
|
|||||||
Reference in New Issue
Block a user