mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-10-10 02:16:12 -05:00
Good sonar
This commit is contained in:
@@ -426,7 +426,7 @@ export class WorkflowEditDialogComponent
|
|||||||
|
|
||||||
private allowedActionTypes = []
|
private allowedActionTypes = []
|
||||||
|
|
||||||
private triggerConditionOptionsMap = new WeakMap<
|
private readonly triggerConditionOptionsMap = new WeakMap<
|
||||||
FormArray,
|
FormArray,
|
||||||
TriggerConditionOption[]
|
TriggerConditionOption[]
|
||||||
>()
|
>()
|
||||||
@@ -654,21 +654,21 @@ export class WorkflowEditDialogComponent
|
|||||||
filter_custom_field_query: null,
|
filter_custom_field_query: null,
|
||||||
}
|
}
|
||||||
|
|
||||||
conditions.controls.forEach((control) => {
|
for (const control of conditions.controls) {
|
||||||
const type = control.get('type').value as TriggerConditionType
|
const type = control.get('type').value as TriggerConditionType
|
||||||
const values = control.get('values').value
|
const values = control.get('values').value
|
||||||
|
|
||||||
if (values === null || values === undefined) {
|
if (values === null || values === undefined) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(values) && values.length === 0) {
|
if (Array.isArray(values) && values.length === 0) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const handler = CONDITION_FILTER_HANDLERS[type]
|
const handler = CONDITION_FILTER_HANDLERS[type]
|
||||||
handler?.apply(aggregate, values)
|
handler?.apply(aggregate, values)
|
||||||
})
|
}
|
||||||
|
|
||||||
trigger.filter_has_tags = aggregate.filter_has_tags
|
trigger.filter_has_tags = aggregate.filter_has_tags
|
||||||
trigger.filter_has_all_tags = aggregate.filter_has_all_tags
|
trigger.filter_has_all_tags = aggregate.filter_has_all_tags
|
||||||
@@ -734,19 +734,19 @@ export class WorkflowEditDialogComponent
|
|||||||
private buildConditionFormArray(trigger: WorkflowTrigger): FormArray {
|
private buildConditionFormArray(trigger: WorkflowTrigger): FormArray {
|
||||||
const conditions = new FormArray([])
|
const conditions = new FormArray([])
|
||||||
|
|
||||||
this.conditionDefinitions.forEach((definition) => {
|
for (const definition of this.conditionDefinitions) {
|
||||||
const handler = CONDITION_FILTER_HANDLERS[definition.id]
|
const handler = CONDITION_FILTER_HANDLERS[definition.id]
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = handler.extract(trigger)
|
const value = handler.extract(trigger)
|
||||||
if (!handler.hasValue(value)) {
|
if (!handler.hasValue(value)) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
conditions.push(this.createConditionFormGroup(definition.id, value))
|
conditions.push(this.createConditionFormGroup(definition.id, value))
|
||||||
})
|
}
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
}
|
}
|
||||||
@@ -760,25 +760,20 @@ export class WorkflowEditDialogComponent
|
|||||||
const options = this.getConditionTypeOptionsForArray(conditions)
|
const options = this.getConditionTypeOptionsForArray(conditions)
|
||||||
const currentType = conditions.at(conditionIndex).get('type')
|
const currentType = conditions.at(conditionIndex).get('type')
|
||||||
.value as TriggerConditionType
|
.value as TriggerConditionType
|
||||||
const usedTypes = conditions.controls.map(
|
const usedTypes = new Set(
|
||||||
|
conditions.controls.map(
|
||||||
(control) => control.get('type').value as TriggerConditionType
|
(control) => control.get('type').value as TriggerConditionType
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
options.forEach((option) => {
|
for (const option of options) {
|
||||||
if (option.allowMultipleEntries) {
|
if (option.allowMultipleEntries) {
|
||||||
option.disabled = false
|
option.disabled = false
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const usedElsewhere = usedTypes.some((type, idx) => {
|
option.disabled = usedTypes.has(option.id) && option.id !== currentType
|
||||||
if (idx === conditionIndex) {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
return type === option.id
|
|
||||||
})
|
|
||||||
|
|
||||||
option.disabled = usedElsewhere && option.id !== currentType
|
|
||||||
})
|
|
||||||
|
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
@@ -822,7 +817,7 @@ export class WorkflowEditDialogComponent
|
|||||||
triggerFormGroup.markAsDirty()
|
triggerFormGroup.markAsDirty()
|
||||||
triggerFormGroup.markAsTouched()
|
triggerFormGroup.markAsTouched()
|
||||||
|
|
||||||
return conditions.at(conditions.length - 1) as FormGroup
|
return conditions.at(-1) as FormGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
removeCondition(triggerFormGroup: FormGroup, conditionIndex: number) {
|
removeCondition(triggerFormGroup: FormGroup, conditionIndex: number) {
|
||||||
@@ -956,7 +951,7 @@ export class WorkflowEditDialogComponent
|
|||||||
const parsed = JSON.parse(rawValue)
|
const parsed = JSON.parse(rawValue)
|
||||||
const expression = new CustomFieldQueryExpression(parsed)
|
const expression = new CustomFieldQueryExpression(parsed)
|
||||||
model.queries = [expression]
|
model.queries = [expression]
|
||||||
} catch (error) {
|
} catch {
|
||||||
model.clear(false)
|
model.clear(false)
|
||||||
model.addInitialAtom()
|
model.addInitialAtom()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user