This commit is contained in:
jonaswinkler 2021-01-04 17:08:52 +01:00
parent 32f371fcb6
commit 9bbcb9319c
7 changed files with 77 additions and 45 deletions

View File

@ -99,12 +99,54 @@
<table class="table table-sm border shadow-sm" *ngIf="displayMode == 'details'"> <table class="table table-sm border shadow-sm" *ngIf="displayMode == 'details'">
<thead> <thead>
<th></th> <th></th>
<th class="d-none d-lg-table-cell" i18n>ASN</th> <th class="d-none d-lg-table-cell"
<th class="d-none d-md-table-cell" i18n>Correspondent</th> sortable="archive_serial_number"
<th i18n>Title</th> [currentSortField]="list.sortField"
<th class="d-none d-xl-table-cell" i18n>Document type</th> [currentSortReverse]="list.sortReverse"
<th i18n>Created</th> (sort)="onSort($event)"
<th class="d-none d-xl-table-cell" i18n>Added</th> i18n>
ASN
</th>
<th class="d-none d-md-table-cell"
sortable="correspondent__name"
[currentSortField]="list.sortField"
[currentSortReverse]="list.sortReverse"
(sort)="onSort($event)"
i18n>
Correspondent
</th>
<th
sortable="title"
[currentSortField]="list.sortField"
[currentSortReverse]="list.sortReverse"
(sort)="onSort($event)"
i18n>
Title
</th>
<th class="d-none d-xl-table-cell"
sortable="document_type__name"
[currentSortField]="list.sortField"
[currentSortReverse]="list.sortReverse"
(sort)="onSort($event)"
i18n>
Document type
</th>
<th
sortable="created"
[currentSortField]="list.sortField"
[currentSortReverse]="list.sortReverse"
(sort)="onSort($event)"
i18n>
Created
</th>
<th class="d-none d-xl-table-cell"
sortable="added"
[currentSortField]="list.sortField"
[currentSortReverse]="list.sortReverse"
(sort)="onSort($event)"
i18n>
Added
</th>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let d of list.documents; trackBy: trackByDocumentId" [ngClass]="list.isSelected(d) ? 'table-row-selected' : ''"> <tr *ngFor="let d of list.documents; trackBy: trackByDocumentId" [ngClass]="list.isSelected(d) ? 'table-row-selected' : ''">

View File

@ -1,8 +1,9 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { AfterViewInit, Component, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { PaperlessDocument } from 'src/app/data/paperless-document'; import { PaperlessDocument } from 'src/app/data/paperless-document';
import { PaperlessSavedView } from 'src/app/data/paperless-saved-view'; import { PaperlessSavedView } from 'src/app/data/paperless-saved-view';
import { SortableDirective, SortEvent } from 'src/app/directives/sortable.directive';
import { DocumentListViewService } from 'src/app/services/document-list-view.service'; import { DocumentListViewService } from 'src/app/services/document-list-view.service';
import { DOCUMENT_SORT_FIELDS } from 'src/app/services/rest/document.service'; import { DOCUMENT_SORT_FIELDS } from 'src/app/services/rest/document.service';
import { SavedViewService } from 'src/app/services/rest/saved-view.service'; import { SavedViewService } from 'src/app/services/rest/saved-view.service';
@ -28,6 +29,8 @@ export class DocumentListComponent implements OnInit {
@ViewChild("filterEditor") @ViewChild("filterEditor")
private filterEditor: FilterEditorComponent private filterEditor: FilterEditorComponent
@ViewChildren(SortableDirective) headers: QueryList<SortableDirective>;
displayMode = 'smallCards' // largeCards, smallCards, details displayMode = 'smallCards' // largeCards, smallCards, details
get isFiltered() { get isFiltered() {
@ -42,6 +45,10 @@ export class DocumentListComponent implements OnInit {
return DOCUMENT_SORT_FIELDS return DOCUMENT_SORT_FIELDS
} }
onSort(event: SortEvent) {
this.list.setSort(event.column, event.reverse)
}
get isBulkEditing(): boolean { get isBulkEditing(): boolean {
return this.list.selected.size > 0 return this.list.selected.size > 0
} }
@ -73,7 +80,6 @@ export class DocumentListComponent implements OnInit {
}) })
} }
loadViewConfig(view: PaperlessSavedView) { loadViewConfig(view: PaperlessSavedView) {
this.list.load(view) this.list.load(view)
this.list.reload() this.list.reload()

View File

@ -9,10 +9,10 @@
<table class="table table-striped border shadow"> <table class="table table-striped border shadow">
<thead> <thead>
<tr> <tr>
<th scope="col" sortable="name" (sort)="onSort($event)" i18n>Name</th> <th scope="col" sortable="name" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Name</th>
<th scope="col" sortable="matching_algorithm" (sort)="onSort($event)" i18n>Matching</th> <th scope="col" sortable="matching_algorithm" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Matching</th>
<th scope="col" sortable="document_count" (sort)="onSort($event)" i18n>Document count</th> <th scope="col" sortable="document_count" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Document count</th>
<th scope="col" sortable="last_correspondence" (sort)="onSort($event)" i18n>Last correspondence</th> <th scope="col" sortable="last_correspondence" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Last correspondence</th>
<th scope="col" i18n>Actions</th> <th scope="col" i18n>Actions</th>
</tr> </tr>
</thead> </thead>

View File

@ -10,9 +10,9 @@
<table class="table table-striped border shadow"> <table class="table table-striped border shadow">
<thead> <thead>
<tr> <tr>
<th scope="col" sortable="name" (sort)="onSort($event)" i18n>Name</th> <th scope="col" sortable="name" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Name</th>
<th scope="col" sortable="matching_algorithm" (sort)="onSort($event)" i18n>Matching</th> <th scope="col" sortable="matching_algorithm" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Matching</th>
<th scope="col" sortable="document_count" (sort)="onSort($event)" i18n>Document count</th> <th scope="col" sortable="document_count" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Document count</th>
<th scope="col" i18n>Actions</th> <th scope="col" i18n>Actions</th>
</tr> </tr>
</thead> </thead>

View File

@ -39,21 +39,8 @@ export abstract class GenericListComponent<T extends ObjectWithId> implements On
} }
onSort(event: SortEvent) { onSort(event: SortEvent) {
if (event.sorted) {
this.sortField = event.column this.sortField = event.column
this.sortReverse = event.reverse this.sortReverse = event.reverse
} else {
this.sortField = null
this.sortReverse = false
}
this.headers.forEach(header => {
if (header.sortable !== this.sortField) {
header.sorted = false
}
});
this.reloadData() this.reloadData()
} }

View File

@ -10,10 +10,10 @@
<table class="table table-striped border shadow-sm"> <table class="table table-striped border shadow-sm">
<thead> <thead>
<tr> <tr>
<th scope="col" sortable="name" (sort)="onSort($event)" i18n>Name</th> <th scope="col" sortable="name" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Name</th>
<th scope="col" i18n>Color</th> <th scope="col" i18n>Color</th>
<th scope="col" sortable="matching_algorithm" (sort)="onSort($event)" i18n>Matching</th> <th scope="col" sortable="matching_algorithm" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Matching</th>
<th scope="col" sortable="document_count" (sort)="onSort($event)" i18n>Document count</th> <th scope="col" sortable="document_count" [currentSortField]="sortField" [currentSortReverse]="sortReverse" (sort)="onSort($event)" i18n>Document count</th>
<th scope="col" i18n>Actions</th> <th scope="col" i18n>Actions</th>
</tr> </tr>
</thead> </thead>

View File

@ -2,15 +2,14 @@ import { Directive, EventEmitter, Input, Output } from '@angular/core';
export interface SortEvent { export interface SortEvent {
column: string column: string
sorted: boolean
reverse: boolean reverse: boolean
} }
@Directive({ @Directive({
selector: 'th[sortable]', selector: 'th[sortable]',
host: { host: {
'[class.asc]': 'sorted && !reverse', '[class.asc]': 'currentSortField == sortable && !currentSortReverse',
'[class.des]': 'sorted && reverse', '[class.des]': 'currentSortField == sortable && currentSortReverse',
'(click)': 'rotate()' '(click)': 'rotate()'
} }
}) })
@ -22,22 +21,20 @@ export class SortableDirective {
sortable: string = ''; sortable: string = '';
@Input() @Input()
sorted: boolean = false currentSortReverse: boolean = false
@Input() @Input()
reverse: boolean = false currentSortField: string
@Output() sort = new EventEmitter<SortEvent>(); @Output() sort = new EventEmitter<SortEvent>();
rotate() { rotate() {
if (!this.sorted) { if (this.currentSortField != this.sortable) {
this.sorted = true this.sort.emit({column: this.sortable, reverse: false});
this.reverse = false } else if (this.currentSortField == this.sortable && !this.currentSortReverse) {
} else if (this.sorted && !this.reverse) { this.sort.emit({column: this.currentSortField, reverse: true});
this.reverse = true
} else { } else {
this.sorted = false this.sort.emit({column: null, reverse: false});
} }
this.sort.emit({column: this.sortable, sorted: this.sorted, reverse: this.reverse});
} }
} }