2023-03-28 14:25:08 +02:00
|
|
|
import { JsonPipe } from '@angular/common';
|
2023-03-27 14:16:53 +02:00
|
|
|
import { Component, Inject, OnInit, SecurityContext } from '@angular/core';
|
2023-03-28 14:25:08 +02:00
|
|
|
import { FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms';
|
2023-03-27 14:16:53 +02:00
|
|
|
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
2023-03-28 14:25:08 +02:00
|
|
|
import { MatSelectChange } from '@angular/material/select';
|
2023-03-23 15:05:39 +01:00
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2023-03-28 14:25:08 +02:00
|
|
|
import { KeyValue, SimpleResource, WfConf, WfParam, WfSection } from '../common/is.model';
|
2023-03-23 12:24:56 +01:00
|
|
|
import { ISService } from '../common/is.service';
|
2023-03-27 14:16:53 +02:00
|
|
|
import { ResMetadataDialog } from '../resources/resources.component';
|
2023-03-23 12:24:56 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-wf-confs',
|
|
|
|
templateUrl: './wf-confs.component.html',
|
|
|
|
styleUrls: ['./wf-confs.component.css']
|
|
|
|
})
|
|
|
|
export class WfConfsComponent implements OnInit {
|
|
|
|
|
|
|
|
section?: WfSection;
|
|
|
|
confs: KeyValue[] = [];
|
2023-03-23 15:05:39 +01:00
|
|
|
conf?: WfConf;
|
2023-03-23 12:24:56 +01:00
|
|
|
|
2023-03-23 15:05:39 +01:00
|
|
|
constructor(public service: ISService, public route: ActivatedRoute, public router: Router, public dialog: MatDialog) {
|
2023-03-23 12:24:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.route.params.subscribe(params => {
|
|
|
|
let sectionId = params['section'];
|
2023-03-23 15:05:39 +01:00
|
|
|
let confId = params['conf'];
|
2023-03-23 12:24:56 +01:00
|
|
|
|
2023-03-23 15:05:39 +01:00
|
|
|
if (confId) {
|
|
|
|
this.service.loadWfConfiguration(confId, (conf: WfConf) => {
|
|
|
|
this.conf = conf;
|
|
|
|
if (conf.section) {
|
|
|
|
this.service.loadWfSections((data: WfSection[]) => this.section = data.find(s => s.id == conf?.section));
|
|
|
|
this.service.loadWfConfigurations(conf.section, (data: KeyValue[]) => this.confs = data);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (sectionId) {
|
|
|
|
this.service.loadWfSections((data: WfSection[]) => this.section = data.find(s => s.id == sectionId));
|
|
|
|
this.service.loadWfConfigurations(sectionId, (data: KeyValue[]) => {
|
|
|
|
this.confs = data;
|
|
|
|
if (data.length > 0) {
|
|
|
|
this.router.navigate(['/wfs/conf', data[0].k]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log("One of the following parameters is missing: sectionId or confId");
|
|
|
|
}
|
|
|
|
});
|
2023-03-23 12:24:56 +01:00
|
|
|
}
|
2023-03-27 14:16:53 +02:00
|
|
|
|
|
|
|
openAddWfConfDialog(): void {
|
|
|
|
const dialogRef = this.dialog.open(WfConfDialog, {
|
|
|
|
data: {
|
|
|
|
id: '',
|
|
|
|
name: '',
|
|
|
|
section: this.section?.id,
|
|
|
|
enabled: true,
|
|
|
|
priority: 75,
|
|
|
|
workflow: '',
|
|
|
|
schedulingEnabled: false,
|
2023-03-28 11:12:10 +02:00
|
|
|
cronExpression: '0 30 12 1/1 * ?',
|
2023-03-27 14:16:53 +02:00
|
|
|
cronMinInterval: 9600,
|
|
|
|
details: new Map,
|
|
|
|
configured: true,
|
|
|
|
systemParams: new Map,
|
|
|
|
userParams: new Map
|
|
|
|
},
|
|
|
|
width: '80%'
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
|
|
if (result) this.router.navigate(['/wfs/conf', result.id]);;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'wf-conf-dialog',
|
|
|
|
templateUrl: 'wf-conf-dialog.html',
|
|
|
|
styleUrls: ['./wf-confs.component.css']
|
|
|
|
})
|
2023-03-28 14:25:08 +02:00
|
|
|
|
|
|
|
export class WfConfDialog implements OnInit {
|
|
|
|
|
|
|
|
wfTemplates: SimpleResource[] = [];
|
|
|
|
wfParameters: WfParam[] = [];
|
2023-03-28 11:12:10 +02:00
|
|
|
|
|
|
|
wfConfFormStep1 = new FormGroup({
|
|
|
|
workflow: new FormControl('', [Validators.required]),
|
|
|
|
});
|
|
|
|
|
|
|
|
wfConfFormStep2 = new FormGroup({
|
2023-03-27 14:16:53 +02:00
|
|
|
name: new FormControl('', [Validators.required]),
|
|
|
|
//details: Map<string, string>,
|
|
|
|
enabled: new FormControl(true, [Validators.required]),
|
|
|
|
priority: new FormControl(75, [Validators.required, Validators.min(1), Validators.max(100)]),
|
2023-03-28 11:12:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
wfConfFormStep3 = new FormGroup({
|
|
|
|
//systemParams: Map<string, string>,
|
|
|
|
//userParams: Map<string, string>
|
|
|
|
});
|
|
|
|
|
|
|
|
wfConfFormStep4 = new FormGroup({
|
2023-03-27 14:16:53 +02:00
|
|
|
schedulingEnabled: new FormControl(false, [Validators.required]),
|
|
|
|
cronExpression: new FormControl("", [Validators.required]),
|
|
|
|
cronMinInterval: new FormControl("", [Validators.required]),
|
|
|
|
});
|
|
|
|
|
2023-03-28 11:12:10 +02:00
|
|
|
wfConfFormFinal = new FormGroup({});
|
|
|
|
|
2023-03-27 14:16:53 +02:00
|
|
|
constructor(public dialogRef: MatDialogRef<ResMetadataDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
|
2023-03-28 11:12:10 +02:00
|
|
|
this.wfConfFormStep1.get('workflow')?.setValue(data.workflow);
|
|
|
|
|
|
|
|
this.wfConfFormStep2.get('name')?.setValue(data.name);
|
|
|
|
this.wfConfFormStep2.get('enabled')?.setValue(data.enabled);
|
|
|
|
this.wfConfFormStep2.get('priority')?.setValue(data.priority);
|
2023-03-27 14:16:53 +02:00
|
|
|
//details
|
2023-03-28 11:12:10 +02:00
|
|
|
|
2023-03-27 14:16:53 +02:00
|
|
|
//systemParams,
|
|
|
|
//userParams
|
2023-03-28 11:12:10 +02:00
|
|
|
|
|
|
|
this.wfConfFormStep4.get('schedulingEnabled')?.setValue(data.schedulingEnabled);
|
|
|
|
this.wfConfFormStep4.get('cronExpression')?.setValue(data.cronExpression);
|
|
|
|
this.wfConfFormStep4.get('cronMinInterval')?.setValue(data.cronMinInterval);
|
2023-03-27 14:16:53 +02:00
|
|
|
}
|
2023-03-28 14:25:08 +02:00
|
|
|
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));
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2023-03-27 14:16:53 +02:00
|
|
|
|
|
|
|
onSubmit(): void {
|
2023-03-28 11:12:10 +02:00
|
|
|
const conf = Object.assign({}, this.data, this.wfConfFormStep1.value, this.wfConfFormStep2.value, this.wfConfFormStep3.value, this.wfConfFormStep4.value);
|
|
|
|
this.service.saveWfConfiguration(conf, (data: void) => this.dialogRef.close(1), this.wfConfFormFinal);
|
2023-03-27 14:16:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onNoClick(): void {
|
|
|
|
this.dialogRef.close();
|
|
|
|
}
|
2023-03-23 12:24:56 +01:00
|
|
|
}
|