mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
Fix: workflow edit form loses unsaved changes in v2.3.1 (#5299)
This commit is contained in:
parent
a41dbdd12c
commit
86338465fb
@ -66,7 +66,7 @@ const workflow: Workflow = {
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('ConsumptionTemplateEditDialogComponent', () => {
|
describe('WorkflowEditDialogComponent', () => {
|
||||||
let component: WorkflowEditDialogComponent
|
let component: WorkflowEditDialogComponent
|
||||||
let settingsService: SettingsService
|
let settingsService: SettingsService
|
||||||
let fixture: ComponentFixture<WorkflowEditDialogComponent>
|
let fixture: ComponentFixture<WorkflowEditDialogComponent>
|
||||||
@ -219,6 +219,7 @@ describe('ConsumptionTemplateEditDialogComponent', () => {
|
|||||||
const action1 = workflow.actions[0]
|
const action1 = workflow.actions[0]
|
||||||
const action2 = workflow.actions[1]
|
const action2 = workflow.actions[1]
|
||||||
component.object = workflow
|
component.object = workflow
|
||||||
|
component.ngOnInit()
|
||||||
component.onActionDrop({ previousIndex: 0, currentIndex: 1 } as CdkDragDrop<
|
component.onActionDrop({ previousIndex: 0, currentIndex: 1 } as CdkDragDrop<
|
||||||
WorkflowAction[]
|
WorkflowAction[]
|
||||||
>)
|
>)
|
||||||
|
@ -19,6 +19,7 @@ import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service
|
|||||||
import { CustomField } from 'src/app/data/custom-field'
|
import { CustomField } from 'src/app/data/custom-field'
|
||||||
import {
|
import {
|
||||||
DocumentSource,
|
DocumentSource,
|
||||||
|
WorkflowTrigger,
|
||||||
WorkflowTriggerType,
|
WorkflowTriggerType,
|
||||||
} from 'src/app/data/workflow-trigger'
|
} from 'src/app/data/workflow-trigger'
|
||||||
import {
|
import {
|
||||||
@ -157,7 +158,7 @@ export class WorkflowEditDialogComponent
|
|||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
super.ngOnInit()
|
super.ngOnInit()
|
||||||
this.updateTriggerActionFields()
|
this.updateAllTriggerActionFields()
|
||||||
}
|
}
|
||||||
|
|
||||||
get triggerFields(): FormArray {
|
get triggerFields(): FormArray {
|
||||||
@ -168,9 +169,10 @@ export class WorkflowEditDialogComponent
|
|||||||
return this.objectForm.get('actions') as FormArray
|
return this.objectForm.get('actions') as FormArray
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateTriggerActionFields(emitEvent: boolean = false) {
|
private createTriggerField(
|
||||||
this.triggerFields.clear({ emitEvent: false })
|
trigger: WorkflowTrigger,
|
||||||
this.object?.triggers.forEach((trigger) => {
|
emitEvent: boolean = false
|
||||||
|
) {
|
||||||
this.triggerFields.push(
|
this.triggerFields.push(
|
||||||
new FormGroup({
|
new FormGroup({
|
||||||
id: new FormControl(trigger.id),
|
id: new FormControl(trigger.id),
|
||||||
@ -192,10 +194,12 @@ export class WorkflowEditDialogComponent
|
|||||||
}),
|
}),
|
||||||
{ emitEvent }
|
{ emitEvent }
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
|
||||||
this.actionFields.clear({ emitEvent: false })
|
private createActionField(
|
||||||
this.object?.actions.forEach((action) => {
|
action: WorkflowAction,
|
||||||
|
emitEvent: boolean = false
|
||||||
|
) {
|
||||||
this.actionFields.push(
|
this.actionFields.push(
|
||||||
new FormGroup({
|
new FormGroup({
|
||||||
id: new FormControl(action.id),
|
id: new FormControl(action.id),
|
||||||
@ -214,6 +218,17 @@ export class WorkflowEditDialogComponent
|
|||||||
}),
|
}),
|
||||||
{ emitEvent }
|
{ emitEvent }
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateAllTriggerActionFields(emitEvent: boolean = false) {
|
||||||
|
this.triggerFields.clear({ emitEvent: false })
|
||||||
|
this.object?.triggers.forEach((trigger) => {
|
||||||
|
this.createTriggerField(trigger, emitEvent)
|
||||||
|
})
|
||||||
|
|
||||||
|
this.actionFields.clear({ emitEvent: false })
|
||||||
|
this.object?.actions.forEach((action) => {
|
||||||
|
this.createActionField(action, emitEvent)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +248,7 @@ export class WorkflowEditDialogComponent
|
|||||||
if (!this.object) {
|
if (!this.object) {
|
||||||
this.object = Object.assign({}, this.objectForm.value)
|
this.object = Object.assign({}, this.objectForm.value)
|
||||||
}
|
}
|
||||||
this.object.triggers.push({
|
const trigger: WorkflowTrigger = {
|
||||||
type: WorkflowTriggerType.Consumption,
|
type: WorkflowTriggerType.Consumption,
|
||||||
sources: [],
|
sources: [],
|
||||||
filter_filename: null,
|
filter_filename: null,
|
||||||
@ -245,9 +260,9 @@ export class WorkflowEditDialogComponent
|
|||||||
matching_algorithm: MATCH_NONE,
|
matching_algorithm: MATCH_NONE,
|
||||||
match: null,
|
match: null,
|
||||||
is_insensitive: true,
|
is_insensitive: true,
|
||||||
})
|
}
|
||||||
|
this.object.triggers.push(trigger)
|
||||||
this.updateTriggerActionFields()
|
this.createTriggerField(trigger)
|
||||||
}
|
}
|
||||||
|
|
||||||
get actionTypeOptions() {
|
get actionTypeOptions() {
|
||||||
@ -262,7 +277,7 @@ export class WorkflowEditDialogComponent
|
|||||||
if (!this.object) {
|
if (!this.object) {
|
||||||
this.object = Object.assign({}, this.objectForm.value)
|
this.object = Object.assign({}, this.objectForm.value)
|
||||||
}
|
}
|
||||||
this.object.actions.push({
|
const action: WorkflowAction = {
|
||||||
type: WorkflowActionType.Assignment,
|
type: WorkflowActionType.Assignment,
|
||||||
assign_title: null,
|
assign_title: null,
|
||||||
assign_tags: [],
|
assign_tags: [],
|
||||||
@ -275,19 +290,19 @@ export class WorkflowEditDialogComponent
|
|||||||
assign_change_users: [],
|
assign_change_users: [],
|
||||||
assign_change_groups: [],
|
assign_change_groups: [],
|
||||||
assign_custom_fields: [],
|
assign_custom_fields: [],
|
||||||
})
|
}
|
||||||
|
this.object.actions.push(action)
|
||||||
this.updateTriggerActionFields()
|
this.createActionField(action)
|
||||||
}
|
}
|
||||||
|
|
||||||
removeTrigger(index: number) {
|
removeTrigger(index: number) {
|
||||||
this.object.triggers.splice(index, 1)
|
this.object.triggers.splice(index, 1).pop()
|
||||||
this.updateTriggerActionFields()
|
this.triggerFields.removeAt(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
removeAction(index: number) {
|
removeAction(index: number) {
|
||||||
this.object.actions.splice(index, 1)
|
this.object.actions.splice(index, 1)
|
||||||
this.updateTriggerActionFields()
|
this.actionFields.removeAt(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
onActionDrop(event: CdkDragDrop<WorkflowAction[]>) {
|
onActionDrop(event: CdkDragDrop<WorkflowAction[]>) {
|
||||||
@ -296,8 +311,10 @@ export class WorkflowEditDialogComponent
|
|||||||
event.previousIndex,
|
event.previousIndex,
|
||||||
event.currentIndex
|
event.currentIndex
|
||||||
)
|
)
|
||||||
|
const actionField = this.actionFields.at(event.previousIndex)
|
||||||
|
this.actionFields.removeAt(event.previousIndex)
|
||||||
|
this.actionFields.insert(event.currentIndex, actionField)
|
||||||
// removing id will effectively re-create the actions in this order
|
// removing id will effectively re-create the actions in this order
|
||||||
this.object.actions.forEach((a) => (a.id = null))
|
this.object.actions.forEach((a) => (a.id = null))
|
||||||
this.updateTriggerActionFields()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user