Skip to content

Commit 4001f0c

Browse files
Merge pull request #39 from asoftwareworld/feature/5.0x
fixed calculation issue
2 parents a1acdae + 1c46775 commit 4001f0c

File tree

16 files changed

+125
-134
lines changed

16 files changed

+125
-134
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asoftwareworld/form-builder",
3-
"version": "5.0.1",
3+
"version": "5.0.2",
44
"author": "Anish Sharma",
55
"license": "MIT",
66
"scripts": {

src/assets/data/basic-control.json

Lines changed: 81 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,112 @@
11
[
22
{
3-
"id": "1",
4-
"label": "User Profile ",
5-
"subtype": "h2",
3+
"customClass": "",
4+
"label": "BBM WHEELS Details",
5+
"subtype": "h1",
66
"column": "col-md-12",
77
"style": "text-left",
88
"controlType": "header"
99
},
1010
{
1111
"id": "1",
12-
"tooltip": "Enter firstname",
13-
"label": "Firstname",
14-
"value": "",
15-
"style": "outline",
16-
"column": "col-md-4",
17-
"maxlength": 50,
18-
"minlength": 0,
19-
"isRequired": true,
20-
"controlType": "textbox"
21-
},
22-
{
23-
"id": "1",
24-
"tooltip": "Enter middle name",
25-
"label": "Middle name",
12+
"tooltip": "Enter Text",
13+
"label": "Machine Details",
2614
"value": "",
2715
"style": "outline",
28-
"column": "col-md-4",
16+
"column": "col-md-6",
17+
"pattern": "",
18+
"customClass": "",
19+
"customErrorMsg": "",
2920
"maxlength": 50,
3021
"minlength": 0,
3122
"isRequired": false,
32-
"controlType": "textbox"
33-
},
34-
{
35-
"id": "1",
36-
"tooltip": "Enter lastname",
37-
"label": "Lastname",
38-
"value": "",
39-
"style": "outline",
40-
"column": "col-md-4",
41-
"maxlength": 50,
42-
"minlength": 0,
43-
"isRequired": true,
44-
"controlType": "textbox"
23+
"controlType": "textfield"
4524
},
4625
{
47-
"id": "1",
48-
"tooltip": "Enter username",
49-
"label": "Username",
50-
"value": "",
26+
"tooltip": "Enter calculation",
27+
"label": "Calculation",
5128
"style": "outline",
5229
"column": "col-md-6",
53-
"maxlength": 50,
54-
"minlength": 0,
55-
"isRequired": true,
56-
"controlType": "textbox"
30+
"customClass": "",
31+
"operations": [
32+
{
33+
"id": "da27",
34+
"label": "BBM Wheels Posizione",
35+
"value": "",
36+
"operationValue": "",
37+
"control": {
38+
"id": "EXPORT_MACHINE(IITASALS000250)_PARAMETER(Ruota 1 lato # A Posizione (mm))",
39+
"tooltip": "Ruota 1 lato # A Posizione (mm) from BBM WHEELS",
40+
"label": "BBM Wheels Posizione",
41+
"value": "",
42+
"style": "outline",
43+
"column": "col-md-6",
44+
"customClass": "",
45+
"maxlength": 50,
46+
"minlength": 0,
47+
"isRequired": false,
48+
"controlType": "number",
49+
"guid": "da27"
50+
}
51+
},
52+
{
53+
"id": "4a6e",
54+
"label": "BBM Wheels Forza",
55+
"value": "",
56+
"operationValue": "+",
57+
"control": {
58+
"id": "EXPORT_MACHINE(IITASALS000250)_PARAMETER(Disco lato #3 (B) Forza (kN))",
59+
"tooltip": "Disco lato #3 (B) Forza (kN)) from BBM WHEELS",
60+
"label": "BBM Wheels Forza",
61+
"value": "",
62+
"style": "outline",
63+
"column": "col-md-6",
64+
"customClass": "",
65+
"maxlength": 50,
66+
"minlength": 0,
67+
"isRequired": false,
68+
"controlType": "number",
69+
"guid": "4a6e"
70+
}
71+
},
72+
{
73+
"id": "",
74+
"label": "",
75+
"value": "",
76+
"operationValue": "",
77+
"control": ""
78+
}
79+
],
80+
"controlType": "calculation",
81+
"placeholder": "Field 1 + Field 2 = ",
82+
"value": "0"
5783
},
5884
{
59-
"id": "1",
60-
"tooltip": "Enter email address",
61-
"label": "Email Address",
62-
"value": "",
85+
"id": "EXPORT_MACHINE(IITASALS000250)_PARAMETER(Ruota 1 lato # A Posizione (mm))",
86+
"tooltip": "Ruota 1 lato # A Posizione (mm) from BBM WHEELS",
87+
"label": "BBM Wheels Posizione",
88+
"value": "12",
6389
"style": "outline",
6490
"column": "col-md-6",
91+
"customClass": "",
6592
"maxlength": 50,
6693
"minlength": 0,
67-
"isRequired": true,
68-
"controlType": "textbox"
69-
},
70-
{
71-
"id": "1",
72-
"tooltip": "Enter phone number",
73-
"label": "Phone number",
74-
"value": "",
75-
"style": "outline",
76-
"column": "col-md-12",
77-
"maxlength": 50,
78-
"minlength": 0,
79-
"isRequired": true,
80-
"controlType": "textbox"
81-
},
82-
{
83-
"id": "1",
84-
"tooltip": "Enter country",
85-
"label": "Country",
86-
"value": "",
87-
"style": "outline",
88-
"column": "col-md-4",
89-
"maxlength": 50,
90-
"minlength": 0,
91-
"isRequired": true,
92-
"controlType": "textbox"
93-
},
94-
{
95-
"id": "1",
96-
"tooltip": "Enter state",
97-
"label": "State",
98-
"value": "",
99-
"style": "outline",
100-
"column": "col-md-4",
101-
"maxlength": 50,
102-
"minlength": 0,
103-
"isRequired": true,
104-
"controlType": "textbox"
105-
},
106-
{
107-
"id": "1",
108-
"tooltip": "Enter city",
109-
"label": "City",
110-
"value": "",
111-
"style": "outline",
112-
"column": "col-md-4",
113-
"maxlength": 50,
114-
"minlength": 0,
115-
"isRequired": true,
116-
"controlType": "textbox"
94+
"isRequired": false,
95+
"controlType": "number",
96+
"guid": "da27"
11797
},
11898
{
119-
"id": "1",
120-
"tooltip": "Enter address",
121-
"label": "Address",
122-
"value": "",
99+
"id": "EXPORT_MACHINE(IITASALS000250)_PARAMETER(Disco lato #3 (B) Forza (kN))",
100+
"tooltip": "Disco lato #3 (B) Forza (kN)) from BBM WHEELS",
101+
"label": "BBM Wheels Forza",
102+
"value": "12",
123103
"style": "outline",
124-
"column": "col-md-12",
104+
"column": "col-md-6",
105+
"customClass": "",
125106
"maxlength": 50,
126107
"minlength": 0,
127-
"isRequired": true,
128-
"controlType": "textarea"
129-
},
130-
{
131-
"id": "1",
132-
"tooltip": "Click Save",
133-
"label": "Save",
134-
"type": "button",
135-
"color": "primary",
136-
"style": "mat-raised-button",
137-
"column": "col-md-12",
138108
"isRequired": false,
139-
"controlType": "button"
109+
"controlType": "number",
110+
"guid": "4a6e"
140111
}
141112
]

src/components/form-control/calculation/calculation-dialog.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ <h4 mat-dialog-title>Edit Property</h4>
9999
<div class="col-md-4" *ngIf="operations.controls[index].value.operationValue != 'x̄'">
100100
<mat-form-field appearance="outline" class="asw-mat-form-field">
101101
<mat-label>Operator {{index+1}}</mat-label>
102-
<mat-select formControlName="control"
102+
<mat-select formControlName="label"
103103
matTooltip="Select operator {{index+1}}" required>
104-
<mat-option *ngFor="let control of data.numberControls" [value]="control">
104+
<mat-option *ngFor="let control of data.numberControls" [value]="control.label">
105105
{{control.label}}
106106
</mat-option>
107107
</mat-select>

src/components/form-control/calculation/calculation-dialog.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ export class AswCalculationDialog implements OnInit {
9999

100100
onOperationChange(event: MatSelectChange, operation: any): void {
101101
if (event.value === 'x̄') {
102-
operation.controls.control.setErrors(null);
102+
operation.controls.label.setErrors(null);
103103
} else {
104-
operation.controls.control.setValidators(Validators.required);
104+
operation.controls.label.setValidators(Validators.required);
105105
}
106106
}
107107
}

src/components/form-control/calculation/calculation.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<mat-label>{{control.label}}</mat-label>
44
<input matInput type="text"
55
[placeholder]="control.placeholder"
6-
[(ngModel)]="control.value"
6+
[(ngModel)]="control.value"
77
#input="ngModel"
8-
(change)="onChange(control)"
8+
(ngModelChange)="onChange(control)"
99
[matTooltip]="control.tooltip" [disabled]="true">
1010
<mat-error class="asw-mat-error" *ngIf="input.invalid && (input.dirty || input.touched)">
1111
<mat-error class="asw-mat-error" *ngIf="input?.errors?.required">

src/components/form-control/calculation/calculation.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Component, EventEmitter, Input, Output } from '@angular/core';
1010
import { MatDialog } from '@angular/material/dialog';
1111
import { AswConfirmDialog } from '@asoftwareworld/form-builder/form-control/confirm-dialog';
1212
import { Constants, ObjectUtils } from '@asoftwareworld/form-builder/form-control/core';
13+
import { NumberControl } from '@asoftwareworld/form-builder/form-control/number';
1314
import { CalculationControl } from './calculation-control';
1415
import { AswCalculationDialog } from './calculation-dialog';
1516

@@ -60,14 +61,21 @@ export class AswCalculation {
6061
}
6162
if (!control.operations.length) {
6263
numberControls.forEach((x, index) => {
63-
const operation = {
64-
id: x.guid,
65-
label: x.label,
66-
value: x.value,
67-
operationValue: index === 0 ? '' : '+',
68-
control: x
69-
};
70-
control.operations.push(operation);
64+
control.operations.push(this.setControloperations(x, index));
65+
});
66+
} else {
67+
control.operations.map((operation, index) => {
68+
const numberControl = numberControls.find(element => element.guid === operation.id);
69+
if (numberControl) {
70+
const updatedOperation = {
71+
id: numberControl.guid,
72+
label: numberControl.label,
73+
value: numberControl.value,
74+
operationValue: operation.operationValue,
75+
control: numberControl
76+
};
77+
control.operations.splice(index, 1, updatedOperation);
78+
}
7179
});
7280
}
7381

@@ -84,6 +92,17 @@ export class AswCalculation {
8492
});
8593
}
8694

95+
private setControloperations(control: NumberControl, index: number): any {
96+
const operation = {
97+
id: control.guid,
98+
label: control.label,
99+
value: control.value,
100+
operationValue: index === 0 ? '' : '+',
101+
control
102+
};
103+
return operation;
104+
}
105+
87106
onChange(control: CalculationControl): void {
88107
this.aswModelChange.emit(control);
89108
}

src/components/form-control/core/shared-dialog/multi-select/multi-select-dialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class AswMultiSelectDialog implements OnInit {
9191
isRequired: control.isRequired,
9292
column: control.column,
9393
value: control.value ?? '',
94-
isDisabled: control.isDisabled
94+
isDisabled: control.isDisabled ?? false
9595
});
9696
const optionFormGroup = control.options.map((option: any) => this.formBuilder.group(option));
9797
const optionFormArray = this.formBuilder.array(optionFormGroup);

src/components/form-control/core/shared-dialog/single-select/single-select-dialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class AswSingleSelectDialog implements OnInit {
9090
column: control.column,
9191
customClass: control.customClass ?? '',
9292
isRequired: control.isRequired,
93-
isDisabled: control.isDisabled
93+
isDisabled: control.isDisabled ?? false
9494
});
9595
const optionFormGroup = control.options.map((option: any) => this.formBuilder.group(option));
9696
const optionFormArray = this.formBuilder.array(optionFormGroup);

src/components/form-control/core/shared-dialog/text/text-dialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class AswTextDialog implements OnInit {
6464
column: control.column,
6565
style: control.style,
6666
isRequired: control.isRequired,
67-
isDisabled: control.isDisabled
67+
isDisabled: control.isDisabled ?? false
6868
});
6969
}
7070

src/components/form-control/datepicker/datepicker-dialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class AswDatepickerDialog implements OnInit {
5959
style: control.style,
6060
column: control.column,
6161
isRequired: control.isRequired,
62-
isDisabled: control.isDisabled
62+
isDisabled: control.isDisabled ?? false
6363
});
6464
}
6565

src/components/form-control/gps/gps-dialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class AswGpsDialog implements OnInit {
7373
column: control.column,
7474
style: control.style,
7575
isRequired: control.isRequired,
76-
isDisabled: control.isDisabled
76+
isDisabled: control.isDisabled ?? false
7777
});
7878
}
7979

src/components/form-control/number/number-dialog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class AswNumberDialog implements OnInit {
6262
column: control.column,
6363
style: control.style,
6464
isRequired: control.isRequired,
65-
isDisabled: control.isDisabled
65+
isDisabled: control.isDisabled ?? false
6666
});
6767
}
6868

src/components/form-control/number/number.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[placeholder]="control.label"
77
[(ngModel)]="control.value"
88
#input="ngModel"
9-
(change)="onChange(control)"
9+
(ngModelChange)="onChange(control)"
1010
(keypress)="objectUtils.keyPressNumbersWithDecimal($event)"
1111
[matTooltip]="control.tooltip"
1212
[maxlength]="control.maxlength"

src/components/form-control/number/number.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class AswNumber implements OnInit {
4646
const id = (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
4747
if (this.control) {
4848
this.control.guid = this.control.guid ? this.control.guid : id;
49+
Promise.resolve().then(() => this.onChange(this.control ? this.control : null as any));
4950
}
5051
}
5152

0 commit comments

Comments
 (0)