Skip to content

Commit

Permalink
feat: filter view component created
Browse files Browse the repository at this point in the history
  • Loading branch information
markuczy committed Oct 31, 2024
1 parent f5f3ff6 commit 447d818
Show file tree
Hide file tree
Showing 18 changed files with 1,037 additions and 30 deletions.
18 changes: 18 additions & 0 deletions libs/angular-accelerator/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@
"CUSTOM_GROUP": "Benutzerdefinierte Gruppe",
"NO_GROUP_SELECTED": "Keine Gruppe ausgewählt"
},
"OCX_FILTER_VIEW": {
"NO_FILTERS": "Keine Filter ausgewählt",
"RESET_FILTERS_BUTTON": {
"ARIA_LABEL": "Angewandte Filter zurücksetzen",
"DETAIL": "Angewandte Filter zurücksetzen"
},
"FILTER_YES": "Ja",
"FILTER_NO": "Nein",
"MANAGE_FILTERS_BUTTON": {
"LABEL": "Filter",
"ARIA_LABEL": "Aktive Filter verwalten",
"DETAIL": "Aktive Filter verwalten"
},
"TABLE": {
"COLUMN_NAME": "Spaltenname",
"VALUE": "Filterwert"
}
},
"OCX_SEARCH_HEADER": {
"TOGGLE_BUTTON": {
"SIMPLE": {
Expand Down
18 changes: 18 additions & 0 deletions libs/angular-accelerator/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@
"CUSTOM_GROUP": "Custom group",
"NO_GROUP_SELECTED": "No group selected"
},
"OCX_FILTER_VIEW": {
"NO_FILTERS": "No filters selected",
"RESET_FILTERS_BUTTON": {
"ARIA_LABEL": "Reset applied filters",
"DETAIL": "Reset applied filters"
},
"FILTER_YES": "Yes",
"FILTER_NO": "No",
"MANAGE_FILTERS_BUTTON": {
"LABEL": "Filters",
"ARIA_LABEL": "Manage active filters",
"DETAIL": "Manage active filters"
},
"TABLE": {
"COLUMN_NAME": "Column name",
"VALUE": "Filter value"
}
},
"OCX_SEARCH_HEADER": {
"TOGGLE_BUTTON": {
"SIMPLE": {
Expand Down
2 changes: 2 additions & 0 deletions libs/angular-accelerator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ export * from './lib/utils/create-remote-component-translate-loader.utils'
export * from './lib/utils/enum-to-dropdown-options.utils'
export * from './lib/utils/criteria.utils'
export * from './lib/utils/string-and-array-helper-functions.utils'
export * from './lib/utils/template.utils'
export * from './lib/utils/filter.utils'
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import { MessageModule } from 'primeng/message'
import { SharedModule } from 'primeng/api'
import { CheckboxModule } from 'primeng/checkbox'
import { FloatLabelModule } from 'primeng/floatlabel'
import { ChipModule } from 'primeng/chip'
import { OverlayPanelModule } from 'primeng/overlaypanel'

@NgModule({
imports: [
BreadcrumbModule,
ChipModule,
CheckboxModule,
DropdownModule,
ButtonModule,
Expand All @@ -33,10 +36,12 @@ import { FloatLabelModule } from 'primeng/floatlabel'
SkeletonModule,
MessageModule,
FloatLabelModule,
OverlayPanelModule,
SharedModule,
],
exports: [
BreadcrumbModule,
ChipModule,
CheckboxModule,
DropdownModule,
ButtonModule,
Expand All @@ -51,6 +56,7 @@ import { FloatLabelModule } from 'primeng/floatlabel'
SkeletonModule,
MessageModule,
FloatLabelModule,
OverlayPanelModule,
SharedModule,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { TooltipOnOverflowDirective } from './directives/tooltipOnOverflow.direc
import { DynamicPipe } from './pipes/dynamic.pipe'
import { OcxTimeAgoPipe } from './pipes/ocxtimeago.pipe'
import { DynamicLocaleId } from './utils/dynamic-locale-id'
import { FilterViewComponent } from './components/filter-view/filter-view.component'

export class AngularAcceleratorMissingTranslationHandler implements MissingTranslationHandler {
handle(params: MissingTranslationHandlerParams) {
Expand Down Expand Up @@ -75,6 +76,7 @@ function appInitializer(userService: UserService) {
OcxTimeAgoPipe,
AdvancedDirective,
TooltipOnOverflowDirective,
FilterViewComponent,
],
providers: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { ObjectUtils } from '../../utils/objectutils'
import { DataSortBase } from '../data-sort-base/data-sort-base'
import { MultiSelectItem } from 'primeng/multiselect'
import { Filter, FilterType } from '../../model/filter.model'
import { findTemplate } from '../../utils/template.utils'

export type Primitive = number | string | boolean | bigint | Date
export type Row = {
Expand Down Expand Up @@ -786,17 +787,6 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
[TemplateType.FILTERCELL]: this.filterTemplatesData,
}

findTemplate(templates: PrimeTemplate[], names: string[]): PrimeTemplate | undefined {
for (let index = 0; index < names.length; index++) {
const name = names[index]
const template = templates.find((template) => template.name === name)
if (template) {
return template
}
}
return undefined
}

getColumnTypeTemplate(templates: PrimeTemplate[], columnType: ColumnType, templateType: TemplateType) {
let template: TemplateRef<any> | undefined

Expand Down Expand Up @@ -847,7 +837,7 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon

return (
template ??
this.findTemplate(templates, this.templatesDataMap[templateType].templateNames[columnType])?.template ??
findTemplate(templates, this.templatesDataMap[templateType].templateNames[columnType])?.template ??
null
)
}
Expand All @@ -863,7 +853,7 @@ export class DataTableComponent extends DataSortBase implements OnInit, AfterCon
]).pipe(
map(([t, vt, pt]) => {
const templates = [...(t ?? []), ...(vt ?? []), ...(pt ?? [])]
const columnTemplate = this.findTemplate(
const columnTemplate = findTemplate(
templates,
templatesData.idSuffix.map((suffix) => column.id + suffix)
)?.template
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
<div *ngIf="columnFilterDataList$ | async as columnFilters" class="flex flex-wrap align-items-center gap-2">
<ng-container *ngIf="showChips; else noChipsContent">
<ng-container *ocxIfBreakpoint="'desktop'; elseTemplate: noChipsContent">
<p-button
id="resetFiltersButton"
(onClick)="onResetFilersClick()"
icon="pi pi-eraser"
pTooltip="{{ 'OCX_FILTER_VIEW.RESET_FILTERS_BUTTON.DETAIL' | translate }}"
tooltipPosition="top"
tooltipEvent="hover"
[ariaLabel]="'OCX_FILTER_VIEW.RESET_FILTERS_BUTTON.ARIA_LABEL' | translate"
></p-button>
<ng-container *ngIf="columnFilters.length <= 0">
<ng-container *ngIf="_fitlerViewNoSelection; else defaultNoFilters" [ngTemplateOutlet]="_fitlerViewNoSelection">
</ng-container>
<ng-template #defaultNoFilters>
<span>{{ 'OCX_FILTER_VIEW.NO_FILTERS' | translate }}</span>
</ng-template>
</ng-container>
<ng-container *ngIf="(chipTemplates$ | async) ?? {} as templates">
<ng-container *ngIf="selectDisplayedChips(columnFilters) as selectedColumnFilters">
<ng-container *ngFor="let columnFilter of selectedColumnFilters">
<p-chip [removable]="true" (onRemove)="onChipRemove(columnFilter)" [styleClass]="chipStyleClass">
<ng-container
*ngIf="_filterViewChipContent; else chipContentTemplate"
[ngTemplateOutlet]="_filterViewChipContent"
[ngTemplateOutletContext]="{
columnFilter: columnFilter,
filterValueTemplates: templates,
truthyTemplate: _truthyTemplate,
filterValueTemplate: _chipTemplate
}"
>
</ng-container>
<ng-template #chipContentTemplate>
<span class="p-chip-text flex flex-nowrap"
>{{columnFilter.column.nameKey | translate}}:
<nobr>
<ng-container
*ngIf="columnFilter.filter.filterType === FilterType.EQUAL || !columnFilter.filter.filterType"
[ngTemplateOutlet]="_chipTemplate"
[ngTemplateOutletContext]="{
templates: templates,
columnFilter: columnFilter
}"
></ng-container>
<ng-container *ngIf="columnFilter.filter.filterType === FilterType.TRUTHY">
<ng-container
[ngTemplateOutlet]="_truthyTemplate"
[ngTemplateOutletContext]="{
value: columnFilter.filter.value
}"
></ng-container>
</ng-container>
</nobr>
</span>
</ng-template>
</p-chip>
</ng-container>
<ng-container *ngIf="selectedColumnFilters.length < columnFilters.length">
<p-chip (click)="showPanel($event)" class="cursor-pointer">
<ng-container
*ngIf="_filterViewShowMoreChip; else showMoreChipTemplate"
[ngTemplateOutlet]="_filterViewShowMoreChip"
[ngTemplateOutletContext]="{
$implicit: columnFilters.length - selectedColumnFilters.length
}"
>
</ng-container>
<ng-template #showMoreChipTemplate>
<span class="p-chip-text flex flex-nowrap">
+{{columnFilters.length - selectedColumnFilters.length}}
</span>
</ng-template>
</p-chip>
<ng-container [ngTemplateOutlet]="_filterTablePanel"></ng-container>
</ng-container>
</ng-container>
</ng-container>
</ng-container>
</ng-container>
<ng-template #noChipsContent>
<p-button
id="manageFiltersButton"
(onClick)="showPanel($event)"
icon="pi pi-sliders-h"
label="{{ 'OCX_FILTER_VIEW.MANAGE_FILTERS_BUTTON.LABEL' | translate }}"
pTooltip="{{ 'OCX_FILTER_VIEW.MANAGE_FILTERS_BUTTON.DETAIL' | translate }}"
tooltipPosition="top"
tooltipEvent="hover"
[badge]="columnFilters.length"
[ariaLabel]="'OCX_FILTER_VIEW.MANAGE_FILTERS_BUTTON.ARIA_LABEL' | translate"
></p-button>
<ng-container [ngTemplateOutlet]="_filterTablePanel"></ng-container>
</ng-template>

<ng-template #filterTablePanel>
<p-overlayPanel *ngIf="tableTemplates$ | async as templates" #op [showCloseIcon]="true">
<ng-template pTemplate="content">
<!-- [frozenActionColumn]=""
[actionColumnPosition]=""
[paginator]=""
[page]=""
[filters]=""
[sortDirection]=""
[sortColumn]=""
[sortStates]=""
[clientSideFiltering]=""
[clientSideSorting]=""
[pageSizes]=""
(sorted)=""
(filtered)=""
(deleteTableRow)=""
[parentTemplates]="templatesForChildren$ | async"
(pageChanged)=""
(pageSizeChanged)=""
[pageSize]=""
(componentStateChanged)=""
[emptyResultsMessage]=""
-->
<ocx-data-table [rows]="(columnFilterDataRows$ | async) ?? []" [columns]="columnFilterTableColumns">
<ng-template pTemplate="columnIdCell" let-rowObject="rowObject" let-column="column">
<ng-container
[ngTemplateOutlet]="_tableValueTemplate"
[ngTemplateOutletContext]="{
templates: templates,
rowObject: rowObject,
column: column
}"
>
</ng-container>
</ng-template>
<ng-template pTemplate="valueIdCell" let-rowObject="rowObject" let-column="column">
<ng-container
[ngTemplateOutlet]="_tableValueTemplate"
[ngTemplateOutletContext]="{
templates: templates,
rowObject: rowObject,
column: column
}"
>
</ng-container>
</ng-template>
</ocx-data-table>
</ng-template>
</p-overlayPanel>
</ng-template>
</div>

<ng-template #tableValueTemplate let-templates="templates" let-rowObject="rowObject" let-column="column">
<ng-container
*ngIf="column.id !== 'value'"
[ngTemplateOutlet]="templates[column.id]"
[ngTemplateOutletContext]="{
rowObject: rowObject,
column: column
}"
>
</ng-container>
<ng-container *ngIf="column.id === 'value'">
<ng-container *ngIf="getColumnByNameKey(resolveFieldData(rowObject, 'column')) as valueColumn">
<ng-container
*ngIf="!valueColumn.filterType || valueColumn.filterType === FilterType.EQUAL"
[ngTemplateOutlet]="templates[valueColumn.id]"
[ngTemplateOutletContext]="{
rowObject: rowObject,
column: column
}"
>
</ng-container>
<ng-container
*ngIf="valueColumn.filterType === FilterType.TRUTHY"
[ngTemplateOutlet]="_truthyTemplate"
[ngTemplateOutletContext]="{
value: resolveFieldData(rowObject, column.id)
}"
>
</ng-container>
</ng-container>
</ng-container>
</ng-template>

<ng-template #chipTemplate let-templates="templates" let-columnFilter="columnFilter">
<ng-container
*ngIf="templates[columnFilter.column.id] as template"
[ngTemplateOutlet]="template"
[ngTemplateOutletContext]="{
rowObject: getRowObjectFromFiterData(columnFilter),
column: columnFilter.column
}"
>
</ng-container>
</ng-template>

<ng-template #truthyTemplate let-value="value">
<ng-container *ngIf="value"> {{'OCX_FILTER_VIEW.FILTER_YES' | translate}} </ng-container>
<ng-container *ngIf="!value"> {{'OCX_FILTER_VIEW.FILTER_NO' | translate}} </ng-container>
</ng-template>

<ng-template pTemplate="defaultStringValue" let-rowObject="rowObject" let-column="column">
<ng-container> {{ resolveFieldData(rowObject, column.id)}} </ng-container>
</ng-template>

<ng-template pTemplate="defaultNumberValue" let-rowObject="rowObject" let-column="column">
<ng-container> {{ resolveFieldData(rowObject, column.id) | number }} </ng-container>
</ng-template>

<ng-template pTemplate="defaultCustomValue" let-rowObject="rowObject" let-column="column"> </ng-template>

<ng-template pTemplate="defaultDateValue" let-rowObject="rowObject" let-column="column">
<ng-container> {{ resolveFieldData(rowObject, column.id) | date: column.dateFormat ?? 'medium' }} </ng-container>
</ng-template>

<ng-template pTemplate="defaultRelativeDateValue" let-rowObject="rowObject" let-column="column">
<ng-container>
{{ 'OCX_DATA_TABLE.EDITED' | translate }} {{ resolveFieldData(rowObject, column.id) | timeago }}
</ng-container>
</ng-template>

<ng-template pTemplate="defaultTranslationKeyValue" let-rowObject="rowObject" let-column="column">
<ng-container> {{ resolveFieldData(rowObject, column.id) | translate }}</ng-container>
</ng-template>
Empty file.
Loading

0 comments on commit 447d818

Please sign in to comment.