Skip to content

Commit 5719f06

Browse files
authored
Merge pull request #4273 from 4Science/task/main/DURACOM-354
Fix missing input fields for integer script parameters
2 parents 67e91e3 + 00143d2 commit 5719f06

35 files changed

+265
-25
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<input [attr.aria-label]="'process.new.parameter.label' | translate" required #integer="ngModel" type="number" step="1" name="integer-value-{{index}}" class="form-control" id="integer-value-{{index}}" [ngModel]="value" (ngModelChange)="setValue($event)"/>
2+
@if (integer.invalid && (integer.dirty || integer.touched)) {
3+
<div
4+
class="alert alert-danger validation-error mb-0">
5+
@if (integer.errors.required) {
6+
<div>
7+
{{'process.new.parameter.integer.required' | translate}}
8+
</div>
9+
}
10+
</div>
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
:host {
2+
display: flex;
3+
flex-direction: column;
4+
gap: calc(var(--bs-spacer) / 2);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import {
2+
ComponentFixture,
3+
fakeAsync,
4+
TestBed,
5+
tick,
6+
waitForAsync,
7+
} from '@angular/core/testing';
8+
import { FormsModule } from '@angular/forms';
9+
import { By } from '@angular/platform-browser';
10+
import {
11+
TranslateLoader,
12+
TranslateModule,
13+
} from '@ngx-translate/core';
14+
15+
import { TranslateLoaderMock } from '../../../../../shared/mocks/translate-loader.mock';
16+
import { IntegerValueInputComponent } from './integer-value-input.component';
17+
18+
describe('IntegerValueInputComponent', () => {
19+
let component: IntegerValueInputComponent;
20+
let fixture: ComponentFixture<IntegerValueInputComponent>;
21+
22+
beforeEach(waitForAsync(() => {
23+
TestBed.configureTestingModule({
24+
imports: [
25+
FormsModule,
26+
TranslateModule.forRoot({
27+
loader: {
28+
provide: TranslateLoader,
29+
useClass: TranslateLoaderMock,
30+
},
31+
}),
32+
IntegerValueInputComponent,
33+
],
34+
providers: [],
35+
})
36+
.compileComponents();
37+
}));
38+
39+
beforeEach(() => {
40+
fixture = TestBed.createComponent(IntegerValueInputComponent);
41+
component = fixture.componentInstance;
42+
fixture.detectChanges();
43+
});
44+
45+
it('should create', () => {
46+
expect(component).toBeTruthy();
47+
});
48+
49+
it('should not show a validation error if the input field was left untouched but left empty', () => {
50+
const validationError = fixture.debugElement.query(By.css('.validation-error'));
51+
expect(validationError).toBeFalsy();
52+
});
53+
54+
it('should show a validation error if the input field was touched but left empty', fakeAsync(() => {
55+
component.value = undefined;
56+
fixture.detectChanges();
57+
tick();
58+
59+
const input = fixture.debugElement.query(By.css('input'));
60+
input.triggerEventHandler('blur', null);
61+
62+
fixture.detectChanges();
63+
64+
const validationError = fixture.debugElement.query(By.css('.validation-error'));
65+
expect(validationError).toBeTruthy();
66+
}));
67+
68+
it('should not show a validation error if the input field was touched but not left empty', fakeAsync(() => {
69+
component.value = 1;
70+
fixture.detectChanges();
71+
tick();
72+
73+
const input = fixture.debugElement.query(By.css('input'));
74+
input.triggerEventHandler('blur', null);
75+
76+
fixture.detectChanges();
77+
78+
const validationError = fixture.debugElement.query(By.css('.validation-error'));
79+
expect(validationError).toBeFalsy();
80+
}));
81+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
Component,
3+
Input,
4+
OnInit,
5+
Optional,
6+
} from '@angular/core';
7+
import {
8+
ControlContainer,
9+
FormsModule,
10+
NgForm,
11+
} from '@angular/forms';
12+
import { TranslateModule } from '@ngx-translate/core';
13+
14+
import { controlContainerFactory } from '../../../process-form-factory';
15+
import { ValueInputComponent } from '../value-input.component';
16+
17+
/**
18+
* Represents the user-inputted value of an integer parameter
19+
*/
20+
@Component({
21+
selector: 'ds-integer-value-input',
22+
templateUrl: './integer-value-input.component.html',
23+
styleUrls: ['./integer-value-input.component.scss'],
24+
viewProviders: [{ provide: ControlContainer,
25+
useFactory: controlContainerFactory,
26+
deps: [[new Optional(), NgForm]] }],
27+
standalone: true,
28+
imports: [FormsModule, TranslateModule],
29+
})
30+
export class IntegerValueInputComponent extends ValueInputComponent<number> implements OnInit {
31+
/**
32+
* The current value of the integer
33+
*/
34+
value: number;
35+
36+
/**
37+
* Initial value of the field
38+
*/
39+
@Input() initialValue;
40+
41+
ngOnInit(): void {
42+
this.value = this.initialValue;
43+
}
44+
45+
setValue(value) {
46+
this.value = value;
47+
this.updateValue.emit(value);
48+
}
49+
}

src/app/process-page/form/process-parameters/parameter-value-input/parameter-value-input.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
@case (parameterTypes.STRING) {
44
<ds-string-value-input [initialValue]="initialValue" (updateValue)="updateValue.emit($event)" [index]="index"></ds-string-value-input>
55
}
6+
@case (parameterTypes.INTEGER) {
7+
<ds-integer-value-input [initialValue]="initialValue" (updateValue)="updateValue.emit($event)" [index]="index"></ds-integer-value-input>
8+
}
69
@case (parameterTypes.OUTPUT) {
710
<ds-string-value-input [initialValue]="initialValue" (updateValue)="updateValue.emit($event)" [index]="index"></ds-string-value-input>
811
}

src/app/process-page/form/process-parameters/parameter-value-input/parameter-value-input.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { controlContainerFactory } from '../../process-form-factory';
1717
import { BooleanValueInputComponent } from './boolean-value-input/boolean-value-input.component';
1818
import { DateValueInputComponent } from './date-value-input/date-value-input.component';
1919
import { FileValueInputComponent } from './file-value-input/file-value-input.component';
20+
import { IntegerValueInputComponent } from './number-value-input/integer-value-input.component';
2021
import { StringValueInputComponent } from './string-value-input/string-value-input.component';
2122

2223
/**
@@ -30,7 +31,7 @@ import { StringValueInputComponent } from './string-value-input/string-value-inp
3031
useFactory: controlContainerFactory,
3132
deps: [[new Optional(), NgForm]] }],
3233
standalone: true,
33-
imports: [StringValueInputComponent, DateValueInputComponent, FileValueInputComponent, BooleanValueInputComponent],
34+
imports: [StringValueInputComponent, DateValueInputComponent, FileValueInputComponent, BooleanValueInputComponent, IntegerValueInputComponent],
3435
})
3536
export class ParameterValueInputComponent {
3637
@Input() index: number;

src/app/process-page/scripts/script-parameter-type.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
export enum ScriptParameterType {
55
STRING = 'String',
6+
INTEGER = 'Integer',
67
DATE = 'date',
78
BOOLEAN = 'boolean',
89
FILE = 'InputStream',

src/assets/i18n/ar.json5

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6045,6 +6045,9 @@
60456045
// "process.new.parameter.file.required": "Please select a file",
60466046
"process.new.parameter.file.required": "يرجى تحديد ملف",
60476047

6048+
// "process.new.parameter.integer.required": "Parameter value is required",
6049+
"process.new.parameter.integer.required": "قيمة المتغير مطلوبة",
6050+
60486051
// "process.new.parameter.string.required": "Parameter value is required",
60496052
"process.new.parameter.string.required": "قيمة المتغير مطلوبة",
60506053

@@ -11456,4 +11459,4 @@
1145611459
"embargo.listelement.badge": "Embargo until {{ date }}",
1145711460

1145811461

11459-
}
11462+
}

src/assets/i18n/bn.json5

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6525,6 +6525,9 @@
65256525
// "process.new.parameter.file.required": "Please select a file",
65266526
"process.new.parameter.file.required": "দয়াকরে একটি ফাইল নির্বাচন করুন",
65276527

6528+
// "process.new.parameter.integer.required": "Parameter value is required",
6529+
"process.new.parameter.integer.required": "পরামিতির মান প্রয়োজন",
6530+
65286531
// "process.new.parameter.string.required": "Parameter value is required",
65296532
"process.new.parameter.string.required": "পরামিতির মান প্রয়োজন",
65306533

@@ -12379,4 +12382,4 @@
1237912382
"embargo.listelement.badge": "Embargo until {{ date }}",
1238012383

1238112384

12382-
}
12385+
}

src/assets/i18n/ca.json5

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5850,6 +5850,9 @@
58505850
// "process.new.parameter.file.required": "Please select a file",
58515851
"process.new.parameter.file.required": "Si us plau seleccioneu un fitxer",
58525852

5853+
// "process.new.parameter.integer.required": "Parameter value is required",
5854+
"process.new.parameter.integer.required": "Es requereix el valor del paràmetre",
5855+
58535856
// "process.new.parameter.string.required": "Parameter value is required",
58545857
"process.new.parameter.string.required": "Es requereix el valor del paràmetre",
58555858

@@ -10771,4 +10774,4 @@
1077110774
"embargo.listelement.badge": "Embargo until {{ date }}",
1077210775

1077310776

10774-
}
10777+
}

0 commit comments

Comments
 (0)