@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.
- package/.eslintrc.json +48 -0
- package/README.md +314 -3
- package/jest.config.ts +21 -0
- package/ng-package.json +11 -0
- package/package.json +16 -31
- package/project.json +36 -0
- package/{index.d.ts → src/index.ts} +1 -1
- package/src/lib/common/angular-helper.ts +44 -0
- package/src/lib/common/constants.ts +5 -0
- package/src/lib/common/control.models.ts +80 -0
- package/src/lib/common/datasource-component.model.spec.ts +42 -0
- package/src/lib/common/datasource-component.model.ts +43 -0
- package/{lib/common/deactivate-guard.model.d.ts → src/lib/common/deactivate-guard.model.ts} +2 -1
- package/src/lib/common/download-file.ts +20 -0
- package/src/lib/common/filter.ts +7 -0
- package/{lib/common/icons.d.ts → src/lib/common/icons.ts} +34 -34
- package/{lib/common/index.d.ts → src/lib/common/index.ts} +10 -10
- package/{lib/common/notificable-property.model.d.ts → src/lib/common/notificable-property.model.ts} +5 -4
- package/src/lib/common/rxjs.spec.ts +58 -0
- package/src/lib/common/rxjs.ts +21 -0
- package/src/lib/components/action-button-group/action-button-group.model.ts +15 -0
- package/src/lib/components/action-button-group/action-button.model.ts +15 -0
- package/{lib/components/action-button-group/index.d.ts → src/lib/components/action-button-group/index.ts} +2 -2
- package/src/lib/components/base-form/base-form-input.component.ts +120 -0
- package/src/lib/components/base-form/base-form.component.ts +236 -0
- package/src/lib/components/base-form/directives/detail-store.directive.ts +219 -0
- package/{lib/components/base-form/index.d.ts → src/lib/components/base-form/index.ts} +2 -2
- package/src/lib/components/base-form/models/base-form-input.models.ts +11 -0
- package/src/lib/components/base-form/models/base-form.models.ts +31 -0
- package/{lib/components/base-form/models/index.d.ts → src/lib/components/base-form/models/index.ts} +1 -1
- package/{lib/components/breadcrumb/breadcrumb.model.d.ts → src/lib/components/breadcrumb/breadcrumb.model.ts} +6 -1
- package/src/lib/components/breadcrumb/breadcrumb.service.ts +9 -0
- package/src/lib/components/breadcrumb/breadcrumbcore.component.ts +117 -0
- package/src/lib/components/breadcrumb/index.ts +3 -0
- package/{lib/components/button/button.model.d.ts → src/lib/components/button/button.model.ts} +5 -1
- package/src/lib/components/button/index.ts +1 -0
- package/{lib/components/calendar/calendar.model.d.ts → src/lib/components/calendar/calendar.model.ts} +6 -2
- package/src/lib/components/calendar/index.ts +1 -0
- package/{lib/components/checkbox/checkbox.model.d.ts → src/lib/components/checkbox/checkbox.model.ts} +5 -1
- package/src/lib/components/checkbox/index.ts +1 -0
- package/src/lib/components/confirm-dialog/confirm-dialog.model.ts +31 -0
- package/src/lib/components/confirm-dialog/index.ts +1 -0
- package/{lib/components/dropdown/dropdown.model.d.ts → src/lib/components/dropdown/dropdown.model.ts} +5 -1
- package/src/lib/components/dropdown/index.ts +1 -0
- package/{lib/components/dropdown-button/dropdown-button.model.d.ts → src/lib/components/dropdown-button/dropdown-button.model.ts} +18 -14
- package/src/lib/components/dropdown-button/index.ts +1 -0
- package/src/lib/components/dynamic-component/dynamic-component.model.ts +2 -0
- package/src/lib/components/dynamic-component/index.ts +1 -0
- package/src/lib/components/filter/filter.model.ts +17 -0
- package/{lib/components/filter/index.d.ts → src/lib/components/filter/index.ts} +1 -1
- package/{lib/components/form-field/form-field.model.d.ts → src/lib/components/form-field/form-field.model.ts} +6 -2
- package/src/lib/components/form-field/index.ts +1 -0
- package/{lib/components/generic-field/generic-field.model.d.ts → src/lib/components/generic-field/generic-field.model.ts} +5 -1
- package/src/lib/components/generic-field/index.ts +1 -0
- package/src/lib/components/generic-form/generic-form.component.ts +33 -0
- package/{lib/components/generic-form/index.d.ts → src/lib/components/generic-form/index.ts} +1 -1
- package/{lib/components/header/header.model.d.ts → src/lib/components/header/header.model.ts} +9 -2
- package/src/lib/components/header/index.ts +1 -0
- package/src/lib/components/icons/icons.component.ts +22 -0
- package/src/lib/components/icons/icons.model.ts +16 -0
- package/src/lib/components/icons/index.ts +2 -0
- package/{lib/components/index.d.ts → src/lib/components/index.ts} +2 -0
- package/src/lib/components/input-group/index.ts +1 -0
- package/{lib/components/input-group/input-group.model.d.ts → src/lib/components/input-group/input-group.model.ts} +7 -2
- package/src/lib/components/loader/index.ts +1 -0
- package/src/lib/components/loader/loader.model.ts +7 -0
- package/src/lib/components/multiselect/index.ts +1 -0
- package/{lib/components/multiselect/mutiselect.model.d.ts → src/lib/components/multiselect/mutiselect.model.ts} +6 -2
- package/src/lib/components/number-input/index.ts +1 -0
- package/{lib/components/number-input/number-input.model.d.ts → src/lib/components/number-input/number-input.model.ts} +6 -2
- package/{lib/components/page-header/index.d.ts → src/lib/components/page-header/index.ts} +1 -1
- package/{lib/components/page-header/page-header.model.d.ts → src/lib/components/page-header/page-header.model.ts} +5 -1
- package/src/lib/components/page-header/page-header.service.ts +9 -0
- package/src/lib/components/page-header/page-headercore.component.ts +42 -0
- package/src/lib/components/password/index.ts +1 -0
- package/{lib/components/password/password.model.d.ts → src/lib/components/password/password.model.ts} +9 -3
- package/src/lib/components/radiobutton/index.ts +1 -0
- package/{lib/components/radiobutton/radiobutton.model.d.ts → src/lib/components/radiobutton/radiobutton.model.ts} +8 -3
- package/src/lib/components/section/index.ts +1 -0
- package/{lib/components/section/section.model.d.ts → src/lib/components/section/section.model.ts} +6 -2
- package/src/lib/components/side-menu/directives/side-menu-service.directive.ts +31 -0
- package/{lib/components/side-menu/index.d.ts → src/lib/components/side-menu/index.ts} +1 -1
- package/src/lib/components/side-menu/services/side-menu-provider.service.ts +13 -0
- package/src/lib/components/side-menu/services/side-menu.service.ts +62 -0
- package/src/lib/components/side-menu/side-menu.model.ts +67 -0
- package/src/lib/components/slider/index.ts +1 -0
- package/{lib/components/slider/slider.model.d.ts → src/lib/components/slider/slider.model.ts} +6 -2
- package/src/lib/components/snackbar/index.ts +1 -0
- package/src/lib/components/snackbar/snackbar.model.ts +7 -0
- package/src/lib/components/stepper/index.ts +1 -0
- package/{lib/components/stepper/stepper.model.d.ts → src/lib/components/stepper/stepper.model.ts} +10 -5
- package/src/lib/components/switch/index.ts +1 -0
- package/src/lib/components/switch/switch.model.ts +8 -0
- package/src/lib/components/tab-view/index.ts +1 -0
- package/{lib/components/tab-view/tab-view.model.d.ts → src/lib/components/tab-view/tab-view.model.ts} +8 -3
- package/src/lib/components/table/column-configuration.ts +38 -0
- package/src/lib/components/table/table-builder.ts +93 -0
- package/src/lib/components/table/table-column.directive.ts +62 -0
- package/src/lib/components/table/table.models.ts +261 -0
- package/src/lib/components/table-filter/index.ts +1 -0
- package/{lib/components/table-filter/table-filter.model.d.ts → src/lib/components/table-filter/table-filter.model.ts} +6 -1
- package/src/lib/components/tag/index.ts +1 -0
- package/src/lib/components/tag/tag.model.ts +13 -0
- package/src/lib/components/textarea/index.ts +1 -0
- package/{lib/components/textarea/textarea.model.d.ts → src/lib/components/textarea/textarea.model.ts} +5 -1
- package/src/lib/components/textfield/index.ts +1 -0
- package/{lib/components/textfield/textfield.model.d.ts → src/lib/components/textfield/textfield.model.ts} +6 -2
- package/src/lib/components/tooltip/index.ts +1 -0
- package/src/lib/components/tooltip/tooltip.model.ts +13 -0
- package/src/lib/components/unsubscribe.component.ts +12 -0
- package/src/lib/directives/datasource.directive.ts +275 -0
- package/{lib/directives/index.d.ts → src/lib/directives/index.ts} +4 -4
- package/src/lib/directives/shortcut.directive.ts +37 -0
- package/src/lib/directives/table-datasource.directive.ts +184 -0
- package/src/lib/directives/table-filter.directive.ts +69 -0
- package/src/lib/format/format.ts +74 -0
- package/src/lib/pipes/error/error.codes.ts +11 -0
- package/src/lib/pipes/error/error.models.ts +27 -0
- package/src/lib/pipes/error/error.pipe.ts +27 -0
- package/src/lib/pipes/error/warning.codes.ts +5 -0
- package/src/lib/pipes/error/warning.pipe.ts +27 -0
- package/src/lib/pipes/helper/enumToList.pipe.ts +16 -0
- package/{lib/pipes/index.d.ts → src/lib/pipes/index.ts} +1 -1
- package/src/lib/pipes/keyOrFn/keyOrFn.pipe.ts +23 -0
- package/src/lib/services/confirm-dialog.service.ts +44 -0
- package/{lib/services/index.d.ts → src/lib/services/index.ts} +4 -4
- package/src/lib/services/leave-form.service.ts +53 -0
- package/src/lib/services/screen-size.service.ts +25 -0
- package/src/lib/services/table.service.ts +22 -0
- package/src/test-setup.ts +8 -0
- package/tsconfig.json +28 -0
- package/tsconfig.lib.json +17 -0
- package/tsconfig.lib.prod.json +9 -0
- package/tsconfig.spec.json +16 -0
- package/fesm2022/verisoft-ui-core.mjs +0 -2013
- package/fesm2022/verisoft-ui-core.mjs.map +0 -1
- package/lib/common/angular-helper.d.ts +0 -1
- package/lib/common/constants.d.ts +0 -3
- package/lib/common/control.models.d.ts +0 -62
- package/lib/common/datasource-component.model.d.ts +0 -19
- package/lib/common/download-file.d.ts +0 -2
- package/lib/common/filter.d.ts +0 -1
- package/lib/common/rxjs.d.ts +0 -2
- package/lib/components/action-button-group/action-button-group.model.d.ts +0 -12
- package/lib/components/action-button-group/action-button.model.d.ts +0 -14
- package/lib/components/base-form/base-form-input.component.d.ts +0 -30
- package/lib/components/base-form/base-form.component.d.ts +0 -50
- package/lib/components/base-form/directives/detail-store.directive.d.ts +0 -35
- package/lib/components/base-form/models/base-form-input.models.d.ts +0 -7
- package/lib/components/base-form/models/base-form.models.d.ts +0 -18
- package/lib/components/breadcrumb/breadcrumb.service.d.ts +0 -8
- package/lib/components/breadcrumb/breadcrumbcore.component.d.ts +0 -30
- package/lib/components/breadcrumb/index.d.ts +0 -3
- package/lib/components/button/index.d.ts +0 -1
- package/lib/components/calendar/index.d.ts +0 -1
- package/lib/components/checkbox/index.d.ts +0 -1
- package/lib/components/confirm-dialog/confirm-dialog.model.d.ts +0 -25
- package/lib/components/confirm-dialog/index.d.ts +0 -1
- package/lib/components/dropdown/index.d.ts +0 -1
- package/lib/components/dropdown-button/index.d.ts +0 -1
- package/lib/components/dynamic-component/dynamic-component.model.d.ts +0 -3
- package/lib/components/dynamic-component/index.d.ts +0 -1
- package/lib/components/filter/filter.model.d.ts +0 -13
- package/lib/components/form-field/index.d.ts +0 -1
- package/lib/components/generic-field/index.d.ts +0 -1
- package/lib/components/generic-form/generic-form.component.d.ts +0 -30
- package/lib/components/header/index.d.ts +0 -1
- package/lib/components/icons/icons.component.d.ts +0 -6
- package/lib/components/icons/icons.model.d.ts +0 -6
- package/lib/components/icons/index.d.ts +0 -2
- package/lib/components/input-group/index.d.ts +0 -1
- package/lib/components/loader/index.d.ts +0 -1
- package/lib/components/loader/loader.model.d.ts +0 -3
- package/lib/components/multiselect/index.d.ts +0 -1
- package/lib/components/number-input/index.d.ts +0 -1
- package/lib/components/page-header/page-header.service.d.ts +0 -8
- package/lib/components/page-header/page-headercore.component.d.ts +0 -20
- package/lib/components/password/index.d.ts +0 -1
- package/lib/components/radiobutton/index.d.ts +0 -1
- package/lib/components/section/index.d.ts +0 -1
- package/lib/components/side-menu/directives/side-menu-service.directive.d.ts +0 -11
- package/lib/components/side-menu/services/side-menu-provider.service.d.ts +0 -10
- package/lib/components/side-menu/services/side-menu.service.d.ts +0 -15
- package/lib/components/side-menu/side-menu.model.d.ts +0 -42
- package/lib/components/slider/index.d.ts +0 -1
- package/lib/components/snackbar/index.d.ts +0 -1
- package/lib/components/snackbar/snackbar.model.d.ts +0 -3
- package/lib/components/stepper/index.d.ts +0 -1
- package/lib/components/switch/index.d.ts +0 -1
- package/lib/components/switch/switch.model.d.ts +0 -4
- package/lib/components/tab-view/index.d.ts +0 -1
- package/lib/components/table/column-configuration.d.ts +0 -12
- package/lib/components/table/table-builder.d.ts +0 -15
- package/lib/components/table/table-column.directive.d.ts +0 -25
- package/lib/components/table/table.models.d.ts +0 -132
- package/lib/components/table-filter/index.d.ts +0 -1
- package/lib/components/textarea/index.d.ts +0 -1
- package/lib/components/textfield/index.d.ts +0 -1
- package/lib/components/unsubscribe.component.d.ts +0 -9
- package/lib/directives/datasource.directive.d.ts +0 -32
- package/lib/directives/shortcut.directive.d.ts +0 -11
- package/lib/directives/table-datasource.directive.d.ts +0 -29
- package/lib/directives/table-filter.directive.d.ts +0 -17
- package/lib/format/format.d.ts +0 -9
- package/lib/pipes/error/error.codes.d.ts +0 -5
- package/lib/pipes/error/error.models.d.ts +0 -8
- package/lib/pipes/error/error.pipe.d.ts +0 -8
- package/lib/pipes/error/warning.codes.d.ts +0 -5
- package/lib/pipes/error/warning.pipe.d.ts +0 -8
- package/lib/pipes/helper/enumToList.pipe.d.ts +0 -7
- package/lib/pipes/keyOrFn/keyOrFn.pipe.d.ts +0 -7
- package/lib/services/confirm-dialog.service.d.ts +0 -12
- package/lib/services/leave-form.service.d.ts +0 -13
- package/lib/services/screen-size.service.d.ts +0 -10
- package/lib/services/table.service.d.ts +0 -13
- /package/{lib/components/table/index.d.ts → src/lib/components/table/index.ts} +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EventEmitter, SimpleChanges } from '@angular/core';
|
|
2
|
+
import { FilterEvent, LazyLoadEvent, RequestParams } from '@verisoft/core';
|
|
3
|
+
|
|
4
|
+
export interface DataSourceComponentModel<TEntity> {
|
|
5
|
+
ngOnChanges?: (changes: SimpleChanges) => void;
|
|
6
|
+
lazy: boolean;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
filter: boolean;
|
|
9
|
+
options: TEntity[] | undefined;
|
|
10
|
+
optionValue: string | undefined;
|
|
11
|
+
optionLabel: string | undefined;
|
|
12
|
+
showed: EventEmitter<any>;
|
|
13
|
+
cleared: EventEmitter<any>;
|
|
14
|
+
filtered: EventEmitter<FilterEvent>;
|
|
15
|
+
lazyLoad: EventEmitter<LazyLoadEvent>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function setDataToArray<T>(
|
|
19
|
+
targetArray: (T | undefined)[] | undefined,
|
|
20
|
+
data: T[],
|
|
21
|
+
offset = 0,
|
|
22
|
+
total: number | undefined = undefined,
|
|
23
|
+
defaultItem: T | undefined = undefined
|
|
24
|
+
): (T | undefined)[] {
|
|
25
|
+
const totalItems = total ?? data.length + offset;
|
|
26
|
+
if (!targetArray) {
|
|
27
|
+
targetArray = Array(totalItems).fill(defaultItem);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (targetArray.length < totalItems) {
|
|
31
|
+
targetArray = targetArray.concat(
|
|
32
|
+
new Array(totalItems - targetArray.length).fill(defaultItem)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < data.length; i++) {
|
|
37
|
+
targetArray[i + offset] = data[i] ?? defaultItem;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return targetArray;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ExtendedRequestType<T> = RequestParams<T> & { useNewData: boolean}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function downloadText(
|
|
2
|
+
filename: string,
|
|
3
|
+
text: string,
|
|
4
|
+
mimeType: string | undefined = 'text/plain'
|
|
5
|
+
): void {
|
|
6
|
+
const blob = new Blob([text], { type: mimeType });
|
|
7
|
+
downloadFile(filename, blob);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function downloadFile(
|
|
11
|
+
filename: string,
|
|
12
|
+
blob: Blob
|
|
13
|
+
): void {
|
|
14
|
+
const url = window.URL.createObjectURL(blob);
|
|
15
|
+
const a = document.createElement('a');
|
|
16
|
+
a.href = url;
|
|
17
|
+
a.download = filename;
|
|
18
|
+
a.click();
|
|
19
|
+
window.URL.revokeObjectURL(url);
|
|
20
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
export interface CommonIcons {
|
|
2
|
-
add: string;
|
|
3
|
-
minus: string;
|
|
4
|
-
delete: string;
|
|
5
|
-
filter: string;
|
|
6
|
-
download: string;
|
|
7
|
-
save: string;
|
|
8
|
-
print: string;
|
|
9
|
-
edit: string;
|
|
10
|
-
settings: string;
|
|
11
|
-
house: string;
|
|
12
|
-
calendar: string;
|
|
13
|
-
chevronRight: string;
|
|
14
|
-
chevronLeft: string;
|
|
15
|
-
chevronDown: string;
|
|
16
|
-
chevronUp: string;
|
|
17
|
-
checkbox: string;
|
|
18
|
-
warning: string;
|
|
19
|
-
search: string;
|
|
20
|
-
action: string;
|
|
21
|
-
user: string;
|
|
22
|
-
logout: string;
|
|
23
|
-
crossCircle: string;
|
|
24
|
-
infoCircle: string;
|
|
25
|
-
cross: string;
|
|
26
|
-
arrowLeft: string;
|
|
27
|
-
arrowRight: string;
|
|
28
|
-
questionCircle: string;
|
|
29
|
-
checkCircle: string;
|
|
30
|
-
sitemap: string;
|
|
31
|
-
check: string;
|
|
32
|
-
envelope: string;
|
|
33
|
-
loader: string;
|
|
34
|
-
}
|
|
1
|
+
export interface CommonIcons {
|
|
2
|
+
add: string;
|
|
3
|
+
minus: string;
|
|
4
|
+
delete: string;
|
|
5
|
+
filter: string;
|
|
6
|
+
download: string;
|
|
7
|
+
save: string;
|
|
8
|
+
print: string;
|
|
9
|
+
edit: string;
|
|
10
|
+
settings: string;
|
|
11
|
+
house: string;
|
|
12
|
+
calendar: string;
|
|
13
|
+
chevronRight: string;
|
|
14
|
+
chevronLeft: string;
|
|
15
|
+
chevronDown: string;
|
|
16
|
+
chevronUp: string;
|
|
17
|
+
checkbox: string;
|
|
18
|
+
warning: string;
|
|
19
|
+
search: string;
|
|
20
|
+
action: string;
|
|
21
|
+
user: string;
|
|
22
|
+
logout: string;
|
|
23
|
+
crossCircle: string;
|
|
24
|
+
infoCircle: string;
|
|
25
|
+
cross: string;
|
|
26
|
+
arrowLeft: string;
|
|
27
|
+
arrowRight: string;
|
|
28
|
+
questionCircle: string;
|
|
29
|
+
checkCircle: string;
|
|
30
|
+
sitemap: string;
|
|
31
|
+
check: string;
|
|
32
|
+
envelope: string;
|
|
33
|
+
loader: string;
|
|
34
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from './angular-helper';
|
|
2
|
-
export * from './control.models';
|
|
3
|
-
export * from './constants';
|
|
4
|
-
export * from './datasource-component.model';
|
|
5
|
-
export * from './filter';
|
|
6
|
-
export * from './notificable-property.model';
|
|
7
|
-
export * from './rxjs';
|
|
8
|
-
export * from './icons';
|
|
9
|
-
export * from './download-file';
|
|
10
|
-
export * from './deactivate-guard.model'
|
|
1
|
+
export * from './angular-helper';
|
|
2
|
+
export * from './control.models';
|
|
3
|
+
export * from './constants';
|
|
4
|
+
export * from './datasource-component.model';
|
|
5
|
+
export * from './filter';
|
|
6
|
+
export * from './notificable-property.model';
|
|
7
|
+
export * from './rxjs';
|
|
8
|
+
export * from './icons';
|
|
9
|
+
export * from './download-file';
|
|
10
|
+
export * from './deactivate-guard.model'
|
package/{lib/common/notificable-property.model.d.ts → src/lib/common/notificable-property.model.ts}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
|
|
3
|
+
export interface NotificableProperty {
|
|
4
|
+
propertyChanged: Observable<unknown>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { QueryList } from '@angular/core';
|
|
2
|
+
import { skip, Subject } from 'rxjs';
|
|
3
|
+
import { NotificableProperty } from './notificable-property.model';
|
|
4
|
+
import { queryListChanged } from './rxjs';
|
|
5
|
+
|
|
6
|
+
describe('queryListChanged', () => {
|
|
7
|
+
let queryList: QueryList<NotificableProperty>;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
queryList = new QueryList<NotificableProperty>();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should emit initial value', (done) => {
|
|
14
|
+
queryListChanged(queryList).subscribe((result) => {
|
|
15
|
+
expect(result).toEqual([]);
|
|
16
|
+
done();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should emit when propertyChanged emits', (done) => {
|
|
21
|
+
const propertyChanged = new Subject<void>();
|
|
22
|
+
const item = { propertyChanged } as NotificableProperty;
|
|
23
|
+
queryList.reset([item]);
|
|
24
|
+
queryList.notifyOnChanges();
|
|
25
|
+
|
|
26
|
+
queryListChanged(queryList)
|
|
27
|
+
.pipe(skip(1))
|
|
28
|
+
.subscribe((result) => {
|
|
29
|
+
expect(result).toEqual([item]);
|
|
30
|
+
done();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
propertyChanged.next();
|
|
35
|
+
}, 60);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should debounce emissions', (done) => {
|
|
39
|
+
const propertyChanged = new Subject<void>();
|
|
40
|
+
const item = { propertyChanged } as NotificableProperty;
|
|
41
|
+
queryList.reset([item]);
|
|
42
|
+
queryList.notifyOnChanges();
|
|
43
|
+
|
|
44
|
+
const emittedValues: NotificableProperty[][] = [];
|
|
45
|
+
queryListChanged(queryList).subscribe((result) => {
|
|
46
|
+
emittedValues.push(result);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
propertyChanged.next();
|
|
50
|
+
propertyChanged.next();
|
|
51
|
+
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
expect(emittedValues.length).toBe(1);
|
|
54
|
+
expect(emittedValues[0]).toEqual([item]);
|
|
55
|
+
done();
|
|
56
|
+
}, 100);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { QueryList } from '@angular/core';
|
|
2
|
+
import { debounceTime, map, merge, startWith, switchMap } from 'rxjs';
|
|
3
|
+
import { NotificableProperty } from './notificable-property.model';
|
|
4
|
+
|
|
5
|
+
export function queryListChanged<TEntity>(list: QueryList<TEntity>) {
|
|
6
|
+
return list.changes.pipe(
|
|
7
|
+
startWith({}),
|
|
8
|
+
switchMap(() => {
|
|
9
|
+
const actionPropertyChanges$ = list
|
|
10
|
+
.toArray()
|
|
11
|
+
.filter((action) => (<NotificableProperty>action).propertyChanged)
|
|
12
|
+
.map((action) => (<NotificableProperty>action).propertyChanged);
|
|
13
|
+
|
|
14
|
+
return merge(...actionPropertyChanges$).pipe(
|
|
15
|
+
startWith({}),
|
|
16
|
+
map(() => list.toArray())
|
|
17
|
+
);
|
|
18
|
+
}),
|
|
19
|
+
debounceTime(50)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { IconPositionType } from '../../common';
|
|
3
|
+
import { ActionButton } from './action-button.model';
|
|
4
|
+
|
|
5
|
+
export const ACTION_BUTTON_GROUP_COMPONENT_TOKEN =
|
|
6
|
+
new InjectionToken<ActionButtonGroupCore>('ActionButtonGroupComponentToken');
|
|
7
|
+
|
|
8
|
+
export interface ActionButtonGroupCore {
|
|
9
|
+
maxItems: number;
|
|
10
|
+
maxItemsMobile: number;
|
|
11
|
+
items: ActionButton[];
|
|
12
|
+
menuIconPos: IconPositionType;
|
|
13
|
+
menuIcon: string;
|
|
14
|
+
label?: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EventEmitter } from '@angular/core';
|
|
2
|
+
import { ControlSeverityType, FieldSizeType, NotificableProperty } from '../../common';
|
|
3
|
+
|
|
4
|
+
export interface ActionButton extends NotificableProperty {
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
toolTip?: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
icon?: string;
|
|
9
|
+
outlined: boolean;
|
|
10
|
+
raised: boolean;
|
|
11
|
+
severity?: ControlSeverityType;
|
|
12
|
+
label?: string;
|
|
13
|
+
size?: FieldSizeType;
|
|
14
|
+
click: EventEmitter<MouseEvent>;
|
|
15
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './action-button-group.model';
|
|
2
|
-
export * from './action-button.model';
|
|
1
|
+
export * from './action-button-group.model';
|
|
2
|
+
export * from './action-button.model';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
|
|
2
|
+
import { Component, inject, Input, OnInit } from '@angular/core';
|
|
3
|
+
import {
|
|
4
|
+
AbstractControl,
|
|
5
|
+
ControlValueAccessor,
|
|
6
|
+
FormControl,
|
|
7
|
+
FormControlDirective,
|
|
8
|
+
FormControlName,
|
|
9
|
+
FormGroupDirective,
|
|
10
|
+
NgControl,
|
|
11
|
+
NgModel,
|
|
12
|
+
ReactiveFormsModule,
|
|
13
|
+
} from '@angular/forms';
|
|
14
|
+
import { ERROR_PROVIDER_TOKEN } from '@verisoft/core';
|
|
15
|
+
import { BaseInputControls } from './models/base-form-input.models';
|
|
16
|
+
|
|
17
|
+
const noop = () => {
|
|
18
|
+
/* */
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
@Component({
|
|
22
|
+
template: '',
|
|
23
|
+
imports: [ReactiveFormsModule]
|
|
24
|
+
})
|
|
25
|
+
export class BaseFormInputComponent
|
|
26
|
+
implements BaseInputControls<any>, ControlValueAccessor, OnInit
|
|
27
|
+
{
|
|
28
|
+
readonly ngControl?: NgControl;
|
|
29
|
+
|
|
30
|
+
readonly errorService = inject(ERROR_PROVIDER_TOKEN);
|
|
31
|
+
|
|
32
|
+
formControl!: FormControl;
|
|
33
|
+
|
|
34
|
+
constructor(private readonly control: NgControl) {
|
|
35
|
+
this.ngControl = control;
|
|
36
|
+
if (this.control) {
|
|
37
|
+
this.ngControl.valueAccessor = this;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Input()
|
|
42
|
+
label?: string;
|
|
43
|
+
|
|
44
|
+
@Input()
|
|
45
|
+
required = false;
|
|
46
|
+
|
|
47
|
+
@Input()
|
|
48
|
+
readonly!: boolean;
|
|
49
|
+
|
|
50
|
+
@Input()
|
|
51
|
+
disabled!: boolean;
|
|
52
|
+
|
|
53
|
+
@Input()
|
|
54
|
+
tooltip!: string;
|
|
55
|
+
|
|
56
|
+
@Input()
|
|
57
|
+
formDisplay: 'flex' | 'block' = 'flex';
|
|
58
|
+
|
|
59
|
+
@Input()
|
|
60
|
+
clearable = true;
|
|
61
|
+
|
|
62
|
+
@Input()
|
|
63
|
+
placeholder?: string = '';
|
|
64
|
+
|
|
65
|
+
@Input()
|
|
66
|
+
testId?: string;
|
|
67
|
+
|
|
68
|
+
inputId = Math.random().toString(36).substring(2);
|
|
69
|
+
|
|
70
|
+
selectionChanged: any = noop;
|
|
71
|
+
|
|
72
|
+
onTouch: any = noop;
|
|
73
|
+
|
|
74
|
+
registerOnChange(fn: any): void {
|
|
75
|
+
this.selectionChanged = fn;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
registerOnTouched(fn: any): void {
|
|
79
|
+
this.onTouch = fn;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
83
|
+
writeValue(value: any): void {}
|
|
84
|
+
|
|
85
|
+
ngOnInit(): void {
|
|
86
|
+
if (this.ngControl) {
|
|
87
|
+
if (this.ngControl instanceof FormControlName) {
|
|
88
|
+
this.formControl =
|
|
89
|
+
this.ngControl.control ||
|
|
90
|
+
((this.ngControl.formDirective as FormGroupDirective)?.form.controls[
|
|
91
|
+
this.ngControl.name as string
|
|
92
|
+
] as FormControl);
|
|
93
|
+
} else if (
|
|
94
|
+
this.ngControl instanceof FormControlDirective ||
|
|
95
|
+
this.ngControl instanceof NgModel
|
|
96
|
+
) {
|
|
97
|
+
this.formControl = this.ngControl.control;
|
|
98
|
+
if (this.ngControl instanceof NgModel) {
|
|
99
|
+
this.formControl.valueChanges.subscribe(() =>
|
|
100
|
+
this.ngControl?.viewToModelUpdate(this.control?.value)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
this.formControl = new FormControl();
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
this.formControl = new FormControl();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
isRequired() {
|
|
112
|
+
if (this.ngControl) {
|
|
113
|
+
const validator = this.ngControl?.control?.validator?.(
|
|
114
|
+
{} as AbstractControl
|
|
115
|
+
);
|
|
116
|
+
return this.required || (validator && validator['required']);
|
|
117
|
+
}
|
|
118
|
+
return this.required;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AfterViewInit,
|
|
3
|
+
ChangeDetectorRef,
|
|
4
|
+
Directive,
|
|
5
|
+
EventEmitter,
|
|
6
|
+
HostListener,
|
|
7
|
+
inject,
|
|
8
|
+
Input,
|
|
9
|
+
OnChanges,
|
|
10
|
+
OnDestroy,
|
|
11
|
+
OnInit,
|
|
12
|
+
Output,
|
|
13
|
+
SimpleChanges,
|
|
14
|
+
ViewChild,
|
|
15
|
+
} from '@angular/core';
|
|
16
|
+
import { FormGroup } from '@angular/forms';
|
|
17
|
+
import { cloneDeep } from 'lodash-es';
|
|
18
|
+
import { Subject, takeUntil, filter, map, Observable } from 'rxjs';
|
|
19
|
+
import { PreventUnsavedChangesCore } from '../../common';
|
|
20
|
+
import { PreventUnsavedChangesDirective } from '../../services';
|
|
21
|
+
import { FormState, isFormStateEqual } from './models';
|
|
22
|
+
@Directive({
|
|
23
|
+
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
24
|
+
selector: '[v-baseForm]',
|
|
25
|
+
standalone: true,
|
|
26
|
+
})
|
|
27
|
+
export abstract class BaseFormDirective<T extends object>
|
|
28
|
+
implements OnInit, OnChanges, OnDestroy, AfterViewInit, PreventUnsavedChangesCore
|
|
29
|
+
{
|
|
30
|
+
@Input() data!: T | any;
|
|
31
|
+
@Output() dataChange = new EventEmitter<T>();
|
|
32
|
+
@Output() statusChange = new EventEmitter<FormState>();
|
|
33
|
+
@Output() formSubmit = new EventEmitter<T>();
|
|
34
|
+
@Output() formClear = new EventEmitter<void>();
|
|
35
|
+
|
|
36
|
+
formDestroyed$ = new Subject<void>();
|
|
37
|
+
keys: { key: string; alias?: string; type?: string; readOnly: string }[] = [];
|
|
38
|
+
formGroup!: FormGroup;
|
|
39
|
+
cd = inject(ChangeDetectorRef);
|
|
40
|
+
valueInitialization = false;
|
|
41
|
+
lastState!: FormState;
|
|
42
|
+
guardViewChild!: ViewChild;
|
|
43
|
+
formSubmitted = false;
|
|
44
|
+
protected guard = inject(PreventUnsavedChangesDirective);
|
|
45
|
+
|
|
46
|
+
@HostListener('window:beforeunload', ['$event'])
|
|
47
|
+
unloadHandler(event: BeforeUnloadEvent) {
|
|
48
|
+
if (this.formGroup.dirty) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
canDeactivate(): Observable<boolean> | Promise<boolean> | boolean {
|
|
54
|
+
if (this.formGroup.dirty && !this.formSubmitted) {
|
|
55
|
+
const result = this.guard.showConfirmationDialog();
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ngOnInit(): void {
|
|
63
|
+
this.initializeFormGroup();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ngOnChanges(changes: SimpleChanges): void {
|
|
67
|
+
if (changes['data'] && this.formGroup) {
|
|
68
|
+
this.valueInitialization = true;
|
|
69
|
+
const dirty = this.formGroup.dirty;
|
|
70
|
+
|
|
71
|
+
this.formGroup.patchValue(this.fromModel(this.data), {
|
|
72
|
+
emitEvent: false,
|
|
73
|
+
onlySelf: true,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
this.formGroup.updateValueAndValidity();
|
|
77
|
+
if (!dirty) {
|
|
78
|
+
this.formGroup.markAsPristine();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.valueInitialization = false;
|
|
82
|
+
this.createAndEmitIfFormStateChanged();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
ngAfterViewInit() {
|
|
87
|
+
this.cd.detectChanges();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
ngOnDestroy(): void {
|
|
91
|
+
this.formDestroyed$.next();
|
|
92
|
+
this.formDestroyed$.complete();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
abstract createFormGroup(): FormGroup;
|
|
96
|
+
|
|
97
|
+
createCompleteData() {
|
|
98
|
+
const change = this.toModel(this.formGroup?.value);
|
|
99
|
+
this.recursiveObjectAttributesTransformation(change);
|
|
100
|
+
const updatedData = this.applyChanges(
|
|
101
|
+
cloneDeep(this.data),
|
|
102
|
+
cloneDeep(change)
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return updatedData;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
submit() {
|
|
109
|
+
this.formSubmitted = true;
|
|
110
|
+
this.formGroup.markAllAsTouched();
|
|
111
|
+
if (!this.formGroup.invalid) {
|
|
112
|
+
this.formSubmit.emit(this.createCompleteData());
|
|
113
|
+
}
|
|
114
|
+
this.formGroup.markAsPristine();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
clear() {
|
|
118
|
+
this.formClear.emit();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private initializeFormGroup() {
|
|
122
|
+
this.formGroup = this.createFormGroup();
|
|
123
|
+
this.valueInitialization = true;
|
|
124
|
+
this.formGroup.patchValue(this.fromModel(this.data), {
|
|
125
|
+
emitEvent: false,
|
|
126
|
+
onlySelf: true,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
this.formGroup.markAsPristine();
|
|
130
|
+
this.initValueChanges();
|
|
131
|
+
this.initStatusChanges();
|
|
132
|
+
this.valueInitialization = false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private initValueChanges() {
|
|
136
|
+
this.formGroup.valueChanges
|
|
137
|
+
.pipe(
|
|
138
|
+
takeUntil(this.formDestroyed$),
|
|
139
|
+
filter(() => !this.valueInitialization),
|
|
140
|
+
map((value) => {
|
|
141
|
+
const change = this.toModel(value);
|
|
142
|
+
this.recursiveObjectAttributesTransformation(change);
|
|
143
|
+
const updatedData = this.applyChanges(
|
|
144
|
+
cloneDeep(this.data),
|
|
145
|
+
cloneDeep(change)
|
|
146
|
+
);
|
|
147
|
+
return updatedData;
|
|
148
|
+
})
|
|
149
|
+
)
|
|
150
|
+
.subscribe((updatedData) => {
|
|
151
|
+
this.dataChange.emit(updatedData);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private initStatusChanges() {
|
|
156
|
+
this.formGroup.statusChanges
|
|
157
|
+
.pipe(takeUntil(this.formDestroyed$))
|
|
158
|
+
.subscribe(() => {
|
|
159
|
+
if (!this.valueInitialization) {
|
|
160
|
+
this.createAndEmitIfFormStateChanged();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
this.createAndEmitIfFormStateChanged();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private createAndEmitIfFormStateChanged() {
|
|
168
|
+
const formState: FormState = {
|
|
169
|
+
valid: !this.formGroup.invalid,
|
|
170
|
+
dirty: this.formGroup.dirty,
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
if (!isFormStateEqual(formState, this.lastState)) {
|
|
174
|
+
this.lastState = formState;
|
|
175
|
+
this.statusChange.emit(formState);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
protected applyChanges(data: T, changes: Partial<T>): T {
|
|
180
|
+
return Object.assign(data || ({} as T), changes);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
protected toModel(data: T): Partial<T> {
|
|
184
|
+
return data || {};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
protected fromModel(data: T): T {
|
|
188
|
+
return { ...(data || {}) } as T;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private recursiveObjectAttributesTransformation(obj: any): void {
|
|
192
|
+
this.recursiveObjectAttributesTraversal(
|
|
193
|
+
obj,
|
|
194
|
+
this.transformEmptyStringToNullStringFn
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private recursiveObjectAttributesTraversal(
|
|
199
|
+
obj: any,
|
|
200
|
+
transformationFn: (obj: any, key: string) => void
|
|
201
|
+
) {
|
|
202
|
+
if (
|
|
203
|
+
obj === null ||
|
|
204
|
+
transformationFn === null ||
|
|
205
|
+
typeof transformationFn !== 'function'
|
|
206
|
+
) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const traverse = (obj: any) => {
|
|
211
|
+
for (const key in obj) {
|
|
212
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
213
|
+
if (obj.hasOwnProperty(key)) {
|
|
214
|
+
transformationFn(obj, key);
|
|
215
|
+
|
|
216
|
+
if (typeof obj[key] === 'object') {
|
|
217
|
+
traverse(obj[key]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
traverse(obj);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private transformEmptyStringToNullStringFn(obj: any, key: string) {
|
|
227
|
+
// if empty string - transformation to null string
|
|
228
|
+
if (typeof obj[key] === 'string' && obj[key] === '') {
|
|
229
|
+
try {
|
|
230
|
+
obj[key] = null;
|
|
231
|
+
} catch (error) {
|
|
232
|
+
console.error(`Cannot modify ${key}: ${error}`)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|