@one-paragon/angular-utilities 2.8.3 → 2.8.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.
Files changed (203) hide show
  1. package/karma.conf.js +43 -0
  2. package/ng-package.json +7 -0
  3. package/package.json +15 -27
  4. package/src/action-state/action-state-spinner/action-state-spinner.component.css +16 -0
  5. package/src/action-state/action-state-spinner/action-state-spinner.component.html +7 -0
  6. package/src/action-state/action-state-spinner/action-state-spinner.component.spec.ts +25 -0
  7. package/src/action-state/action-state-spinner/action-state-spinner.component.ts +26 -0
  8. package/src/action-state/action-state-ui/action-state-ui.module.ts +13 -0
  9. package/src/action-state/index.ts +8 -0
  10. package/src/action-state/ngrx-ext/ngrx-ext.module.ts +14 -0
  11. package/src/action-state/ngrx.ts +69 -0
  12. package/src/http-request-state/RequestStateFactory.ts +56 -0
  13. package/src/http-request-state/RequestStateStore.ts +360 -0
  14. package/src/http-request-state/deprecated.ts +20 -0
  15. package/src/http-request-state/directives/HttpStateDirectiveBase.ts +29 -0
  16. package/src/http-request-state/directives/http-error-state-directive.ts +21 -0
  17. package/src/http-request-state/directives/http-inProgress-state-directive.ts +19 -0
  18. package/src/http-request-state/directives/http-notStarted-state-directive.ts +19 -0
  19. package/src/http-request-state/directives/http-success-state-directive.ts +29 -0
  20. package/src/http-request-state/directives/index.ts +5 -0
  21. package/src/http-request-state/directives/request-state-directive.spec.ts +73 -0
  22. package/src/http-request-state/directives/request-state-directive.ts +78 -0
  23. package/src/http-request-state/documentation/CREATE-REQUESTOR.md +667 -0
  24. package/src/http-request-state/documentation/README.md +191 -0
  25. package/src/http-request-state/documentation/REQUEST-STATE-STORE-CONFIG.md +648 -0
  26. package/src/http-request-state/documentation/REQUESTOR.md +616 -0
  27. package/src/http-request-state/helpers.ts +30 -0
  28. package/src/http-request-state/http-state-module.ts +23 -0
  29. package/src/http-request-state/index.ts +7 -0
  30. package/src/http-request-state/models/view-context.ts +18 -0
  31. package/src/http-request-state/observable.spec.ts +43 -0
  32. package/src/http-request-state/request-state.ts +66 -0
  33. package/src/http-request-state/rxjs/getRequestorBody.ts +10 -0
  34. package/src/http-request-state/rxjs/getRequestorState.ts +8 -0
  35. package/src/http-request-state/rxjs/index.ts +4 -0
  36. package/src/http-request-state/rxjs/tapError.ts +16 -0
  37. package/src/http-request-state/rxjs/tapSuccess.ts +16 -0
  38. package/src/http-request-state/strategies.spec.ts +42 -0
  39. package/src/http-request-state/types.ts +54 -0
  40. package/src/ngrx/actionable-selector.ts +189 -0
  41. package/src/ngrx/index.ts +1 -0
  42. package/src/public-api.ts +40 -0
  43. package/src/rxjs/defaultShareReplay.ts +8 -0
  44. package/src/rxjs/index.ts +5 -0
  45. package/src/rxjs/mapError.ts +8 -0
  46. package/src/rxjs/rxjs-operators.ts +130 -0
  47. package/src/rxjs/subjectifier.ts +17 -0
  48. package/src/rxjs/subscriber.directive.ts +57 -0
  49. package/src/specs/clickSubject.spec.ts +99 -0
  50. package/src/specs/dialog.spec.ts +101 -0
  51. package/src/specs/toggleGroupDirective.spec.ts +229 -0
  52. package/src/table-builder/classes/DefaultSettings.ts +11 -0
  53. package/src/table-builder/classes/MatTableObservableDataSource.ts +23 -0
  54. package/src/table-builder/classes/TableBuilderConfig.ts +49 -0
  55. package/src/table-builder/classes/TableBuilderDataSource.ts +64 -0
  56. package/src/table-builder/classes/TableState.ts +96 -0
  57. package/src/table-builder/classes/data-store.ts +10 -0
  58. package/src/table-builder/classes/display-col.ts +5 -0
  59. package/src/table-builder/classes/filter-info.ts +129 -0
  60. package/src/table-builder/classes/table-builder-general-settings.ts +233 -0
  61. package/src/table-builder/classes/table-builder.ts +105 -0
  62. package/src/table-builder/classes/table-store.helpers.ts +109 -0
  63. package/src/table-builder/classes/table-store.ts +540 -0
  64. package/src/table-builder/components/array-column.component.ts +34 -0
  65. package/src/table-builder/components/column-builder/column-builder.component.html +109 -0
  66. package/src/table-builder/components/column-builder/column-builder.component.scss +43 -0
  67. package/src/table-builder/components/column-builder/column-builder.component.spec.ts +49 -0
  68. package/src/table-builder/components/column-builder/column-builder.component.ts +130 -0
  69. package/src/table-builder/components/column-builder/column-helpers.ts +54 -0
  70. package/src/table-builder/components/column-header-menu/column-header-menu.component.html +128 -0
  71. package/src/table-builder/components/column-header-menu/column-header-menu.component.scss +97 -0
  72. package/src/table-builder/components/column-header-menu/column-header-menu.component.ts +113 -0
  73. package/src/table-builder/components/date-filter/date-filter.component.html +39 -0
  74. package/src/table-builder/components/date-filter/date-filter.component.ts +33 -0
  75. package/src/table-builder/components/date-time-filter/date-time-filter.component.html +25 -0
  76. package/src/table-builder/components/date-time-filter/date-time-filter.component.ts +33 -0
  77. package/src/table-builder/components/filter/filter.component.html +120 -0
  78. package/src/table-builder/components/filter/filter.component.scss +60 -0
  79. package/src/table-builder/components/filter/filter.component.spec.ts +86 -0
  80. package/src/table-builder/components/filter/filter.component.ts +73 -0
  81. package/src/table-builder/components/filter/in-list/in-list-filter.component.ts +171 -0
  82. package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.html +60 -0
  83. package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.scss +57 -0
  84. package/src/table-builder/components/gen-col-displayer/gen-col-displayer.component.ts +44 -0
  85. package/src/table-builder/components/generic-table/generic-table.component.html +140 -0
  86. package/src/table-builder/components/generic-table/generic-table.component.scss +45 -0
  87. package/src/table-builder/components/generic-table/generic-table.component.ts +531 -0
  88. package/src/table-builder/components/generic-table/paginator.component.ts +125 -0
  89. package/src/table-builder/components/group-by-list/group-by-list.component.css +24 -0
  90. package/src/table-builder/components/group-by-list/group-by-list.component.html +21 -0
  91. package/src/table-builder/components/group-by-list/group-by-list.component.spec.ts +23 -0
  92. package/src/table-builder/components/group-by-list/group-by-list.component.ts +26 -0
  93. package/src/table-builder/components/in-filter/in-filter.component.css +22 -0
  94. package/src/table-builder/components/in-filter/in-filter.component.html +38 -0
  95. package/src/table-builder/components/in-filter/in-filter.component.ts +66 -0
  96. package/src/table-builder/components/index.ts +9 -0
  97. package/src/table-builder/components/initialization-component/initialization.component.html +78 -0
  98. package/src/table-builder/components/initialization-component/initialization.component.ts +28 -0
  99. package/src/table-builder/components/link-column.component.ts +42 -0
  100. package/src/table-builder/components/number-filter/number-filter.component.css +10 -0
  101. package/src/table-builder/components/number-filter/number-filter.component.html +32 -0
  102. package/src/table-builder/components/number-filter/number-filter.component.spec.ts +30 -0
  103. package/src/table-builder/components/number-filter/number-filter.component.ts +34 -0
  104. package/src/table-builder/components/profiles-menu/profiles-menu.component.html +77 -0
  105. package/src/table-builder/components/profiles-menu/profiles-menu.component.scss +126 -0
  106. package/src/table-builder/components/profiles-menu/profiles-menu.component.spec.ts +23 -0
  107. package/src/table-builder/components/profiles-menu/profiles-menu.component.ts +64 -0
  108. package/src/table-builder/components/reset-menu/reset-menu.component.css +3 -0
  109. package/src/table-builder/components/reset-menu/reset-menu.component.html +10 -0
  110. package/src/table-builder/components/reset-menu/reset-menu.component.ts +87 -0
  111. package/src/table-builder/components/scroll-strategy.ts +139 -0
  112. package/src/table-builder/components/sort-menu/sort-menu.component-store.ts +57 -0
  113. package/src/table-builder/components/sort-menu/sort-menu.component.html +115 -0
  114. package/src/table-builder/components/sort-menu/sort-menu.component.scss +119 -0
  115. package/src/table-builder/components/sort-menu/sort-menu.component.ts +88 -0
  116. package/src/table-builder/components/table-container/table-container.component.html +94 -0
  117. package/src/table-builder/components/table-container/table-container.component.scss +60 -0
  118. package/src/table-builder/components/table-container/table-container.component.ts +467 -0
  119. package/src/table-builder/components/table-container/table-container.helpers/data-state.helpers.ts +113 -0
  120. package/src/table-builder/components/table-container/table-container.helpers/filter-state.helpers.ts +125 -0
  121. package/src/table-builder/components/table-container/table-container.helpers/groupBy.helpers.ts +172 -0
  122. package/src/table-builder/components/table-container/table-container.helpers/meta-data.helpers.ts +19 -0
  123. package/src/table-builder/components/table-container/table-container.helpers/sort-state.helpers.ts +47 -0
  124. package/src/table-builder/components/table-container/tableProps.ts +21 -0
  125. package/src/table-builder/components/table-container/virtual-scroll-container.ts +216 -0
  126. package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.html +42 -0
  127. package/src/table-builder/components/table-container-filter/filter-list/filter-list.component.ts +47 -0
  128. package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.css +40 -0
  129. package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.html +11 -0
  130. package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.spec.ts +85 -0
  131. package/src/table-builder/components/table-container-filter/gen-filter-displayer/gen-filter-displayer.component.ts +35 -0
  132. package/src/table-builder/components/table-container-filter/table-wrapper-filter-store.ts +13 -0
  133. package/src/table-builder/components/table-header-menu/table-header-menu.component.css +21 -0
  134. package/src/table-builder/components/table-header-menu/table-header-menu.component.html +48 -0
  135. package/src/table-builder/components/table-header-menu/table-header-menu.component.ts +36 -0
  136. package/src/table-builder/directives/custom-cell-directive.ts +63 -0
  137. package/src/table-builder/directives/custom-header-directive.ts +16 -0
  138. package/src/table-builder/directives/group-row-directive.ts +91 -0
  139. package/src/table-builder/directives/index.ts +8 -0
  140. package/src/table-builder/directives/multi-sort.directive.spec.ts +124 -0
  141. package/src/table-builder/directives/multi-sort.directive.ts +58 -0
  142. package/src/table-builder/directives/resize-column.directive.ts +107 -0
  143. package/src/table-builder/directives/table-wrapper.directive.ts +13 -0
  144. package/src/table-builder/directives/tb-filter.directive.ts +376 -0
  145. package/src/table-builder/documentation/table-builder/CUSTOM-CELL.md +568 -0
  146. package/src/table-builder/documentation/table-builder/CUSTOM-GROUP-ROW.md +356 -0
  147. package/src/table-builder/documentation/table-builder/METADATA-DOCUMENTATION.md +517 -0
  148. package/src/table-builder/documentation/table-builder/STYLER-STYLE.md +228 -0
  149. package/src/table-builder/documentation/table-builder/TABLE-BUILDER-CONFIG.md +325 -0
  150. package/src/table-builder/documentation/table-builder/TABLE-BUILDER-SETTINGS.md +515 -0
  151. package/src/table-builder/documentation/table-builder/TABLE-BUILDER.md +430 -0
  152. package/src/table-builder/documentation/table-builder/TABLE-CONTAINER.md +628 -0
  153. package/src/table-builder/enums/filterTypes.ts +39 -0
  154. package/src/table-builder/functions/boolean-filter-function.ts +12 -0
  155. package/src/table-builder/functions/date-filter-function.ts +85 -0
  156. package/src/table-builder/functions/download-data.ts +11 -0
  157. package/src/table-builder/functions/null-filter-function.ts +9 -0
  158. package/src/table-builder/functions/number-filter-function.ts +47 -0
  159. package/src/table-builder/functions/sort-data-function.ts +80 -0
  160. package/src/table-builder/functions/string-filter-function.ts +59 -0
  161. package/src/table-builder/interfaces/ColumnInfo.ts +9 -0
  162. package/src/table-builder/interfaces/dictionary.ts +3 -0
  163. package/src/table-builder/interfaces/meta-data.ts +279 -0
  164. package/src/table-builder/ngrx/tableBuilderStateStore.ts +203 -0
  165. package/src/table-builder/pipes/column-total.pipe.ts +16 -0
  166. package/src/table-builder/pipes/format-filter-type.pipe.ts +12 -0
  167. package/src/table-builder/pipes/format-filter-value.pipe.ts +71 -0
  168. package/src/table-builder/pipes/key-display.ts +13 -0
  169. package/src/table-builder/services/all-values-filter-creator.service.ts +92 -0
  170. package/src/table-builder/services/export-to-csv.service.ts +117 -0
  171. package/src/table-builder/services/link-creator.service.ts +98 -0
  172. package/src/table-builder/services/table-template-service.ts +47 -0
  173. package/src/table-builder/services/transform-creator.ts +90 -0
  174. package/src/table-builder/specs/table-custom-filters.spec.ts +262 -0
  175. package/src/table-builder/styles/collapser.styles.scss +16 -0
  176. package/src/table-builder/table-builder.module.ts +42 -0
  177. package/src/table-builder/types/group-types.ts +42 -0
  178. package/src/table-builder/types/index.ts +1 -0
  179. package/src/test.ts +17 -0
  180. package/src/utilities/array-helpers.ts +13 -0
  181. package/src/utilities/directives/auto-focus.directive.ts +20 -0
  182. package/src/utilities/directives/clickEmitterDirective.ts +15 -0
  183. package/src/utilities/directives/clickSubject.ts +19 -0
  184. package/src/utilities/directives/conditional-classes.directive.ts +36 -0
  185. package/src/utilities/directives/dialog-service.ts +19 -0
  186. package/src/utilities/directives/dialog.ts +174 -0
  187. package/src/utilities/directives/mat-toggle-group-directive.ts +60 -0
  188. package/src/utilities/directives/prevent-enter.directive.ts +12 -0
  189. package/src/utilities/directives/stop-propagation.directive.ts +19 -0
  190. package/src/utilities/directives/styler.ts +45 -0
  191. package/src/utilities/directives/trim-whitespace.directive.ts +20 -0
  192. package/src/utilities/index.ts +22 -0
  193. package/src/utilities/module.ts +53 -0
  194. package/src/utilities/pipes/function.pipe.ts +21 -0
  195. package/src/utilities/pipes/phone.pipe.ts +20 -0
  196. package/src/utilities/pipes/space-case.pipes.spec.ts +47 -0
  197. package/src/utilities/pipes/space-case.pipes.ts +29 -0
  198. package/tsconfig.lib.json +20 -0
  199. package/tsconfig.lib.prod.json +10 -0
  200. package/tsconfig.spec.json +17 -0
  201. package/fesm2022/one-paragon-angular-utilities.mjs +0 -7328
  202. package/fesm2022/one-paragon-angular-utilities.mjs.map +0 -1
  203. package/types/one-paragon-angular-utilities.d.ts +0 -2197
@@ -0,0 +1,203 @@
1
+ import { ComponentStore } from "@ngrx/component-store";
2
+ import { Injectable, Signal } from "@angular/core";
3
+ import { Dictionary } from "../interfaces/dictionary";
4
+ import { PersistedTableState } from "../classes/TableState";
5
+ import { isCustomFilter } from "../classes/filter-info";
6
+
7
+ @Injectable({ providedIn: 'root' })
8
+ export class TableBuilderStateStore extends ComponentStore<GlobalStorageState> {
9
+ constructor(){
10
+ super(loadGlobalStorageState() || defaultStorageState)
11
+ }
12
+
13
+ //selectors
14
+ $selectLocalTableProfile = (profileKey:string): Signal<Profile | undefined> => this.selectSignal(state =>
15
+ state.localProfiles[profileKey]);
16
+
17
+ $selectLocalTableStateForView = (tableId: string) => this.selectSignal(
18
+ this.$selectLocalTableProfile(tableId),
19
+ (profile) => {
20
+ if(profile?.current) {
21
+ return profile.states[profile.current];
22
+ }
23
+ if(profile?.localSavedState) return profile.localSavedState;
24
+ return null;
25
+ }
26
+ )
27
+
28
+ $selectLocalProfileCurrentKey = (key:string) => this.selectSignal(
29
+ this.$selectLocalTableProfile(key),
30
+ (profile) => profile?.current);
31
+
32
+ $selectLocalProfileDefaultKey = (key:string) => this.selectSignal(
33
+ this.$selectLocalTableProfile(key),
34
+ (profile) => profile?.default);
35
+
36
+ $selectLocalProfileKeys = (tableId:string) => this.selectSignal(
37
+ this.$selectLocalTableProfile(tableId),
38
+ (profile) => Object.keys(profile?.states || {})
39
+ );
40
+
41
+
42
+ // reducers
43
+
44
+
45
+ saveTableSettingsToLocalAndStorage = (tableId: string, stateName: string, tableState: PersistedTableState, asDefault?: boolean) => {
46
+ this.saveTableStateToStorage(tableId, stateName, tableState, asDefault);
47
+ this.saveTableStateToLocal({ tableId, tableState, stateName, asDefault });
48
+ }
49
+
50
+ saveTableStateToLocal = this.updater((state, props: { tableId: string, tableState: PersistedTableState, stateName?: string, asDefault?: boolean }) => {
51
+ let profile = state.localProfiles[props.tableId];
52
+ if(!profile?.states) {
53
+ profile = { states: {} };
54
+ }
55
+ if(!props.stateName){
56
+ profile = { ...profile, localSavedState: props.tableState };
57
+ } else {
58
+ profile = { ...profile, states: { ...profile.states, [props.stateName]: props.tableState } };
59
+ }
60
+ if(props.asDefault){
61
+ profile.default = props.stateName;
62
+ }
63
+ return { ...state, localProfiles: { ...state.localProfiles, [props.tableId]: profile } }
64
+ });
65
+
66
+ saveTableStateToStorage = (tableId: string, stateName: string, tableState: PersistedTableState, asDefault = false) => {
67
+ const globalSavedState: PersistedGlobalStorageSate = JSON.parse(localStorage.getItem('global-state-storage') ?? JSON.stringify(defaultStorageState) );
68
+ globalSavedState.localProfiles[tableId] ??= { states: {} };
69
+ const savableState = { ...tableState };
70
+ savableState.filters = Object.values(savableState.filters || {}).filter(f => !isCustomFilter(f) || !f.notSavable).reduce((obj: any, filter) => {
71
+ obj[filter.filterId!] = savableState.filters![filter.filterId!];
72
+ return obj;
73
+ }, {});
74
+ globalSavedState.localProfiles[tableId].states[stateName] = savableState;
75
+ if(asDefault){
76
+ globalSavedState.localProfiles[tableId].default = stateName;
77
+ }
78
+ localStorage.setItem('global-state-storage', JSON.stringify( globalSavedState));
79
+ }
80
+
81
+ addNewStateToLocalAndStorage = (tableId: string, newStateName: string, tableState: PersistedTableState, asDefault?: boolean) => {
82
+ this.saveTableSettingsToLocalAndStorage(tableId, newStateName, tableState, asDefault);
83
+ this.setLocalCurrentState({ tableId: tableId, currentStateKey: newStateName });
84
+ }
85
+
86
+ setLocalCurrentState = this.updater((state, props: { tableId: string, currentStateKey: string }) => {
87
+ const profile = state.localProfiles[props.tableId] || { states: {} };
88
+ profile.current = props.currentStateKey;
89
+ return { ...state, localProfiles: { ...state.localProfiles, [props.tableId]: { ...profile } } };
90
+ });
91
+
92
+ setDefaultInLocalAndStorage = (tableId: string, newDefault: string) => {
93
+ this.setDefaultInLocal({ default: newDefault, key: tableId });
94
+ this.setDefaultInStorage(tableId, newDefault);
95
+ }
96
+
97
+ setDefaultInLocal = this.updater((state, props: { key: string, default: string }) => {
98
+ if(state.localProfiles[props.key]?.states[props.default]) {
99
+ return ({ ...state, localProfiles: { ...state.localProfiles, [props.key]: { ...state.localProfiles[props.key], default: props.default } } });
100
+ }
101
+ return state;
102
+ });
103
+
104
+ unsetDefaultFromLocalAndStorage = (tableId: string) => {
105
+ this.unsetDefaultFromLocal(tableId);
106
+ this.unsetDefaultFromStorage(tableId);
107
+ }
108
+
109
+ unsetDefaultFromLocal = (tableId: string) => {
110
+ this.patchState(tables => {
111
+ const profile = { ...tables.localProfiles[tableId] };
112
+ if(profile) {
113
+ delete profile.default;
114
+ }
115
+ return { ...tables, localProfiles: { ...tables.localProfiles, [tableId]: profile } };
116
+ });
117
+ }
118
+
119
+ unsetDefaultFromStorage = (tableId: string) => {
120
+ const globalSavedState: GlobalStorageState = JSON.parse(localStorage.getItem('global-state-storage') ?? JSON.stringify(defaultStorageState) );
121
+ if(globalSavedState.localProfiles[tableId]) {
122
+ delete globalSavedState.localProfiles[tableId].default;
123
+ localStorage.setItem('global-state-storage', JSON.stringify( globalSavedState));
124
+ }
125
+ }
126
+
127
+ setDefaultInStorage = (tableId: string, stateName: string) => {
128
+ const tableProfile = this.$selectLocalTableProfile(tableId)();
129
+ const globalSavedState: GlobalStorageState = JSON.parse(localStorage.getItem('global-state-storage') ?? JSON.stringify(defaultStorageState) );
130
+ let savedProfile = globalSavedState.localProfiles[stateName];
131
+ if(!savedProfile?.states) {
132
+ savedProfile = { default: stateName, states: tableProfile!.states };
133
+ } else {
134
+ savedProfile.default = stateName;
135
+ }
136
+ globalSavedState.localProfiles[tableId] = savedProfile;
137
+ localStorage.setItem('global-state-storage', JSON.stringify( globalSavedState));
138
+ }
139
+
140
+ deleteLocalProfilesState = this.updater((state, props: { key: string, stateKey: string }) => {
141
+ let profile = state.localProfiles[props.key];
142
+ if(profile) {
143
+ const current = profile.current === props.stateKey ? profile.default : profile.current;
144
+ profile = { ...profile, current, states: { ...profile.states } };
145
+ delete profile.states[props.stateKey];
146
+ if(current === props.stateKey) {
147
+ profile.current = undefined;
148
+ }
149
+ return { ...state, localProfiles: { ...state.localProfiles, [props.key]: profile } };
150
+ } else {
151
+ return state;
152
+ }
153
+ });
154
+
155
+ deleteProfileFromLocalAndStorage = (key: string, stateKey: string) => {
156
+ const globalSavedState: GlobalStorageState = JSON.parse(localStorage.getItem('global-state-storage') ?? JSON.stringify(defaultStorageState) );
157
+ if(!globalSavedState.localProfiles[key]) {
158
+ return;
159
+ } else {
160
+ delete (globalSavedState.localProfiles[key].states ?? {})[stateKey];
161
+ }
162
+ if(globalSavedState.localProfiles[key].default === stateKey) {
163
+ globalSavedState.localProfiles[key].default = undefined;
164
+ }
165
+ localStorage.setItem('global-state-storage', JSON.stringify( globalSavedState));
166
+ this.deleteLocalProfilesState({ key, stateKey })
167
+ }
168
+ }
169
+
170
+ function loadGlobalStorageState() : GlobalStorageState | void {
171
+ const storage = localStorage.getItem('global-state-storage');
172
+
173
+ if(storage) {
174
+ const s: GlobalStorageState = (JSON.parse(storage) as PersistedGlobalStorageSate);
175
+ s.localProfiles ??= {};
176
+ for(const key in s.localProfiles){
177
+ const profile = s.localProfiles[key];
178
+ s.localProfiles[key] = { ...profile, current: profile.default } as Profile
179
+ }
180
+ return { ...defaultStorageState, ...s };
181
+ }
182
+ }
183
+
184
+ interface PersistedProfile {
185
+ states: Dictionary<PersistedTableState>;
186
+ default?: string;
187
+ }
188
+ export interface Profile extends PersistedProfile {
189
+ current?: string;
190
+ localSavedState?: PersistedTableState;
191
+ }
192
+
193
+ export interface GlobalStorageState {
194
+ localProfiles: Dictionary<Profile>;
195
+ }
196
+
197
+ interface PersistedGlobalStorageSate {
198
+ localProfiles: Dictionary<PersistedProfile>;
199
+ }
200
+
201
+ export const defaultStorageState: GlobalStorageState = {
202
+ localProfiles: {}
203
+ }
@@ -0,0 +1,16 @@
1
+ import { Pipe, PipeTransform } from '@angular/core';
2
+ import { MetaData } from '../interfaces/meta-data';
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 } from '../enums/filterTypes';
3
+
4
+ @Pipe({ name: 'formatFilterType' })
5
+ export class FormatFilterTypePipe implements PipeTransform {
6
+ transform(filterType: FilterType, value: any){
7
+ if(filterType === FilterType.IsNull){
8
+ return value ? filterType : 'Is Not Blank'
9
+ }
10
+ return filterType;
11
+ }
12
+ }
@@ -0,0 +1,71 @@
1
+ import { Pipe, PipeTransform, computed, inject } from '@angular/core';
2
+ import { TableStore } from '../classes/table-store';
3
+ import { FieldType, MetaData } from '../interfaces/meta-data';
4
+ import { FilterType } from '../enums/filterTypes';
5
+ import { spaceCase } from '../../utilities/pipes/space-case.pipes';
6
+ import { DateTimeFilterFuncs } from '../functions/date-filter-function';
7
+ import { currencyFormatter, dateFormatter } from '../services/transform-creator';
8
+ import { isBlankValueFilter } from '../services/all-values-filter-creator.service';
9
+
10
+
11
+ @Pipe({ name: 'formatFilterValue' })
12
+ export class FormatFilterValuePipe implements PipeTransform {
13
+ tableState = inject(TableStore);
14
+
15
+ transform(value: any, key: string, filterType: FilterType) {
16
+ return computed(() => transform(value, this.tableState.$getMetaData(key)(), filterType));
17
+ }
18
+ }
19
+
20
+ const transform = (value: any, meta: MetaData, filterType: FilterType): string => {
21
+ if(filterType === FilterType.IsNull) {
22
+ return '';
23
+ }
24
+ if(value && (filterType === FilterType.In )){
25
+ if(meta.fieldType === FieldType.Enum) {
26
+ return value.map((v: any) => mapSpecial(v) || spaceCase(meta.additional!.enumMap![v])).join(', ') ?? value;
27
+ }
28
+ if(meta.fieldType === FieldType.Date || meta.fieldType === FieldType.DateTime) {
29
+ return value.map( (v: any) => mapSpecial(v) || mapDate(v, meta, filterType)).join(', ') ?? value;
30
+ }
31
+ if(meta.fieldType === FieldType.Number || meta.fieldType === FieldType.Currency) {
32
+ return value.map( (v: any) => mapSpecial(v) || mapNumber(v, meta)).join(', ') ?? value;
33
+ }
34
+ return value.map(v => mapSpecial(v) || v).join(', ') ?? value;
35
+ }
36
+ if(filterType === FilterType.NumberBetween && (meta.fieldType === FieldType.Number || meta.fieldType === FieldType.Currency)){
37
+ return mapNumber(value.Start, meta) + ' - ' + mapNumber(value.End, meta);
38
+ }
39
+ if(filterType === FilterType.DateBetween){
40
+ return mapDate(value.Start, meta, filterType) + ' - ' + mapDate(value.End, meta, filterType);
41
+ }
42
+ if(meta.fieldType === FieldType.Date || meta.fieldType === FieldType.DateTime){
43
+ return mapDate(value, meta, filterType);
44
+ }
45
+ if(meta.fieldType === FieldType.Currency){
46
+ return mapNumber(value, meta);
47
+ }
48
+ return value
49
+ }
50
+
51
+ function mapDate(value: any, meta: MetaData, filterType: FilterType){
52
+ if(meta.fieldType === FieldType.Date){
53
+ return dateFormatter(value, 'shortDate');
54
+ }
55
+ if(meta.fieldType === FieldType.DateTime){
56
+ return (!!DateTimeFilterFuncs[filterType] ? dateFormatter(value, 'shortDate') : dateFormatter(value, 'short')) || '';
57
+ }
58
+ return value
59
+ }
60
+
61
+ function mapNumber(value: any, meta: MetaData){
62
+ if(meta.fieldType === FieldType.Currency){
63
+ return currencyFormatter(value);
64
+ }
65
+ return value;
66
+ }
67
+
68
+ function mapSpecial(value: any){
69
+ if(isBlankValueFilter(value)) return 'BLANK';
70
+ return undefined
71
+ }
@@ -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,92 @@
1
+ import { Dictionary } from "@ngrx/entity";
2
+ import { AllValueOptions, FieldType, MetaData } from "../interfaces/meta-data";
3
+ import { TableBuilderConfig } from "../classes/TableBuilderConfig";
4
+ import { createTransformer } from "./transform-creator";
5
+
6
+ export function buildInAllValuesFilter(
7
+ config: TableBuilderConfig,
8
+ previousMeta: MetaData[],
9
+ currentMeta: MetaData[],
10
+ data: any[],
11
+ metaTimestamp: number,
12
+ dataTimestamp: number,
13
+ currentAllFilters: Dictionary<any[]>){
14
+
15
+ const currentAll = currentMeta.filter(m => {
16
+ const filterable = m.additional?.filterOptions?.filterableValues;
17
+ return filterable === 'all values' || (filterable as AllValueOptions)?.allValues === true;
18
+ });
19
+
20
+ if(dataTimestamp > metaTimestamp){
21
+ return currentAll.reduce((dict, md) => {
22
+ dict[md.key] = buildFilter(data, md, config);
23
+ return dict;
24
+ }, {})
25
+ }
26
+ const previousAll = previousMeta.filter(m => {
27
+ const filterable = m.additional?.filterOptions?.filterableValues;
28
+ return filterable === 'all values' || (filterable as AllValueOptions)?.allValues === true;
29
+ });
30
+ const newCurrent = currentAll.filter(c => previousAll.every(p => c.key !== p.key));
31
+ if(newCurrent.length){
32
+ const c = { ...currentAllFilters }
33
+ newCurrent.forEach(md => c[md.key] = buildFilter(data, md, config));
34
+ return c;
35
+ }
36
+
37
+ return currentAllFilters;
38
+ }
39
+ export const blankValueFilter = '__tb_sp_blank';
40
+ export const blankValueAndEmptyStringFilter = '__tb_sp_BLANK';
41
+ function buildFilter(data: any[], metaData: MetaData, config: TableBuilderConfig){
42
+ const map = metaData.fieldType == FieldType.Currency ? (v => v == null ? v : v[metaData.key])
43
+ : typeof metaData.filterLogic?.filterBy === 'function' && !(metaData.additional?.filterOptions?.filterableValues as AllValueOptions)?.doNotIncludeBlanks ? metaData.filterLogic?.filterBy
44
+ : createTransformer(metaData, config, true, false);
45
+ const mapped: [any, any][] = data.map(v => {
46
+ const mappedV = map(v);
47
+ return [mappedV?.toString(), mappedV]
48
+ });
49
+
50
+ const blankAsOption = (metaData?.additional?.filterOptions?.filterableValues as AllValueOptions)?.doNotIncludeBlanks !== true;
51
+ const stringsAsBlanks = (metaData?.additional?.filterOptions?.filterableValues as AllValueOptions)?.doNotTreatEmptyStringsAsBlanks !== true;
52
+
53
+ const blankAsOptionAndHasBlanks = blankAsOption && mapped.some(([, v]) => v == undefined || (stringsAsBlanks && v === ''));
54
+ if(blankAsOptionAndHasBlanks) {
55
+ if(stringsAsBlanks) {
56
+ mapped.push(['BLANK', blankValueAndEmptyStringFilter]);
57
+ } else {
58
+ mapped.push(['BLANK', blankValueFilter]);
59
+ }
60
+ }
61
+ return [...new Map(mapped).values()].filter(v => v != undefined && (!blankAsOption || !stringsAsBlanks || v !== '')).sort((a, b) => {
62
+ const isSymbolA = typeof a === 'symbol';
63
+ const isSymbolB = typeof b === 'symbol';
64
+
65
+ if(isSymbolA || isSymbolB) return 0; // keep symbols in place
66
+
67
+ return String(a).localeCompare(String(b)); // normal string sort
68
+ });
69
+ }
70
+
71
+ export const splitOutBlankFilter = <T>(arr: T[]) => {
72
+ const result = Object.groupBy(arr, v => isBlankValueFilter(v) ? 'blank' : 'values');
73
+ const blank = result.blank?.at(0);
74
+ const blankFilter = blank === blankValueFilter ?
75
+ (val) => val == undefined
76
+ : blank === blankValueAndEmptyStringFilter ? (val) => {
77
+ return (val === '' || val == null)}
78
+ : undefined;
79
+
80
+ return ({
81
+ blankFilter,
82
+ values: result.values || [],
83
+ })
84
+ }
85
+
86
+ export function isBlankValueFilter(val: any) {
87
+ return val === blankValueFilter || val === blankValueAndEmptyStringFilter;
88
+ }
89
+
90
+ export function isNotBlankValueFilter(val: any) {
91
+ return !isBlankValueFilter(val);
92
+ }
@@ -0,0 +1,117 @@
1
+ import { DatePipe } from '@angular/common';
2
+ import { Injectable, computed, inject } from '@angular/core';
3
+ import { TableStore } from '../classes/table-store';
4
+ import { TableBuilderConfigToken, TableBuilderExport } from '../classes/TableBuilderConfig';
5
+ import { downloadData } from '../functions/download-data';
6
+ import { ArrayAdditional, ArrayStyle, FieldType, MetaData } from '../interfaces/meta-data';
7
+ import { isPipe } from './transform-creator';
8
+ import { getFactory } from '../functions/sort-data-function';
9
+ import { spaceCase } from '../../utilities';
10
+ import { cloneDeep, merge } from 'lodash';
11
+
12
+ @Injectable()
13
+ export class ExportToCsvService<T> {
14
+ private state = inject(TableStore);
15
+ private config = inject(TableBuilderConfigToken);
16
+ private datePipe = inject(DatePipe);
17
+
18
+ private $exportSettings = computed<TableBuilderExport>(() => {
19
+ const globalSettings = this.config?.defaultTableSettings?.tableSettings?.exportSettings
20
+ || {};
21
+ const tableSettings = (this.state.$notPersistedTableSettings()?.exportSettings || {}) ;
22
+ return merge({}, globalSettings, tableSettings);
23
+ });
24
+
25
+ exportToCsv = (data: T[]) => {
26
+ const hiddenKeys = this.state.selectSignal(s => s.hiddenKeys)();
27
+ const meta = this.state.$metaDataArray().filter(md => !md.noExport && !hiddenKeys.includes(md.key));
28
+ const extraLinkCols = this.getExtraLinkCols(meta);
29
+ const csv = this.csvData(data, [...meta, ...extraLinkCols]);
30
+ downloadData(csv, 'export.csv', 'text/csv') ;
31
+ }
32
+
33
+ private getExtraLinkCols = (meta: MetaData<T>[]) => {
34
+ return meta.filter(md => {
35
+ if(!md.additional?.link) return;
36
+ const exportForCol = merge({}, this.$exportSettings(), md.additional?.export);
37
+ return exportForCol.mapLink === 'add link' || exportForCol.mapLink === 'add excel';
38
+ }).map(md => {
39
+ const exportForCol = merge({}, this.$exportSettings(), md.additional?.export);
40
+ const newCol = cloneDeep(md);
41
+ newCol.additional!.export ??= {} as TableBuilderExport;
42
+ newCol.additional!.export!.mapLink = exportForCol.mapLink === 'add link' ? 'as link' : 'as excel',
43
+ newCol.displayName = newCol.additional!.export!.linkColumnName || ((newCol.displayName || newCol.key) + ' - (Link)')
44
+ return newCol;
45
+ })
46
+ }
47
+
48
+ private csvData = (data:Array<T>, metaData: MetaData<T>[]) => {
49
+ const res = data.map(row => metaData.map(meta => this.metaToField(meta, row)).join(','));
50
+ res.unshift(metaData.map(meta => meta.displayName || meta.key).join(','));
51
+ return res.join('\n');
52
+ }
53
+
54
+ metaToField = (meta: MetaData<T>, row: T) => {
55
+ const metaExport = meta.additional?.export;
56
+ if(metaExport?.mapForExport) return metaExport.mapForExport(row);
57
+
58
+ const exportForCol = merge({}, this.$exportSettings(), metaExport);
59
+ let val: any = getFactory(meta.key)(row);
60
+ if(val == null) return val
61
+ if(meta.additional?.link && exportForCol.mapLink === 'as link' || exportForCol.mapLink === 'as excel'){
62
+ let mapper = this.state.$getLinkInfo(meta)()?.link;
63
+ if(mapper){
64
+ let mapped = mapper(row);
65
+ if(exportForCol!.linkDomainPrefix){
66
+ const bet = mapped.startsWith('/') ? '' : '/';
67
+ mapped = `${exportForCol!.linkDomainPrefix}${bet}${mapped}`;
68
+ }
69
+ if(exportForCol.mapLink === 'as excel'){
70
+ mapped = this.cleanValForCsv(`=HYPERLINK("${mapped}", "${mapped}")`);
71
+ }
72
+ return mapped;
73
+ }
74
+ }
75
+ val = this.cleanValForCsv(this.stringByType(meta, row, val, exportForCol));
76
+ return val;
77
+ }
78
+
79
+ private stringByType(meta: MetaData<T>, row: T, val: any, exportForCol: TableBuilderExport ){
80
+ if(meta.map){
81
+ return meta.map(row);
82
+ }
83
+ switch (meta.fieldType) {
84
+ case FieldType.Date:
85
+ const dateFormat = meta.additional?.export?.dateFormat || exportForCol?.dateFormat || meta.additional?.dateFormat;
86
+ return this.transformDate(val, dateFormat);
87
+ case FieldType.DateTime:
88
+ const dateTimeFormat = meta.additional?.export?.dateTimeFormat || exportForCol?.dateTimeFormat || meta.additional?.dateTimeOptions?.format;
89
+ return this.transformDate(val, dateTimeFormat);
90
+ case FieldType.String:
91
+ const prepend: string = meta.additional?.export?.prepend || exportForCol?.prepend || '';
92
+ return prepend + val;
93
+ case FieldType.Array:
94
+ const style = meta.additional?.arrayStyle ?? this.config.arrayDefaults?.arrayStyle;
95
+ const limit = meta.additional?.limit ?? this.config.arrayDefaults?.limit;
96
+ return (val as Array<string>).slice(0, limit).join(style === ArrayStyle.NewLine ? '\n' : ', ');
97
+ case FieldType.Enum:
98
+ return exportForCol?.mapEnumToString ? spaceCase(meta.additional!.enumMap![val]) : val;
99
+ }
100
+ return val;
101
+ }
102
+
103
+ cleanValForCsv(val: any) {
104
+ if(typeof val === 'string' && (val.includes(',') || val.includes('"') || val.includes('\n'))) {
105
+ val = val.replaceAll('"', '""');
106
+ val = '"' + val + '"';
107
+ }
108
+ return val;
109
+ }
110
+
111
+ private transformDate(val: any, dateFormat: any) {
112
+ if(this.config.transformers && this.config.transformers[FieldType.Date]) {
113
+ return this.config.transformers[FieldType.Date]!(val);
114
+ }
115
+ return this.datePipe.transform(val, dateFormat);
116
+ }
117
+ }
@@ -0,0 +1,98 @@
1
+ import { MetaData } from "../interfaces/meta-data";
2
+ import { Dictionary } from "@ngrx/entity";
3
+ import { QueryParamsHandling } from "@angular/router";
4
+ import { getFactory } from "../functions/sort-data-function";
5
+
6
+ export function createLinkCreatorDict<T>(metaDatas: MetaData<T>[]){
7
+ return metaDatas.reduce((acc, md) => {
8
+ if(md.additional?.link){ acc[md.key] = createLinkCreator(md)}
9
+ return acc;
10
+ }, {} as Dictionary<LinkInfo>)
11
+ }
12
+
13
+ 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
+
18
+ const qp = useRouterLink ?
19
+ metaData.additional!.link!.routerLinkOptions?.queryParams?.reduce((map, [key, value]) => {
20
+ map[key] = typeof value === 'function' ? value : parseInterpolated(value);
21
+ return map;
22
+ }, {})
23
+ : undefined;
24
+
25
+ const routerLinkOptions = useRouterLink ? {
26
+ queryParams: (element: T) => metaData.additional!.link!.routerLinkOptions?.queryParams?.reduce((map, [key, value]) => {
27
+ map[key] = qp![key](element);
28
+ return map;
29
+ }, {}) ?? null,
30
+ fragment: metaData.additional!.link?.routerLinkOptions?.fragment,
31
+ preserveFragment: metaData.additional!.link!.routerLinkOptions?.preserveFragment ?? false,
32
+ queryParamsHandling: metaData.additional!.link!.routerLinkOptions?.queryParamsHandling ?? '',
33
+ }
34
+ : undefined;
35
+
36
+ if(hasRoute) {
37
+ const value = metaData.additional!.link!.interpolatedRoute!;
38
+ return ({
39
+ link: typeof value === 'function' ? (element: T) => value(element) : parseInterpolated(value),
40
+ target,
41
+ useRouterLink,
42
+ routerLinkOptions,
43
+ });
44
+ } else {
45
+ const slashIfNeeded = !metaData.additional?.link?.base?.endsWith('/') ? '/' : '';
46
+ const base = metaData.additional!.link?.base;
47
+ const getKey = key(metaData);
48
+ return ({
49
+ link: (element: T) => `${base}${slashIfNeeded}${getKey(element)}`,
50
+ target,
51
+ useRouterLink,
52
+ routerLinkOptions,
53
+ });
54
+ }
55
+ }
56
+
57
+ const key = (metaData : MetaData) => metaData.additional!.link?.urlKey ?
58
+ getFactory(metaData.additional!.link!.urlKey as string)
59
+ :
60
+ getFactory(metaData.key);
61
+
62
+ export interface LinkInfo {
63
+ link: (element: any) => string;
64
+ target: string;
65
+ useRouterLink: boolean;
66
+ routerLinkOptions?: {
67
+ queryParams: (element: any) => any;
68
+ fragment?: string;
69
+ preserveFragment?: boolean;
70
+ queryParamsHandling?: QueryParamsHandling;
71
+ }
72
+ }
73
+
74
+ function parseInterpolated(input: string) {
75
+ // Match either content inside curly braces or content between curly braces
76
+ const parts = input.split(/({[\w.]+})/);
77
+
78
+ const result = parts
79
+ .filter(part => part !== '') // Remove empty strings
80
+ .map(part => {
81
+ if(part.startsWith('{') && part.endsWith('}')) {
82
+ // For interpolated values, remove the curly braces
83
+ return {
84
+ type: 'interpolated',
85
+ val: getFactory(part.slice(1, -1))
86
+ };
87
+ } else {
88
+ return {
89
+ type: 'string',
90
+ val: part
91
+ };
92
+ }
93
+ }) as ({type: 'string', val:string} | {type:'interpolated', val: (t:any) => string})[];
94
+
95
+ return function(val: any){
96
+ return result.map(part => part.type === 'string' ? part.val : part.val(val)).join('');
97
+ }
98
+ }
@@ -0,0 +1,47 @@
1
+ import { EnvironmentInjector, createComponent, inject } from "@angular/core";
2
+ import { Injectable, TemplateRef } from "@angular/core";
3
+ import { ArrayAdditional, ArrayStyle, FieldType, MetaData } from "../interfaces/meta-data";
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
+ environmentInjector = inject(EnvironmentInjector);
10
+ tableConfig = inject(TableBuilderConfigToken);
11
+ initConfig = createComponent(InitializationComponent, {
12
+ environmentInjector: this.environmentInjector,
13
+ });
14
+ initializationComponentInstance = this.initConfig.instance;
15
+ getTemplate(metaData: MetaData) : TemplateRef<any> {
16
+
17
+ if(metaData.fieldType === FieldType.Array){
18
+ const arrayStyle = metaData.additional?.arrayStyle ?? this.tableConfig?.arrayDefaults?.arrayStyle;
19
+ return arrayStyle === ArrayStyle.NewLine
20
+ ? this.initializationComponentInstance.$arrayNewLineTemplate()
21
+ : this.initializationComponentInstance.$arrayCommaTemplate();
22
+ }
23
+
24
+ if(metaData.fieldType === FieldType.ImageUrl) {
25
+ return this.initializationComponentInstance.$imageUrlTemplate();
26
+ }
27
+
28
+ const useIcon = metaData.useIcon || (metaData.fieldType === FieldType.Boolean && metaData.useIcon !== false);
29
+ if(metaData.additional?.link){
30
+ const router = metaData.additional?.link?.useRouterLink;
31
+ if(router) {
32
+ return useIcon
33
+ ? this.initializationComponentInstance.$routerLinkWithIconTemplate()
34
+ : this.initializationComponentInstance.$routerLinkTemplate();
35
+ }
36
+ return useIcon
37
+ ? this.initializationComponentInstance.$linkWithIconTemplate()!
38
+ : this.initializationComponentInstance.$linkTemplate();
39
+ }
40
+
41
+ if(useIcon){
42
+ return this.initializationComponentInstance.$defaultWithIcon();
43
+ }
44
+
45
+ return this.initializationComponentInstance.$defaultTemplate();
46
+ }
47
+ }