diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index 6ec2b3815..f2f1533d0 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -943,11 +943,11 @@ src/app/components/document-list/document-list.component.html - 175 + 177 src/app/services/rest/document.service.ts - 32 + 262 @@ -1674,7 +1674,7 @@ src/app/components/document-list/document-list.component.html - 201 + 203 src/app/components/document-list/filter-editor/filter-editor.component.html @@ -1682,7 +1682,7 @@ src/app/services/rest/document.service.ts - 29 + 255 @@ -2251,7 +2251,7 @@ src/app/components/document-list/document-list.component.ts - 99 + 97 src/app/components/manage/management-list/management-list.component.html @@ -4822,7 +4822,7 @@ src/app/services/rest/document.service.ts - 27 + 239 @@ -4849,7 +4849,7 @@ src/app/services/rest/document.service.ts - 26 + 236 @@ -5166,7 +5166,7 @@ src/app/components/document-list/document-list.component.html - 184 + 186 src/app/components/document-list/filter-editor/filter-editor.component.html @@ -5174,7 +5174,7 @@ src/app/services/rest/document.service.ts - 28 + 249 @@ -5189,7 +5189,7 @@ src/app/components/document-list/document-list.component.html - 193 + 195 src/app/components/document-list/filter-editor/filter-editor.component.html @@ -5861,7 +5861,7 @@ src/app/components/document-list/document-list.component.html - 225 + 227 @@ -5872,7 +5872,7 @@ src/app/components/document-list/document-list.component.html - 232 + 234 @@ -5897,7 +5897,7 @@ src/app/components/document-list/document-list.component.html - 252 + 256 @@ -5908,7 +5908,7 @@ src/app/components/document-list/document-list.component.html - 259 + 263 @@ -6094,7 +6094,7 @@ src/app/services/rest/document.service.ts - 25 + 226 @@ -6115,60 +6115,60 @@ Sort by owner src/app/components/document-list/document-list.component.html - 163 + 164 Owner src/app/components/document-list/document-list.component.html - 167 + 168 src/app/services/rest/document.service.ts - 33 + 271 Sort by notes src/app/components/document-list/document-list.component.html - 171 + 173 Sort by document type src/app/components/document-list/document-list.component.html - 180 + 182 Sort by storage path src/app/components/document-list/document-list.component.html - 189 + 191 Sort by created date src/app/components/document-list/document-list.component.html - 197 + 199 Sort by added date src/app/components/document-list/document-list.component.html - 204 + 206 Added src/app/components/document-list/document-list.component.html - 208 + 210 src/app/components/document-list/filter-editor/filter-editor.component.html @@ -6176,28 +6176,28 @@ src/app/services/rest/document.service.ts - 30 + 256 Edit document src/app/components/document-list/document-list.component.html - 230 + 232 View "" saved successfully. src/app/components/document-list/document-list.component.ts - 209 + 207 View "" created successfully. src/app/components/document-list/document-list.component.ts - 250 + 248 @@ -7532,14 +7532,14 @@ Modified src/app/services/rest/document.service.ts - 31 + 257 Search score src/app/services/rest/document.service.ts - 40 + 277 Score is a value returned by the full text search engine and specifies how well a result matches the given query diff --git a/src-ui/src/app/components/document-list/document-list.component.html b/src-ui/src/app/components/document-list/document-list.component.html index 3cce1496b..d2f714951 100644 --- a/src-ui/src/app/components/document-list/document-list.component.html +++ b/src-ui/src/app/components/document-list/document-list.component.html @@ -40,7 +40,7 @@
- @for (f of getSortFields(); track f) { + @for (f of getSortFields(); track f.name) { @@ -158,13 +158,15 @@ [currentSortReverse]="list.sortReverse" (sort)="onSort($event)" i18n>Title - Owner + @if (permissionService.currentUserCan(PermissionAction.View, PermissionType.User)) { + Owner + } @if (notesEnabled) { } - - {{d.owner | username}} - + @if (permissionService.currentUserCan(PermissionAction.View, PermissionType.User)) { + + {{d.owner | username}} + + } @if (notesEnabled) { @if (d.notes.length) { diff --git a/src-ui/src/app/components/document-list/document-list.component.spec.ts b/src-ui/src/app/components/document-list/document-list.component.spec.ts index 77dc03f84..7c52b665a 100644 --- a/src-ui/src/app/components/document-list/document-list.component.spec.ts +++ b/src-ui/src/app/components/document-list/document-list.component.spec.ts @@ -48,11 +48,7 @@ import { DocumentCardLargeComponent } from './document-card-large/document-card- import { DocumentTitlePipe } from 'src/app/pipes/document-title.pipe' import { UsernamePipe } from 'src/app/pipes/username.pipe' import { Document } from 'src/app/data/document' -import { - DOCUMENT_SORT_FIELDS, - DOCUMENT_SORT_FIELDS_FULLTEXT, - DocumentService, -} from 'src/app/services/rest/document.service' +import { DocumentService } from 'src/app/services/rest/document.service' import { ConfirmDialogComponent } from '../common/confirm-dialog/confirm-dialog.component' import { SafeHtmlPipe } from 'src/app/pipes/safehtml.pipe' import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-view-config-dialog.component' @@ -199,7 +195,9 @@ describe('DocumentListComponent', () => { }, ] fixture.detectChanges() - expect(component.getSortFields()).toEqual(DOCUMENT_SORT_FIELDS) + expect(component.getSortFields()).toEqual( + documentService.getSortFields(false) + ) documentListService.filterRules = [ { @@ -208,7 +206,9 @@ describe('DocumentListComponent', () => { }, ] fixture.detectChanges() - expect(component.getSortFields()).toEqual(DOCUMENT_SORT_FIELDS_FULLTEXT) + expect(component.getSortFields()).toEqual( + documentService.getSortFields(true) + ) }) it('should determine if filtered, support reset', () => { @@ -578,7 +578,7 @@ describe('DocumentListComponent', () => { fixture.detectChanges() expect( fixture.debugElement.queryAll(By.directive(SortableDirective)) - ).toHaveLength(5) + ).toHaveLength(4) }) it('should support toggle on document objects', () => { diff --git a/src-ui/src/app/components/document-list/document-list.component.ts b/src-ui/src/app/components/document-list/document-list.component.ts index 7d27f4e3e..5ba477938 100644 --- a/src-ui/src/app/components/document-list/document-list.component.ts +++ b/src-ui/src/app/components/document-list/document-list.component.ts @@ -25,10 +25,7 @@ import { import { ConsumerStatusService } from 'src/app/services/consumer-status.service' import { DocumentListViewService } from 'src/app/services/document-list-view.service' import { OpenDocumentsService } from 'src/app/services/open-documents.service' -import { - DOCUMENT_SORT_FIELDS, - DOCUMENT_SORT_FIELDS_FULLTEXT, -} from 'src/app/services/rest/document.service' +import { DocumentService } from 'src/app/services/rest/document.service' import { PermissionsService } from 'src/app/services/permissions.service' import { SavedViewService } from 'src/app/services/rest/saved-view.service' import { SettingsService } from 'src/app/services/settings.service' @@ -56,7 +53,8 @@ export class DocumentListComponent private consumerStatusService: ConsumerStatusService, public openDocumentsService: OpenDocumentsService, private settingsService: SettingsService, - public permissionService: PermissionsService + public permissionService: PermissionsService, + private documentService: DocumentService ) { super() } @@ -102,9 +100,9 @@ export class DocumentListComponent } getSortFields() { - return isFullTextFilterRule(this.list.filterRules) - ? DOCUMENT_SORT_FIELDS_FULLTEXT - : DOCUMENT_SORT_FIELDS + return this.documentService.getSortFields( + isFullTextFilterRule(this.list.filterRules) + ) } set listSortReverse(reverse: boolean) { diff --git a/src-ui/src/app/services/document-list-view.service.ts b/src-ui/src/app/services/document-list-view.service.ts index e1881c2f2..9561b5726 100644 --- a/src-ui/src/app/services/document-list-view.service.ts +++ b/src-ui/src/app/services/document-list-view.service.ts @@ -12,11 +12,7 @@ import { SavedView } from '../data/saved-view' import { SETTINGS_KEYS } from '../data/ui-settings' import { DOCUMENT_LIST_SERVICE } from '../data/storage-keys' import { paramsFromViewState, paramsToViewState } from '../utils/query-params' -import { - DocumentService, - DOCUMENT_SORT_FIELDS, - SelectionData, -} from './rest/document.service' +import { DocumentService, SelectionData } from './rest/document.service' import { SettingsService } from './settings.service' /** @@ -281,9 +277,9 @@ export class DocumentListViewService { errorMessage = Object.keys(error.error) .map((fieldName) => { const fieldError: Array = error.error[fieldName] - return `${DOCUMENT_SORT_FIELDS.find( - (f) => f.field == fieldName - )?.name}: ${fieldError[0]}` + return `${this.documentService + .getSortFields(false) + .find((f) => f.field == fieldName)?.name}: ${fieldError[0]}` }) .join(', ') } else { diff --git a/src-ui/src/app/services/rest/document.service.ts b/src-ui/src/app/services/rest/document.service.ts index 5c0f0a1dc..4f0e9e554 100644 --- a/src-ui/src/app/services/rest/document.service.ts +++ b/src-ui/src/app/services/rest/document.service.ts @@ -21,26 +21,6 @@ import { import { SettingsService } from '../settings.service' import { SETTINGS, SETTINGS_KEYS } from 'src/app/data/ui-settings' -export const DOCUMENT_SORT_FIELDS = [ - { field: 'archive_serial_number', name: $localize`ASN` }, - { field: 'correspondent__name', name: $localize`Correspondent` }, - { field: 'title', name: $localize`Title` }, - { field: 'document_type__name', name: $localize`Document type` }, - { field: 'created', name: $localize`Created` }, - { field: 'added', name: $localize`Added` }, - { field: 'modified', name: $localize`Modified` }, - { field: 'num_notes', name: $localize`Notes` }, - { field: 'owner', name: $localize`Owner` }, -] - -export const DOCUMENT_SORT_FIELDS_FULLTEXT = [ - ...DOCUMENT_SORT_FIELDS, - { - field: 'score', - name: $localize`:Score is a value returned by the full text search engine and specifies how well a result matches the given query:Search score`, - }, -] - export interface SelectionDataItem { id: number document_count: number @@ -241,4 +221,64 @@ export class DocumentService extends AbstractPaperlessService { public set searchQuery(query: string) { this._searchQuery = query } + + getSortFields(fulltext: boolean) { + let result = [{ field: 'archive_serial_number', name: $localize`ASN` }] + + if ( + this.permissionsService.currentUserCan( + PermissionAction.View, + PermissionType.Correspondent + ) + ) { + result.push({ + field: 'correspondent__name', + name: $localize`Correspondent`, + }) + } + result.push({ field: 'title', name: $localize`Title` }) + + if ( + this.permissionsService.currentUserCan( + PermissionAction.View, + PermissionType.DocumentType + ) + ) { + result.push({ + field: 'document_type__name', + name: $localize`Document type`, + }) + } + + result.push( + ...[ + { field: 'created', name: $localize`Created` }, + { field: 'added', name: $localize`Added` }, + { field: 'modified', name: $localize`Modified` }, + ] + ) + + if (this.settingsService.get(SETTINGS_KEYS.NOTES_ENABLED)) { + result.push({ field: 'num_notes', name: $localize`Notes` }) + } + + if ( + this.permissionsService.currentUserCan( + PermissionAction.View, + PermissionType.User + ) + ) { + result.push({ field: 'owner', name: $localize`Owner` }) + } + + if (fulltext) { + result.push({ + field: 'score', + name: $localize`:Score is a value returned by the full text search engine and specifies how well a result matches the given query:Search score`, + }) + } + + console.log('Returing sort fields', result) + return result + } }