From 2d974bc0264082ba387de1bbf2952e6fa0545405 Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Fri, 30 Oct 2020 22:51:16 +0100 Subject: [PATCH] refactor constant --- .../document-list/document-list.component.ts | 4 ++-- .../services/document-list-view.service.ts | 21 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) 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 21537d224..0f18a8a65 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 @@ -3,7 +3,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { cloneFilterRules, FilterRule } from 'src/app/data/filter-rule'; import { SavedViewConfig } from 'src/app/data/saved-view-config'; -import { DocumentListViewService } from 'src/app/services/document-list-view.service'; +import { DocumentListViewService, SORT_FIELDS } from 'src/app/services/document-list-view.service'; import { SavedViewConfigService } from 'src/app/services/saved-view-config.service'; import { SaveViewConfigDialogComponent } from './save-view-config-dialog/save-view-config-dialog.component'; @@ -26,7 +26,7 @@ export class DocumentListComponent implements OnInit { showFilter = false getSortFields() { - return DocumentListViewService.SORT_FIELDS + return SORT_FIELDS } setSort(field: string) { 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 323a0a38e..91ac52d13 100644 --- a/src-ui/src/app/services/document-list-view.service.ts +++ b/src-ui/src/app/services/document-list-view.service.ts @@ -5,6 +5,15 @@ import { PaperlessDocument } from '../data/paperless-document'; import { SavedViewConfig } from '../data/saved-view-config'; import { DocumentService } from './rest/document.service'; +export const SORT_FIELDS = [ + {field: "correspondent__name", name: "Correspondent"}, + {field: 'title', name: 'Title'}, + {field: 'archive_serial_number', name: 'ASN'}, + {field: 'created', name: 'Created'}, + {field: 'added', name: 'Added'}, + {field: 'modified', name: 'Modified'} +] + @Injectable({ providedIn: 'root' }) @@ -12,15 +21,6 @@ export class DocumentListViewService { static DEFAULT_SORT_FIELD = 'created' - static SORT_FIELDS = [ - {field: "correspondent__name", name: "Correspondent"}, - {field: 'title', name: 'Title'}, - {field: 'archive_serial_number', name: 'ASN'}, - {field: 'created', name: 'Created'}, - {field: 'added', name: 'Added'}, - {field: 'modified', name: 'Modified'} - ] - documents: PaperlessDocument[] = [] currentPage = 1 collectionSize: number @@ -63,14 +63,13 @@ export class DocumentListViewService { } getOrderingQueryParam(sortField: string, sortDirection: string) { - if (DocumentListViewService.SORT_FIELDS.find(f => f.field == sortField)) { + if (SORT_FIELDS.find(f => f.field == sortField)) { return (sortDirection == 'des' ? '-' : '') + sortField } else { return DocumentListViewService.DEFAULT_SORT_FIELD } } - //TODO: refactor setFilterRules(filterRules: FilterRule[]) { this.currentFilterRules = cloneFilterRules(filterRules) }