added switch for parameter types

This commit is contained in:
lotte
2020-03-23 10:49:45 +01:00
committed by Art Lowel
parent 7c9c45b7cb
commit 68e2a08af2
10 changed files with 74 additions and 17 deletions

View File

@@ -1,14 +1,16 @@
<div class="form-group">
<div class="form-row">
<select required id="process-parameters"
class="form-control"
class="form-control col"
name="script"
[(ngModel)]="selectedParameter"
#param="ngModel">
<option [ngValue]="undefined">Add a parameter...</option>
<option *ngFor="let param of parameters">
<option *ngFor="let param of parameters" [ngValue]="param.name">
{{param.nameLong || param.name}}
</option>
</select>
<ds-string-input></ds-string-input>
<button><span class="fas fa-trash"></span></button>
<ds-parameter-value-input [parameter]="selectedScriptParameter" class="d-block col"></ds-parameter-value-input>
<button *ngIf="removable" class="btn btn-light col-1" (click)="removeParameter.emit(parameterValue);"><span class="fas fa-trash"></span></button>
<span *ngIf="!removable" class="col-1"></span>
</div>

View File

@@ -11,6 +11,8 @@ import { hasNoValue } from '../../../../shared/empty.util';
export class ParameterSelectComponent implements OnInit {
@Input() parameterValue: ProcessParameter;
@Input() parameters: ScriptParameter[];
@Input() removable: boolean;
@Output() removeParameter: EventEmitter<ProcessParameter> = new EventEmitter<ProcessParameter>();
@Output() changeParameter: EventEmitter<ProcessParameter> = new EventEmitter<ProcessParameter>();
ngOnInit(): void {
@@ -19,6 +21,10 @@ export class ParameterSelectComponent implements OnInit {
}
}
get selectedScriptParameter(): ScriptParameter {
return this.parameters.find((parameter: ScriptParameter) => parameter.name === this.selectedParameter);
}
get selectedParameter(): string {
return this.parameterValue ? this.parameterValue.name : undefined;
}

View File

@@ -0,0 +1,3 @@
<div [ngSwitch]="parameter?.type">
<ds-string-value-input *ngSwitchCase="parameterTypes.STRING"></ds-string-value-input>
</div>

View File

@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ParameterValueInputComponent } from './parameter-value-input.component';
describe('ParameterValueInputComponent', () => {
let component: ParameterValueInputComponent;
let fixture: ComponentFixture<ParameterValueInputComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ParameterValueInputComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ParameterValueInputComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,13 @@
import { Component, Input, OnChanges, OnInit } from '@angular/core';
import { ScriptParameterType } from '../../../scripts/script-parameter-type.model';
import { ScriptParameter } from '../../../scripts/script-parameter.model';
@Component({
selector: 'ds-parameter-value-input',
templateUrl: './parameter-value-input.component.html',
styleUrls: ['./parameter-value-input.component.scss']
})
export class ParameterValueInputComponent {
@Input() parameter: ScriptParameter;
parameterTypes = ScriptParameterType;
}

View File

@@ -1,8 +1,10 @@
<div class="form-group" *ngIf="script">
<label>Parameters</label>
<ds-parameter-select
*ngFor="let value of parameterValues; let i = index;"
*ngFor="let value of parameterValues; let i = index; let last = last"
[parameters]="script.parameters"
[parameterValue]="value"
[removable]="!last"
(removeParameter)="removeParameter(i)"
(changeParameter)="updateParameter($event, i)"></ds-parameter-select>
</div>

View File

@@ -29,6 +29,10 @@ export class ProcessParametersComponent implements OnChanges {
}
}
removeParameter(index: number) {
this.parameterValues = this.parameterValues.filter((value, i) => i !== index);
}
addParameter() {
this.parameterValues = [...this.parameterValues, new ProcessParameter()];
}

View File

@@ -9,6 +9,7 @@ import { ScriptHelpComponent } from './new/script-help/script-help.component';
import { ParameterSelectComponent } from './new/process-parameters/parameter-select/parameter-select.component';
import { ProcessParametersComponent } from './new/process-parameters/process-parameters.component';
import { StringValueInputComponent } from './new/process-parameters/parameter-value-input/string-value-input/string-value-input.component';
import { ParameterValueInputComponent } from './new/process-parameters/parameter-value-input/parameter-value-input.component';
@NgModule({
imports: [
@@ -22,6 +23,7 @@ import { StringValueInputComponent } from './new/process-parameters/parameter-va
ParameterSelectComponent,
ProcessParametersComponent,
StringValueInputComponent,
ParameterValueInputComponent,
],
entryComponents: [
],

View File

@@ -2,9 +2,9 @@
* List of parameter types used for scripts
*/
export enum ScriptParameterType {
STRING = 'string',
STRING = 'String',
DATE = 'date',
BOOLEAN = 'boolean',
FILE = 'file',
OUTPUT = 'output'
FILE = 'InputStream',
OUTPUT = 'OutputStream'
}