@verisoft/ui-core 20.1.0 → 20.1.2

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 (137) hide show
  1. package/fesm2022/verisoft-ui-core.mjs +2026 -0
  2. package/fesm2022/verisoft-ui-core.mjs.map +1 -0
  3. package/index.d.ts +1126 -0
  4. package/package.json +18 -6
  5. package/.eslintrc.json +0 -48
  6. package/jest.config.ts +0 -21
  7. package/ng-package.json +0 -11
  8. package/project.json +0 -36
  9. package/src/index.ts +0 -6
  10. package/src/lib/common/angular-helper.ts +0 -44
  11. package/src/lib/common/constants.ts +0 -5
  12. package/src/lib/common/control.models.ts +0 -80
  13. package/src/lib/common/datasource-component.model.spec.ts +0 -42
  14. package/src/lib/common/datasource-component.model.ts +0 -43
  15. package/src/lib/common/deactivate-guard.model.ts +0 -5
  16. package/src/lib/common/download-file.ts +0 -20
  17. package/src/lib/common/filter.ts +0 -7
  18. package/src/lib/common/icons.ts +0 -34
  19. package/src/lib/common/index.ts +0 -10
  20. package/src/lib/common/notificable-property.model.ts +0 -5
  21. package/src/lib/common/rxjs.spec.ts +0 -58
  22. package/src/lib/common/rxjs.ts +0 -21
  23. package/src/lib/components/action-button-group/action-button-group.model.ts +0 -15
  24. package/src/lib/components/action-button-group/action-button.model.ts +0 -15
  25. package/src/lib/components/action-button-group/index.ts +0 -2
  26. package/src/lib/components/base-form/base-form-input.component.ts +0 -120
  27. package/src/lib/components/base-form/base-form.component.ts +0 -236
  28. package/src/lib/components/base-form/directives/detail-store.directive.ts +0 -219
  29. package/src/lib/components/base-form/index.ts +0 -4
  30. package/src/lib/components/base-form/models/base-form-input.models.ts +0 -11
  31. package/src/lib/components/base-form/models/base-form.models.ts +0 -31
  32. package/src/lib/components/base-form/models/index.ts +0 -2
  33. package/src/lib/components/breadcrumb/breadcrumb.model.ts +0 -21
  34. package/src/lib/components/breadcrumb/breadcrumb.service.ts +0 -9
  35. package/src/lib/components/breadcrumb/breadcrumbcore.component.ts +0 -117
  36. package/src/lib/components/breadcrumb/index.ts +0 -3
  37. package/src/lib/components/button/button.model.ts +0 -21
  38. package/src/lib/components/button/index.ts +0 -1
  39. package/src/lib/components/calendar/calendar.model.ts +0 -16
  40. package/src/lib/components/calendar/index.ts +0 -1
  41. package/src/lib/components/checkbox/checkbox.model.ts +0 -10
  42. package/src/lib/components/checkbox/index.ts +0 -1
  43. package/src/lib/components/confirm-dialog/confirm-dialog.model.ts +0 -31
  44. package/src/lib/components/confirm-dialog/index.ts +0 -1
  45. package/src/lib/components/dropdown/dropdown.model.ts +0 -16
  46. package/src/lib/components/dropdown/index.ts +0 -1
  47. package/src/lib/components/dropdown-button/dropdown-button.model.ts +0 -18
  48. package/src/lib/components/dropdown-button/index.ts +0 -1
  49. package/src/lib/components/dynamic-component/dynamic-component.model.ts +0 -2
  50. package/src/lib/components/dynamic-component/index.ts +0 -1
  51. package/src/lib/components/filter/filter.model.ts +0 -17
  52. package/src/lib/components/filter/index.ts +0 -1
  53. package/src/lib/components/form-field/form-field.model.ts +0 -15
  54. package/src/lib/components/form-field/index.ts +0 -1
  55. package/src/lib/components/generic-field/generic-field.model.ts +0 -10
  56. package/src/lib/components/generic-field/index.ts +0 -1
  57. package/src/lib/components/generic-form/generic-form.component.ts +0 -33
  58. package/src/lib/components/generic-form/index.ts +0 -1
  59. package/src/lib/components/header/header.model.ts +0 -18
  60. package/src/lib/components/header/index.ts +0 -1
  61. package/src/lib/components/icons/icons.component.ts +0 -22
  62. package/src/lib/components/icons/icons.model.ts +0 -16
  63. package/src/lib/components/icons/index.ts +0 -2
  64. package/src/lib/components/index.ts +0 -37
  65. package/src/lib/components/input-group/index.ts +0 -1
  66. package/src/lib/components/input-group/input-group.model.ts +0 -17
  67. package/src/lib/components/loader/index.ts +0 -1
  68. package/src/lib/components/loader/loader.model.ts +0 -7
  69. package/src/lib/components/multiselect/index.ts +0 -1
  70. package/src/lib/components/multiselect/mutiselect.model.ts +0 -13
  71. package/src/lib/components/number-input/index.ts +0 -1
  72. package/src/lib/components/number-input/number-input.model.ts +0 -14
  73. package/src/lib/components/page-header/index.ts +0 -3
  74. package/src/lib/components/page-header/page-header.model.ts +0 -11
  75. package/src/lib/components/page-header/page-header.service.ts +0 -9
  76. package/src/lib/components/page-header/page-headercore.component.ts +0 -42
  77. package/src/lib/components/password/index.ts +0 -1
  78. package/src/lib/components/password/password.model.ts +0 -25
  79. package/src/lib/components/radiobutton/index.ts +0 -1
  80. package/src/lib/components/radiobutton/radiobutton.model.ts +0 -16
  81. package/src/lib/components/section/index.ts +0 -1
  82. package/src/lib/components/section/section.model.ts +0 -11
  83. package/src/lib/components/side-menu/directives/side-menu-service.directive.ts +0 -31
  84. package/src/lib/components/side-menu/index.ts +0 -4
  85. package/src/lib/components/side-menu/services/side-menu-provider.service.ts +0 -13
  86. package/src/lib/components/side-menu/services/side-menu.service.ts +0 -62
  87. package/src/lib/components/side-menu/side-menu.model.ts +0 -67
  88. package/src/lib/components/slider/index.ts +0 -1
  89. package/src/lib/components/slider/slider.model.ts +0 -13
  90. package/src/lib/components/snackbar/index.ts +0 -1
  91. package/src/lib/components/snackbar/snackbar.model.ts +0 -7
  92. package/src/lib/components/stepper/index.ts +0 -1
  93. package/src/lib/components/stepper/stepper.model.ts +0 -24
  94. package/src/lib/components/switch/index.ts +0 -1
  95. package/src/lib/components/switch/switch.model.ts +0 -8
  96. package/src/lib/components/tab-view/index.ts +0 -1
  97. package/src/lib/components/tab-view/tab-view.model.ts +0 -22
  98. package/src/lib/components/table/column-configuration.ts +0 -38
  99. package/src/lib/components/table/index.ts +0 -4
  100. package/src/lib/components/table/table-builder.ts +0 -93
  101. package/src/lib/components/table/table-column.directive.ts +0 -62
  102. package/src/lib/components/table/table.models.ts +0 -261
  103. package/src/lib/components/table-filter/index.ts +0 -1
  104. package/src/lib/components/table-filter/table-filter.model.ts +0 -22
  105. package/src/lib/components/tag/index.ts +0 -1
  106. package/src/lib/components/tag/tag.model.ts +0 -13
  107. package/src/lib/components/textarea/index.ts +0 -1
  108. package/src/lib/components/textarea/textarea.model.ts +0 -13
  109. package/src/lib/components/textfield/index.ts +0 -1
  110. package/src/lib/components/textfield/textfield.model.ts +0 -13
  111. package/src/lib/components/tooltip/index.ts +0 -1
  112. package/src/lib/components/tooltip/tooltip.model.ts +0 -13
  113. package/src/lib/components/unsubscribe.component.ts +0 -12
  114. package/src/lib/directives/datasource.directive.ts +0 -275
  115. package/src/lib/directives/index.ts +0 -4
  116. package/src/lib/directives/shortcut.directive.ts +0 -37
  117. package/src/lib/directives/table-datasource.directive.ts +0 -184
  118. package/src/lib/directives/table-filter.directive.ts +0 -69
  119. package/src/lib/format/format.ts +0 -74
  120. package/src/lib/pipes/error/error.codes.ts +0 -11
  121. package/src/lib/pipes/error/error.models.ts +0 -27
  122. package/src/lib/pipes/error/error.pipe.ts +0 -27
  123. package/src/lib/pipes/error/warning.codes.ts +0 -5
  124. package/src/lib/pipes/error/warning.pipe.ts +0 -27
  125. package/src/lib/pipes/helper/enumToList.pipe.ts +0 -16
  126. package/src/lib/pipes/index.ts +0 -7
  127. package/src/lib/pipes/keyOrFn/keyOrFn.pipe.ts +0 -23
  128. package/src/lib/services/confirm-dialog.service.ts +0 -44
  129. package/src/lib/services/index.ts +0 -4
  130. package/src/lib/services/leave-form.service.ts +0 -53
  131. package/src/lib/services/screen-size.service.ts +0 -25
  132. package/src/lib/services/table.service.ts +0 -22
  133. package/src/test-setup.ts +0 -8
  134. package/tsconfig.json +0 -28
  135. package/tsconfig.lib.json +0 -17
  136. package/tsconfig.lib.prod.json +0 -9
  137. package/tsconfig.spec.json +0 -16
@@ -1,120 +0,0 @@
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
- }
@@ -1,236 +0,0 @@
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
- }
@@ -1,219 +0,0 @@
1
- import {
2
- Directive,
3
- AfterViewInit,
4
- inject,
5
- Input,
6
- OnInit,
7
- ChangeDetectorRef,
8
- OnDestroy,
9
- } from '@angular/core';
10
- import { ActivatedRoute } from '@angular/router';
11
- import { createFeatureSelector, createSelector, Store } from '@ngrx/store';
12
- import {
13
- BackendValidationError,
14
- createInitDetailAction,
15
- createInitNewDetailAction,
16
- createResetStateAction,
17
- createUpdateDetailAction,
18
- createUpdateDetailSetErrorsAction,
19
- createUpdateFormStateAction,
20
- DetailState,
21
- } from '@verisoft/store';
22
- import { takeUntil } from 'rxjs';
23
- import { UnsubscribeComponent } from '../../unsubscribe.component';
24
- import { BaseFormDirective } from '../base-form.component';
25
-
26
- @Directive({
27
- // eslint-disable-next-line @angular-eslint/directive-selector
28
- selector: '[v-useDetailStore]',
29
- exportAs: 'useDetailStore',
30
- standalone: true,
31
- })
32
- export class DetailStoreDirective
33
- extends UnsubscribeComponent
34
- implements OnInit, AfterViewInit, OnDestroy
35
- {
36
- @Input({ required: true }) form!: BaseFormDirective<any>;
37
-
38
- @Input({ required: true }) detailsRepository!: string;
39
-
40
- @Input() autoBind = true;
41
-
42
- @Input() detailId!: string | number | undefined;
43
-
44
- @Input({ required: true }) ngrxFeatureKey!: string;
45
-
46
- @Input() destroyForm = true;
47
-
48
- @Input() readonly = false;
49
-
50
- @Input() readonlyControlNames: string[] = [];
51
-
52
- store = inject(Store);
53
- cdr = inject(ChangeDetectorRef);
54
- route = inject(ActivatedRoute);
55
-
56
- private itemCache: any = null;
57
- private loaded!: boolean;
58
-
59
- ngOnInit(): void {
60
- if (!this.loaded) {
61
- this.listenFormState();
62
- }
63
- this.listenFormChange();
64
- this.listenFormStatusChange();
65
- }
66
-
67
- ngAfterViewInit(): void {
68
- if (this.autoBind && !this.loaded) {
69
- this.initForm();
70
- }
71
- }
72
-
73
- override ngOnDestroy(): void {
74
- super.ngOnDestroy();
75
- if (this.destroyForm) {
76
- this.store.dispatch(createResetStateAction(this.detailsRepository)());
77
- }
78
- }
79
-
80
- private initForm() {
81
- if (this.detailId === 'create') {
82
- this.store.dispatch(createInitNewDetailAction(this.detailsRepository)());
83
- } else {
84
- this.store.dispatch(
85
- createInitDetailAction(this.detailsRepository)({ obj: this.detailId })
86
- );
87
- }
88
-
89
- if (this.readonly) {
90
- this.form.formGroup.disable();
91
- return;
92
- }
93
-
94
- this.readonlyControlNames.forEach(x => {
95
- this.form.formGroup.get(x)?.disable();
96
- });
97
- }
98
-
99
- private listenFormState() {
100
- const selectIncomeData = createSelector(
101
- createFeatureSelector<any>(this.ngrxFeatureKey),
102
- (state: any) => state?.[this.detailsRepository] as DetailState<any>
103
- );
104
- this.store
105
- .select(selectIncomeData)
106
- .pipe(takeUntil(this.destroyed$))
107
- .subscribe(
108
- (
109
- { item, loaded, backendValidationErrors } = {
110
- item: undefined,
111
- loaded: false,
112
- saveItemState: { saveInProgress: false },
113
- backendValidationErrors: []
114
- }
115
- ) => {
116
- if (item
117
- && ((item.validationErrors || item.validationWarnings) && !this.form.formGroup.dirty)
118
- || backendValidationErrors.length
119
- ) {
120
- this.handleValidation(
121
- 'propertyName',
122
- item.validationWarnings || [],
123
- 'validationWarning',
124
- 'warningMessage'
125
- );
126
- this.handleValidation(
127
- 'propertyName',
128
- item.validationErrors || [],
129
- 'validationError',
130
- 'errorMessage'
131
- );
132
-
133
- if (this.itemCache && this.isStateChanged(item) && backendValidationErrors.length) {
134
- backendValidationErrors = this.dispatchErrors(item, backendValidationErrors);
135
- }
136
-
137
- this.handleBackendValidation(backendValidationErrors);
138
- this.cdr.markForCheck();
139
- }
140
-
141
- this.itemCache = item;
142
-
143
- this.loaded = loaded;
144
- this.cdr.detectChanges();
145
- }
146
- );
147
- }
148
-
149
- private listenFormChange() {
150
- this.form.dataChange.pipe(takeUntil(this.destroyed$)).subscribe((item) => {
151
- this.store.dispatch(
152
- createUpdateDetailAction(this.detailsRepository)({ item })
153
- );
154
- });
155
- }
156
-
157
- private listenFormStatusChange() {
158
- this.form.statusChange
159
- .pipe(takeUntil(this.destroyed$))
160
- .subscribe((formState) => {
161
- this.store.dispatch(
162
- createUpdateFormStateAction(this.detailsRepository)({ formState })
163
- );
164
- });
165
- }
166
-
167
- private handleValidation = (
168
- controlName: string,
169
- errors: any[],
170
- errorKey: string,
171
- messageKey: string
172
- ) => {
173
- if (errors.length > 0) return;
174
- errors.forEach((error: any) => {
175
- const control = this.form.formGroup.get(error[controlName]);
176
- if (control) {
177
- control.disabled
178
- ? control.disable({ emitEvent: false, onlySelf: true })
179
- : control.enable({ emitEvent: false, onlySelf: true });
180
- control.setErrors(
181
- { [errorKey]: error[messageKey] },
182
- { emitEvent: true }
183
- );
184
- control.markAsDirty();
185
- }
186
- });
187
- };
188
-
189
- private handleBackendValidation(errors: BackendValidationError[]) {
190
- errors.forEach(({ parameters, code }: BackendValidationError) => {
191
- const control = this.form.formGroup.get(this.normalizePropertyNames(parameters));
192
- if (!control) return;
193
-
194
- control[control.disabled ? "disable" : "enable"]({ emitEvent: false, onlySelf: true });
195
- control.setErrors({ "validationError": code }, { emitEvent: true });
196
- control.markAsDirty();
197
- });
198
- }
199
-
200
- private dispatchErrors(item: any, errors: BackendValidationError[]): BackendValidationError[] {
201
- const error = errors.filter((e: BackendValidationError) => {
202
- return this.itemCache[this.normalizePropertyNames(e.parameters)] === item[this.normalizePropertyNames(e.parameters)];
203
- });
204
-
205
- this.store.dispatch(
206
- createUpdateDetailSetErrorsAction(this.detailsRepository)({ error })
207
- );
208
-
209
- return error;
210
- }
211
-
212
- private normalizePropertyNames(input: string): string {
213
- return String(input[0]).toLocaleLowerCase() + String(input).slice(1);
214
- }
215
-
216
- private isStateChanged(item: any): boolean {
217
- return item !== this.itemCache;
218
- }
219
- }
@@ -1,4 +0,0 @@
1
- export * from './base-form-input.component';
2
- export * from './base-form.component'
3
- export * from './directives/detail-store.directive';
4
- export * from './models';
@@ -1,11 +0,0 @@
1
- import { NgControl } from '@angular/forms';
2
-
3
- export abstract class BaseInputControls<T> {
4
- value?: T | null;
5
-
6
- readonly ngControl?: NgControl;
7
-
8
- readonly label?: string;
9
-
10
- readonly required!: boolean;
11
- }
@@ -1,31 +0,0 @@
1
- export interface BaseFormCore {
2
- label?: string;
3
- required: boolean;
4
- readonly: boolean;
5
- tooltip: string;
6
- formDisplay: 'flex' | 'block';
7
- clearable: boolean;
8
- placeholder?: string
9
- testId?: string;
10
- }
11
-
12
- export interface BaseFormDirectiveCore<T> {
13
- initialData: T | any;
14
- }
15
-
16
- export interface FormState {
17
- dirty: boolean;
18
- valid: boolean;
19
- }
20
-
21
- export function isFormStateEqual(current: FormState, other: FormState) {
22
- if (!current && !other) {
23
- return true;
24
- }
25
-
26
- if (current && other) {
27
- return current.dirty === other.dirty && current.valid === other.valid;
28
- }
29
-
30
- return false;
31
- }
@@ -1,2 +0,0 @@
1
- export * from './base-form-input.models';
2
- export * from './base-form.models';
@@ -1,21 +0,0 @@
1
- import { InjectionToken } from '@angular/core';
2
- import { ActivatedRoute } from "@angular/router";
3
- import { MenuItem } from '../side-menu';
4
-
5
- export const BREADCRUMB_COMPONENT_TOKEN = new InjectionToken<BreadcrumbCore>(
6
- 'BreadcrumbComponentToken'
7
- );
8
-
9
- export interface BreadcrumbCore {
10
- items: MenuItem[];
11
- homeRoute: string;
12
- useHomeRoute: boolean;
13
- }
14
-
15
- export interface Breadcrumb {
16
- label: string;
17
- routerLink?: string;
18
- url?: string;
19
- active?: boolean;
20
- activatedRoute?: ActivatedRoute;
21
- }
@@ -1,9 +0,0 @@
1
- import { EventEmitter, Injectable, Output } from '@angular/core';
2
- import { Breadcrumb } from './breadcrumb.model';
3
-
4
- @Injectable({
5
- providedIn: 'root',
6
- })
7
- export class BreadcrumbService {
8
- @Output() routeChange: EventEmitter<Breadcrumb> = new EventEmitter();
9
- }