@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
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Dictionary } from './dictionary';
|
|
2
|
+
import { PipeTransform, Predicate, TemplateRef } from '@angular/core';
|
|
3
|
+
import { TableBuilderExport } from '../classes/TableBuilderConfig';
|
|
4
|
+
import { QueryParamsHandling } from '@angular/router';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export enum FieldType {
|
|
8
|
+
Unknown = 0,
|
|
9
|
+
Date = 1,
|
|
10
|
+
Link = 2,
|
|
11
|
+
ImageUrl = 3,
|
|
12
|
+
Currency = 4,
|
|
13
|
+
Array = 5,
|
|
14
|
+
Hidden = 6,
|
|
15
|
+
Number = 7,
|
|
16
|
+
String = 8,
|
|
17
|
+
Boolean = 9,
|
|
18
|
+
PhoneNumber = 10,
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated For mapped properties use proper type (for sorting and filtering) with `map`.
|
|
21
|
+
* For unmapped properties use `FieldType.NotMapped` with map.
|
|
22
|
+
*/
|
|
23
|
+
Expression = 11,
|
|
24
|
+
Enum = 12,
|
|
25
|
+
DateTime = 13,
|
|
26
|
+
NotMapped = 14,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export enum SortDirection {
|
|
30
|
+
asc= 'asc',
|
|
31
|
+
desc= 'desc'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export enum Target {
|
|
35
|
+
Blank = '_blank',
|
|
36
|
+
Self = '_self',
|
|
37
|
+
Parent = '_parent',
|
|
38
|
+
Top = '_top'
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface BaseMeta <T = any> {
|
|
42
|
+
displayName?: string;
|
|
43
|
+
additional?: Additional<T>;
|
|
44
|
+
order?: number;
|
|
45
|
+
preSort?: SortDef;
|
|
46
|
+
width?: string;
|
|
47
|
+
noExport?: boolean;
|
|
48
|
+
noFilter?: boolean;
|
|
49
|
+
noSort?: boolean;
|
|
50
|
+
customCell?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated Please use map instead
|
|
53
|
+
*/
|
|
54
|
+
transform?: ((o: T, ...args: any[])=> any) | ((o: string, ...args: any[])=> any) | PipeTransform;
|
|
55
|
+
click?: (element: T, key: string ) => void;
|
|
56
|
+
template?: TemplateRef<any>;
|
|
57
|
+
classes?: Dictionary<Predicate<T>>;
|
|
58
|
+
toolTip?: string | ((t:T) => string);
|
|
59
|
+
useIcon?: boolean;
|
|
60
|
+
map? : (t:T) => any;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface MappedMetaData<T = any, AdditionalFields extends string[] = []> extends BaseMeta<T> {
|
|
64
|
+
key: (keyof T | AdditionalFields[number]) & string;
|
|
65
|
+
fieldType: Exclude<typeof FieldType[keyof typeof FieldType], FieldType.NotMapped | FieldType.Expression>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type MetaData<T = any, AdditionalFields extends string[] = []> = MappedMetaData<T, AdditionalFields> | NotMappedMetaData<T>;
|
|
69
|
+
|
|
70
|
+
export interface NotMappedMetaData<T = any> extends BaseMeta<T> {
|
|
71
|
+
key: string;
|
|
72
|
+
fieldType: FieldType.NotMapped | FieldType.Expression;
|
|
73
|
+
}
|
|
74
|
+
export interface ReportDef<DataType = any> {
|
|
75
|
+
data: DataType[];
|
|
76
|
+
metaData: MetaData [];
|
|
77
|
+
totalRecords?: number;
|
|
78
|
+
count: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface SortDef {
|
|
82
|
+
direction: SortDirection;
|
|
83
|
+
precedence?: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface FilterOptions {
|
|
87
|
+
filterableValues : string[]
|
|
88
|
+
}
|
|
89
|
+
export interface DateTimeOptions {
|
|
90
|
+
format?: string;
|
|
91
|
+
includeSeconds?: boolean;
|
|
92
|
+
includeMilliseconds: boolean;
|
|
93
|
+
}
|
|
94
|
+
type interpolatedRoute = string;
|
|
95
|
+
export interface Additional<T = any> {
|
|
96
|
+
link? : {
|
|
97
|
+
base?: string;
|
|
98
|
+
urlKey?: string;
|
|
99
|
+
target?: Target;
|
|
100
|
+
useRouterLink?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* If you want to use a route with interpolated params, you can use this. Wrap the property name in curly braces.
|
|
103
|
+
* For example, if interpolatedRoute = /users/{id}/edit, {id} will be replaced with the value of the element's id property.
|
|
104
|
+
*/
|
|
105
|
+
interpolatedRoute?: interpolatedRoute;
|
|
106
|
+
routerLinkOptions?:{
|
|
107
|
+
queryParams?: [string, interpolatedRoute][];
|
|
108
|
+
fragment?: string;
|
|
109
|
+
preserveFragment?: boolean;
|
|
110
|
+
queryParamsHandling?: QueryParamsHandling;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
footer?: { type: 'sum' };
|
|
114
|
+
export?: TableBuilderExport;
|
|
115
|
+
dateFormat?: string;
|
|
116
|
+
dateTimeOptions?: DateTimeOptions;
|
|
117
|
+
filterOptions?: FilterOptions;
|
|
118
|
+
styles?: Dictionary<string | {condition: (t:T) => boolean | true, value: (t:T) => string | string}>;
|
|
119
|
+
columnPartStyles?: {
|
|
120
|
+
header?: Dictionary<string>,
|
|
121
|
+
body?: Dictionary<string | {condition: (t: T) => boolean | true, value: (t: T) => string | string}>,
|
|
122
|
+
footer?: Dictionary<string>,
|
|
123
|
+
}
|
|
124
|
+
columnPartClasses?: {
|
|
125
|
+
header?: Dictionary<Predicate<T>>,
|
|
126
|
+
footer?: Dictionary<Predicate<T>>,
|
|
127
|
+
}
|
|
128
|
+
enumMap?: {[key:number]:string};
|
|
129
|
+
boolean? : {
|
|
130
|
+
showForFalse? : true | { icon : string },
|
|
131
|
+
forTrue? : { icon : string }
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export enum ArrayStyle {
|
|
136
|
+
CommaDelimited,
|
|
137
|
+
NewLine
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface ArrayAdditional extends Additional {
|
|
141
|
+
limit?: number;
|
|
142
|
+
arrayStyle?: ArrayStyle;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
export function metaDataArrToDict<T = MetaData>(arr: MetaData[], transform?: (m : MetaData) => T): Dictionary<T>{
|
|
148
|
+
const dict = {};
|
|
149
|
+
if(transform){
|
|
150
|
+
arr.forEach(e => dict[e.key] = transform(e));
|
|
151
|
+
} else {
|
|
152
|
+
arr.forEach(e => dict[e.key] = e);
|
|
153
|
+
}
|
|
154
|
+
return dict;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface CustomCellMeta extends Pick<MetaData, 'key' | 'displayName' | 'preSort' | 'fieldType' | 'order' | 'width'>{
|
|
158
|
+
customCell: true;
|
|
159
|
+
noExport?: boolean;
|
|
160
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { ComponentStore } from "@ngrx/component-store";
|
|
2
|
+
import { Injectable, Signal } from "@angular/core";
|
|
3
|
+
import { Observable, filter, tap } from "rxjs";
|
|
4
|
+
import { concatLatestFrom } from '@ngrx/operators';
|
|
5
|
+
import { Dictionary } from "../interfaces/dictionary";
|
|
6
|
+
import { PersistedTableState, TableState } from "../classes/TableState";
|
|
7
|
+
|
|
8
|
+
@Injectable({ providedIn: 'root'})
|
|
9
|
+
export class TableBuilderStateStore extends ComponentStore<GlobalStorageState> {
|
|
10
|
+
constructor(){
|
|
11
|
+
super(loadGlobalStorageState() || defaultStorageState)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//selectors
|
|
15
|
+
$selectLocalTableProfile = (profileKey:string): Signal<Profile | undefined> => this.selectSignal(state =>
|
|
16
|
+
state.localProfiles[profileKey]);
|
|
17
|
+
|
|
18
|
+
$selectLocalTableStateForView = (tableId: string) => this.selectSignal(
|
|
19
|
+
this.$selectLocalTableProfile(tableId),
|
|
20
|
+
(profile) => {
|
|
21
|
+
if(profile?.current) {
|
|
22
|
+
return profile.states[profile.current];
|
|
23
|
+
}
|
|
24
|
+
if(profile?.localSavedState) return profile.localSavedState;
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
$selectLocalProfileCurrentKey = (key:string) => this.selectSignal(
|
|
30
|
+
this.$selectLocalTableProfile(key),
|
|
31
|
+
(profile) => profile?.current);
|
|
32
|
+
|
|
33
|
+
$selectLocalProfileDefaultKey = (key:string) => this.selectSignal(
|
|
34
|
+
this.$selectLocalTableProfile(key),
|
|
35
|
+
(profile) => profile?.default);
|
|
36
|
+
|
|
37
|
+
$selectLocalProfileKeys = (tableId:string) => this.selectSignal(
|
|
38
|
+
this.$selectLocalTableProfile(tableId),
|
|
39
|
+
(profile) => Object.keys(profile?.states || {})
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// reducers
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
saveTableSettingsToLocalAndStorage = (tableId: string, stateName: string, tableState: PersistedTableState, asDefault?: boolean) => {
|
|
47
|
+
this.saveTableStateToStorage(tableId, stateName, tableState, asDefault);
|
|
48
|
+
this.saveTableStateToLocal({ tableId, tableState, stateName, asDefault });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
saveTableStateToLocal = this.updater((state, props: { tableId: string, tableState: PersistedTableState, stateName?: string, asDefault?: boolean }) => {
|
|
52
|
+
let profile = state.localProfiles[props.tableId];
|
|
53
|
+
if(!profile?.states) {
|
|
54
|
+
profile = {states:{}};
|
|
55
|
+
}
|
|
56
|
+
if(!props.stateName){
|
|
57
|
+
profile = {...profile, localSavedState: props.tableState };
|
|
58
|
+
} else {
|
|
59
|
+
profile = {...profile, states: {...profile.states, [props.stateName] : props.tableState} };
|
|
60
|
+
}
|
|
61
|
+
if(props.asDefault){
|
|
62
|
+
profile.default = props.stateName;
|
|
63
|
+
}
|
|
64
|
+
return {...state, localProfiles: {...state.localProfiles, [props.tableId]: profile} }
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
saveTableStateToStorage = (tableId: string, stateName: string, tableState: PersistedTableState, asDefault = false) => {
|
|
68
|
+
const globalSavedState: PersistedGlobalStorageSate = JSON.parse(localStorage.getItem('global-state-storage') ?? JSON.stringify(defaultStorageState) );
|
|
69
|
+
globalSavedState.localProfiles[tableId] ??= { states : {}}
|
|
70
|
+
globalSavedState.localProfiles[tableId].states[stateName] = tableState;
|
|
71
|
+
if(asDefault){
|
|
72
|
+
globalSavedState.localProfiles[tableId].default = stateName;
|
|
73
|
+
}
|
|
74
|
+
localStorage.setItem('global-state-storage', JSON.stringify( globalSavedState));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
addNewStateToLocalAndStorage = (tableId: string, newStateName: string, tableState: PersistedTableState, asDefault?: boolean) => {
|
|
78
|
+
this.saveTableSettingsToLocalAndStorage(tableId, newStateName, tableState, asDefault);
|
|
79
|
+
this.setLocalCurrentState({ tableId: tableId, currentStateKey: newStateName});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
setLocalCurrentState = this.updater((state, props: { tableId: string, currentStateKey: string }) => {
|
|
83
|
+
const profile = state.localProfiles[props.tableId] || { states: {}};
|
|
84
|
+
profile.current = props.currentStateKey;
|
|
85
|
+
return {...state, localProfiles: {...state.localProfiles, [props.tableId]: {...profile}}};
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
setDefaultInLocalAndStorage = (tableId: string, newDefault: string) => {
|
|
89
|
+
this.setDefaultInLocal({ default: newDefault, key: tableId });
|
|
90
|
+
this.setDefaultInStorage(tableId, newDefault);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setDefaultInLocal = this.updater((state, props: { key: string, default: string }) => {
|
|
94
|
+
if(state.localProfiles[props.key]?.states[props.default]) {
|
|
95
|
+
return ({...state, localProfiles: {...state.localProfiles, [props.key]: {...state.localProfiles[props.key], default: props.default} } });
|
|
96
|
+
}
|
|
97
|
+
return state;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
unsetDefaultFromLocalAndStorage = (tableId: string) => {
|
|
101
|
+
this.unsetDefaultFromLocal(tableId);
|
|
102
|
+
this.unsetDefaultFromStorage(tableId);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
unsetDefaultFromLocal = (tableId: string) => {
|
|
106
|
+
this.patchState(tables => {
|
|
107
|
+
const profile = { ...tables.localProfiles[tableId] };
|
|
108
|
+
if(profile) {
|
|
109
|
+
delete profile.default;
|
|
110
|
+
}
|
|
111
|
+
return { ...tables, localProfiles: { ...tables.localProfiles, [tableId]: profile } };
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
unsetDefaultFromStorage = (tableId: string) => {
|
|
116
|
+
const globalSavedState: GlobalStorageState = JSON.parse(localStorage.getItem('global-state-storage') ?? JSON.stringify(defaultStorageState) );
|
|
117
|
+
if(globalSavedState.localProfiles[tableId]) {
|
|
118
|
+
delete globalSavedState.localProfiles[tableId].default;
|
|
119
|
+
localStorage.setItem('global-state-storage', JSON.stringify( globalSavedState));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
setDefaultInStorage = (tableId: string, stateName: string) => {
|
|
124
|
+
const tableProfile = this.$selectLocalTableProfile(tableId)();
|
|
125
|
+
const globalSavedState: GlobalStorageState = JSON.parse(localStorage.getItem('global-state-storage') ?? JSON.stringify(defaultStorageState) );
|
|
126
|
+
let savedProfile = globalSavedState.localProfiles[stateName];
|
|
127
|
+
if(!savedProfile?.states) {
|
|
128
|
+
savedProfile = { default: stateName, states : tableProfile!.states };
|
|
129
|
+
} else {
|
|
130
|
+
savedProfile.default = stateName;
|
|
131
|
+
}
|
|
132
|
+
globalSavedState.localProfiles[tableId] = savedProfile;
|
|
133
|
+
localStorage.setItem('global-state-storage', JSON.stringify( globalSavedState));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
deleteLocalProfilesState = this.updater((state, props: { key: string, stateKey: string }) => {
|
|
137
|
+
let profile = state.localProfiles[props.key];
|
|
138
|
+
if(profile) {
|
|
139
|
+
const current = profile.current === props.stateKey ? profile.default : profile.current;
|
|
140
|
+
profile = {...profile,current, states: { ...profile.states}};
|
|
141
|
+
delete profile.states[props.stateKey];
|
|
142
|
+
if(current === props.stateKey) {
|
|
143
|
+
profile.current = undefined;
|
|
144
|
+
}
|
|
145
|
+
return {...state, localProfiles: {...state.localProfiles, [props.key]: profile} };
|
|
146
|
+
} else {
|
|
147
|
+
return state;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
deleteProfileFromLocalAndStorage = (key: string, stateKey: string) => {
|
|
152
|
+
const globalSavedState: GlobalStorageState = JSON.parse(localStorage.getItem('global-state-storage') ?? JSON.stringify(defaultStorageState) );
|
|
153
|
+
if(!globalSavedState.localProfiles[key]) {
|
|
154
|
+
return;
|
|
155
|
+
} else {
|
|
156
|
+
delete (globalSavedState.localProfiles[key].states ?? {})[stateKey];
|
|
157
|
+
}
|
|
158
|
+
if(globalSavedState.localProfiles[key].default === stateKey) {
|
|
159
|
+
globalSavedState.localProfiles[key].default = undefined;
|
|
160
|
+
}
|
|
161
|
+
localStorage.setItem('global-state-storage', JSON.stringify( globalSavedState));
|
|
162
|
+
this.deleteLocalProfilesState({ key, stateKey })
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function loadGlobalStorageState() : GlobalStorageState | void {
|
|
167
|
+
const storage = localStorage.getItem('global-state-storage');
|
|
168
|
+
|
|
169
|
+
if(storage) {
|
|
170
|
+
const s: GlobalStorageState = (JSON.parse(storage) as PersistedGlobalStorageSate);
|
|
171
|
+
s.localProfiles ??= {};
|
|
172
|
+
for(const key in s.localProfiles){
|
|
173
|
+
const profile = s.localProfiles[key];
|
|
174
|
+
s.localProfiles[key] = { ...profile, current: profile.default } as Profile
|
|
175
|
+
}
|
|
176
|
+
return {...defaultStorageState, ...s};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
interface PersistedProfile {
|
|
181
|
+
states: Dictionary<PersistedTableState>;
|
|
182
|
+
default?: string;
|
|
183
|
+
}
|
|
184
|
+
export interface Profile extends PersistedProfile {
|
|
185
|
+
current?: string;
|
|
186
|
+
localSavedState?: PersistedTableState;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface GlobalStorageState {
|
|
190
|
+
localProfiles: Dictionary<Profile>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface PersistedGlobalStorageSate {
|
|
194
|
+
localProfiles: Dictionary<PersistedProfile>;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export const defaultStorageState: GlobalStorageState = {
|
|
198
|
+
localProfiles: {}
|
|
199
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
import { MetaData } from '../interfaces/report-def';
|
|
3
|
+
import {sumBy} from 'lodash';
|
|
4
|
+
|
|
5
|
+
@Pipe({
|
|
6
|
+
name: 'columnTotal',
|
|
7
|
+
})
|
|
8
|
+
export class ColumnTotalPipe implements PipeTransform {
|
|
9
|
+
transform(data: any[], metaData: MetaData) {
|
|
10
|
+
const dataToCalculate = data.filter(d => !d.isGroupHeader)
|
|
11
|
+
switch (metaData.additional!.footer!.type) {
|
|
12
|
+
case 'sum':
|
|
13
|
+
return sumBy(dataToCalculate, metaData.key);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
+
import { FilterType, FilterTypes } from '../enums/filterTypes';
|
|
3
|
+
|
|
4
|
+
@Pipe({name: 'formatFilterType' })
|
|
5
|
+
export class FormatFilterTypePipe implements PipeTransform {
|
|
6
|
+
transform(filterType: FilterType, value: any){
|
|
7
|
+
if(filterType === FilterTypes.IsNull){
|
|
8
|
+
return value ? filterType : 'Is Not Blank'
|
|
9
|
+
}
|
|
10
|
+
return filterType;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Pipe, PipeTransform, computed, inject } from '@angular/core';
|
|
2
|
+
import { TableStore } from '../classes/table-store';
|
|
3
|
+
import { Observable } from 'rxjs';
|
|
4
|
+
import { map } from 'rxjs/operators';
|
|
5
|
+
import { FieldType, MetaData } from '../interfaces/report-def';
|
|
6
|
+
import { DatePipe } from '@angular/common';
|
|
7
|
+
import { FilterType, FilterTypes } from '../enums/filterTypes';
|
|
8
|
+
import { spaceCase } from '../../utilities/pipes/space-case.pipes';
|
|
9
|
+
import { DateTimeFilterFuncs } from '../functions/date-filter-function';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@Pipe({name: 'formatFilterValue' })
|
|
13
|
+
export class FormatFilterValuePipe implements PipeTransform {
|
|
14
|
+
tableState = inject(TableStore);
|
|
15
|
+
private datePipe = inject(DatePipe);
|
|
16
|
+
|
|
17
|
+
transform(value: any, key: string, filterType: FilterType) {
|
|
18
|
+
return computed(() => transform(value, this.tableState.$getMetaData(key)(), filterType));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const transform = (value: any, meta: MetaData, filterType: FilterType): string => {
|
|
23
|
+
if(filterType === FilterTypes.IsNull) {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
if(value && (filterType === FilterTypes.In )){
|
|
27
|
+
if(meta.fieldType === FieldType.Enum) {
|
|
28
|
+
return value.map( (v: any) => spaceCase(meta.additional!.enumMap![v])).join(', ') ?? value;
|
|
29
|
+
}
|
|
30
|
+
return value.join(', ') ?? value;
|
|
31
|
+
}
|
|
32
|
+
if(filterType === FilterTypes.NumberBetween){
|
|
33
|
+
return value.Start + ' - ' + value.End;
|
|
34
|
+
}
|
|
35
|
+
if(meta.fieldType === FieldType.Date){
|
|
36
|
+
return new DatePipe('en-US').transform(value, 'MM/dd/yy') || '';
|
|
37
|
+
}
|
|
38
|
+
if(meta.fieldType === FieldType.DateTime){
|
|
39
|
+
return (!!DateTimeFilterFuncs[filterType] ? new DatePipe('en-US').transform(value, 'short') : new DatePipe('en-US').transform(value, 'MM/dd/yy')) || '';
|
|
40
|
+
}
|
|
41
|
+
return value
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Pipe, PipeTransform, computed, inject } from '@angular/core';
|
|
2
|
+
import { TableStore } from '../classes/table-store';
|
|
3
|
+
import { spaceCase } from '../../utilities/pipes/space-case.pipes';
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
import { map } from 'rxjs/operators';
|
|
6
|
+
|
|
7
|
+
@Pipe({name: 'keyDisplay' })
|
|
8
|
+
export class KeyDisplayPipe implements PipeTransform {
|
|
9
|
+
tableState = inject(TableStore);
|
|
10
|
+
|
|
11
|
+
transform = (key: string) =>
|
|
12
|
+
computed(() => this.tableState.$getMetaData(key)()?.displayName || spaceCase(key))
|
|
13
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { DatePipe } from '@angular/common';
|
|
2
|
+
import { Injectable, inject } from '@angular/core';
|
|
3
|
+
import { TableStore } from '../classes/table-store';
|
|
4
|
+
import { TableBuilderConfigToken } from '../classes/TableBuilderConfig';
|
|
5
|
+
import { downloadData } from '../functions/download-data';
|
|
6
|
+
import { ArrayAdditional, ArrayStyle, FieldType, MetaData } from '../interfaces/report-def';
|
|
7
|
+
import { isPipe } from './transform-creator';
|
|
8
|
+
import { get } from 'lodash';
|
|
9
|
+
|
|
10
|
+
@Injectable()
|
|
11
|
+
export class ExportToCsvService<T> {
|
|
12
|
+
state = inject(TableStore);
|
|
13
|
+
private config = inject(TableBuilderConfigToken);
|
|
14
|
+
private datePipe = inject(DatePipe);
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
exportToCsv = (data: T[]) => {
|
|
18
|
+
const hiddenKeys = this.state.selectSignal(s => s.hiddenKeys)();
|
|
19
|
+
const meta = this.state.$metaDataArray().filter(md => !md.noExport && !hiddenKeys.includes(md.key));
|
|
20
|
+
const csv = this.csvData(data, meta);
|
|
21
|
+
downloadData(csv,'export.csv', 'text/csv') ;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
csvData = (data:Array<T>, metaData: MetaData<T>[]) => {
|
|
25
|
+
const res = data.map(row => metaData.map(meta => this.metaToField(meta, row)).join(','));
|
|
26
|
+
res.unshift(metaData.map(meta => meta.displayName || meta.key).join(','));
|
|
27
|
+
return res.join('\n');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
metaToField = (meta: MetaData<T>, row: T) => {
|
|
31
|
+
let val: any = get( row,meta.key);
|
|
32
|
+
if (val == null && !meta.transform) return val
|
|
33
|
+
if(meta.transform && meta.fieldType !== FieldType.Expression){
|
|
34
|
+
const transform = meta.transform as any;
|
|
35
|
+
return isPipe(transform) ? transform.transform(val) : transform(val);
|
|
36
|
+
}
|
|
37
|
+
if(meta.map){
|
|
38
|
+
return meta.map(row);
|
|
39
|
+
}
|
|
40
|
+
switch (meta.fieldType) {
|
|
41
|
+
case FieldType.Date:
|
|
42
|
+
const dateFormat = meta.additional?.export?.dateFormat || this.config?.export?.dateFormat || meta.additional?.dateFormat;
|
|
43
|
+
val = this.transform(val, dateFormat);
|
|
44
|
+
break;
|
|
45
|
+
case FieldType.DateTime:
|
|
46
|
+
const dateTimeFormat = meta.additional?.export?.dateTimeFormat || this.config?.export?.dateTimeFormat || meta.additional?.dateTimeOptions?.format;
|
|
47
|
+
val = this.transform(val, dateTimeFormat);
|
|
48
|
+
break;
|
|
49
|
+
case FieldType.String:
|
|
50
|
+
const prepend: string = meta.additional?.export?.prepend || this.config?.export?.prepend || '';
|
|
51
|
+
val = prepend + val;
|
|
52
|
+
break;
|
|
53
|
+
case FieldType.Array:
|
|
54
|
+
const style = (meta.additional as ArrayAdditional).arrayStyle ?? this.config.arrayDefaults?.arrayStyle;
|
|
55
|
+
const limit = (meta.additional as ArrayAdditional).limit ?? this.config.arrayDefaults?.limit;
|
|
56
|
+
val = (val as Array<string>).slice(0, limit).join(style === ArrayStyle.NewLine ? '\n' : ', ');
|
|
57
|
+
break;
|
|
58
|
+
case FieldType.Expression:
|
|
59
|
+
val = (meta.transform as any)(row);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
if (typeof val === 'string' && (val.includes(',') || val.includes('"') || val.includes('\n'))) {
|
|
63
|
+
val = val.replaceAll('"', '""');
|
|
64
|
+
val = '"' + val + '"';
|
|
65
|
+
}
|
|
66
|
+
return val;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private transform(val: any, dateFormat: any) {
|
|
70
|
+
if (this.config.transformers && this.config.transformers[FieldType.Date]) {
|
|
71
|
+
return this.config.transformers[FieldType.Date]!(val);
|
|
72
|
+
}
|
|
73
|
+
return this.datePipe.transform(val, dateFormat);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { get } from "lodash";
|
|
2
|
+
import { FieldType, MetaData } from "../interfaces/report-def";
|
|
3
|
+
import { Dictionary } from "@ngrx/entity";
|
|
4
|
+
import { QueryParamsHandling } from "@angular/router";
|
|
5
|
+
|
|
6
|
+
export function createLinkCreatorDict<T>(metaDatas: MetaData<T>[]){
|
|
7
|
+
return metaDatas.reduce((acc, md) => {
|
|
8
|
+
if(md.fieldType === FieldType.Link){ acc[md.key]= createLinkCreator(md)}
|
|
9
|
+
return acc;
|
|
10
|
+
},{} as Dictionary<LinkInfo>)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function createLinkCreator<T>(metaData: MetaData<T>): LinkInfo{
|
|
14
|
+
const target = metaData.additional?.link?.target || '_blank';
|
|
15
|
+
const useRouterLink = metaData.additional?.link?.useRouterLink || false;
|
|
16
|
+
const hasRoute = !!metaData.additional?.link?.interpolatedRoute;
|
|
17
|
+
const routerLinkOptions = useRouterLink ? {
|
|
18
|
+
queryParams: (element) => metaData.additional!.link!.routerLinkOptions?.queryParams?.reduce((map, [key, value]) => {
|
|
19
|
+
map[key] = parseInterpolated(value, element);
|
|
20
|
+
return map;
|
|
21
|
+
}, {}) ?? null,
|
|
22
|
+
fragment: metaData.additional!.link?.routerLinkOptions?.fragment,
|
|
23
|
+
preserveFragment: metaData.additional!.link!.routerLinkOptions?.preserveFragment ?? false,
|
|
24
|
+
queryParamsHandling: metaData.additional!.link!.routerLinkOptions?.queryParamsHandling ?? '',
|
|
25
|
+
}
|
|
26
|
+
: undefined;
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if (hasRoute) {
|
|
30
|
+
return ({
|
|
31
|
+
link: (element: T) => parseInterpolated(metaData.additional!.link!.interpolatedRoute!, element),
|
|
32
|
+
target,
|
|
33
|
+
useRouterLink,
|
|
34
|
+
routerLinkOptions,
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
const slashIfNeeded = !metaData.additional?.link?.base?.endsWith('/') ? '/' : '';
|
|
38
|
+
const base = metaData.additional!.link?.base;
|
|
39
|
+
const getKey = key(metaData);
|
|
40
|
+
return ({
|
|
41
|
+
link: (element: T) => `${base}${slashIfNeeded}${getKey(element)}`,
|
|
42
|
+
target,
|
|
43
|
+
useRouterLink,
|
|
44
|
+
routerLinkOptions,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const key = (metaData : MetaData) => metaData.additional!.link?.urlKey ?
|
|
50
|
+
(element:any) => get(element, (metaData.additional!.link!.urlKey as string))
|
|
51
|
+
:
|
|
52
|
+
(element:any) => get(element, metaData.key);
|
|
53
|
+
|
|
54
|
+
const parseInterpolated = ( interpolatedString: string, element: any ) =>
|
|
55
|
+
interpolatedString.replace(/{([^}]+)}/g, (_, key) => get(element ,key));
|
|
56
|
+
|
|
57
|
+
export interface LinkInfo {
|
|
58
|
+
link: (element: any) => string;
|
|
59
|
+
target: string;
|
|
60
|
+
useRouterLink: boolean;
|
|
61
|
+
routerLinkOptions?: {
|
|
62
|
+
queryParams: (element: any) => any;
|
|
63
|
+
fragment?: string;
|
|
64
|
+
preserveFragment?: boolean;
|
|
65
|
+
queryParamsHandling?: QueryParamsHandling;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { EnvironmentInjector, Injector, createComponent, inject } from "@angular/core";
|
|
2
|
+
import { Injectable, TemplateRef } from "@angular/core";
|
|
3
|
+
import { ArrayAdditional, ArrayStyle, FieldType, MetaData } from "../interfaces/report-def";
|
|
4
|
+
import { InitializationComponent } from "../components/initialization-component/initialization-component";
|
|
5
|
+
import { TableBuilderConfigToken } from "../classes/TableBuilderConfig";
|
|
6
|
+
|
|
7
|
+
@Injectable({providedIn: 'root'})
|
|
8
|
+
export class TableTemplateService {
|
|
9
|
+
instance!: InitializationComponent;
|
|
10
|
+
templates;
|
|
11
|
+
|
|
12
|
+
initTemplates() {
|
|
13
|
+
this.templates = { };
|
|
14
|
+
this.templates[FieldType.Array] = this.instance.arrayNewLineTemplate;
|
|
15
|
+
this.templates[FieldType.Array + .5] = this.instance.arrayCommaTemplate;
|
|
16
|
+
this.templates[FieldType.Boolean] = this.instance.defaultWithIcon;
|
|
17
|
+
this.templates[FieldType.Currency] = this.instance.defaultTemplate;
|
|
18
|
+
this.templates[FieldType.Date] = this.instance.defaultTemplate;
|
|
19
|
+
this.templates[FieldType.DateTime] = this.instance.defaultTemplate;
|
|
20
|
+
this.templates[FieldType.Expression] = this.instance.defaultTemplate;
|
|
21
|
+
this.templates[FieldType.NotMapped] = this.instance.defaultTemplate;
|
|
22
|
+
this.templates[FieldType.ImageUrl] = this.instance.imageUrlTemplate;
|
|
23
|
+
this.templates[FieldType.Link] = this.instance.linkTemplate;
|
|
24
|
+
this.templates[FieldType.Link + .5] = this.instance.routerLinkTemplate;
|
|
25
|
+
this.templates[FieldType.Number] = this.instance.defaultTemplate;
|
|
26
|
+
this.templates[FieldType.PhoneNumber] = this.instance.defaultTemplate;
|
|
27
|
+
this.templates[FieldType.String] = this.instance.defaultTemplate;
|
|
28
|
+
this.templates[FieldType.Unknown] = this.instance.defaultTemplate;
|
|
29
|
+
this.templates[FieldType.Enum] = this.instance.defaultTemplate;
|
|
30
|
+
}
|
|
31
|
+
getTemplate(metaData: MetaData) : TemplateRef<any> {
|
|
32
|
+
const arrayStyle = (metaData.additional as ArrayAdditional)?.arrayStyle ?? this.tableConfig?.arrayDefaults?.arrayStyle;
|
|
33
|
+
let tmp = metaData.fieldType === FieldType.Link && metaData.additional?.link?.useRouterLink
|
|
34
|
+
? this.templates[FieldType.Link + .5]
|
|
35
|
+
:
|
|
36
|
+
metaData.fieldType === FieldType.Array && arrayStyle === ArrayStyle.CommaDelimited
|
|
37
|
+
? this.templates[FieldType.Array + .5]
|
|
38
|
+
:
|
|
39
|
+
this.templates[metaData.fieldType];
|
|
40
|
+
if(metaData.useIcon) {
|
|
41
|
+
if(tmp === this.instance.defaultTemplate) {
|
|
42
|
+
tmp = this.instance.defaultWithIcon;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return tmp;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
constructor() {
|
|
49
|
+
const ei = inject(EnvironmentInjector);
|
|
50
|
+
|
|
51
|
+
const c = createComponent(InitializationComponent, {
|
|
52
|
+
environmentInjector: ei,
|
|
53
|
+
});
|
|
54
|
+
this.instance = c.instance;
|
|
55
|
+
this.initTemplates();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
tableConfig = inject(TableBuilderConfigToken);
|
|
59
|
+
}
|