Add related_document and direct link from task UI

This commit is contained in:
Michael Shamoon 2022-09-27 20:50:26 -07:00
parent 5162bdd404
commit 4fe37f6aee
4 changed files with 40 additions and 6 deletions

View File

@ -74,11 +74,18 @@
</button> </button>
</td> </td>
<td scope="row"> <td scope="row">
<div class="btn-group" role="group">
<button class="btn btn-sm btn-outline-secondary" (click)="dismissTask(task); $event.stopPropagation();"> <button class="btn btn-sm btn-outline-secondary" (click)="dismissTask(task); $event.stopPropagation();">
<svg class="sidebaricon" fill="currentColor"> <svg class="sidebaricon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#check"/> <use xlink:href="assets/bootstrap-icons.svg#check"/>
</svg>&nbsp;<ng-container i18n>Dismiss</ng-container> </svg>&nbsp;<ng-container i18n>Dismiss</ng-container>
</button> </button>
<button *ngIf="task.related_document" class="btn btn-sm btn-outline-primary" (click)="dismissAndGo(task); $event.stopPropagation();">
<svg class="sidebaricon" fill="currentColor">
<use xlink:href="assets/bootstrap-icons.svg#file-text"/>
</svg>&nbsp;<ng-container i18n>Open Document</ng-container>
</button>
</div>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@ -1,4 +1,5 @@
import { Component, OnInit, OnDestroy } from '@angular/core' import { Component, OnInit, OnDestroy } from '@angular/core'
import { Router } from '@angular/router'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { Subject, first } from 'rxjs' import { Subject, first } from 'rxjs'
import { PaperlessTask } from 'src/app/data/paperless-task' import { PaperlessTask } from 'src/app/data/paperless-task'
@ -24,7 +25,8 @@ export class TasksComponent implements OnInit, OnDestroy {
constructor( constructor(
public tasksService: TasksService, public tasksService: TasksService,
private modalService: NgbModal private modalService: NgbModal,
private readonly router: Router
) {} ) {}
ngOnInit() { ngOnInit() {
@ -64,6 +66,11 @@ export class TasksComponent implements OnInit, OnDestroy {
} }
} }
dismissAndGo(task: PaperlessTask) {
this.dismissTask(task)
this.router.navigate(['documents', task.related_document])
}
expandTask(task: PaperlessTask) { expandTask(task: PaperlessTask) {
this.expandedTask = this.expandedTask == task.id ? undefined : task.id this.expandedTask = this.expandedTask == task.id ? undefined : task.id
} }

View File

@ -28,4 +28,6 @@ export interface PaperlessTask extends ObjectWithId {
done?: Date done?: Date
result: string result: string
related_document?: number
} }

View File

@ -633,6 +633,7 @@ class TasksViewSerializer(serializers.ModelSerializer):
"acknowledged", "acknowledged",
"task_name", "task_name",
"name", "name",
"related_document",
) )
type = serializers.SerializerMethodField() type = serializers.SerializerMethodField()
@ -726,6 +727,23 @@ class TasksViewSerializer(serializers.ModelSerializer):
return result return result
related_document = serializers.SerializerMethodField()
def get_related_document(self, obj):
result = ""
regexp = r"New document id (\d+) created"
if (
hasattr(obj, "attempted_task")
and obj.attempted_task
and obj.attempted_task.status == "SUCCESS"
):
try:
result = re.search(regexp, obj.attempted_task.result).group(1)
except Exception:
pass
return result
class AcknowledgeTasksViewSerializer(serializers.Serializer): class AcknowledgeTasksViewSerializer(serializers.Serializer):