@verisoft/ui-core 19.0.0-rc001 → 20.1.0

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 (216) hide show
  1. package/.eslintrc.json +48 -0
  2. package/README.md +314 -3
  3. package/jest.config.ts +21 -0
  4. package/ng-package.json +11 -0
  5. package/package.json +16 -31
  6. package/project.json +36 -0
  7. package/{index.d.ts → src/index.ts} +1 -1
  8. package/src/lib/common/angular-helper.ts +44 -0
  9. package/src/lib/common/constants.ts +5 -0
  10. package/src/lib/common/control.models.ts +80 -0
  11. package/src/lib/common/datasource-component.model.spec.ts +42 -0
  12. package/src/lib/common/datasource-component.model.ts +43 -0
  13. package/{lib/common/deactivate-guard.model.d.ts → src/lib/common/deactivate-guard.model.ts} +2 -1
  14. package/src/lib/common/download-file.ts +20 -0
  15. package/src/lib/common/filter.ts +7 -0
  16. package/{lib/common/icons.d.ts → src/lib/common/icons.ts} +34 -34
  17. package/{lib/common/index.d.ts → src/lib/common/index.ts} +10 -10
  18. package/{lib/common/notificable-property.model.d.ts → src/lib/common/notificable-property.model.ts} +5 -4
  19. package/src/lib/common/rxjs.spec.ts +58 -0
  20. package/src/lib/common/rxjs.ts +21 -0
  21. package/src/lib/components/action-button-group/action-button-group.model.ts +15 -0
  22. package/src/lib/components/action-button-group/action-button.model.ts +15 -0
  23. package/{lib/components/action-button-group/index.d.ts → src/lib/components/action-button-group/index.ts} +2 -2
  24. package/src/lib/components/base-form/base-form-input.component.ts +120 -0
  25. package/src/lib/components/base-form/base-form.component.ts +236 -0
  26. package/src/lib/components/base-form/directives/detail-store.directive.ts +219 -0
  27. package/{lib/components/base-form/index.d.ts → src/lib/components/base-form/index.ts} +2 -2
  28. package/src/lib/components/base-form/models/base-form-input.models.ts +11 -0
  29. package/src/lib/components/base-form/models/base-form.models.ts +31 -0
  30. package/{lib/components/base-form/models/index.d.ts → src/lib/components/base-form/models/index.ts} +1 -1
  31. package/{lib/components/breadcrumb/breadcrumb.model.d.ts → src/lib/components/breadcrumb/breadcrumb.model.ts} +6 -1
  32. package/src/lib/components/breadcrumb/breadcrumb.service.ts +9 -0
  33. package/src/lib/components/breadcrumb/breadcrumbcore.component.ts +117 -0
  34. package/src/lib/components/breadcrumb/index.ts +3 -0
  35. package/{lib/components/button/button.model.d.ts → src/lib/components/button/button.model.ts} +5 -1
  36. package/src/lib/components/button/index.ts +1 -0
  37. package/{lib/components/calendar/calendar.model.d.ts → src/lib/components/calendar/calendar.model.ts} +6 -2
  38. package/src/lib/components/calendar/index.ts +1 -0
  39. package/{lib/components/checkbox/checkbox.model.d.ts → src/lib/components/checkbox/checkbox.model.ts} +5 -1
  40. package/src/lib/components/checkbox/index.ts +1 -0
  41. package/src/lib/components/confirm-dialog/confirm-dialog.model.ts +31 -0
  42. package/src/lib/components/confirm-dialog/index.ts +1 -0
  43. package/{lib/components/dropdown/dropdown.model.d.ts → src/lib/components/dropdown/dropdown.model.ts} +5 -1
  44. package/src/lib/components/dropdown/index.ts +1 -0
  45. package/{lib/components/dropdown-button/dropdown-button.model.d.ts → src/lib/components/dropdown-button/dropdown-button.model.ts} +18 -14
  46. package/src/lib/components/dropdown-button/index.ts +1 -0
  47. package/src/lib/components/dynamic-component/dynamic-component.model.ts +2 -0
  48. package/src/lib/components/dynamic-component/index.ts +1 -0
  49. package/src/lib/components/filter/filter.model.ts +17 -0
  50. package/{lib/components/filter/index.d.ts → src/lib/components/filter/index.ts} +1 -1
  51. package/{lib/components/form-field/form-field.model.d.ts → src/lib/components/form-field/form-field.model.ts} +6 -2
  52. package/src/lib/components/form-field/index.ts +1 -0
  53. package/{lib/components/generic-field/generic-field.model.d.ts → src/lib/components/generic-field/generic-field.model.ts} +5 -1
  54. package/src/lib/components/generic-field/index.ts +1 -0
  55. package/src/lib/components/generic-form/generic-form.component.ts +33 -0
  56. package/{lib/components/generic-form/index.d.ts → src/lib/components/generic-form/index.ts} +1 -1
  57. package/{lib/components/header/header.model.d.ts → src/lib/components/header/header.model.ts} +9 -2
  58. package/src/lib/components/header/index.ts +1 -0
  59. package/src/lib/components/icons/icons.component.ts +22 -0
  60. package/src/lib/components/icons/icons.model.ts +16 -0
  61. package/src/lib/components/icons/index.ts +2 -0
  62. package/{lib/components/index.d.ts → src/lib/components/index.ts} +2 -0
  63. package/src/lib/components/input-group/index.ts +1 -0
  64. package/{lib/components/input-group/input-group.model.d.ts → src/lib/components/input-group/input-group.model.ts} +7 -2
  65. package/src/lib/components/loader/index.ts +1 -0
  66. package/src/lib/components/loader/loader.model.ts +7 -0
  67. package/src/lib/components/multiselect/index.ts +1 -0
  68. package/{lib/components/multiselect/mutiselect.model.d.ts → src/lib/components/multiselect/mutiselect.model.ts} +6 -2
  69. package/src/lib/components/number-input/index.ts +1 -0
  70. package/{lib/components/number-input/number-input.model.d.ts → src/lib/components/number-input/number-input.model.ts} +6 -2
  71. package/{lib/components/page-header/index.d.ts → src/lib/components/page-header/index.ts} +1 -1
  72. package/{lib/components/page-header/page-header.model.d.ts → src/lib/components/page-header/page-header.model.ts} +5 -1
  73. package/src/lib/components/page-header/page-header.service.ts +9 -0
  74. package/src/lib/components/page-header/page-headercore.component.ts +42 -0
  75. package/src/lib/components/password/index.ts +1 -0
  76. package/{lib/components/password/password.model.d.ts → src/lib/components/password/password.model.ts} +9 -3
  77. package/src/lib/components/radiobutton/index.ts +1 -0
  78. package/{lib/components/radiobutton/radiobutton.model.d.ts → src/lib/components/radiobutton/radiobutton.model.ts} +8 -3
  79. package/src/lib/components/section/index.ts +1 -0
  80. package/{lib/components/section/section.model.d.ts → src/lib/components/section/section.model.ts} +6 -2
  81. package/src/lib/components/side-menu/directives/side-menu-service.directive.ts +31 -0
  82. package/{lib/components/side-menu/index.d.ts → src/lib/components/side-menu/index.ts} +1 -1
  83. package/src/lib/components/side-menu/services/side-menu-provider.service.ts +13 -0
  84. package/src/lib/components/side-menu/services/side-menu.service.ts +62 -0
  85. package/src/lib/components/side-menu/side-menu.model.ts +67 -0
  86. package/src/lib/components/slider/index.ts +1 -0
  87. package/{lib/components/slider/slider.model.d.ts → src/lib/components/slider/slider.model.ts} +6 -2
  88. package/src/lib/components/snackbar/index.ts +1 -0
  89. package/src/lib/components/snackbar/snackbar.model.ts +7 -0
  90. package/src/lib/components/stepper/index.ts +1 -0
  91. package/{lib/components/stepper/stepper.model.d.ts → src/lib/components/stepper/stepper.model.ts} +10 -5
  92. package/src/lib/components/switch/index.ts +1 -0
  93. package/src/lib/components/switch/switch.model.ts +8 -0
  94. package/src/lib/components/tab-view/index.ts +1 -0
  95. package/{lib/components/tab-view/tab-view.model.d.ts → src/lib/components/tab-view/tab-view.model.ts} +8 -3
  96. package/src/lib/components/table/column-configuration.ts +38 -0
  97. package/src/lib/components/table/table-builder.ts +93 -0
  98. package/src/lib/components/table/table-column.directive.ts +62 -0
  99. package/src/lib/components/table/table.models.ts +261 -0
  100. package/src/lib/components/table-filter/index.ts +1 -0
  101. package/{lib/components/table-filter/table-filter.model.d.ts → src/lib/components/table-filter/table-filter.model.ts} +6 -1
  102. package/src/lib/components/tag/index.ts +1 -0
  103. package/src/lib/components/tag/tag.model.ts +13 -0
  104. package/src/lib/components/textarea/index.ts +1 -0
  105. package/{lib/components/textarea/textarea.model.d.ts → src/lib/components/textarea/textarea.model.ts} +5 -1
  106. package/src/lib/components/textfield/index.ts +1 -0
  107. package/{lib/components/textfield/textfield.model.d.ts → src/lib/components/textfield/textfield.model.ts} +6 -2
  108. package/src/lib/components/tooltip/index.ts +1 -0
  109. package/src/lib/components/tooltip/tooltip.model.ts +13 -0
  110. package/src/lib/components/unsubscribe.component.ts +12 -0
  111. package/src/lib/directives/datasource.directive.ts +275 -0
  112. package/{lib/directives/index.d.ts → src/lib/directives/index.ts} +4 -4
  113. package/src/lib/directives/shortcut.directive.ts +37 -0
  114. package/src/lib/directives/table-datasource.directive.ts +184 -0
  115. package/src/lib/directives/table-filter.directive.ts +69 -0
  116. package/src/lib/format/format.ts +74 -0
  117. package/src/lib/pipes/error/error.codes.ts +11 -0
  118. package/src/lib/pipes/error/error.models.ts +27 -0
  119. package/src/lib/pipes/error/error.pipe.ts +27 -0
  120. package/src/lib/pipes/error/warning.codes.ts +5 -0
  121. package/src/lib/pipes/error/warning.pipe.ts +27 -0
  122. package/src/lib/pipes/helper/enumToList.pipe.ts +16 -0
  123. package/{lib/pipes/index.d.ts → src/lib/pipes/index.ts} +1 -1
  124. package/src/lib/pipes/keyOrFn/keyOrFn.pipe.ts +23 -0
  125. package/src/lib/services/confirm-dialog.service.ts +44 -0
  126. package/{lib/services/index.d.ts → src/lib/services/index.ts} +4 -4
  127. package/src/lib/services/leave-form.service.ts +53 -0
  128. package/src/lib/services/screen-size.service.ts +25 -0
  129. package/src/lib/services/table.service.ts +22 -0
  130. package/src/test-setup.ts +8 -0
  131. package/tsconfig.json +28 -0
  132. package/tsconfig.lib.json +17 -0
  133. package/tsconfig.lib.prod.json +9 -0
  134. package/tsconfig.spec.json +16 -0
  135. package/fesm2022/verisoft-ui-core.mjs +0 -2013
  136. package/fesm2022/verisoft-ui-core.mjs.map +0 -1
  137. package/lib/common/angular-helper.d.ts +0 -1
  138. package/lib/common/constants.d.ts +0 -3
  139. package/lib/common/control.models.d.ts +0 -62
  140. package/lib/common/datasource-component.model.d.ts +0 -19
  141. package/lib/common/download-file.d.ts +0 -2
  142. package/lib/common/filter.d.ts +0 -1
  143. package/lib/common/rxjs.d.ts +0 -2
  144. package/lib/components/action-button-group/action-button-group.model.d.ts +0 -12
  145. package/lib/components/action-button-group/action-button.model.d.ts +0 -14
  146. package/lib/components/base-form/base-form-input.component.d.ts +0 -30
  147. package/lib/components/base-form/base-form.component.d.ts +0 -50
  148. package/lib/components/base-form/directives/detail-store.directive.d.ts +0 -35
  149. package/lib/components/base-form/models/base-form-input.models.d.ts +0 -7
  150. package/lib/components/base-form/models/base-form.models.d.ts +0 -18
  151. package/lib/components/breadcrumb/breadcrumb.service.d.ts +0 -8
  152. package/lib/components/breadcrumb/breadcrumbcore.component.d.ts +0 -30
  153. package/lib/components/breadcrumb/index.d.ts +0 -3
  154. package/lib/components/button/index.d.ts +0 -1
  155. package/lib/components/calendar/index.d.ts +0 -1
  156. package/lib/components/checkbox/index.d.ts +0 -1
  157. package/lib/components/confirm-dialog/confirm-dialog.model.d.ts +0 -25
  158. package/lib/components/confirm-dialog/index.d.ts +0 -1
  159. package/lib/components/dropdown/index.d.ts +0 -1
  160. package/lib/components/dropdown-button/index.d.ts +0 -1
  161. package/lib/components/dynamic-component/dynamic-component.model.d.ts +0 -3
  162. package/lib/components/dynamic-component/index.d.ts +0 -1
  163. package/lib/components/filter/filter.model.d.ts +0 -13
  164. package/lib/components/form-field/index.d.ts +0 -1
  165. package/lib/components/generic-field/index.d.ts +0 -1
  166. package/lib/components/generic-form/generic-form.component.d.ts +0 -30
  167. package/lib/components/header/index.d.ts +0 -1
  168. package/lib/components/icons/icons.component.d.ts +0 -6
  169. package/lib/components/icons/icons.model.d.ts +0 -6
  170. package/lib/components/icons/index.d.ts +0 -2
  171. package/lib/components/input-group/index.d.ts +0 -1
  172. package/lib/components/loader/index.d.ts +0 -1
  173. package/lib/components/loader/loader.model.d.ts +0 -3
  174. package/lib/components/multiselect/index.d.ts +0 -1
  175. package/lib/components/number-input/index.d.ts +0 -1
  176. package/lib/components/page-header/page-header.service.d.ts +0 -8
  177. package/lib/components/page-header/page-headercore.component.d.ts +0 -20
  178. package/lib/components/password/index.d.ts +0 -1
  179. package/lib/components/radiobutton/index.d.ts +0 -1
  180. package/lib/components/section/index.d.ts +0 -1
  181. package/lib/components/side-menu/directives/side-menu-service.directive.d.ts +0 -11
  182. package/lib/components/side-menu/services/side-menu-provider.service.d.ts +0 -10
  183. package/lib/components/side-menu/services/side-menu.service.d.ts +0 -15
  184. package/lib/components/side-menu/side-menu.model.d.ts +0 -42
  185. package/lib/components/slider/index.d.ts +0 -1
  186. package/lib/components/snackbar/index.d.ts +0 -1
  187. package/lib/components/snackbar/snackbar.model.d.ts +0 -3
  188. package/lib/components/stepper/index.d.ts +0 -1
  189. package/lib/components/switch/index.d.ts +0 -1
  190. package/lib/components/switch/switch.model.d.ts +0 -4
  191. package/lib/components/tab-view/index.d.ts +0 -1
  192. package/lib/components/table/column-configuration.d.ts +0 -12
  193. package/lib/components/table/table-builder.d.ts +0 -15
  194. package/lib/components/table/table-column.directive.d.ts +0 -25
  195. package/lib/components/table/table.models.d.ts +0 -132
  196. package/lib/components/table-filter/index.d.ts +0 -1
  197. package/lib/components/textarea/index.d.ts +0 -1
  198. package/lib/components/textfield/index.d.ts +0 -1
  199. package/lib/components/unsubscribe.component.d.ts +0 -9
  200. package/lib/directives/datasource.directive.d.ts +0 -32
  201. package/lib/directives/shortcut.directive.d.ts +0 -11
  202. package/lib/directives/table-datasource.directive.d.ts +0 -29
  203. package/lib/directives/table-filter.directive.d.ts +0 -17
  204. package/lib/format/format.d.ts +0 -9
  205. package/lib/pipes/error/error.codes.d.ts +0 -5
  206. package/lib/pipes/error/error.models.d.ts +0 -8
  207. package/lib/pipes/error/error.pipe.d.ts +0 -8
  208. package/lib/pipes/error/warning.codes.d.ts +0 -5
  209. package/lib/pipes/error/warning.pipe.d.ts +0 -8
  210. package/lib/pipes/helper/enumToList.pipe.d.ts +0 -7
  211. package/lib/pipes/keyOrFn/keyOrFn.pipe.d.ts +0 -7
  212. package/lib/services/confirm-dialog.service.d.ts +0 -12
  213. package/lib/services/leave-form.service.d.ts +0 -13
  214. package/lib/services/screen-size.service.d.ts +0 -10
  215. package/lib/services/table.service.d.ts +0 -13
  216. /package/{lib/components/table/index.d.ts → src/lib/components/table/index.ts} +0 -0
@@ -0,0 +1,275 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import {
3
+ ChangeDetectorRef,
4
+ Directive,
5
+ inject,
6
+ Input,
7
+ OnChanges,
8
+ OnInit,
9
+ SimpleChanges,
10
+ } from '@angular/core';
11
+ import {
12
+ BASE_URL_PATH,
13
+ convertDatasource,
14
+ DataSourceFunctionType,
15
+ DatasourceType,
16
+ DEFAULT_SEARCH_LIMIT,
17
+ FilterEvent,
18
+ LazyLoadEvent,
19
+ normalizeRequest,
20
+ Page,
21
+ RequestParams,
22
+ } from '@verisoft/core';
23
+ import {
24
+ BehaviorSubject,
25
+ catchError,
26
+ debounceTime,
27
+ filter,
28
+ map,
29
+ of,
30
+ switchMap,
31
+ takeUntil,
32
+ tap,
33
+ } from 'rxjs';
34
+ import {
35
+ DataSourceComponentModel,
36
+ DEFAULT_DEBOUNCE_TIME,
37
+ ExtendedRequestType,
38
+ setComponentProperties,
39
+ setDataToArray,
40
+ } from '../common';
41
+ import {
42
+ DROPDOWN_COMPONENT_TOKEN,
43
+ DropdownCore,
44
+ GENERIC_FIELD_COMPONENT_TOKEN,
45
+ GenericFieldCore,
46
+ MULTISELECT_COMPONENT_TOKEN,
47
+ MultiselectCore,
48
+ UnsubscribeComponent,
49
+ } from '../components';
50
+
51
+ @Directive({
52
+ selector:
53
+ // eslint-disable-next-line @angular-eslint/directive-selector
54
+ 'v-dropdown[useDatasource], v-multiselect[useDatasource], v-generic-field[useDatasource]',
55
+ standalone: true,
56
+ })
57
+ export class DatasourceDirective<T>
58
+ extends UnsubscribeComponent
59
+ implements OnChanges, OnInit
60
+ {
61
+ @Input() datasource!: DatasourceType<T>;
62
+
63
+ @Input() autoBind = true;
64
+
65
+ @Input() loadingText = '... loading ...';
66
+
67
+ @Input() filterField: string | undefined = 'fulltext';
68
+
69
+ @Input() transformFn?: (data: T) => unknown;
70
+
71
+ @Input() extraFilter!: any;
72
+
73
+ get activeComponent(): DataSourceComponentModel<T> {
74
+ return (this.dropdownComponent ??
75
+ this.multiSelectComponent ??
76
+ this.genericField) as DataSourceComponentModel<T>;
77
+ }
78
+
79
+ private httpClient = inject(HttpClient);
80
+
81
+ private baseUrl: string = inject(BASE_URL_PATH);
82
+
83
+ private changeDetectorRef = inject(ChangeDetectorRef);
84
+
85
+ private isAllDataLoaded = false;
86
+
87
+ private parameters$ = new BehaviorSubject<Partial<ExtendedRequestType<T>>>({});
88
+
89
+ private lastParameter = {};
90
+
91
+ private dropdownComponent = inject<DropdownCore<T>>(
92
+ DROPDOWN_COMPONENT_TOKEN,
93
+ { optional: true }
94
+ );
95
+
96
+ private multiSelectComponent = inject<MultiselectCore<T>>(
97
+ MULTISELECT_COMPONENT_TOKEN,
98
+ {
99
+ optional: true,
100
+ }
101
+ );
102
+
103
+ private genericField = inject<GenericFieldCore<T>>(
104
+ GENERIC_FIELD_COMPONENT_TOKEN,
105
+ { optional: true }
106
+ );
107
+
108
+ private dataSourceService?: DataSourceFunctionType<T>;
109
+
110
+ private loadingPlaceholderItem: { [key: string]: unknown } = {};
111
+
112
+ ngOnInit(): void {
113
+ this.activeComponent.showed
114
+ .pipe(takeUntil(this.destroyed$))
115
+ .subscribe(() => {
116
+ if (
117
+ !this.autoBind &&
118
+ !this.activeComponent.options &&
119
+ !this.activeComponent.loading
120
+ ) {
121
+ this.parameters$.next({});
122
+ }
123
+ });
124
+
125
+ this.activeComponent.lazyLoad
126
+ .pipe(takeUntil(this.destroyed$))
127
+ .subscribe((value: LazyLoadEvent) => {
128
+ this.parameters$.next({ offset: value?.offset, limit: value?.limit });
129
+ });
130
+
131
+ this.activeComponent.filtered
132
+ .pipe(takeUntil(this.destroyed$))
133
+ .subscribe((value: FilterEvent) => {
134
+ const property = this.filterField ?? this.activeComponent.optionLabel;
135
+ if (property) {
136
+ this.parameters$.next({
137
+ offset: 0,
138
+ filter: {
139
+ [property]: value.filter ? value.filter : undefined,
140
+ ...(this.extraFilter ?? {})
141
+ } as Partial<T>,
142
+ useNewData: true,
143
+ });
144
+ }
145
+ });
146
+
147
+ this.parameters$
148
+ .pipe(
149
+ takeUntil(this.destroyed$),
150
+ filter(request => !this.isDataForRequestLoaded(request)),
151
+ map((request) => {
152
+ const extendedParams = normalizeRequest({ ...this.lastParameter, ...request }, DEFAULT_SEARCH_LIMIT) as ExtendedRequestType<T>;
153
+ extendedParams.useNewData = request.useNewData ?? false;
154
+ return extendedParams;
155
+ }),
156
+ tap((request) => {
157
+ this.lastParameter = request;
158
+ }),
159
+ debounceTime(DEFAULT_DEBOUNCE_TIME),
160
+ tap(() => {
161
+ this.changeComponent(this.activeComponent, {
162
+ loading: true,
163
+ });
164
+ }),
165
+ switchMap((request) =>
166
+ this.dataSourceService
167
+ ? this.dataSourceService(request as RequestParams<T>).pipe(
168
+ map((response) => ({ request, response }))
169
+ )
170
+ : of({
171
+ request,
172
+ response: {
173
+ data: [] as T[],
174
+ total: 0,
175
+ limit: request.limit,
176
+ offset: request.offset,
177
+ } as Page<T>,
178
+ })
179
+ ),
180
+ catchError((request) => {
181
+ this.changeComponent(this.activeComponent, {
182
+ loading: false,
183
+ });
184
+ return of({
185
+ request: request as ExtendedRequestType<T>,
186
+ response: {
187
+ data: [] as T[],
188
+ total: 0,
189
+ limit: request.limit,
190
+ offset: request.offset,
191
+ } as Page<T>,
192
+ });
193
+ })
194
+ )
195
+ .subscribe(({ request, response }) =>
196
+ this.setDataToControl(request, response)
197
+ );
198
+ }
199
+
200
+ ngOnChanges(changes: SimpleChanges): void {
201
+ if (changes['datasource']) {
202
+ this.dataSourceService = convertDatasource(
203
+ this.datasource,
204
+ this.baseUrl,
205
+ this.httpClient
206
+ );
207
+
208
+ if (this.autoBind) {
209
+ this.parameters$.next({ offset: 0 });
210
+ }
211
+ }
212
+ }
213
+
214
+ private isDataForRequestLoaded(request: Partial<ExtendedRequestType<T>>) {
215
+ if (request.useNewData) {
216
+ return false;
217
+ }
218
+
219
+ const offset = request.offset ?? 0;
220
+ const limit = request.limit ?? DEFAULT_SEARCH_LIMIT;
221
+ const options = this.activeComponent.options;
222
+ if (!options) {
223
+ return false;
224
+ }
225
+
226
+ if (options.length < offset + limit) {
227
+ return false;
228
+ }
229
+
230
+ const allItemsFilled = options.slice(offset, offset + limit).every(item => item !== undefined && item != this.loadingPlaceholderItem);
231
+ return allItemsFilled;
232
+ }
233
+
234
+ private setDataToControl(request: ExtendedRequestType<T>, result: Page<T>): void {
235
+ this.isAllDataLoaded = result.total <= result.data.length;
236
+ const data = result.data;
237
+ const total = result.total;
238
+ const offset = request.offset;
239
+ const transferedData = this.transformFn
240
+ ? data.map((x) => this.transformFn?.(x))
241
+ : data;
242
+
243
+ if (this.activeComponent.optionLabel) {
244
+ this.loadingPlaceholderItem[this.activeComponent.optionLabel] =
245
+ this.loadingText;
246
+ }
247
+
248
+ if (this.activeComponent.optionValue) {
249
+ this.loadingPlaceholderItem[this.activeComponent.optionValue] = -1;
250
+ }
251
+
252
+ const options = request.useNewData ? undefined : this.activeComponent.options;
253
+ const newOptions = setDataToArray(
254
+ options,
255
+ transferedData,
256
+ offset,
257
+ total,
258
+ this.loadingPlaceholderItem
259
+ );
260
+
261
+ this.changeComponent(this.activeComponent, {
262
+ options: newOptions as T[],
263
+ loading: false,
264
+ lazy: !this.isAllDataLoaded,
265
+ });
266
+ }
267
+
268
+ private changeComponent(
269
+ component: DataSourceComponentModel<T>,
270
+ value: Partial<DataSourceComponentModel<T>>
271
+ ) {
272
+ setComponentProperties(component, value);
273
+ this.changeDetectorRef.detectChanges();
274
+ }
275
+ }
@@ -1,4 +1,4 @@
1
- export * from './datasource.directive';
2
- export * from './table-datasource.directive';
3
- export * from './shortcut.directive';
4
- export * from './table-filter.directive';
1
+ export * from './datasource.directive';
2
+ export * from './table-datasource.directive';
3
+ export * from './shortcut.directive';
4
+ export * from './table-filter.directive';
@@ -0,0 +1,37 @@
1
+ import { Directive, HostListener, Input } from "@angular/core";
2
+
3
+ @Directive({
4
+ // eslint-disable-next-line @angular-eslint/directive-selector
5
+ selector: 'v-button[useShortCut]',
6
+ exportAs: 'useShortCut',
7
+ standalone: true,
8
+ })
9
+ export class ButtonShortCutDirective
10
+ {
11
+ @Input() shortCutFn?: () => void;
12
+ @Input() shortCutKey!: string;
13
+
14
+ private keyMap: { [key: string]: boolean } = {};
15
+
16
+ @HostListener('document:keydown', ['$event'])
17
+ onKeyDown(event: KeyboardEvent) {
18
+ this.keyMap[event.key.toLowerCase()] = true;
19
+ this.checkShortcut();
20
+ }
21
+
22
+ @HostListener('document:keyup', ['$event'])
23
+ onKeyUp(event: KeyboardEvent) {
24
+ this.keyMap[event.key.toLowerCase()] = false;
25
+ }
26
+
27
+ private checkShortcut() {
28
+ if (this.shortCutKey && this.shortCutFn) {
29
+ const keys = this.shortCutKey.toLowerCase().split('+');
30
+ const isShortcutPressed = keys.every((key) => this.keyMap[key]);
31
+ if (isShortcutPressed) {
32
+ this.shortCutFn?.();
33
+ keys.forEach((key) => (this.keyMap[key] = false));
34
+ }
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,184 @@
1
+ import { HttpClient } from '@angular/common/http';
2
+ import {
3
+ ChangeDetectorRef,
4
+ Directive,
5
+ inject,
6
+ Input,
7
+ OnChanges,
8
+ OnInit,
9
+ SimpleChanges,
10
+ } from '@angular/core';
11
+ import { Store } from '@ngrx/store';
12
+ import {
13
+ BASE_URL_PATH,
14
+ BaseHttpService,
15
+ convertDatasource,
16
+ DataSourceFunctionType,
17
+ DatasourceType,
18
+ LazyLoadEvent,
19
+ normalizeRequest,
20
+ Page,
21
+ RequestParams,
22
+ } from '@verisoft/core';
23
+ import {
24
+ BehaviorSubject,
25
+ catchError,
26
+ debounceTime,
27
+ map,
28
+ of,
29
+ switchMap,
30
+ takeUntil,
31
+ tap,
32
+ } from 'rxjs';
33
+ import {
34
+ DEFAULT_DEBOUNCE_TIME,
35
+ ExtendedRequestType,
36
+ isFilterEmpty,
37
+ setComponentProperties,
38
+ } from '../common';
39
+ import {
40
+ TABLE_COMPONENT_TOKEN,
41
+ TableCore,
42
+ UnsubscribeComponent,
43
+ } from '../components';
44
+
45
+ @Directive({
46
+ // eslint-disable-next-line @angular-eslint/directive-selector
47
+ selector: 'v-table[useDatasource]',
48
+ exportAs: 'useDatasource',
49
+ standalone: true,
50
+ })
51
+ export class TableDatasourceDirective<T>
52
+ extends UnsubscribeComponent
53
+ implements OnInit, OnChanges
54
+ {
55
+ protected readonly store = inject(Store);
56
+
57
+ @Input() autoBind = true;
58
+
59
+ @Input({ required: true }) tableName!: string;
60
+
61
+ @Input() debounceTime = DEFAULT_DEBOUNCE_TIME;
62
+
63
+ @Input() datasource!: DatasourceType<T>;
64
+
65
+ @Input() extraFilter!: any;
66
+
67
+ @Input() transformFn?: (data: T) => unknown;
68
+
69
+ private tableComponent = inject<TableCore<T>>(TABLE_COMPONENT_TOKEN, {
70
+ self: true,
71
+ });
72
+ private changeDetectorRef = inject(ChangeDetectorRef);
73
+ private httpClient = inject(HttpClient);
74
+ private baseUrl: string = inject(BASE_URL_PATH);
75
+
76
+ private dataSourceService?: DataSourceFunctionType<T>;
77
+ private parameters$ = new BehaviorSubject<Partial<ExtendedRequestType<T>>>({});
78
+
79
+ params$ = this.parameters$.asObservable();
80
+
81
+ ngOnInit(): void {
82
+ if (!this.tableName) {
83
+ throw new Error('Property tableName must be defined.');
84
+ }
85
+
86
+ this.tableComponent.lazyLoad.pipe(takeUntil(this.destroyed$)).subscribe((value: LazyLoadEvent) => {
87
+ this.parameters$.next({
88
+ offset: value?.offset,
89
+ limit: value?.limit,
90
+ filter: { ...value?.filter, ...this.extraFilter },
91
+ sort: value?.sort,
92
+ });
93
+ });
94
+
95
+ this.parameters$
96
+ .pipe(
97
+ takeUntil(this.destroyed$),
98
+ map((request) =>
99
+ normalizeRequest({
100
+ ...request,
101
+ filter: { ...request.filter, ...this.extraFilter },
102
+ })
103
+ ),
104
+ debounceTime(this.debounceTime),
105
+ tap(() => {
106
+ this.changeComponent(this.tableComponent, {
107
+ lazy: true,
108
+ loading: true,
109
+ });
110
+ }),
111
+ switchMap((request) =>
112
+ this.dataSourceService
113
+ ? this.dataSourceService(request).pipe(
114
+ map((response) => ({ request, response }))
115
+ )
116
+ : of({
117
+ request,
118
+ response: {
119
+ data: [] as T[],
120
+ total: 0,
121
+ limit: request.limit,
122
+ offset: request.offset,
123
+ } as Page<T>,
124
+ })
125
+ ),
126
+ catchError((request) => {
127
+ this.changeComponent(this.tableComponent, {
128
+ loading: false,
129
+ });
130
+ return of({
131
+ request: request as ExtendedRequestType<T>,
132
+ response: {
133
+ data: [] as T[],
134
+ total: 0,
135
+ limit: request.limit,
136
+ offset: request.offset,
137
+ } as Page<T>,
138
+ });
139
+ })
140
+ )
141
+ .subscribe(({ request, response }) =>
142
+ this.setDataToControl(request, response)
143
+ );
144
+ }
145
+
146
+ ngOnChanges(changes: SimpleChanges): void {
147
+ if (changes['datasource']) {
148
+ this.dataSourceService = convertDatasource(
149
+ this.datasource,
150
+ this.baseUrl,
151
+ this.httpClient
152
+ );
153
+
154
+ if (this.autoBind) {
155
+ this.parameters$.next({ offset: 0 });
156
+ }
157
+ }
158
+ }
159
+
160
+ reload() {
161
+ this.parameters$.next({ ...this.parameters$.value });
162
+ }
163
+
164
+ private changeComponent(
165
+ component: TableCore<T>,
166
+ value: Partial<TableCore<T>>
167
+ ) {
168
+ setComponentProperties(component, value);
169
+ this.changeDetectorRef.detectChanges();
170
+ }
171
+
172
+ private setDataToControl(request: RequestParams<T>, result: Page<T>): void {
173
+ const data = result.data;
174
+ const total = result.total;
175
+ const transferedData = this.transformFn ? data.map((x) => this.transformFn?.(x)) : data;
176
+
177
+ this.changeComponent(this.tableComponent, {
178
+ lazy: !isFilterEmpty(request.filter) || data?.length < total || this.datasource instanceof BaseHttpService,
179
+ data: transferedData as T[],
180
+ loading: false,
181
+ total,
182
+ });
183
+ }
184
+ }
@@ -0,0 +1,69 @@
1
+ import {
2
+ ChangeDetectorRef,
3
+ Directive,
4
+ inject,
5
+ Input,
6
+ OnChanges,
7
+ OnDestroy,
8
+ SimpleChanges,
9
+ } from '@angular/core';
10
+ import { debounceTime, Subject, Subscription } from 'rxjs';
11
+ import { DEFAULT_DEBOUNCE_TIME, setComponentProperties } from '../common';
12
+ import { FilterCore, TABLE_COMPONENT_TOKEN, TableCore } from '../components';
13
+
14
+ @Directive({
15
+ // eslint-disable-next-line @angular-eslint/directive-selector
16
+ selector: 'v-table[useFilter]',
17
+ standalone: true,
18
+ exportAs: 'tableFilterDirective',
19
+ })
20
+ export class TableFilterDirective<T> implements OnChanges, OnDestroy {
21
+ @Input({ required: true }) filterComponent!: FilterCore;
22
+
23
+ private filterChange$ = new Subject<T>();
24
+ private subscription: Subscription | undefined = undefined;
25
+
26
+ private tableComponent = inject<TableCore<T>>(TABLE_COMPONENT_TOKEN);
27
+
28
+ private changeDetectorRef = inject(ChangeDetectorRef);
29
+
30
+ ngOnChanges(changes: SimpleChanges): void {
31
+ if (changes['filterComponent']) {
32
+ this.unRegister();
33
+ this.register();
34
+ }
35
+ }
36
+
37
+ private onFilterChange(value: T): void {
38
+ if (this.tableComponent?.filter !== value) {
39
+ setComponentProperties(this.tableComponent, {
40
+ filter: value,
41
+ currentPage: 1,
42
+ });
43
+
44
+ this.changeDetectorRef.detectChanges();
45
+ }
46
+ }
47
+
48
+ ngOnDestroy(): void {
49
+ this.unRegister();
50
+ }
51
+
52
+ private unRegister() {
53
+ this.subscription?.unsubscribe();
54
+ }
55
+
56
+ private register() {
57
+ this.filterComponent.registerOnChange((value: T) => {
58
+ this.filterChange$.next(value);
59
+ });
60
+
61
+ this.subscription = this.filterChange$
62
+ .pipe(
63
+ debounceTime(
64
+ this.filterComponent.debounceTime ? 0 : DEFAULT_DEBOUNCE_TIME
65
+ )
66
+ )
67
+ .subscribe((value) => this.onFilterChange(value));
68
+ }
69
+ }
@@ -0,0 +1,74 @@
1
+ import { toCzechDateTimeString } from "@verisoft/core";
2
+
3
+ /* eslint-disable @typescript-eslint/ban-types */
4
+ export class Format {
5
+ static concatArray(value: any[], itemFormatter?: Function, delimeter = ';') {
6
+ if (!value) {
7
+ return '';
8
+ }
9
+
10
+ return value
11
+ .map(item => itemFormatter ? itemFormatter(item) : item)
12
+ .filter(item => item !== undefined && item !== null)
13
+ .join(`${delimeter} `);
14
+ }
15
+
16
+ static czechDate(value: Date | string) {
17
+ return toCzechDateTimeString(value);
18
+ }
19
+
20
+ static date(value: Date | string) {
21
+ if (!value) {
22
+ return '';
23
+ }
24
+
25
+ if (typeof value === 'string') {
26
+ value = new Date(value);
27
+ }
28
+
29
+ return value.getDate() + '. ' + (value.getMonth() + 1) + '. ' + value.getFullYear();
30
+ }
31
+
32
+ static dateAndTime(value: Date | string) {
33
+ if (!value) {
34
+ return '';
35
+ }
36
+
37
+ if (typeof value === 'string') {
38
+ value = new Date(value);
39
+ }
40
+
41
+ return ('0' + value.getDate()).slice(-2)
42
+ + '.' + ('0' + (value.getMonth() + 1)).slice(-2)
43
+ + '.' + value.getFullYear() + ' ' + ('0' + value.getHours()).slice(-2)
44
+ + ':' + ('0' + value.getMinutes()).slice(-2) + ':' + ('0' + value.getSeconds()).slice(-2);
45
+ }
46
+
47
+ static convertToUserLocaleDate(value?: Date | string) {
48
+ if (!value) {
49
+ return '';
50
+ }
51
+
52
+ if (typeof value === 'string') {
53
+ value = new Date(value);
54
+ }
55
+
56
+ return value.toLocaleDateString(navigator.language, { timeZone: 'UTC' });
57
+ }
58
+
59
+ static bool(value: boolean) {
60
+ if (value) {
61
+ return 'Yes';
62
+ } else {
63
+ return 'No';
64
+ }
65
+ }
66
+
67
+ static boolWithIcon(value: boolean) {
68
+ if (value) {
69
+ return `<span>✓</span>`;
70
+ } else {
71
+ return `<span>⨯</span>`;
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,11 @@
1
+ type ErrorCodesFn = (value?: any) => string;
2
+
3
+ export const ErrorCodesFns: { [key: string]: ErrorCodesFn } = {
4
+ required: () => `This field is required!`,
5
+ email: () => `Email is in wrong format!`,
6
+ iban: () => `IBAN is in wrong format!`,
7
+ lowStrength: () => `Password too weak!`,
8
+ customPasswordRequirements: () => `Password does not meet minimal requirements.`,
9
+ fieldsNotMatching: () => `Passwords are not the same!`,
10
+ validationError: (value: any) => `${value}`,
11
+ };
@@ -0,0 +1,27 @@
1
+ import { AbstractControl, ValidationErrors } from '@angular/forms';
2
+
3
+ type ErrorValue = { key: string; value: string } | null;
4
+
5
+ export function getFirstErrorFromControl<T extends AbstractControl>(
6
+ control: T
7
+ ): ErrorValue {
8
+ if (!control || !control.errors) {
9
+ return null;
10
+ }
11
+ const errors = control.errors ?? false;
12
+ if (errors) {
13
+ const key = Object.keys(control.errors)[0];
14
+ const value = control.errors[key];
15
+ return { key, value };
16
+ }
17
+ return null;
18
+ }
19
+
20
+ export function getFirstError(errors: ValidationErrors): ErrorValue {
21
+ if (errors) {
22
+ const key = Object.keys(errors)[0];
23
+ const value = errors[key];
24
+ return { key, value };
25
+ }
26
+ return null;
27
+ }