Feature: improve history display of object names etc (#7102)

This commit is contained in:
shamoon
2024-06-26 19:52:08 -07:00
committed by GitHub
parent 29e6371cd1
commit 0643db4347
3 changed files with 141 additions and 2 deletions

View File

@@ -1,6 +1,12 @@
import { Component, Input, OnInit } from '@angular/core'
import { Observable, first, map, of } from 'rxjs'
import { AuditLogAction, AuditLogEntry } from 'src/app/data/auditlog-entry'
import { DataType } from 'src/app/data/datatype'
import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
import { DocumentService } from 'src/app/services/rest/document.service'
import { StoragePathService } from 'src/app/services/rest/storage-path.service'
import { UserService } from 'src/app/services/rest/user.service'
@Component({
selector: 'pngx-document-history',
@@ -20,7 +26,13 @@ export class DocumentHistoryComponent implements OnInit {
public loading: boolean = true
public entries: AuditLogEntry[] = []
constructor(private documentService: DocumentService) {}
constructor(
private documentService: DocumentService,
private correspondentService: CorrespondentService,
private storagePathService: StoragePathService,
private documentTypeService: DocumentTypeService,
private userService: UserService
) {}
ngOnInit(): void {
if (this._documentId) {
@@ -33,4 +45,31 @@ export class DocumentHistoryComponent implements OnInit {
})
}
}
getPrettyName(type: DataType | string, id: string): Observable<string> {
switch (type) {
case DataType.Correspondent:
return this.correspondentService.getCached(parseInt(id, 10)).pipe(
first(),
map((correspondent) => correspondent?.name ?? id)
)
case DataType.DocumentType:
return this.documentTypeService.getCached(parseInt(id, 10)).pipe(
first(),
map((documentType) => documentType?.name ?? id)
)
case DataType.StoragePath:
return this.storagePathService.getCached(parseInt(id, 10)).pipe(
first(),
map((storagePath) => storagePath?.path ?? id)
)
case 'owner':
return this.userService.getCached(parseInt(id, 10)).pipe(
first(),
map((user) => user?.username ?? id)
)
default:
return of(id)
}
}
}