dnet-applications/frontends/dnet-is-application/src/app/wf-confs/wf-confs.component.ts

133 lines
4.1 KiB
TypeScript

import { Component, Inject, OnInit, SecurityContext } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { KeyValue, WfConf, WfSection } from '../common/is.model';
import { ISService } from '../common/is.service';
import { ResMetadataDialog } from '../resources/resources.component';
@Component({
selector: 'app-wf-confs',
templateUrl: './wf-confs.component.html',
styleUrls: ['./wf-confs.component.css']
})
export class WfConfsComponent implements OnInit {
section?: WfSection;
confs: KeyValue[] = [];
conf?: WfConf;
constructor(public service: ISService, public route: ActivatedRoute, public router: Router, public dialog: MatDialog) {
}
ngOnInit() {
this.route.params.subscribe(params => {
let sectionId = params['section'];
let confId = params['conf'];
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");
}
});
}
openAddWfConfDialog(): void {
const dialogRef = this.dialog.open(WfConfDialog, {
data: {
id: '',
name: '',
section: this.section?.id,
enabled: true,
priority: 75,
workflow: '',
schedulingEnabled: false,
cronExpression: '0 30 12 1/1 * ?',
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']
})
export class WfConfDialog {
wfConfFormStep1 = new FormGroup({
workflow: new FormControl('', [Validators.required]),
});
wfConfFormStep2 = new FormGroup({
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)]),
});
wfConfFormStep3 = new FormGroup({
//systemParams: Map<string, string>,
//userParams: Map<string, string>
});
wfConfFormStep4 = new FormGroup({
schedulingEnabled: new FormControl(false, [Validators.required]),
cronExpression: new FormControl("", [Validators.required]),
cronMinInterval: new FormControl("", [Validators.required]),
});
wfConfFormFinal = new FormGroup({});
constructor(public dialogRef: MatDialogRef<ResMetadataDialog>, @Inject(MAT_DIALOG_DATA) public data: any, public service: ISService) {
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);
//details
//systemParams,
//userParams
this.wfConfFormStep4.get('schedulingEnabled')?.setValue(data.schedulingEnabled);
this.wfConfFormStep4.get('cronExpression')?.setValue(data.cronExpression);
this.wfConfFormStep4.get('cronMinInterval')?.setValue(data.cronMinInterval);
}
onSubmit(): void {
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);
}
onNoClick(): void {
this.dialogRef.close();
}
}