This commit is contained in:
Michele Artini 2023-03-28 14:25:08 +02:00
parent 6676c7f26c
commit bc9fe2c716
3 changed files with 56 additions and 6 deletions

View File

@ -232,6 +232,14 @@ export interface WfConf {
userParams: Map<string, string>
}
export interface WfParam {
name: string,
description?: string,
type?: string,
defaultValue?: any,
required: boolean
}
export interface WfSubscription {
// TODO
}

View File

@ -8,7 +8,9 @@
<ng-template matStepLabel>Choose Workflow</ng-template>
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;">
<mat-label>Workflow</mat-label>
<input matInput formControlName="workflow" />
<mat-select matInput formControlName="workflow" (selectionChange)="onChangeWfTemplate($event)">
<mat-option *ngFor="let i of wfTemplates" [value]="i.id">{{i.name}} ({{i.subtype}})</mat-option>
</mat-select>
<mat-error *ngIf="wfConfFormStep1.get('workflow')?.invalid">This field is
<strong>required</strong></mat-error>
</mat-form-field>
@ -44,7 +46,16 @@
</mat-step>
<mat-step [stepControl]="wfConfFormStep3" label="Worflow Parameters">
<form [formGroup]="wfConfFormStep3">
<mat-form-field appearance="fill" floatLabel="always" style="width: 100%;" *ngFor="let p of wfParameters">
<mat-label>{{p.name}}</mat-label>
<input matInput [formControlName]="p.name" *ngIf="p.type != 'boolean'" />
<mat-select matInput [formControlName]="p.name" *ngIf="p.type == 'boolean'">
<mat-option></mat-option>
<mat-option value="true">true</mat-option>
<mat-option value="false">false</mat-option>
</mat-select>
<mat-error *ngIf="wfConfFormStep3.get(p.name)?.invalid">Invalid value</mat-error>
</mat-form-field>
<div>
<button mat-stroked-button color="primary" matStepperPrevious>Back</button>
<button mat-stroked-button color="primary" matStepperNext>Next</button>

View File

@ -1,8 +1,10 @@
import { JsonPipe } from '@angular/common';
import { Component, Inject, OnInit, SecurityContext } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { MatSelectChange } from '@angular/material/select';
import { ActivatedRoute, Router } from '@angular/router';
import { KeyValue, WfConf, WfSection } from '../common/is.model';
import { KeyValue, SimpleResource, WfConf, WfParam, WfSection } from '../common/is.model';
import { ISService } from '../common/is.service';
import { ResMetadataDialog } from '../resources/resources.component';
@ -78,13 +80,16 @@ export class WfConfsComponent implements OnInit {
templateUrl: 'wf-conf-dialog.html',
styleUrls: ['./wf-confs.component.css']
})
export class WfConfDialog {
export class WfConfDialog implements OnInit {
wfTemplates: SimpleResource[] = [];
wfParameters: WfParam[] = [];
wfConfFormStep1 = new FormGroup({
workflow: new FormControl('', [Validators.required]),
});
wfConfFormStep2 = new FormGroup({
name: new FormControl('', [Validators.required]),
//details: Map<string, string>,
@ -120,6 +125,32 @@ export class WfConfDialog {
this.wfConfFormStep4.get('cronExpression')?.setValue(data.cronExpression);
this.wfConfFormStep4.get('cronMinInterval')?.setValue(data.cronMinInterval);
}
ngOnInit(): void {
this.service.loadSimpleResources("wf_template", (data: SimpleResource[]) => this.wfTemplates = data);
}
onChangeWfTemplate(e: MatSelectChange): void {
this.service.loadSimpleResourceContent(e.value, (data: any) => {
console.log(data);
if (data.parameters) {
this.wfParameters = data.parameters;
} else {
this.wfParameters = JSON.parse(data).parameters;
}
console.log(this.wfParameters);
this.wfConfFormStep3.controls = {};
this.wfParameters.forEach(p => {
let validations: ValidatorFn[] = [];
if (p.required) { validations.push(Validators.required); }
if (p.type == 'number') { validations.push(Validators.pattern('^[0-9]*$')); }
this.wfConfFormStep3.addControl(p.name, new FormControl('', validations));
})
});
}
onSubmit(): void {
const conf = Object.assign({}, this.data, this.wfConfFormStep1.value, this.wfConfFormStep2.value, this.wfConfFormStep3.value, this.wfConfFormStep4.value);