@one-paragon/angular-utilities 2.0.0-beta.2 → 2.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/karma.conf.js +44 -0
- package/ng-package.json +7 -0
- package/package.json +15 -27
- package/src/action-state/action-state-spinner/action-state-spinner.component.css +16 -0
- package/src/action-state/action-state-spinner/action-state-spinner.component.html +6 -0
- package/src/action-state/action-state-spinner/action-state-spinner.component.spec.ts +25 -0
- package/src/action-state/action-state-spinner/action-state-spinner.component.ts +25 -0
- package/src/action-state/action-state-ui/action-state-ui.module.ts +13 -0
- package/{action-state/index.d.ts → src/action-state/index.ts} +8 -4
- package/src/action-state/ngrx-ext/ngrx-ext.module.ts +15 -0
- package/src/action-state/ngrx.ts +69 -0
- package/src/http-request-state/HttpRequestStateFactory.ts +66 -0
- package/src/http-request-state/HttpRequestStateStore.ts +191 -0
- package/src/http-request-state/directives/HttpStateDirectiveBase.ts +29 -0
- package/src/http-request-state/directives/http-error-state-directive.ts +21 -0
- package/src/http-request-state/directives/http-inProgress-state-directive.ts +19 -0
- package/src/http-request-state/directives/http-notStarted-state-directive.ts +19 -0
- package/src/http-request-state/directives/http-success-state-directive.ts +29 -0
- package/{http-request-state/directives/index.d.ts → src/http-request-state/directives/index.ts} +5 -5
- package/src/http-request-state/directives/request-state-directive.spec.ts +72 -0
- package/src/http-request-state/directives/request-state-directive.ts +78 -0
- package/src/http-request-state/helpers.ts +30 -0
- package/src/http-request-state/http-request-state.ts +69 -0
- package/src/http-request-state/http-state-module.ts +23 -0
- package/{http-request-state/index.d.ts → src/http-request-state/index.ts} +6 -6
- package/src/http-request-state/observable.spec.ts +43 -0
- package/src/http-request-state/rxjs/getRequestorBody.ts +10 -0
- package/src/http-request-state/rxjs/getRequestorState.ts +8 -0
- package/{http-request-state/rxjs/index.d.ts → src/http-request-state/rxjs/index.ts} +4 -4
- package/src/http-request-state/rxjs/tapError.ts +16 -0
- package/src/http-request-state/rxjs/tapSuccess.ts +16 -0
- package/src/http-request-state/strategies.spec.ts +42 -0
- package/src/http-request-state/types.ts +55 -0
- package/src/ngrx/actionable-selector.ts +150 -0
- package/src/ngrx/index.ts +1 -0
- package/{public-api.d.ts → src/public-api.ts} +35 -16
- package/src/rxjs/defaultShareReplay.ts +8 -0
- package/{rxjs/index.d.ts → src/rxjs/index.ts} +5 -5
- package/src/rxjs/mapError.ts +8 -0
- package/src/rxjs/rxjs-operators.ts +132 -0
- package/src/rxjs/subjectifier.ts +17 -0
- package/src/rxjs/subscriber.directive.ts +57 -0
- package/src/specs/clickSubject.spec.ts +95 -0
- package/src/specs/dialog.spec.ts +101 -0
- package/src/specs/toggleGroupDirective.spec.ts +229 -0
- package/src/table-builder/classes/DefaultSettings.ts +11 -0
- package/src/table-builder/classes/MatTableObservableDataSource.ts +23 -0
- package/src/table-builder/classes/TableBuilderConfig.ts +42 -0
- package/src/table-builder/classes/TableBuilderDataSource.ts +66 -0
- package/src/table-builder/classes/TableState.ts +93 -0
- package/src/table-builder/classes/data-store.ts +10 -0
- package/{table-builder/classes/display-col.d.ts → src/table-builder/classes/display-col.ts} +5 -5
- package/src/table-builder/classes/filter-info.ts +123 -0
- package/src/table-builder/classes/table-builder-general-settings.ts +141 -0
- package/src/table-builder/classes/table-builder.ts +95 -0
- package/src/table-builder/classes/table-store.helpers.ts +102 -0
- package/src/table-builder/classes/table-store.ts +355 -0
- package/src/table-builder/components/array-column.component.ts +34 -0
- package/src/table-builder/components/column-builder/column-builder.component.html +69 -0
- package/src/table-builder/components/column-builder/column-builder.component.scss +43 -0
- package/src/table-builder/components/column-builder/column-builder.component.spec.ts +49 -0
- package/src/table-builder/components/column-builder/column-builder.component.ts +128 -0
- package/src/table-builder/components/column-builder/column-helpers.ts +52 -0
- package/src/table-builder/components/date-filter/date-filter.component.html +23 -0
- package/src/table-builder/components/date-filter/date-filter.component.ts +22 -0
- package/src/table-builder/components/date-time-filter/date-time-filter.component.html +9 -0
- package/src/table-builder/components/date-time-filter/date-time-filter.component.ts +20 -0
- package/src/table-builder/components/filter/filter.component.html +91 -0
- package/src/table-builder/components/filter/filter.component.scss +60 -0
- package/src/table-builder/components/filter/filter.component.spec.ts +87 -0
- package/src/table-builder/components/filter/filter.component.ts +59 -0
- package/src/table-builder/components/filter/in-list/in-list-filter.component.ts +85 -0
- package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.html +55 -0
- package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.scss +57 -0
- package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.ts +44 -0
- package/src/table-builder/components/generic-table/generic-table.component.html +77 -0
- package/src/table-builder/components/generic-table/generic-table.component.scss +38 -0
- package/src/table-builder/components/generic-table/generic-table.component.ts +330 -0
- package/src/table-builder/components/generic-table/paginator.component.ts +97 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.css +8 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.html +12 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.spec.ts +23 -0
- package/src/table-builder/components/group-by-list/group-by-list.component.ts +18 -0
- package/src/table-builder/components/header-menu/header-menu.component.html +105 -0
- package/src/table-builder/components/header-menu/header-menu.component.scss +96 -0
- package/src/table-builder/components/header-menu/header-menu.component.ts +93 -0
- package/src/table-builder/components/in-filter/in-filter.component.css +3 -0
- package/src/table-builder/components/in-filter/in-filter.component.html +19 -0
- package/src/table-builder/components/in-filter/in-filter.component.ts +65 -0
- package/{table-builder/components/index.d.ts → src/table-builder/components/index.ts} +9 -9
- package/src/table-builder/components/initialization-component/initialization-component.html +29 -0
- package/src/table-builder/components/initialization-component/initialization-component.ts +22 -0
- package/src/table-builder/components/link-column.component.ts +45 -0
- package/src/table-builder/components/number-filter/number-filter.component.css +10 -0
- package/src/table-builder/components/number-filter/number-filter.component.html +22 -0
- package/src/table-builder/components/number-filter/number-filter.component.spec.ts +30 -0
- package/src/table-builder/components/number-filter/number-filter.component.ts +25 -0
- package/src/table-builder/components/profiles-menu/profiles-menu.component.html +73 -0
- package/src/table-builder/components/profiles-menu/profiles-menu.component.scss +126 -0
- package/src/table-builder/components/profiles-menu/profiles-menu.component.spec.ts +23 -0
- package/src/table-builder/components/profiles-menu/profiles-menu.component.ts +63 -0
- package/src/table-builder/components/scroll-strategy.ts +76 -0
- package/src/table-builder/components/sort-menu/sort-menu.component-store.ts +57 -0
- package/src/table-builder/components/sort-menu/sort-menu.component.html +109 -0
- package/src/table-builder/components/sort-menu/sort-menu.component.scss +119 -0
- package/src/table-builder/components/sort-menu/sort-menu.component.ts +88 -0
- package/{table-builder/components/table-container/table-container-imports.d.ts → src/table-builder/components/table-container/table-container-imports.ts} +27 -13
- package/src/table-builder/components/table-container/table-container.helpers/data-state.helpers.ts +141 -0
- package/src/table-builder/components/table-container/table-container.helpers/filter-state.helpers.ts +126 -0
- package/src/table-builder/components/table-container/table-container.helpers/groupBy.helpers.ts +86 -0
- package/src/table-builder/components/table-container/table-container.helpers/meta-data.helpers.ts +15 -0
- package/src/table-builder/components/table-container/table-container.helpers/sort-state.helpers.ts +45 -0
- package/src/table-builder/components/table-container/table-container.html +94 -0
- package/src/table-builder/components/table-container/table-container.scss +47 -0
- package/src/table-builder/components/table-container/table-container.spec.ts +154 -0
- package/src/table-builder/components/table-container/table-container.ts +307 -0
- package/src/table-builder/components/table-container/tableProps.ts +18 -0
- package/src/table-builder/components/table-container/virtual-scroll-container.ts +155 -0
- package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.html +31 -0
- package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.ts +44 -0
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.css +42 -0
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.html +10 -0
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.spec.ts +85 -0
- package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.ts +32 -0
- package/src/table-builder/components/table-container-filter/table-wrapper-filter-store.ts +23 -0
- package/src/table-builder/directives/custom-cell-directive.ts +58 -0
- package/{table-builder/directives/index.d.ts → src/table-builder/directives/index.ts} +6 -5
- package/src/table-builder/directives/multi-sort.directive.spec.ts +124 -0
- package/src/table-builder/directives/multi-sort.directive.ts +50 -0
- package/src/table-builder/directives/resize-column.directive.ts +107 -0
- package/src/table-builder/directives/table-wrapper.directive.ts +13 -0
- package/src/table-builder/directives/tb-filter.directive.ts +372 -0
- package/src/table-builder/enums/filterTypes.ts +40 -0
- package/src/table-builder/functions/boolean-filter-function.ts +12 -0
- package/src/table-builder/functions/date-filter-function.ts +68 -0
- package/src/table-builder/functions/download-data.ts +11 -0
- package/src/table-builder/functions/null-filter-function.ts +9 -0
- package/src/table-builder/functions/number-filter-function.ts +41 -0
- package/src/table-builder/functions/sort-data-function.ts +23 -0
- package/src/table-builder/functions/string-filter-function.ts +51 -0
- package/{table-builder/interfaces/ColumnInfo.d.ts → src/table-builder/interfaces/ColumnInfo.ts} +7 -6
- package/src/table-builder/interfaces/column-template.ts +9 -0
- package/{table-builder/interfaces/dictionary.d.ts → src/table-builder/interfaces/dictionary.ts} +3 -3
- package/src/table-builder/interfaces/report-def.ts +160 -0
- package/src/table-builder/ngrx/tableBuilderStateStore.ts +199 -0
- package/src/table-builder/pipes/column-total.pipe.ts +16 -0
- package/src/table-builder/pipes/format-filter-type.pipe.ts +12 -0
- package/src/table-builder/pipes/format-filter-value.pipe.ts +42 -0
- package/src/table-builder/pipes/key-display.ts +13 -0
- package/src/table-builder/services/export-to-csv.service.ts +75 -0
- package/src/table-builder/services/link-creator.service.ts +67 -0
- package/src/table-builder/services/table-template-service.ts +59 -0
- package/src/table-builder/services/transform-creator.ts +94 -0
- package/src/table-builder/specs/table-custom-filters.spec.ts +262 -0
- package/src/table-builder/styles/collapser.styles.scss +16 -0
- package/src/table-builder/table-builder.module.ts +73 -0
- package/src/test.ts +17 -0
- package/src/utilities/array-helpers.ts +13 -0
- package/src/utilities/directives/auto-focus.directive.ts +20 -0
- package/src/utilities/directives/clickEmitterDirective.ts +15 -0
- package/src/utilities/directives/clickSubject.ts +19 -0
- package/src/utilities/directives/conditional-classes.directive.ts +35 -0
- package/src/utilities/directives/dialog-service.ts +19 -0
- package/src/utilities/directives/dialog.ts +142 -0
- package/src/utilities/directives/mat-toggle-group-directive.ts +60 -0
- package/src/utilities/directives/prevent-enter.directive.ts +12 -0
- package/src/utilities/directives/stop-propagation.directive.ts +19 -0
- package/src/utilities/directives/styler.ts +39 -0
- package/src/utilities/directives/trim-whitespace.directive.ts +20 -0
- package/{utilities/index.d.ts → src/utilities/index.ts} +22 -15
- package/src/utilities/module.ts +55 -0
- package/src/utilities/pipes/function.pipe.ts +21 -0
- package/src/utilities/pipes/phone.pipe.ts +15 -0
- package/src/utilities/pipes/space-case.pipes.spec.ts +47 -0
- package/src/utilities/pipes/space-case.pipes.ts +26 -0
- package/tsconfig.lib.json +19 -0
- package/tsconfig.lib.prod.json +10 -0
- package/tsconfig.spec.json +17 -0
- package/action-state/action-state-spinner/action-state-spinner.component.d.ts +0 -12
- package/action-state/action-state-ui/action-state-ui.module.d.ts +0 -7
- package/action-state/ngrx-ext/ngrx-ext.module.d.ts +0 -8
- package/action-state/ngrx.d.ts +0 -31
- package/fesm2022/one-paragon-angular-utilities.mjs +0 -5681
- package/fesm2022/one-paragon-angular-utilities.mjs.map +0 -1
- package/http-request-state/HttpRequestStateFactory.d.ts +0 -17
- package/http-request-state/HttpRequestStateStore.d.ts +0 -58
- package/http-request-state/directives/HttpStateDirectiveBase.d.ts +0 -14
- package/http-request-state/directives/http-error-state-directive.d.ts +0 -9
- package/http-request-state/directives/http-inProgress-state-directive.d.ts +0 -9
- package/http-request-state/directives/http-notStarted-state-directive.d.ts +0 -9
- package/http-request-state/directives/http-success-state-directive.d.ts +0 -16
- package/http-request-state/directives/request-state-directive.d.ts +0 -34
- package/http-request-state/helpers.d.ts +0 -9
- package/http-request-state/http-request-state.d.ts +0 -12
- package/http-request-state/http-state-module.d.ts +0 -11
- package/http-request-state/rxjs/getRequestorBody.d.ts +0 -3
- package/http-request-state/rxjs/getRequestorState.d.ts +0 -3
- package/http-request-state/rxjs/tapError.d.ts +0 -3
- package/http-request-state/rxjs/tapSuccess.d.ts +0 -3
- package/http-request-state/types.d.ts +0 -41
- package/index.d.ts +0 -5
- package/ngrx/actionable-selector.d.ts +0 -31
- package/ngrx/index.d.ts +0 -1
- package/rxjs/defaultShareReplay.d.ts +0 -2
- package/rxjs/mapError.d.ts +0 -2
- package/rxjs/rxjs-operators.d.ts +0 -13
- package/rxjs/subjectifier.d.ts +0 -8
- package/rxjs/subscriber.directive.d.ts +0 -14
- package/table-builder/classes/DefaultSettings.d.ts +0 -9
- package/table-builder/classes/MatTableObservableDataSource.d.ts +0 -9
- package/table-builder/classes/TableBuilderConfig.d.ts +0 -23
- package/table-builder/classes/TableBuilderDataSource.d.ts +0 -18
- package/table-builder/classes/TableState.d.ts +0 -66
- package/table-builder/classes/data-store.d.ts +0 -8
- package/table-builder/classes/filter-info.d.ts +0 -37
- package/table-builder/classes/table-builder-general-settings.d.ts +0 -85
- package/table-builder/classes/table-builder.d.ts +0 -18
- package/table-builder/classes/table-store.d.ts +0 -130
- package/table-builder/classes/table-store.helpers.d.ts +0 -28
- package/table-builder/components/array-column.component.d.ts +0 -15
- package/table-builder/components/column-builder/column-builder.component.d.ts +0 -40
- package/table-builder/components/column-builder/column-helpers.d.ts +0 -36
- package/table-builder/components/date-filter/date-filter.component.d.ts +0 -37
- package/table-builder/components/date-time-filter/date-time-filter.component.d.ts +0 -37
- package/table-builder/components/filter/filter.component.d.ts +0 -46
- package/table-builder/components/filter/in-list/in-list-filter.component.d.ts +0 -23
- package/table-builder/components/gen-col-displayer/gen-col-displayer.component.d.ts +0 -17
- package/table-builder/components/generic-table/generic-table.component.d.ts +0 -72
- package/table-builder/components/generic-table/paginator.component.d.ts +0 -28
- package/table-builder/components/group-by-list/group-by-list.component.d.ts +0 -7
- package/table-builder/components/header-menu/header-menu.component.d.ts +0 -49
- package/table-builder/components/in-filter/in-filter.component.d.ts +0 -20
- package/table-builder/components/initialization-component/initialization-component.d.ts +0 -13
- package/table-builder/components/link-column.component.d.ts +0 -25
- package/table-builder/components/number-filter/number-filter.component.d.ts +0 -39
- package/table-builder/components/profiles-menu/profiles-menu.component.d.ts +0 -32
- package/table-builder/components/scroll-strategy.d.ts +0 -22
- package/table-builder/components/sort-menu/sort-menu.component-store.d.ts +0 -24
- package/table-builder/components/sort-menu/sort-menu.component.d.ts +0 -19
- package/table-builder/components/table-container/table-container.d.ts +0 -83
- package/table-builder/components/table-container/table-container.helpers/data-state.helpers.d.ts +0 -6
- package/table-builder/components/table-container/table-container.helpers/filter-state.helpers.d.ts +0 -19
- package/table-builder/components/table-container/table-container.helpers/groupBy.helpers.d.ts +0 -17
- package/table-builder/components/table-container/table-container.helpers/meta-data.helpers.d.ts +0 -2
- package/table-builder/components/table-container/table-container.helpers/sort-state.helpers.d.ts +0 -8
- package/table-builder/components/table-container/tableProps.d.ts +0 -10
- package/table-builder/components/table-container/virtual-scroll-container.d.ts +0 -36
- package/table-builder/components/table-container-filter/filter-list/filter-list.component.d.ts +0 -15
- package/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.d.ts +0 -12
- package/table-builder/components/table-container-filter/table-wrapper-filter-store.d.ts +0 -14
- package/table-builder/directives/custom-cell-directive.d.ts +0 -32
- package/table-builder/directives/multi-sort.directive.d.ts +0 -10
- package/table-builder/directives/resize-column.directive.d.ts +0 -43
- package/table-builder/directives/table-wrapper.directive.d.ts +0 -8
- package/table-builder/directives/tb-filter.directive.d.ts +0 -113
- package/table-builder/enums/filterTypes.d.ts +0 -36
- package/table-builder/functions/boolean-filter-function.d.ts +0 -3
- package/table-builder/functions/date-filter-function.d.ts +0 -4
- package/table-builder/functions/download-data.d.ts +0 -1
- package/table-builder/functions/null-filter-function.d.ts +0 -2
- package/table-builder/functions/number-filter-function.d.ts +0 -4
- package/table-builder/functions/sort-data-function.d.ts +0 -6
- package/table-builder/functions/string-filter-function.d.ts +0 -5
- package/table-builder/interfaces/report-def.d.ts +0 -151
- package/table-builder/ngrx/tableBuilderStateStore.d.ts +0 -70
- package/table-builder/pipes/column-total.pipe.d.ts +0 -8
- package/table-builder/pipes/format-filter-type.pipe.d.ts +0 -8
- package/table-builder/pipes/format-filter-value.pipe.d.ts +0 -11
- package/table-builder/pipes/key-display.d.ts +0 -9
- package/table-builder/services/export-to-csv.service.d.ts +0 -14
- package/table-builder/services/link-creator.service.d.ts +0 -16
- package/table-builder/services/table-template-service.d.ts +0 -14
- package/table-builder/services/transform-creator.d.ts +0 -15
- package/table-builder/table-builder.module.d.ts +0 -21
- package/utilities/array-helpers.d.ts +0 -1
- package/utilities/directives/auto-focus.directive.d.ts +0 -9
- package/utilities/directives/clickEmitterDirective.d.ts +0 -7
- package/utilities/directives/clickSubject.d.ts +0 -9
- package/utilities/directives/conditional-classes.directive.d.ts +0 -13
- package/utilities/directives/dialog-service.d.ts +0 -10
- package/utilities/directives/dialog.d.ts +0 -44
- package/utilities/directives/mat-toggle-group-directive.d.ts +0 -21
- package/utilities/directives/prevent-enter.directive.d.ts +0 -6
- package/utilities/directives/stop-propagation.directive.d.ts +0 -7
- package/utilities/directives/styler.d.ts +0 -15
- package/utilities/directives/trim-whitespace.directive.d.ts +0 -7
- package/utilities/module.d.ts +0 -19
- package/utilities/pipes/function.pipe.d.ts +0 -11
- package/utilities/pipes/phone.pipe.d.ts +0 -7
- package/utilities/pipes/space-case.pipes.d.ts +0 -17
package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ChangeDetectionStrategy, Component, computed, inject } from '@angular/core';
|
|
2
|
+
import { TableStore } from '../../../classes/table-store';
|
|
3
|
+
import { FilterInfo, isFilterInfo } from '../../../classes/filter-info';
|
|
4
|
+
import { WrapperFilterStore } from '../table-wrapper-filter-store';
|
|
5
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
6
|
+
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
7
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
8
|
+
import { FilterComponent } from '../../filter/filter.component';
|
|
9
|
+
import { MatChipsModule } from '@angular/material/chips';
|
|
10
|
+
import { KeyDisplayPipe } from '../../../pipes/key-display';
|
|
11
|
+
import { FormatFilterTypePipe } from '../../../pipes/format-filter-type.pipe';
|
|
12
|
+
import { FormatFilterValuePipe } from '../../../pipes/format-filter-value.pipe';
|
|
13
|
+
|
|
14
|
+
@Component({
|
|
15
|
+
selector: 'lib-filter-list',
|
|
16
|
+
templateUrl: './filter-list.component.html',
|
|
17
|
+
styleUrls: ['../gen-filter-displayer/gen-filter-displayer.component.css'],
|
|
18
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
19
|
+
imports: [
|
|
20
|
+
MatButtonModule, MatTooltipModule, MatIconModule, FilterComponent,
|
|
21
|
+
MatChipsModule, KeyDisplayPipe, FormatFilterTypePipe, FormatFilterValuePipe
|
|
22
|
+
]
|
|
23
|
+
})
|
|
24
|
+
export class FilterChipsComponent {
|
|
25
|
+
|
|
26
|
+
tableState = inject(TableStore);
|
|
27
|
+
filterStore = inject(WrapperFilterStore);
|
|
28
|
+
|
|
29
|
+
$filters = computed(() =>
|
|
30
|
+
Object.values(this.tableState.$filters()).filter(f => isFilterInfo(f) && !f._isExternallyManaged) as FilterInfo[])
|
|
31
|
+
deleteByIndex(index: number) {
|
|
32
|
+
this.filterStore.deleteByIndex(index);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
addFilter(filter:FilterInfo<any>){
|
|
36
|
+
this.filterStore.addFilter(filter);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
clearAll() {
|
|
40
|
+
this.filterStore.clearAll();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
$currentFilters = this.filterStore.$currentFilters;
|
|
44
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.filter {
|
|
2
|
+
margin: 15px;
|
|
3
|
+
display: inline-block;
|
|
4
|
+
}
|
|
5
|
+
.filter-button {
|
|
6
|
+
color: cornflowerblue;
|
|
7
|
+
font-size: 22px;
|
|
8
|
+
font-weight: 700;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.cancel-button {
|
|
12
|
+
margin-right: 30px;
|
|
13
|
+
font-weight: 700;
|
|
14
|
+
}
|
|
15
|
+
.filter-wrapper{
|
|
16
|
+
margin-top: 1em;
|
|
17
|
+
margin-bottom: 1em;
|
|
18
|
+
float: right;
|
|
19
|
+
}
|
|
20
|
+
.menu {
|
|
21
|
+
margin-bottom: 10px;
|
|
22
|
+
width: 109.1%;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.filter-labels {
|
|
26
|
+
color: cornflowerblue;
|
|
27
|
+
font-size: 17px;
|
|
28
|
+
font-weight: 600;
|
|
29
|
+
}
|
|
30
|
+
.float{
|
|
31
|
+
position: absolute;
|
|
32
|
+
width: fit-content;
|
|
33
|
+
z-index: 101;
|
|
34
|
+
top: 10px;
|
|
35
|
+
right: 180px;
|
|
36
|
+
max-width: 90vw;
|
|
37
|
+
}
|
|
38
|
+
.d-w{
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: row;
|
|
41
|
+
justify-content: flex-end;
|
|
42
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<button stop-propagation class="filter-button" mat-icon-button [matMenuTriggerFor]="menu" [matTooltip]="'Add Filter'">
|
|
2
|
+
<mat-icon class="filter-icon" color="primary">filter_list</mat-icon>
|
|
3
|
+
</button>
|
|
4
|
+
<mat-menu #menu="matMenu">
|
|
5
|
+
@for (md of $filterCols(); track md.key) {
|
|
6
|
+
<button (click)="addFilter(md)" mat-menu-item>
|
|
7
|
+
<span class="filter-labels">{{md.displayName || (md.key | spaceCase)}}</span>
|
|
8
|
+
</button>
|
|
9
|
+
}
|
|
10
|
+
</mat-menu>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { firstValueFrom, of } from 'rxjs';
|
|
2
|
+
import { map } from 'rxjs/operators';
|
|
3
|
+
import { TestBed, ComponentFixture, ComponentFixtureAutoDetect, tick, fakeAsync, flush } from '@angular/core/testing';
|
|
4
|
+
import { GenFilterDisplayerComponent } from './gen-filter-displayer.component';
|
|
5
|
+
import { SpaceCasePipe } from '../../../../utilities/pipes/space-case.pipes';
|
|
6
|
+
import { FilterComponent } from '../../filter/filter.component';
|
|
7
|
+
import { CommonModule } from '@angular/common';
|
|
8
|
+
import { FormsModule } from '@angular/forms';
|
|
9
|
+
import { FieldType } from '../../../interfaces/report-def';
|
|
10
|
+
import { By } from '@angular/platform-browser';
|
|
11
|
+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
|
12
|
+
import { DateFilterComponent } from '../../date-filter/date-filter.component';
|
|
13
|
+
import { TableBuilderModule } from '../../../table-builder.module';
|
|
14
|
+
import { StoreModule } from '@ngrx/store';
|
|
15
|
+
import { EffectsModule } from '@ngrx/effects';
|
|
16
|
+
import { TableStore } from '../../../classes/table-store';
|
|
17
|
+
import { WrapperFilterStore } from '../table-wrapper-filter-store';
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function getMetaData() {
|
|
21
|
+
return of([
|
|
22
|
+
{
|
|
23
|
+
key: 'name',
|
|
24
|
+
displayName: 'first name',
|
|
25
|
+
fieldType: FieldType.String,
|
|
26
|
+
additional: {},
|
|
27
|
+
order: 1
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
key: 'last',
|
|
31
|
+
displayName: 'last name',
|
|
32
|
+
fieldType: FieldType.String,
|
|
33
|
+
additional: {},
|
|
34
|
+
order: 2
|
|
35
|
+
}
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('generic filter displayer', () => {
|
|
40
|
+
let fixture: ComponentFixture<GenFilterDisplayerComponent>;
|
|
41
|
+
let component: GenFilterDisplayerComponent;
|
|
42
|
+
|
|
43
|
+
const clickFilter = (idx: number) => {
|
|
44
|
+
const btn = fixture.debugElement.query(By.css('.filter-button')).nativeElement;
|
|
45
|
+
|
|
46
|
+
btn.click();
|
|
47
|
+
const menu = fixture.debugElement.queryAll(By.css('.mat-menu-item'));
|
|
48
|
+
menu[idx].nativeElement.click();
|
|
49
|
+
};
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
|
|
52
|
+
TestBed.configureTestingModule({
|
|
53
|
+
declarations: [
|
|
54
|
+
GenFilterDisplayerComponent,
|
|
55
|
+
SpaceCasePipe,
|
|
56
|
+
FilterComponent,
|
|
57
|
+
DateFilterComponent,
|
|
58
|
+
],
|
|
59
|
+
providers: [TableStore, WrapperFilterStore,
|
|
60
|
+
{ provide: ComponentFixtureAutoDetect, useValue: true }
|
|
61
|
+
],
|
|
62
|
+
imports: [
|
|
63
|
+
NoopAnimationsModule,
|
|
64
|
+
CommonModule,
|
|
65
|
+
FormsModule,
|
|
66
|
+
TableBuilderModule.forRoot({ defaultTableSettings: { } }),
|
|
67
|
+
StoreModule.forRoot({}),
|
|
68
|
+
EffectsModule.forRoot([])]
|
|
69
|
+
})
|
|
70
|
+
.compileComponents();
|
|
71
|
+
fixture = TestBed.createComponent(GenFilterDisplayerComponent);
|
|
72
|
+
component = fixture.componentInstance;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should get the generic filter displayer component', () => {
|
|
76
|
+
expect(component).toBeDefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should be able to create a filter', async () => {
|
|
80
|
+
clickFilter(0);
|
|
81
|
+
const filter = await firstValueFrom(fixture.componentInstance.filterStore.state$.pipe(map(x => x.filterInfo)));
|
|
82
|
+
expect(filter.length).toBe(1);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Component, ChangeDetectionStrategy, inject, computed } from '@angular/core';
|
|
2
|
+
import { MetaData, FieldType } from '../../../interfaces/report-def';
|
|
3
|
+
import { TableStore } from '../../../classes/table-store';
|
|
4
|
+
import { WrapperFilterStore } from '../table-wrapper-filter-store';
|
|
5
|
+
import { MatButtonModule } from '@angular/material/button';
|
|
6
|
+
import { MatMenuModule } from '@angular/material/menu';
|
|
7
|
+
import { MatTooltipModule } from '@angular/material/tooltip';
|
|
8
|
+
import { SpaceCasePipe, StopPropagationDirective } from '../../../../utilities';
|
|
9
|
+
import { MatIconModule } from '@angular/material/icon';
|
|
10
|
+
|
|
11
|
+
@Component({
|
|
12
|
+
selector: 'tb-filter-displayer',
|
|
13
|
+
templateUrl: './gen-filter-displayer.component.html',
|
|
14
|
+
styleUrls: ['./gen-filter-displayer.component.css'],
|
|
15
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
16
|
+
imports: [
|
|
17
|
+
MatButtonModule, MatMenuModule, MatTooltipModule, StopPropagationDirective, MatIconModule,
|
|
18
|
+
SpaceCasePipe
|
|
19
|
+
]
|
|
20
|
+
})
|
|
21
|
+
export class GenFilterDisplayerComponent {
|
|
22
|
+
protected tableState = inject(TableStore);
|
|
23
|
+
protected filterStore = inject(WrapperFilterStore);
|
|
24
|
+
$filterCols = computed(() => {
|
|
25
|
+
const mds = this.tableState.$metaDataArray();
|
|
26
|
+
return mds.filter(m => m.fieldType !== FieldType.Hidden && m.fieldType !== FieldType.NotMapped && !m.noFilter);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
addFilter(metaData: MetaData) {
|
|
30
|
+
this.filterStore.addFilter({key: metaData.key, fieldType: metaData.fieldType});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Injectable } from "@angular/core";
|
|
2
|
+
import { ComponentStore } from "@ngrx/component-store";
|
|
3
|
+
import { map } from "rxjs/operators";
|
|
4
|
+
import { PartialFilter } from "../../classes/filter-info";
|
|
5
|
+
@Injectable()
|
|
6
|
+
export class WrapperFilterStore extends ComponentStore<{filterInfo:PartialFilter[]}>{
|
|
7
|
+
constructor(){
|
|
8
|
+
super({filterInfo:[]});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
clearAll = this.updater(()=>({filterInfo:[]}));
|
|
12
|
+
deleteByIndex = this.updater((state,index:number)=>{
|
|
13
|
+
const arr = [...state.filterInfo];
|
|
14
|
+
arr.splice(index, 1);
|
|
15
|
+
return {filterInfo:arr};
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
$currentFilters = this.selectSignal(state => state.filterInfo);
|
|
19
|
+
|
|
20
|
+
addFilter = this.updater((state,filter:PartialFilter)=>{
|
|
21
|
+
return ({...state,filterInfo:[...state.filterInfo,filter]});
|
|
22
|
+
})
|
|
23
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Directive, TemplateRef, inject, input, computed, signal } from '@angular/core';
|
|
2
|
+
import { CdkColumnDef } from '@angular/cdk/table';
|
|
3
|
+
import { CustomCellMeta, FieldType, SortDef } from '../interfaces/report-def';
|
|
4
|
+
import { TableBuilder } from '../classes/table-builder';
|
|
5
|
+
|
|
6
|
+
interface CustomCellContext<T> {
|
|
7
|
+
$implicit: T,
|
|
8
|
+
element: T,
|
|
9
|
+
}
|
|
10
|
+
// here is how to use it
|
|
11
|
+
// <generic-table [report]="report">
|
|
12
|
+
// <p *customCell="'column1'; let element = element" [class.makeMeRed]="element?.port">If Port, i will be red</p>
|
|
13
|
+
// <p *customCell="'column2'">I am custom cell two </p>
|
|
14
|
+
// </generic-table>
|
|
15
|
+
@Directive({
|
|
16
|
+
selector: '[customCell]',
|
|
17
|
+
})
|
|
18
|
+
export class CustomCellDirective<T = any> {
|
|
19
|
+
private templateRef = inject<TemplateRef<any>>(TemplateRef, { optional: true });
|
|
20
|
+
public columnDef = inject(CdkColumnDef, { optional: true });
|
|
21
|
+
$customCell = input.required<string>({alias: 'customCell'});
|
|
22
|
+
$displayName = input<string | undefined>(undefined, {alias: 'displayName'});
|
|
23
|
+
$preSort = input<SortDef | undefined>(undefined, {alias: 'preSort'});
|
|
24
|
+
$templateRef = input<TemplateRef<any> | undefined>(this.templateRef || undefined, {alias: 'templateRef'});
|
|
25
|
+
$customCellOrder = input<number | undefined>(undefined, {alias: 'customCellOrder'});
|
|
26
|
+
$customCellWidth = input<string | undefined>(undefined, {alias: 'customCellWidth'});
|
|
27
|
+
/**
|
|
28
|
+
* for type safety, this is a reference to the table builder instance.
|
|
29
|
+
*/
|
|
30
|
+
$customCellTableRef = input<TableBuilder<T> | undefined>(undefined, {alias: 'customCellTableRef'});
|
|
31
|
+
/**
|
|
32
|
+
* true if column not mapped to a property in the data source. Default is false.
|
|
33
|
+
*/
|
|
34
|
+
$customCellNotMapped = input<boolean>(false, {alias: 'customCellNotMapped'});
|
|
35
|
+
$metaData = computed((): CustomCellMeta | undefined => {
|
|
36
|
+
const c= this.$customCell();
|
|
37
|
+
if(!c) return;
|
|
38
|
+
return ({
|
|
39
|
+
key: this.$customCell(),
|
|
40
|
+
displayName: this.$displayName(),
|
|
41
|
+
preSort: this.$preSort(),
|
|
42
|
+
fieldType: this.$customCellNotMapped() ? FieldType.NotMapped : FieldType.Unknown,
|
|
43
|
+
order: this.$customCellOrder(),
|
|
44
|
+
width: this.$customCellWidth(),
|
|
45
|
+
customCell: true,
|
|
46
|
+
noExport: true,
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
$inited = signal(false);
|
|
50
|
+
|
|
51
|
+
ngOnInit(){
|
|
52
|
+
this.$inited.set(true);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static ngTemplateContextGuard<T>(dir: CustomCellDirective<T>, ctx: any): ctx is CustomCellContext<T> {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export * from './custom-cell-directive';
|
|
2
|
-
export * from './multi-sort.directive';
|
|
3
|
-
export * from './resize-column.directive';
|
|
4
|
-
export * from './table-wrapper.directive';
|
|
5
|
-
export * from './tb-filter.directive';
|
|
1
|
+
export * from './custom-cell-directive';
|
|
2
|
+
export * from './multi-sort.directive';
|
|
3
|
+
export * from './resize-column.directive';
|
|
4
|
+
export * from './table-wrapper.directive';
|
|
5
|
+
export * from './tb-filter.directive';
|
|
6
|
+
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { MultiSortDirective } from './multi-sort.directive';
|
|
2
|
+
import { Sort, MatSortable } from '@angular/material/sort';
|
|
3
|
+
import { FieldType } from '../interfaces/report-def';
|
|
4
|
+
import { TableBuilderConfigToken } from '../classes/TableBuilderConfig';
|
|
5
|
+
import { DatePipe } from '@angular/common';
|
|
6
|
+
import { TestBed } from '@angular/core/testing';
|
|
7
|
+
import { StoreModule } from '@ngrx/store';
|
|
8
|
+
import { storageStateReducer } from '../ngrx/reducer';
|
|
9
|
+
import { TableStore } from '../classes/table-store';
|
|
10
|
+
|
|
11
|
+
describe('MultiSortDirective', () => {
|
|
12
|
+
|
|
13
|
+
let directive: MultiSortDirective;
|
|
14
|
+
let rules: Sort[];
|
|
15
|
+
|
|
16
|
+
const data = [
|
|
17
|
+
{
|
|
18
|
+
name: 'Joe',
|
|
19
|
+
age: 10,
|
|
20
|
+
balance: 25
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'Jane',
|
|
24
|
+
age: 20,
|
|
25
|
+
balance: 35
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
const metaData = [
|
|
29
|
+
{
|
|
30
|
+
key: 'name',
|
|
31
|
+
fieldType: FieldType.String,
|
|
32
|
+
additional: {},
|
|
33
|
+
order : 1
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
key: 'age',
|
|
37
|
+
fieldType: FieldType.Number,
|
|
38
|
+
additional: {},
|
|
39
|
+
order : 2
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: 'balance',
|
|
43
|
+
fieldType: FieldType.Number,
|
|
44
|
+
additional: {},
|
|
45
|
+
order : 3
|
|
46
|
+
}
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const initialState = {fullTableState: {
|
|
50
|
+
'test-id': {
|
|
51
|
+
metaData,
|
|
52
|
+
hiddenKeys: [],
|
|
53
|
+
pageSize: 10,
|
|
54
|
+
initialized : true ,
|
|
55
|
+
filters: [],
|
|
56
|
+
sorted : [],
|
|
57
|
+
}
|
|
58
|
+
}};
|
|
59
|
+
|
|
60
|
+
beforeEach(() => {
|
|
61
|
+
TestBed.resetTestingModule ();
|
|
62
|
+
rules = [];
|
|
63
|
+
TestBed.configureTestingModule({
|
|
64
|
+
declarations: [],
|
|
65
|
+
providers: [
|
|
66
|
+
{ provide : TableBuilderConfigToken , useValue: {defaultTableState: { }}},
|
|
67
|
+
DatePipe,
|
|
68
|
+
TableStore
|
|
69
|
+
],
|
|
70
|
+
imports: [
|
|
71
|
+
StoreModule.forRoot({'fullTableState': storageStateReducer}),
|
|
72
|
+
],
|
|
73
|
+
teardown: {destroyAfterEach: true}
|
|
74
|
+
})
|
|
75
|
+
.compileComponents();
|
|
76
|
+
|
|
77
|
+
const store = TestBed.inject(TableStore);
|
|
78
|
+
// stateManager.upda ..tableId = 'test-id';
|
|
79
|
+
// stateManager.initializeState();
|
|
80
|
+
directive = new MultiSortDirective(store);
|
|
81
|
+
|
|
82
|
+
rules = [
|
|
83
|
+
{ active: 'a', direction: 'asc' },
|
|
84
|
+
{ active: 'b', direction: 'asc' },
|
|
85
|
+
{ active: 'c', direction: 'asc' },
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
[...rules].reverse().forEach( rule => store.setSort( {key:rule.active, direction: rule.direction} ));
|
|
89
|
+
directive.ngOnInit();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('Initializing Rules', () => {
|
|
93
|
+
|
|
94
|
+
it('should inititialize the rules', () => {
|
|
95
|
+
expect(directive.rules).toEqual(rules);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe('Updating the rules', () => {
|
|
100
|
+
it('should add new rule to begining of rules array', () => {
|
|
101
|
+
const originalLength = directive.rules.length;
|
|
102
|
+
const sort: MatSortable = { id: 'd', start: 'asc', disableClear: false };
|
|
103
|
+
directive.sort(sort);
|
|
104
|
+
expect(directive.rules.length).toBe(originalLength + 1, 'updated rules length should be one larger than original');
|
|
105
|
+
expect(directive.rules[0].active).toBe(sort.id);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should remove old rule for the column of new rule and replace it with new rule', () => {
|
|
109
|
+
const originalLength = directive.rules.length;
|
|
110
|
+
const sort: MatSortable = { id: 'a', start: 'asc', disableClear: false };
|
|
111
|
+
directive.sort(sort);
|
|
112
|
+
expect(directive.rules.length).toBe(originalLength, 'updated rules length should be same as original');
|
|
113
|
+
expect(directive.rules[0].direction).toBe('desc');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should remove old rule without replacing it if new rule for that column has no direction', () => {
|
|
117
|
+
const originalLength = directive.rules.length;
|
|
118
|
+
const sort: MatSortable = { id: 'a', start: 'asc', disableClear: false };
|
|
119
|
+
directive.sort({...sort});
|
|
120
|
+
directive.sort({...sort});
|
|
121
|
+
expect(directive.rules.length).toBe(originalLength - 1, 'updated rules length should be one smaller than original');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Directive, OnInit, OnDestroy, inject } from '@angular/core';
|
|
2
|
+
import { MatSort, Sort, SortDirection } from '@angular/material/sort';
|
|
3
|
+
import { distinctUntilChanged, distinctUntilKeyChanged, map, tap } from 'rxjs/operators';
|
|
4
|
+
import { TableStore } from '../classes/table-store';
|
|
5
|
+
|
|
6
|
+
@Directive({
|
|
7
|
+
selector: '[multiSort]',
|
|
8
|
+
exportAs: 'multiSort',
|
|
9
|
+
inputs: ['disabled: matSortDisabled'],
|
|
10
|
+
providers: [
|
|
11
|
+
{ provide: MatSort, useExisting: MultiSortDirective }
|
|
12
|
+
],
|
|
13
|
+
})
|
|
14
|
+
export class MultiSortDirective extends MatSort implements OnInit, OnDestroy {
|
|
15
|
+
private state = inject(TableStore);
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this.state.setSort(this.sortChange.pipe(
|
|
21
|
+
distinctUntilChanged((f,s) => f.active === s.active && f.direction === s.direction),
|
|
22
|
+
map(sc => ({ key: sc.active, direction: sc.direction }))));
|
|
23
|
+
this.state.on(
|
|
24
|
+
this.state.sort$,
|
|
25
|
+
(rules) => {
|
|
26
|
+
const topRule = { active: rules[0]?.active || '', direction: rules[0]?.direction || '' as SortDirection};
|
|
27
|
+
const topActiveChanged = topRule.active !== this.active || '';
|
|
28
|
+
const topDirectionChanged = topRule.direction !== this.direction || '';
|
|
29
|
+
if(topActiveChanged || topDirectionChanged){
|
|
30
|
+
this.active = topRule.active;
|
|
31
|
+
this.direction = topRule.direction;
|
|
32
|
+
this.sortChange.emit(topRule);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function sortsAreSame(a: Sort[], b: Sort[]) {
|
|
41
|
+
if (a.length !== b.length) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
for (let i = 0; i < a.length; i++) {
|
|
45
|
+
if (a[i].active !== b[i].active || a[i].direction !== b[i].direction) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Directive, OnInit, Renderer2, Input, ElementRef, booleanAttribute, inject } from "@angular/core";
|
|
2
|
+
import { fromEvent } from "rxjs";
|
|
3
|
+
import { filter, map, switchMap, takeUntil } from "rxjs/operators";
|
|
4
|
+
import { defaultShareReplay } from "../../rxjs";
|
|
5
|
+
import { TableStore } from "../classes/table-store";
|
|
6
|
+
|
|
7
|
+
@Directive({
|
|
8
|
+
selector: "[resizeColumn]",
|
|
9
|
+
})
|
|
10
|
+
export class ResizeColumnDirective implements OnInit{
|
|
11
|
+
private renderer = inject(Renderer2);
|
|
12
|
+
private el = inject(ElementRef);
|
|
13
|
+
store = inject(TableStore);
|
|
14
|
+
|
|
15
|
+
@Input({ alias : 'resizeColumn', transform: booleanAttribute }) resizable: boolean | string = false;
|
|
16
|
+
|
|
17
|
+
@Input() key!: string;
|
|
18
|
+
|
|
19
|
+
ngOnInit(){
|
|
20
|
+
if (this.resizable){
|
|
21
|
+
const {table, columnHead} = this.getTableAndColumnHeadHtmlElements();
|
|
22
|
+
const resizer = this.createResizerSpanInColumnHead(columnHead);
|
|
23
|
+
|
|
24
|
+
const aggregateMouseEventsMapped$ = this.mouseDownThroughMouseUpEventMapper(resizer,columnHead,table)
|
|
25
|
+
|
|
26
|
+
const resizeColsData$ = aggregateMouseEventsMapped$.pipe(
|
|
27
|
+
filter(({mouseMove})=>!!mouseMove.buttons),
|
|
28
|
+
map( ({mouseDownData,mouseMove}) => {
|
|
29
|
+
const {newTableWidth,newColumnWidth} = this.calculateNewWidths(mouseDownData,mouseMove)
|
|
30
|
+
return ({
|
|
31
|
+
key:this.key,
|
|
32
|
+
widthInPixel:newColumnWidth,
|
|
33
|
+
tableSize:newTableWidth,
|
|
34
|
+
})
|
|
35
|
+
}),
|
|
36
|
+
defaultShareReplay()
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
this.store.setUserDefinedWidth(resizeColsData$.pipe(
|
|
40
|
+
map(resizeData => ([{key: this.key, widthInPixel: resizeData.widthInPixel }]))
|
|
41
|
+
));
|
|
42
|
+
|
|
43
|
+
this.store.setTableWidth(resizeColsData$.pipe(
|
|
44
|
+
map(resizeData => resizeData.tableSize )));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
createResizerSpanInColumnHead(columnHead:HTMLElement){
|
|
50
|
+
const resizer = this.renderer.createElement("span");
|
|
51
|
+
this.renderer.addClass(resizer, "resize-holder");
|
|
52
|
+
resizer.style['cursor']='col-resize';
|
|
53
|
+
resizer.style['user-select']='none';
|
|
54
|
+
resizer.style['width']='10px';
|
|
55
|
+
resizer.style['height']='100%';
|
|
56
|
+
resizer.style['position']='absolute';
|
|
57
|
+
resizer.style['right']='0';
|
|
58
|
+
resizer.style['top']='0';
|
|
59
|
+
resizer.style['z-index']='1';
|
|
60
|
+
this.renderer.appendChild(columnHead, resizer);
|
|
61
|
+
return resizer;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
getTableAndColumnHeadHtmlElements():{table:HTMLElement,columnHead:HTMLElement}{
|
|
65
|
+
const columnHead: HTMLElement = this.el.nativeElement;
|
|
66
|
+
const row = this.renderer.parentNode(columnHead);
|
|
67
|
+
const table = this.renderer.parentNode(row);
|
|
68
|
+
return ({table,columnHead})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
mouseDownThroughMouseUpEventMapper(resizer:HTMLElement, columnHead:HTMLElement, table:HTMLElement){
|
|
72
|
+
return this.resizerMouseDownEventMapper(resizer,columnHead,table)
|
|
73
|
+
.pipe(
|
|
74
|
+
switchMap( mouseDownData => fromEvent<MouseEvent>(table, "mousemove").pipe(
|
|
75
|
+
map( mouseMove => ({mouseDownData, mouseMove})),
|
|
76
|
+
takeUntil(fromEvent<MouseEvent>(document, "mouseup"))
|
|
77
|
+
) ),
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
resizerMouseDownEventMapper(resizer:HTMLElement, columnHead:HTMLElement, table:HTMLElement){
|
|
81
|
+
return fromEvent<MouseEvent>(resizer, "mousedown").pipe(
|
|
82
|
+
map(event => ({
|
|
83
|
+
startPageX: event.pageX,
|
|
84
|
+
startColumnWidth: this.getElementWidth(columnHead),
|
|
85
|
+
startTableWidth: this.getElementWidth(table),
|
|
86
|
+
}))
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
calculateNewWidths(mouseDownData: MouseDownData, mouseMove: MouseEvent):{newTableWidth:number,newColumnWidth:number}{
|
|
91
|
+
const change = (mouseMove.pageX - mouseDownData.startPageX );
|
|
92
|
+
let newColumnWidth = mouseDownData.startColumnWidth + change;
|
|
93
|
+
if(newColumnWidth < 1){
|
|
94
|
+
newColumnWidth = 1;
|
|
95
|
+
}
|
|
96
|
+
const columnChange = newColumnWidth - mouseDownData.startColumnWidth;
|
|
97
|
+
const newTableWidth = (mouseDownData.startTableWidth + columnChange);
|
|
98
|
+
return ({newTableWidth,newColumnWidth})
|
|
99
|
+
}
|
|
100
|
+
getElementWidth = (elem:HTMLElement) => (+(globalThis.getComputedStyle(elem).getPropertyValue('width').replace('px','')))
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
interface MouseDownData{
|
|
104
|
+
startPageX:number,
|
|
105
|
+
startColumnWidth:number,
|
|
106
|
+
startTableWidth:number,
|
|
107
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Directive, signal } from "@angular/core";
|
|
2
|
+
import { TableCustomFilterDirective, TableFilterDirective } from "./tb-filter.directive";
|
|
3
|
+
|
|
4
|
+
@Directive({
|
|
5
|
+
selector: '[tbWrapper]',
|
|
6
|
+
})
|
|
7
|
+
export class TableWrapperDirective {
|
|
8
|
+
$registrations = signal([] as (TableCustomFilterDirective | TableFilterDirective)[]);
|
|
9
|
+
|
|
10
|
+
register(filter: TableCustomFilterDirective | TableFilterDirective) {
|
|
11
|
+
this.$registrations.update( registrations => [...registrations,filter] );
|
|
12
|
+
}
|
|
13
|
+
}
|