onshore-forms 0.0.1

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 (45) hide show
  1. package/README.md +1 -0
  2. package/karma.conf.js +44 -0
  3. package/ng-package.json +11 -0
  4. package/package.json +39 -0
  5. package/src/lib/components/form-autocomplete-item/form-autocomplete-item.component.html +46 -0
  6. package/src/lib/components/form-autocomplete-item/form-autocomplete-item.component.scss +0 -0
  7. package/src/lib/components/form-autocomplete-item/form-autocomplete-item.component.ts +133 -0
  8. package/src/lib/components/form-checkbox-item/form-checkbox-item.component.html +23 -0
  9. package/src/lib/components/form-checkbox-item/form-checkbox-item.component.scss +0 -0
  10. package/src/lib/components/form-checkbox-item/form-checkbox-item.component.ts +65 -0
  11. package/src/lib/components/form-colorpicker-item/form-colorpicker-item.component.html +30 -0
  12. package/src/lib/components/form-colorpicker-item/form-colorpicker-item.component.scss +0 -0
  13. package/src/lib/components/form-colorpicker-item/form-colorpicker-item.component.ts +71 -0
  14. package/src/lib/components/form-dropdown-item/form-dropdown-item.component.html +44 -0
  15. package/src/lib/components/form-dropdown-item/form-dropdown-item.component.scss +0 -0
  16. package/src/lib/components/form-dropdown-item/form-dropdown-item.component.ts +68 -0
  17. package/src/lib/components/form-image-item/form-image-item.component.html +79 -0
  18. package/src/lib/components/form-image-item/form-image-item.component.scss +3 -0
  19. package/src/lib/components/form-image-item/form-image-item.component.ts +155 -0
  20. package/src/lib/components/form-input-item/form-input-item.component.html +81 -0
  21. package/src/lib/components/form-input-item/form-input-item.component.scss +3 -0
  22. package/src/lib/components/form-input-item/form-input-item.component.ts +66 -0
  23. package/src/lib/components/form-switch-item/form-switch-item.component.html +8 -0
  24. package/src/lib/components/form-switch-item/form-switch-item.component.scss +0 -0
  25. package/src/lib/components/form-switch-item/form-switch-item.component.ts +72 -0
  26. package/src/lib/components/form-textarea-item/form-textarea-item.component.html +39 -0
  27. package/src/lib/components/form-textarea-item/form-textarea-item.component.scss +0 -0
  28. package/src/lib/components/form-textarea-item/form-textarea-item.component.ts +64 -0
  29. package/src/lib/components/form-validation-output/form-validation-output.component.html +2 -0
  30. package/src/lib/components/form-validation-output/form-validation-output.component.scss +1 -0
  31. package/src/lib/components/form-validation-output/form-validation-output.component.ts +43 -0
  32. package/src/lib/enums/form.enums.ts +24 -0
  33. package/src/lib/models/form.models.ts +70 -0
  34. package/src/lib/onshore-forms.component.ts +20 -0
  35. package/src/lib/onshore-forms.module.ts +78 -0
  36. package/src/lib/onshore-forms.service.ts +172 -0
  37. package/src/public-api.ts +18 -0
  38. package/src/test.ts +27 -0
  39. package/styles/css/main.css +1 -0
  40. package/styles/css/theme1.css +1 -0
  41. package/styles/scss/main.scss +4 -0
  42. package/styles/scss/theme1.scss +8 -0
  43. package/tsconfig.lib.json +16 -0
  44. package/tsconfig.lib.prod.json +12 -0
  45. package/tsconfig.spec.json +17 -0
@@ -0,0 +1,3 @@
1
+ app-form-image-item {
2
+
3
+ }
@@ -0,0 +1,155 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ ChangeDetectorRef,
4
+ Component, EventEmitter, Input, OnDestroy, OnInit,
5
+ Optional, Output,
6
+ Self
7
+ } from '@angular/core';
8
+ import { ControlValueAccessor, NgControl } from '@angular/forms';
9
+ import { Subscription } from 'rxjs';
10
+ import { DialogService } from 'primeng/dynamicdialog';
11
+ import { TranslateService } from '@ngx-translate/core';
12
+ import { OnshoreFormTemplateItem, OnshoreImageItemSettings } from '../../models/form.models';
13
+
14
+ @Component({
15
+ selector: 'onshore-form-image-item',
16
+ templateUrl: './form-image-item.component.html',
17
+ changeDetection: ChangeDetectionStrategy.OnPush,
18
+ })
19
+ export class OnshoreFormImageItemComponent implements ControlValueAccessor, OnInit, OnDestroy {
20
+ @Input() formTemplate!: OnshoreFormTemplateItem;
21
+ @Input() inverseColor: boolean = false;
22
+
23
+ // Image updload params
24
+ @Input() imageWidth: number = 400;
25
+ @Input() imageHeight: number = 400;
26
+ @Input() public containWithinAspectRatio = false;
27
+ @Input() public aspectRatio: number = 1 / 1;
28
+ @Output() imageDeleted: EventEmitter<string> = new EventEmitter();
29
+ @Output() imageCleared: EventEmitter<any> = new EventEmitter();
30
+ @Output() imageSelectedFromMedia: EventEmitter<any> = new EventEmitter();
31
+
32
+ image = '';
33
+ disabled = false;
34
+ webcamDialogVisible: boolean = false;
35
+ imageChooserDialogVisible: boolean = false;
36
+ formSettings: OnshoreImageItemSettings;
37
+
38
+ subscriptions: Array<Subscription> = [];
39
+
40
+ getFileImage(image: any) {
41
+ this.imageChooserDialogVisible = false;
42
+ if(image) {
43
+ this.image = image;
44
+ setTimeout(() => {
45
+ this.cdr.markForCheck();
46
+ this.ngControl?.control?.setValue(this.image);
47
+ this.ngControl?.control?.markAsDirty();
48
+ }, 500);
49
+ }
50
+ }
51
+
52
+ getWebcamImage(image: any) {
53
+ this.webcamDialogVisible = false;
54
+ if(image) {
55
+ this.image = image;
56
+ setTimeout(() => {
57
+ this.cdr.markForCheck();
58
+ this.ngControl?.control?.setValue(this.image);
59
+ this.ngControl?.control?.markAsDirty();
60
+ }, 500);
61
+ }
62
+ }
63
+
64
+ /*searchMedia() {
65
+ this.dialogService.open(SearchMediaComponent,{
66
+ styleClass: 'p-dialog-background-white',
67
+ modal: true,
68
+ header: this.translate.instant('search.media.dialogTitle'),
69
+ data: { targetType: this.formSettings.mediaType }
70
+ }).onClose.subscribe((result) => {
71
+ if(result) {
72
+ this.image = result.url;
73
+ setTimeout(() => {
74
+ this.cdr.markForCheck();
75
+ this.ngControl?.control?.setValue(this.image);
76
+ this.ngControl?.control?.markAsDirty();
77
+ this.imageSelectedFromMedia.next(result);
78
+ }, 500);
79
+ }
80
+ });
81
+ }*/
82
+
83
+ removeImage() {
84
+ if(this.image && !this.image.includes('base64')) {
85
+ this.imageDeleted.emit(this.image);
86
+ } else {
87
+ this.imageCleared.emit();
88
+ }
89
+
90
+ this.ngControl?.control?.setValue(null);
91
+ this.ngControl?.control?.markAsDirty();
92
+ this.image = '';
93
+ }
94
+
95
+ public writeValue(obj: any): void {
96
+ if(obj && !obj.includes('base64')) {
97
+ this.image = obj;
98
+ }
99
+ if(obj == null) {
100
+ this.image = '';
101
+ }
102
+ this.cdr.markForCheck();
103
+ }
104
+
105
+ public registerOnChange(fn: any): void {
106
+ if(this.ngControl.value) {
107
+ this.image = this.ngControl.value;
108
+ this.cdr.markForCheck();
109
+ }
110
+ }
111
+
112
+ public registerOnTouched(fn: any): void {}
113
+
114
+ public setDisabledState?(isDisabled: boolean): void {
115
+ this.disabled = isDisabled;
116
+ this.cdr.markForCheck();
117
+ }
118
+
119
+ ngOnInit(): void {
120
+ this.ngControl.control.valueChanges.subscribe((value) => {
121
+ this.cdr.markForCheck();
122
+ });
123
+ this.ngControl.control.statusChanges.subscribe((status) => {
124
+ this.cdr.markForCheck();
125
+ });
126
+
127
+ if(this.ngControl.control.value == '' && this.formTemplate.default != undefined) {
128
+ this.ngControl.control.setValue(this.formTemplate.default);
129
+ this.cdr.markForCheck();
130
+ }
131
+ if(this.formTemplate.enabled) {
132
+ this.ngControl.control.enable();
133
+ } else {
134
+ this.ngControl.control.disable();
135
+ }
136
+ if(this.formTemplate.settings) {
137
+ this.formSettings = this.formTemplate.settings as OnshoreImageItemSettings;
138
+ }
139
+ }
140
+
141
+ ngOnDestroy() {
142
+ this.subscriptions.forEach((subscription: Subscription) => {
143
+ subscription.unsubscribe();
144
+ });
145
+ this.ngControl.control.disable();
146
+ this.image = null;
147
+ }
148
+
149
+ constructor(private cdr: ChangeDetectorRef,
150
+ @Self() @Optional() public ngControl: NgControl,
151
+ public dialogService: DialogService,
152
+ private translate: TranslateService) {
153
+ this.ngControl.valueAccessor = this;
154
+ }
155
+ }
@@ -0,0 +1,81 @@
1
+ <div class="flex flex-column mb-3">
2
+ <div class="flex justify-content-between align-items-center">
3
+ <b [class.text-muted]="disabled" class="mb-1 white-space-nowrap">
4
+ {{formTemplate.label}}
5
+ <span *ngIf="formTemplate.required" class="tl-color-danger">*</span>
6
+ </b>
7
+ <i *ngIf="formTemplate.tooltip" class="fa fa-info-circle tl-color-black" [pTooltip]="formTemplate.tooltip" tooltipPosition="left" [escape]="false"></i>
8
+ </div>
9
+
10
+ <span class="p-inputgroup w-100">
11
+
12
+ <container-element [ngSwitch]="formTemplate.type" class="w-100" style="width: 100%">
13
+
14
+ <input *ngSwitchDefault
15
+ class="w-100"
16
+ type="text"
17
+ [name]="formTemplate.name"
18
+ [placeholder]="formTemplate.placeholder ?? ''"
19
+ pInputText
20
+ [formControl]="ngControl.control"
21
+ [class.p-invalid]="ngControl.control.touched && ngControl.control.invalid"
22
+ [autocomplete]="'prevent-template-' + formTemplate.name"/>
23
+
24
+ <input *ngSwitchCase="'password'"
25
+ class="w-100"
26
+ [type]="passwordVisible ? 'text' : formTemplate.type"
27
+ [name]="formTemplate.name"
28
+ [placeholder]="formTemplate.placeholder ?? ''"
29
+ pInputText
30
+ [formControl]="ngControl.control"
31
+ [class.p-invalid]="ngControl.control.touched && ngControl.control.invalid"
32
+ [autocomplete]="'prevent-template-' + formTemplate.name"/>
33
+
34
+ <p-inputNumber *ngSwitchCase="'number'"
35
+ class="w-100"
36
+ [name]="formTemplate.name"
37
+ [placeholder]="formTemplate.placeholder ?? 0"
38
+ [formControl]="ngControl.control"
39
+ [class.p-invalid]="ngControl.control.touched && ngControl.control.invalid"
40
+ [autocomplete]="'prevent-template-' + formTemplate.name"
41
+ [step]="formTemplate.settings?.step ?? 1"
42
+ [min]="formTemplate.settings?.min ?? null"
43
+ [max]="formTemplate.settings?.max ?? null">
44
+ </p-inputNumber>
45
+ <!--
46
+ [showButtons]="true"
47
+ buttonLayout="horizontal"
48
+ spinnerMode="horizontal"
49
+ decrementButtonClass="p-button-outlined text-black-50"
50
+ incrementButtonClass="p-button-outlined text-black-50"
51
+ -->
52
+ </container-element>
53
+
54
+ <span class="p-inputgroup-addon">
55
+ <i *ngIf="formTemplate.type != FormTemplateItemType.password" class="fa"
56
+ [class.tl-color-black]="ngControl.control.untouched"
57
+ [class.fa-check]="formTemplate.required && ngControl.control.valid"
58
+ [class.tl-color-primary1]="ngControl.control.touched && ngControl.control.valid"
59
+ [class.fa-exclamation-triangle]="ngControl.control.touched && ngControl.control.invalid"
60
+ [class.tl-color-danger]="ngControl.control.touched && ngControl.control.invalid"
61
+ ></i>
62
+ <i *ngIf="formTemplate.type == FormTemplateItemType.password" class="fa tl-color-black"
63
+ [class.fa-eye-slash]="passwordVisible"
64
+ [class.fa-eye]="!passwordVisible"
65
+ (click)="passwordVisible = !passwordVisible"
66
+ ></i>
67
+ </span>
68
+
69
+ </span>
70
+
71
+ <small *ngIf="formTemplate.description"><i class="fa fa-info-circle"></i> {{formTemplate.description}}</small>
72
+
73
+ <div *ngIf="ngControl.control.touched">
74
+ <onshore-form-validation-output
75
+ [validationItems]="formTemplate.validationItems"
76
+ [validationErrors]="ngControl.control.errors"
77
+ [externValidationPattern]="formTemplate.validationPatternTranslation">
78
+ </onshore-form-validation-output>
79
+ </div>
80
+
81
+ </div>
@@ -0,0 +1,3 @@
1
+ .p-inputtext {
2
+ border-color: var(--color-primary) !important;
3
+ }
@@ -0,0 +1,66 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ ChangeDetectorRef,
4
+ Component,
5
+ Input, OnChanges, OnDestroy,
6
+ OnInit, Optional,
7
+ Self, SimpleChanges
8
+ } from '@angular/core';
9
+ import { ControlValueAccessor, NgControl } from '@angular/forms';
10
+ import { OnshoreFormTemplateItem } from '../../models/form.models';
11
+ import { OnshoreFormTemplateType } from '../../enums/form.enums';
12
+
13
+ @Component({
14
+ selector: 'onshore-form-input-item',
15
+ templateUrl: './form-input-item.component.html',
16
+ styleUrls: ['./form-input-item.component.scss'],
17
+ changeDetection: ChangeDetectionStrategy.OnPush,
18
+ })
19
+ export class OnshoreFormInputItemComponent implements OnInit, ControlValueAccessor, OnChanges, OnDestroy {
20
+ @Input() formTemplate!: OnshoreFormTemplateItem;
21
+
22
+ FormTemplateItemType = OnshoreFormTemplateType;
23
+
24
+ passwordVisible: boolean = false;
25
+ disabled: boolean = false;
26
+
27
+ // ControlValueAccessor interface
28
+ writeValue(obj: any): void {}
29
+ registerOnChange(fn: any): void {}
30
+ registerOnTouched(fn: any): void {}
31
+ setDisabledState?(isDisabled: boolean): void {
32
+ this.disabled = isDisabled;
33
+ }
34
+
35
+
36
+ ngOnInit(): void {
37
+ this.ngControl.control?.valueChanges.subscribe(() => {
38
+ this.cdr.markForCheck();
39
+ });
40
+ this.ngControl.control?.statusChanges.subscribe(() => {
41
+ this.cdr.markForCheck();
42
+ });
43
+ if(this.ngControl.control?.value == '' && this.formTemplate.default != undefined) {
44
+ this.ngControl.control?.setValue(this.formTemplate.default);
45
+ this.cdr.markForCheck();
46
+ }
47
+ if(this.formTemplate.enabled) {
48
+ this.ngControl.control?.enable();
49
+ } else {
50
+ this.ngControl.control?.disable();
51
+ }
52
+ }
53
+
54
+ ngOnChanges(changes: SimpleChanges) {
55
+ this.cdr.markForCheck();
56
+ }
57
+
58
+ ngOnDestroy() {
59
+ this.ngControl.control?.disable();
60
+ }
61
+
62
+ constructor(@Self() @Optional() public ngControl: NgControl,
63
+ private cdr: ChangeDetectorRef) {
64
+ this.ngControl.valueAccessor = this;
65
+ }
66
+ }
@@ -0,0 +1,8 @@
1
+ <div class="flex flex-column pt-1">
2
+ <div class="flex justify-content-between align-items-center">
3
+ <i *ngIf="formTemplate.tooltip" class="fa fa-info-circle tl-color-black" [pTooltip]="formTemplate.tooltip" tooltipPosition="left" [escape]="false"></i>
4
+ </div>
5
+
6
+ <p-inputSwitch [name]="formTemplate.name" [formControl]="ngControl.control" [inputId]="formTemplate.name"></p-inputSwitch>
7
+
8
+ </div>
@@ -0,0 +1,72 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ ChangeDetectorRef,
4
+ Component, EventEmitter,
5
+ Input, OnChanges, OnDestroy,
6
+ OnInit, Optional, Output,
7
+ Self, SimpleChanges
8
+ } from '@angular/core';
9
+ import { ControlValueAccessor, NgControl } from '@angular/forms';
10
+ import { debounceTime, distinctUntilChanged, skip } from 'rxjs';
11
+ import { OnshoreFormTemplateItem } from '../../models/form.models';
12
+
13
+ @Component({
14
+ selector: 'onshore-form-switch-item',
15
+ templateUrl: './form-switch-item.component.html',
16
+ changeDetection: ChangeDetectionStrategy.OnPush,
17
+ })
18
+ export class OnshoreFormSwitchItemComponent implements OnInit, ControlValueAccessor, OnDestroy, OnChanges {
19
+ @Input() formTemplate!: OnshoreFormTemplateItem;
20
+ @Output() valueChange: EventEmitter<boolean> = new EventEmitter();
21
+
22
+ disabled: boolean = false;
23
+
24
+ // ControlValueAccessor interface
25
+ writeValue(obj: any): void {}
26
+ registerOnChange(fn: any): void {}
27
+ registerOnTouched(fn: any): void {}
28
+ setDisabledState?(isDisabled: boolean): void {
29
+ this.disabled = isDisabled;
30
+ }
31
+
32
+
33
+ ngOnInit(): void {
34
+ this.ngControl.control?.valueChanges.pipe(
35
+ debounceTime(100),
36
+ distinctUntilChanged(),
37
+ skip(1)
38
+ ).subscribe(newValue => {
39
+ this.valueChange.emit(this.ngControl.control?.value);
40
+ });
41
+
42
+ this.ngControl.control?.valueChanges.subscribe(() => {
43
+ this.cdr.markForCheck();
44
+ });
45
+ this.ngControl.control?.statusChanges.subscribe(() => {
46
+ this.cdr.markForCheck();
47
+ });
48
+
49
+ if(this.ngControl.control?.value == undefined && this.formTemplate.default != undefined) {
50
+ this.ngControl.control?.setValue(this.formTemplate.default);
51
+ this.cdr.markForCheck();
52
+ }
53
+ if(this.formTemplate.enabled) {
54
+ this.ngControl.control?.enable();
55
+ } else {
56
+ this.ngControl.control?.disable();
57
+ }
58
+ }
59
+
60
+ ngOnChanges(changes: SimpleChanges) {
61
+ this.cdr.markForCheck();
62
+ }
63
+
64
+ ngOnDestroy() {
65
+ this.ngControl.control?.disable();
66
+ }
67
+
68
+ constructor(@Self() @Optional() public ngControl: NgControl,
69
+ private cdr: ChangeDetectorRef) {
70
+ this.ngControl.valueAccessor = this;
71
+ }
72
+ }
@@ -0,0 +1,39 @@
1
+ <div class="flex flex-column mb-3">
2
+ <div class="flex justify-content-between align-items-center">
3
+ <b [class.text-muted]="disabled" class="mb-1 white-space-nowrap">
4
+ {{formTemplate.label}}
5
+ <span *ngIf="formTemplate.required" class="tl-color-danger">*</span>
6
+ </b>
7
+ <i *ngIf="formTemplate.tooltip" class="fa fa-info-circle tl-color-black" [pTooltip]="formTemplate.tooltip" tooltipPosition="left" [escape]="false"></i>
8
+ </div>
9
+
10
+ <span class="p-input-icon-right">
11
+ <i class="fa"
12
+ [class.tl-color-black]="ngControl.control?.untouched"
13
+ [class.fa-check]="ngControl.control?.touched && ngControl.control?.valid"
14
+ [class.text-primary]="ngControl.control?.touched && ngControl.control?.valid"
15
+ [class.fa-exclamation-triangle]="ngControl.control?.touched && ngControl.control?.invalid"
16
+ [class.tl-color-danger]="ngControl.control?.touched && ngControl.control?.invalid"
17
+ ></i>
18
+ <textarea class="w-100"
19
+ [name]="formTemplate.name"
20
+ [placeholder]="formTemplate.label"
21
+ [rows]="3"
22
+ [cols]="30"
23
+ pInputTextarea
24
+ [autoResize]="true"
25
+ [formControl]="ngControl.control"
26
+ [class.p-invalid]="ngControl.control?.touched && ngControl.control?.invalid"></textarea>
27
+ </span>
28
+
29
+ <small *ngIf="formTemplate.description"><i class="fa fa-info-circle"></i> {{formTemplate.description}}</small>
30
+
31
+ <div *ngIf="ngControl.control?.touched">
32
+ <onshore-form-validation-output
33
+ [validationItems]="formTemplate.validationItems"
34
+ [validationErrors]="ngControl.control?.errors"
35
+ [externValidationPattern]="formTemplate.validationPatternTranslation">
36
+ </onshore-form-validation-output>
37
+ </div>
38
+
39
+ </div>
@@ -0,0 +1,64 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ ChangeDetectorRef,
4
+ Component,
5
+ Input, OnChanges, OnDestroy,
6
+ OnInit, Optional,
7
+ Self, SimpleChanges
8
+ } from '@angular/core';
9
+ import { ControlValueAccessor, NgControl } from '@angular/forms';
10
+ import { OnshoreFormTemplateItem } from '../../models/form.models';
11
+ import { OnshoreFormTemplateType } from '../../enums/form.enums';
12
+
13
+ @Component({
14
+ selector: 'onshore-form-textarea-item',
15
+ templateUrl: './form-textarea-item.component.html',
16
+ changeDetection: ChangeDetectionStrategy.OnPush,
17
+ })
18
+ export class OnshoreFormTextareaItemComponent implements OnInit, ControlValueAccessor, OnChanges, OnChanges, OnDestroy {
19
+ @Input() formTemplate!: OnshoreFormTemplateItem;
20
+
21
+ FormTemplateItemType = OnshoreFormTemplateType;
22
+
23
+ disabled: boolean = false;
24
+
25
+ // ControlValueAccessor interface
26
+ writeValue(obj: any): void {}
27
+ registerOnChange(fn: any): void {}
28
+ registerOnTouched(fn: any): void {}
29
+ setDisabledState?(isDisabled: boolean): void {
30
+ this.disabled = isDisabled;
31
+ }
32
+
33
+ ngOnInit(): void {
34
+ this.ngControl.control?.valueChanges.subscribe(() => {
35
+ this.cdr.markForCheck();
36
+ });
37
+ this.ngControl.control?.statusChanges.subscribe(() => {
38
+ this.cdr.markForCheck();
39
+ });
40
+
41
+ if(this.ngControl.control?.value == '' && this.formTemplate.default != undefined) {
42
+ this.ngControl.control?.setValue(this.formTemplate.default);
43
+ this.cdr.markForCheck();
44
+ }
45
+ if(this.formTemplate.enabled) {
46
+ this.ngControl.control?.enable();
47
+ } else {
48
+ this.ngControl.control?.disable();
49
+ }
50
+ }
51
+
52
+ ngOnDestroy() {
53
+ this.ngControl.control?.disable();
54
+ }
55
+
56
+ ngOnChanges(changes: SimpleChanges) {
57
+ this.cdr.markForCheck();
58
+ }
59
+
60
+ constructor(@Self() @Optional() public ngControl: NgControl,
61
+ private cdr: ChangeDetectorRef) {
62
+ this.ngControl.valueAccessor = this;
63
+ }
64
+ }
@@ -0,0 +1,2 @@
1
+ <small *ngIf="validationErrors && validationErrors['pattern']" [innerHTML]="externValidationPattern"></small>
2
+ <small *ngIf="validationTranslation" [innerHTML]="validationTranslation"></small>
@@ -0,0 +1,43 @@
1
+ import {
2
+ ChangeDetectionStrategy,
3
+ ChangeDetectorRef,
4
+ Component,
5
+ Input, OnChanges, SimpleChanges
6
+ } from '@angular/core';
7
+ import { ValidationErrors } from '@angular/forms';
8
+ import { TranslateService } from '@ngx-translate/core';
9
+ import { OnshoreFormValidationItem } from '../../models/form.models';
10
+
11
+ @Component({
12
+ selector: 'onshore-form-validation-output',
13
+ templateUrl: './form-validation-output.component.html',
14
+ changeDetection: ChangeDetectionStrategy.OnPush,
15
+ })
16
+ export class OnshoreFormValidationOutputComponent implements OnChanges {
17
+ @Input() validationErrors!: ValidationErrors | null;
18
+ @Input() externValidationPattern: string = "";
19
+ @Input() validationItems!: OnshoreFormValidationItem[];
20
+
21
+ validationTranslation: string = '';
22
+
23
+ ngOnChanges(changes: SimpleChanges) {
24
+ this.validationTranslation = '';
25
+ if(changes['validationErrors'].currentValue) {
26
+ Object.keys(this.validationErrors!).forEach(error => {
27
+ const exists = Object.values(this.validationItems).filter( validationItem => validationItem.key == error);
28
+ if(exists && exists.length > 0) {
29
+ this.validationTranslation += this.translate.instant('request.error.' + error) + '<br>';
30
+ } else {
31
+ const errorValues = this.validationErrors![error];
32
+ this.validationTranslation += this.translate.instant('form.validation.' + error, errorValues) + '<br>';
33
+ }
34
+ });
35
+ }
36
+ this.cdr.markForCheck();
37
+ }
38
+
39
+ constructor(private cdr: ChangeDetectorRef,
40
+ private translate: TranslateService,) {
41
+
42
+ }
43
+ }
@@ -0,0 +1,24 @@
1
+ export enum OnshoreFormTemplateType {
2
+ text = 'text',
3
+ textarea = 'textarea',
4
+ editor = 'editor',
5
+ password = 'password',
6
+ number = 'number',
7
+ email = 'email',
8
+ phone = 'phone',
9
+ regexp = 'regexp',
10
+ select = 'select',
11
+ check = 'check',
12
+ radio = 'radio',
13
+ image = 'image',
14
+ autocomplete = 'autocomplete',
15
+ color = 'color',
16
+ subform = 'subform'
17
+ }
18
+
19
+ export enum OnshoreImageError {
20
+ none = '',
21
+ fileType = 'fileType',
22
+ ratio = 'ratio',
23
+ size = 'size',
24
+ }
@@ -0,0 +1,70 @@
1
+ import { OnshoreFormTemplateType } from '../enums/form.enums';
2
+
3
+ export interface OnshoreCountryCode {
4
+ id: number;
5
+ name: string;
6
+ alpha2: string;
7
+ alpha3: string;
8
+ currency?: string;
9
+ }
10
+
11
+ export interface OnshoreLanguageLocale {
12
+ id: number;
13
+ name: string;
14
+ code: string;
15
+ }
16
+
17
+ export interface OnshoreInputNumberOptionSettings {
18
+ step?: number;
19
+ min?: number;
20
+ max?: number;
21
+ }
22
+
23
+ export interface OnshoreInputTextOptionSettings {
24
+ minLength?: number;
25
+ maxLength?: number;
26
+ }
27
+
28
+ export interface OnshoreImageItemSettings {
29
+ disableImageSelection?: boolean;
30
+ disableWebcamSelection?: boolean;
31
+ disableMediaSelection?: boolean;
32
+ disableDelete?: boolean;
33
+ imagePlaceholder?: string;
34
+ mediaType?: string;
35
+ }
36
+
37
+ export interface OnshoreDropdownSettings {
38
+ multiple?: boolean;
39
+ showClear?: boolean;
40
+ }
41
+
42
+ export interface OnshoreFormTemplateItem {
43
+ name: string;
44
+ type?: OnshoreFormTemplateType;
45
+ required?: boolean;
46
+ label?: string;
47
+ placeholder?: string;
48
+ tooltip?: string;
49
+ enabled?: boolean;
50
+ options?: OnshoreFormTemplateOptions[] | void[];
51
+ optionDataKey?: string;
52
+ settings?: OnshoreInputNumberOptionSettings | OnshoreInputTextOptionSettings | OnshoreImageItemSettings | OnshoreDropdownSettings;
53
+ default?: any;
54
+ description?: string;
55
+ validationPatternTranslation?: string;
56
+ validationItems?: OnshoreFormValidationItem[];
57
+ validators?: any[];
58
+ subformArray?: OnshoreFormTemplateItem[];
59
+ subformObject?: OnshoreFormTemplateItem[];
60
+ }
61
+
62
+ export interface OnshoreFormTemplateOptions {
63
+ label: string;
64
+ value: any;
65
+ }
66
+
67
+ export interface OnshoreFormValidationItem {
68
+ key: string;
69
+ label: string;
70
+ }
@@ -0,0 +1,20 @@
1
+ import { Component, OnInit } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'lib-onshore-forms',
5
+ template: `
6
+ <p>
7
+ onshore-forms works 2!
8
+ </p>
9
+ `,
10
+ styles: [
11
+ ]
12
+ })
13
+ export class OnshoreFormsComponent implements OnInit {
14
+
15
+ constructor() { }
16
+
17
+ ngOnInit(): void {
18
+ }
19
+
20
+ }