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