mirror of
https://github.com/sartography/cr-connect-bpmn.git
synced 2025-02-04 21:03:52 +00:00
validate category ID's on generation
This commit is contained in:
parent
7380032dcf
commit
5b9160fed2
@ -1,9 +1,10 @@
|
|||||||
import {Component, Inject} from '@angular/core';
|
import {Component, Inject} from '@angular/core';
|
||||||
import {FormGroup} from '@angular/forms';
|
import {FormControl, FormGroup} from '@angular/forms';
|
||||||
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
|
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
|
||||||
import {FormlyFieldConfig, FormlyFormOptions} from '@ngx-formly/core';
|
import {FormlyFieldConfig, FormlyFormOptions} from '@ngx-formly/core';
|
||||||
import {toSnakeCase} from 'sartography-workflow-lib';
|
import {ApiService, toSnakeCase} from 'sartography-workflow-lib';
|
||||||
import {WorkflowSpecCategoryDialogData} from '../../_interfaces/dialog-data';
|
import {WorkflowSpecCategoryDialogData} from '../../_interfaces/dialog-data';
|
||||||
|
import {of} from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-workflow-spec-category-dialog',
|
selector: 'app-workflow-spec-category-dialog',
|
||||||
@ -14,20 +15,21 @@ export class WorkflowSpecCategoryDialogComponent {
|
|||||||
form: FormGroup = new FormGroup({});
|
form: FormGroup = new FormGroup({});
|
||||||
model: any = {};
|
model: any = {};
|
||||||
options: FormlyFormOptions = {};
|
options: FormlyFormOptions = {};
|
||||||
fields: FormlyFieldConfig[] = [
|
fields: FormlyFieldConfig[] = [];
|
||||||
{
|
categories: any;
|
||||||
key: 'id',
|
|
||||||
type: 'input',
|
|
||||||
defaultValue: this.data.id,
|
|
||||||
templateOptions: {
|
constructor(
|
||||||
label: 'ID',
|
private api: ApiService,
|
||||||
type: 'number',
|
public dialogRef: MatDialogRef<WorkflowSpecCategoryDialogComponent>,
|
||||||
placeholder: 'ID of workflow spec category',
|
@Inject(MAT_DIALOG_DATA) public data: WorkflowSpecCategoryDialogData,
|
||||||
required: true,
|
) {
|
||||||
},
|
this.api.getWorkflowSpecCategoryList().subscribe(cats => {
|
||||||
hideExpression: true,
|
this.categories = cats.map(c => c.id);
|
||||||
},
|
|
||||||
{
|
this.fields = [
|
||||||
|
{
|
||||||
key: 'display_name',
|
key: 'display_name',
|
||||||
type: 'input',
|
type: 'input',
|
||||||
defaultValue: this.data.display_name,
|
defaultValue: this.data.display_name,
|
||||||
@ -39,22 +41,69 @@ export class WorkflowSpecCategoryDialogComponent {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'admin',
|
key: 'id',
|
||||||
type: 'checkbox',
|
type: 'input',
|
||||||
defaultValue: this.data.admin ? this.data.admin : false,
|
defaultValue: this.data.id,
|
||||||
templateOptions: {
|
templateOptions: {
|
||||||
label: 'Admin Category',
|
label: 'ID',
|
||||||
description: 'Should this category only be shown to Admins?',
|
placeholder: 'Name of the category',
|
||||||
indeterminate: false,
|
description: 'Enter a name to identify this category. It cannot be changed later.' +
|
||||||
}
|
'It will be converted to all_lowercase_with_underscores when you save.',
|
||||||
}
|
required: true,
|
||||||
];
|
disabled: this.data.id !== null,
|
||||||
|
help: 'This must be in a universal format for XML standards. ' +
|
||||||
|
'It can only contain letters, numbers, and underscores. ' +
|
||||||
|
'It should not start with a digit.',
|
||||||
|
modelOptions:
|
||||||
|
{
|
||||||
|
updateOn: 'focus',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
expressionProperties: {
|
||||||
|
'model.id': (m, formState, field) => {
|
||||||
|
if (!m.id && field.focus) {
|
||||||
|
m.id = m.display_name.replace(/ /g,"_").toLowerCase();
|
||||||
|
field.formControl.markAsDirty();
|
||||||
|
return m.id;
|
||||||
|
} else {
|
||||||
|
return m.id;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'templateOptions.change': (m, formState, field)=> {
|
||||||
|
if (field.focus) {
|
||||||
|
field.formControl.updateValueAndValidity();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
asyncValidators: {
|
||||||
|
uniqueID: {
|
||||||
|
expression: (control: FormControl) => {
|
||||||
|
|
||||||
constructor(
|
return of(this.categories.indexOf(control.value) === -1);
|
||||||
public dialogRef: MatDialogRef<WorkflowSpecCategoryDialogComponent>,
|
},
|
||||||
@Inject(MAT_DIALOG_DATA) public data: WorkflowSpecCategoryDialogData,
|
message: 'This ID name is already taken.',
|
||||||
) {
|
},
|
||||||
|
},
|
||||||
|
validators: {
|
||||||
|
formatter: {
|
||||||
|
expression: (c) => !c.value || /^[A-Za-z_][A-Za-z0-9]*(?:_[A-Za-z0-9]+)*$/.test(c.value),
|
||||||
|
message: (error, field: FormlyFieldConfig) => `"${field.formControl.value}" is not in a valid format.`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'admin',
|
||||||
|
type: 'checkbox',
|
||||||
|
defaultValue: this.data.admin ? this.data.admin : false,
|
||||||
|
templateOptions: {
|
||||||
|
label: 'Admin Category',
|
||||||
|
description: 'Should this category only be shown to Admins?',
|
||||||
|
indeterminate: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onNoClick() {
|
onNoClick() {
|
||||||
|
@ -318,7 +318,6 @@ export class WorkflowSpecListComponent implements OnInit {
|
|||||||
if (selectedSpecName && selectedSpecName === ws.id) {
|
if (selectedSpecName && selectedSpecName === ws.id) {
|
||||||
this.selectedSpec = ws;
|
this.selectedSpec = ws;
|
||||||
this.selectedCatID = ws.category_id;
|
this.selectedCatID = ws.category_id;
|
||||||
// TODO: maybe fix expression changes after init error
|
|
||||||
this.setCatByID(ws.category_id);
|
this.setCatByID(ws.category_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -361,9 +360,8 @@ export class WorkflowSpecListComponent implements OnInit {
|
|||||||
};
|
};
|
||||||
this._updateWorkflowSpecCategory(data.id, newCat);
|
this._updateWorkflowSpecCategory(data.id, newCat);
|
||||||
} else {
|
} else {
|
||||||
// TODO: prompt user for somethin about the id generation
|
|
||||||
const newCat: WorkflowSpecCategory = {
|
const newCat: WorkflowSpecCategory = {
|
||||||
id: data.display_name,
|
id: data.id,
|
||||||
display_name: data.display_name,
|
display_name: data.display_name,
|
||||||
admin: data.admin,
|
admin: data.admin,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user