mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-17 11:21:29 +00:00
Chorehancement: move all bulk operations to async hand-off (#14773)
This commit is contained in:
1 parent
28bb63824f
commit
de75249e51
39 files changed
+1633
-421
No files matched your search
@@ -175,7 +175,13 @@
|
||||
</div>
|
||||
</td>
|
||||
<td class="overflow-auto name-col">
|
||||
<div>{{ taskDisplayName(task) }}</div>
|
||||
@let documentCount = taskDocumentCount(task);
|
||||
<div>
|
||||
{{ taskDisplayName(task) }}
|
||||
@if (documentCount !== null && documentCount > 1) {
|
||||
<small class="text-muted ms-1" i18n>({documentCount, plural, =1 {1 document} other {{{ documentCount }} documents}})</small>
|
||||
}
|
||||
</div>
|
||||
<div class="small text-muted">
|
||||
@if (taskShowsSeparateTypeLabel(task)) {
|
||||
<span class="me-2">{{ task.task_type_display }}</span>
|
||||
|
||||
@@ -895,6 +895,117 @@ describe('TasksComponent', () => {
|
||||
expect(sanityTaskRow.nativeElement.textContent).toContain('System')
|
||||
})
|
||||
|
||||
it.each([
|
||||
['modify_tags', 12, 'Bulk operation: Update tags', '(12 documents)'],
|
||||
['run_workflow', 1, 'Run workflow', null],
|
||||
['delete', 3, 'Bulk operation: Move to trash', '(3 documents)'],
|
||||
['reprocess', 2, 'Bulk operation: Document reprocessing', '(2 documents)'],
|
||||
])(
|
||||
'shows the operation, document count and outcome for %s',
|
||||
(operation, count, label, summary) => {
|
||||
const task: PaperlessTask = {
|
||||
...tasks[4],
|
||||
task_type:
|
||||
operation === 'delete'
|
||||
? PaperlessTaskType.BulkDelete
|
||||
: PaperlessTaskType.BulkUpdate,
|
||||
task_type_display:
|
||||
operation === 'delete' ? 'Bulk Delete' : 'Bulk Update',
|
||||
trigger_source: PaperlessTaskTriggerSource.WebUI,
|
||||
trigger_source_display: 'Web UI',
|
||||
input_data: { operation, document_count: count },
|
||||
result_data: { operation, document_count: count },
|
||||
}
|
||||
component.setSection(TaskSection.Completed)
|
||||
flushTaskLists(25, 1, [task])
|
||||
fixture.detectChanges()
|
||||
|
||||
const name = fixture.nativeElement.querySelector('tbody .name-col')
|
||||
expect(name.textContent).toContain(label)
|
||||
const countLabel = name.querySelector('small.text-muted')
|
||||
if (summary) {
|
||||
expect(countLabel.textContent).toContain(summary)
|
||||
} else {
|
||||
expect(countLabel).toBeNull()
|
||||
expect(name.textContent).not.toContain('Bulk operation:')
|
||||
}
|
||||
expect(name.textContent).not.toContain('·')
|
||||
expect(name.textContent).toContain('Web UI')
|
||||
expect(name.textContent).not.toContain(task.task_type_display)
|
||||
expect(
|
||||
name.closest('tr').querySelector('.results-col').textContent
|
||||
).toContain(
|
||||
[
|
||||
'reprocess',
|
||||
'rotate',
|
||||
'merge',
|
||||
'split',
|
||||
'delete_pages',
|
||||
'edit_pdf',
|
||||
'remove_password',
|
||||
].includes(operation)
|
||||
? 'Submitted for processing'
|
||||
: 'Completed'
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
it('shows operation context while work is pending without reporting completion', () => {
|
||||
const task = {
|
||||
...tasks[2],
|
||||
task_type: PaperlessTaskType.BulkUpdate,
|
||||
task_type_display: 'Bulk Update',
|
||||
input_data: { operation: 'reprocess', document_count: 1 },
|
||||
}
|
||||
component.setSection(TaskSection.InProgress)
|
||||
flushTaskLists(25, 1, [task])
|
||||
fixture.detectChanges()
|
||||
|
||||
const name = fixture.nativeElement.querySelector('tbody .name-col')
|
||||
expect(name.textContent).toContain('Document reprocessing')
|
||||
expect(name.textContent).not.toContain('Bulk operation:')
|
||||
expect(name.querySelector('small')).toBeNull()
|
||||
expect(component.taskResultMessage(task)).toBeNull()
|
||||
})
|
||||
|
||||
it.each([{}, { operation: 'future_operation' }])(
|
||||
'preserves the fallback for legacy or unknown operation data: %j',
|
||||
(input_data) => {
|
||||
const task = {
|
||||
...tasks[4],
|
||||
task_type: PaperlessTaskType.BulkUpdate,
|
||||
task_type_display: 'Bulk Update',
|
||||
input_data,
|
||||
result_data: {},
|
||||
}
|
||||
expect(component.taskDisplayName(task)).toBe('Bulk Update')
|
||||
expect(component.taskDocumentCount(task)).toBeNull()
|
||||
expect(component.taskResultMessage(task)).toBeNull()
|
||||
}
|
||||
)
|
||||
|
||||
it.each([-1, 1.5, '2', null, undefined])(
|
||||
'does not display an invalid document count: %s',
|
||||
(document_count) => {
|
||||
expect(
|
||||
component.taskDocumentCount({
|
||||
...tasks[4],
|
||||
input_data: { operation: 'modify_tags', document_count },
|
||||
})
|
||||
).toBeNull()
|
||||
}
|
||||
)
|
||||
|
||||
it('retains error details for failed operation tasks', () => {
|
||||
expect(
|
||||
component.taskResultMessage({
|
||||
...tasks[0],
|
||||
input_data: { operation: 'modify_tags', document_count: 12 },
|
||||
result_data: { error_message: 'Insufficient permissions' },
|
||||
})
|
||||
).toBe('Insufficient permissions')
|
||||
})
|
||||
|
||||
it('should filter tasks by result', () => {
|
||||
component.setSection(TaskSection.NeedsAttention)
|
||||
component.filterTargetID = 1
|
||||
|
||||
@@ -33,6 +33,10 @@ import { IfPermissionsDirective } from 'src/app/directives/if-permissions.direct
|
||||
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
|
||||
import { TasksService } from 'src/app/services/tasks.service'
|
||||
import { ToastService } from 'src/app/services/toast.service'
|
||||
import {
|
||||
documentOperationHasFollowUpTasks,
|
||||
getDocumentOperationLabel,
|
||||
} from 'src/app/utils/document-operation'
|
||||
import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component'
|
||||
import { PageHeaderComponent } from '../../common/page-header/page-header.component'
|
||||
import { LoadingComponentWithPermissions } from '../../loading-component/loading.component'
|
||||
@@ -414,11 +418,30 @@ export class TasksComponent
|
||||
}
|
||||
|
||||
taskDisplayName(task: PaperlessTask): string {
|
||||
return task.input_data?.filename?.toString() || task.task_type_display
|
||||
const filename = task.input_data?.filename?.toString()
|
||||
if (filename) return filename
|
||||
const operation = this.taskOperationLabel(task)
|
||||
const count = this.taskDocumentCount(task)
|
||||
if (operation && count !== null && count > 1) {
|
||||
return $localize`Bulk operation: ${operation}`
|
||||
}
|
||||
return operation || task.task_type_display
|
||||
}
|
||||
|
||||
taskShowsSeparateTypeLabel(task: PaperlessTask): boolean {
|
||||
return this.taskDisplayName(task) !== task.task_type_display
|
||||
return (
|
||||
!this.taskOperationLabel(task) &&
|
||||
this.taskDisplayName(task) !== task.task_type_display
|
||||
)
|
||||
}
|
||||
|
||||
private taskOperationLabel(task: PaperlessTask): string | null {
|
||||
return getDocumentOperationLabel(task.input_data?.operation)
|
||||
}
|
||||
|
||||
taskDocumentCount(task: PaperlessTask): number | null {
|
||||
const count = task.input_data?.document_count
|
||||
return Number.isInteger(count) && count >= 0 ? count : null
|
||||
}
|
||||
|
||||
taskResultMessage(task: PaperlessTask): string | null {
|
||||
@@ -446,6 +469,15 @@ export class TasksComponent
|
||||
return errorMessage
|
||||
}
|
||||
|
||||
if (
|
||||
task.status === PaperlessTaskStatus.Success &&
|
||||
this.taskOperationLabel(task)
|
||||
) {
|
||||
return documentOperationHasFollowUpTasks(task.input_data?.operation)
|
||||
? $localize`Submitted for processing`
|
||||
: $localize`Completed`
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user