Frontend conditional display of trigger fields
This commit is contained in:
parent
5b95f0a2c6
commit
70b7d1c05b
@ -35,9 +35,9 @@
|
||||
</div>
|
||||
<div ngbAccordion [closeOthers]="true">
|
||||
@for (trigger of object.triggers; track trigger; let i = $index){
|
||||
<div ngbAccordionItem [formGroup]="triggerFields.controls[i]">
|
||||
<div ngbAccordionItem>
|
||||
<div ngbAccordionHeader>
|
||||
<button ngbAccordionButton>{{i + 1}}. {{getTypeOptionName(triggerFields.controls[i].value.type)}}
|
||||
<button ngbAccordionButton>{{i + 1}}. {{getTriggerTypeOptionName(triggerFields.controls[i].value.type)}}
|
||||
|
||||
<button type="button" class="btn btn-link text-danger ms-3" (click)="removeTrigger(i)">
|
||||
<svg class="sidebaricon me-1" fill="currentColor">
|
||||
@ -49,24 +49,7 @@
|
||||
</div>
|
||||
<div ngbAccordionCollapse>
|
||||
<div ngbAccordionBody>
|
||||
|
||||
<input type="hidden" formControlName="id" />
|
||||
<pngx-input-select i18n-title title="Trigger type" [horizontal]="true" [items]="typeOptions" formControlName="type" [error]="error?.type"></pngx-input-select>
|
||||
<p class="small" i18n>Trigger for documents that match <em>all</em> filters specified below.</p>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<pngx-input-select i18n-title title="Filter sources" [items]="sourceOptions" [multiple]="true" formControlName="sources" [error]="error?.sources"></pngx-input-select>
|
||||
<pngx-input-text i18n-title title="Filter filename" formControlName="filter_filename" i18n-hint hint="Apply to documents that match this filename. Wildcards such as *.pdf or *invoice* are allowed. Case insensitive." [error]="error?.filter_filename"></pngx-input-text>
|
||||
<pngx-input-text i18n-title title="Filter path" formControlName="filter_path" i18n-hint hint="Apply to documents that match this path. Wildcards specified as * are allowed. Case insensitive.</a>" [error]="error?.filter_path"></pngx-input-text>
|
||||
<pngx-input-select i18n-title title="Filter mail rule" [items]="mailRules" [allowNull]="true" formControlName="filter_mailrule" i18n-hint hint="Apply to documents consumed via this mail rule." [error]="error?.filter_mailrule"></pngx-input-select>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<pngx-input-tags [allowCreate]="false" i18n-title title="Has tags" formControlName="filter_has_tags"></pngx-input-tags>
|
||||
<pngx-input-select i18n-title title="Has correspondent" [items]="correspondents" [allowNull]="true" formControlName="filter_has_correspondent"></pngx-input-select>
|
||||
<pngx-input-select i18n-title title="Has document type" [items]="documentTypes" [allowNull]="true" formControlName="filter_has_document_type"></pngx-input-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template [ngTemplateOutlet]="triggerForm" [ngTemplateOutletContext]="{ formGroup: triggerFields.controls[i], trigger: trigger }"></ng-template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -108,7 +91,7 @@
|
||||
</div>
|
||||
<div ngbAccordionCollapse>
|
||||
<div ngbAccordionBody>
|
||||
|
||||
<pngx-input-select i18n-title title="Action type" [horizontal]="true" [items]="actionTypeOptions" formControlName="type"></pngx-input-select>
|
||||
<input type="hidden" formControlName="id" />
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
@ -184,3 +167,28 @@
|
||||
<button type="submit" class="btn btn-primary" i18n [disabled]="networkActive">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<ng-template #triggerForm let-formGroup="formGroup" let-trigger="trigger">
|
||||
<div [formGroup]="formGroup">
|
||||
<input type="hidden" formControlName="id" />
|
||||
<pngx-input-select i18n-title title="Trigger type" [horizontal]="true" [items]="triggerTypeOptions" formControlName="type"></pngx-input-select>
|
||||
<p class="small" i18n>Trigger for documents that match <em>all</em> filters specified below.</p>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<pngx-input-text i18n-title title="Filter filename" formControlName="filter_filename" i18n-hint hint="Apply to documents that match this filename. Wildcards such as *.pdf or *invoice* are allowed. Case insensitive." [error]="error?.filter_filename"></pngx-input-text>
|
||||
@if (formGroup.get('type').value === WorkflowTriggerType.Consumption) {
|
||||
<pngx-input-select i18n-title title="Filter sources" [items]="sourceOptions" [multiple]="true" formControlName="sources" [error]="error?.sources"></pngx-input-select>
|
||||
<pngx-input-text i18n-title title="Filter path" formControlName="filter_path" i18n-hint hint="Apply to documents that match this path. Wildcards specified as * are allowed. Case insensitive.</a>" [error]="error?.filter_path"></pngx-input-text>
|
||||
<pngx-input-select i18n-title title="Filter mail rule" [items]="mailRules" [allowNull]="true" formControlName="filter_mailrule" i18n-hint hint="Apply to documents consumed via this mail rule." [error]="error?.filter_mailrule"></pngx-input-select>
|
||||
}
|
||||
</div>
|
||||
@if (formGroup.get('type').value === WorkflowTriggerType.DocumentAdded || formGroup.get('type').value === WorkflowTriggerType.DocumentUpdated) {
|
||||
<div class="col-md-6">
|
||||
<pngx-input-tags [allowCreate]="false" i18n-title title="Has tags" formControlName="filter_has_tags"></pngx-input-tags>
|
||||
<pngx-input-select i18n-title title="Has correspondent" [items]="correspondents" [allowNull]="true" formControlName="filter_has_correspondent"></pngx-input-select>
|
||||
<pngx-input-select i18n-title title="Has document type" [items]="documentTypes" [allowNull]="true" formControlName="filter_has_document_type"></pngx-input-select>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
@ -22,6 +22,7 @@ import { SwitchComponent } from '../../input/switch/switch.component'
|
||||
import { EditDialogMode } from '../edit-dialog.component'
|
||||
import {
|
||||
DOCUMENT_SOURCE_OPTIONS,
|
||||
WORKFLOW_ACTION_OPTIONS,
|
||||
WORKFLOW_TYPE_OPTIONS,
|
||||
WorkflowEditDialogComponent,
|
||||
} from './workflow-edit-dialog.component'
|
||||
@ -32,7 +33,10 @@ import {
|
||||
DocumentSource,
|
||||
} from 'src/app/data/workflow-trigger'
|
||||
import { CdkDragDrop } from '@angular/cdk/drag-drop'
|
||||
import { WorkflowAction } from 'src/app/data/workflow-action'
|
||||
import {
|
||||
WorkflowAction,
|
||||
WorkflowActionType,
|
||||
} from 'src/app/data/workflow-action'
|
||||
|
||||
const workflow: Workflow = {
|
||||
name: 'Workflow 1',
|
||||
@ -50,10 +54,12 @@ const workflow: Workflow = {
|
||||
actions: [
|
||||
{
|
||||
id: 1,
|
||||
type: WorkflowActionType.Assignment,
|
||||
assign_title: 'foo',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
type: WorkflowActionType.Assignment,
|
||||
assign_owner: 2,
|
||||
},
|
||||
],
|
||||
@ -174,11 +180,17 @@ describe('ConsumptionTemplateEditDialogComponent', () => {
|
||||
it('should return source options, type options, type name', () => {
|
||||
// coverage
|
||||
expect(component.sourceOptions).toEqual(DOCUMENT_SOURCE_OPTIONS)
|
||||
expect(component.typeOptions).toEqual(WORKFLOW_TYPE_OPTIONS)
|
||||
expect(component.triggerTypeOptions).toEqual(WORKFLOW_TYPE_OPTIONS)
|
||||
expect(
|
||||
component.getTypeOptionName(WorkflowTriggerType.DocumentAdded)
|
||||
component.getTriggerTypeOptionName(WorkflowTriggerType.DocumentAdded)
|
||||
).toEqual('Document Added')
|
||||
expect(component.getTypeOptionName(null)).toEqual('')
|
||||
expect(component.getTriggerTypeOptionName(null)).toEqual('')
|
||||
expect(component.sourceOptions).toEqual(DOCUMENT_SOURCE_OPTIONS)
|
||||
expect(component.actionTypeOptions).toEqual(WORKFLOW_ACTION_OPTIONS)
|
||||
expect(
|
||||
component.getActionTypeOptionName(WorkflowActionType.Assignment)
|
||||
).toEqual('Assignment')
|
||||
expect(component.getActionTypeOptionName(null)).toEqual('')
|
||||
})
|
||||
|
||||
it('should support add and remove triggers and actions', () => {
|
||||
|
@ -21,7 +21,10 @@ import {
|
||||
DocumentSource,
|
||||
WorkflowTriggerType,
|
||||
} from 'src/app/data/workflow-trigger'
|
||||
import { WorkflowAction } from 'src/app/data/workflow-action'
|
||||
import {
|
||||
WorkflowAction,
|
||||
WorkflowActionType,
|
||||
} from 'src/app/data/workflow-action'
|
||||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'
|
||||
|
||||
export const DOCUMENT_SOURCE_OPTIONS = [
|
||||
@ -54,6 +57,13 @@ export const WORKFLOW_TYPE_OPTIONS = [
|
||||
},
|
||||
]
|
||||
|
||||
export const WORKFLOW_ACTION_OPTIONS = [
|
||||
{
|
||||
id: WorkflowActionType.Assignment,
|
||||
name: $localize`Assignment`,
|
||||
},
|
||||
]
|
||||
|
||||
@Component({
|
||||
selector: 'pngx-workflow-edit-dialog',
|
||||
templateUrl: './workflow-edit-dialog.component.html',
|
||||
@ -63,6 +73,8 @@ export class WorkflowEditDialogComponent
|
||||
extends EditDialogComponent<Workflow>
|
||||
implements OnInit
|
||||
{
|
||||
public WorkflowTriggerType = WorkflowTriggerType
|
||||
|
||||
templates: Workflow[]
|
||||
correspondents: Correspondent[]
|
||||
documentTypes: DocumentType[]
|
||||
@ -170,6 +182,7 @@ export class WorkflowEditDialogComponent
|
||||
this.actionFields.push(
|
||||
new FormGroup({
|
||||
id: new FormControl(action.id),
|
||||
type: new FormControl(action.type),
|
||||
assign_title: new FormControl(action.assign_title),
|
||||
assign_tags: new FormControl(action.assign_tags),
|
||||
assign_owner: new FormControl(action.assign_owner),
|
||||
@ -191,12 +204,12 @@ export class WorkflowEditDialogComponent
|
||||
return DOCUMENT_SOURCE_OPTIONS
|
||||
}
|
||||
|
||||
get typeOptions() {
|
||||
get triggerTypeOptions() {
|
||||
return WORKFLOW_TYPE_OPTIONS
|
||||
}
|
||||
|
||||
getTypeOptionName(type: WorkflowTriggerType): string {
|
||||
return this.typeOptions.find((t) => t.id === type)?.name ?? ''
|
||||
getTriggerTypeOptionName(type: WorkflowTriggerType): string {
|
||||
return this.triggerTypeOptions.find((t) => t.id === type)?.name ?? ''
|
||||
}
|
||||
|
||||
addTrigger() {
|
||||
@ -214,8 +227,17 @@ export class WorkflowEditDialogComponent
|
||||
this.updateTriggerActionFields()
|
||||
}
|
||||
|
||||
get actionTypeOptions() {
|
||||
return WORKFLOW_ACTION_OPTIONS
|
||||
}
|
||||
|
||||
getActionTypeOptionName(type: WorkflowActionType): string {
|
||||
return this.actionTypeOptions.find((t) => t.id === type)?.name ?? ''
|
||||
}
|
||||
|
||||
addAction() {
|
||||
this.object.actions.push({
|
||||
type: WorkflowActionType.Assignment,
|
||||
assign_title: null,
|
||||
assign_tags: [],
|
||||
assign_document_type: null,
|
||||
|
@ -22,6 +22,7 @@ import {
|
||||
DocumentSource,
|
||||
WorkflowTriggerType,
|
||||
} from 'src/app/data/workflow-trigger'
|
||||
import { WorkflowActionType } from 'src/app/data/workflow-action'
|
||||
|
||||
const workflows: Workflow[] = [
|
||||
{
|
||||
@ -40,6 +41,7 @@ const workflows: Workflow[] = [
|
||||
actions: [
|
||||
{
|
||||
id: 1,
|
||||
type: WorkflowActionType.Assignment,
|
||||
assign_title: 'foo',
|
||||
},
|
||||
],
|
||||
@ -59,6 +61,7 @@ const workflows: Workflow[] = [
|
||||
actions: [
|
||||
{
|
||||
id: 2,
|
||||
type: WorkflowActionType.Assignment,
|
||||
assign_title: 'bar',
|
||||
},
|
||||
],
|
||||
|
@ -1,6 +1,11 @@
|
||||
import { ObjectWithId } from './object-with-id'
|
||||
|
||||
export enum WorkflowActionType {
|
||||
Assignment = 1,
|
||||
}
|
||||
export interface WorkflowAction extends ObjectWithId {
|
||||
type: WorkflowActionType
|
||||
|
||||
assign_title?: string
|
||||
|
||||
assign_tags?: number[] // Tag.id
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
DocumentSource,
|
||||
WorkflowTriggerType,
|
||||
} from 'src/app/data/workflow-trigger'
|
||||
import { WorkflowActionType } from 'src/app/data/workflow-action'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: WorkflowService
|
||||
@ -29,6 +30,7 @@ const workflows: Workflow[] = [
|
||||
actions: [
|
||||
{
|
||||
id: 1,
|
||||
type: WorkflowActionType.Assignment,
|
||||
assign_title: 'foo',
|
||||
},
|
||||
],
|
||||
@ -48,6 +50,7 @@ const workflows: Workflow[] = [
|
||||
actions: [
|
||||
{
|
||||
id: 2,
|
||||
type: WorkflowActionType.Assignment,
|
||||
assign_title: 'bar',
|
||||
},
|
||||
],
|
||||
|
@ -223,6 +223,14 @@ class Migration(migrations.Migration):
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
(
|
||||
"type",
|
||||
models.PositiveIntegerField(
|
||||
choices=[(1, "Assignment")],
|
||||
default=1,
|
||||
verbose_name="Workflow Action Type",
|
||||
),
|
||||
),
|
||||
(
|
||||
"assign_title",
|
||||
models.CharField(
|
||||
|
@ -974,6 +974,15 @@ class WorkflowTrigger(models.Model):
|
||||
|
||||
|
||||
class WorkflowAction(models.Model):
|
||||
class WorkflowActionType(models.IntegerChoices):
|
||||
ASSIGNMENT = 1, _("Assignment")
|
||||
|
||||
type = models.PositiveIntegerField(
|
||||
_("Workflow Action Type"),
|
||||
choices=WorkflowActionType.choices,
|
||||
default=WorkflowActionType.ASSIGNMENT,
|
||||
)
|
||||
|
||||
assign_title = models.CharField(
|
||||
_("assign title"),
|
||||
max_length=256,
|
||||
|
@ -1334,6 +1334,7 @@ class WorkflowActionSerializer(serializers.ModelSerializer):
|
||||
model = WorkflowAction
|
||||
fields = [
|
||||
"id",
|
||||
"type",
|
||||
"assign_title",
|
||||
"assign_tags",
|
||||
"assign_correspondent",
|
||||
|
Loading…
x
Reference in New Issue
Block a user