mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
added sorting to management pages
This commit is contained in:
8
src-ui/src/app/directives/sortable.directive.spec.ts
Normal file
8
src-ui/src/app/directives/sortable.directive.spec.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { SortableDirective } from './sortable.directive';
|
||||
|
||||
describe('SortableDirective', () => {
|
||||
it('should create an instance', () => {
|
||||
const directive = new SortableDirective();
|
||||
expect(directive).toBeTruthy();
|
||||
});
|
||||
});
|
30
src-ui/src/app/directives/sortable.directive.ts
Normal file
30
src-ui/src/app/directives/sortable.directive.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Directive, EventEmitter, Input, Output } from '@angular/core';
|
||||
|
||||
export interface SortEvent {
|
||||
column: string;
|
||||
direction: string;
|
||||
}
|
||||
|
||||
const rotate: {[key: string]: string} = { 'asc': 'des', 'des': '', '': 'asc' };
|
||||
|
||||
@Directive({
|
||||
selector: 'th[sortable]',
|
||||
host: {
|
||||
'[class.asc]': 'direction === "asc"',
|
||||
'[class.des]': 'direction === "des"',
|
||||
'(click)': 'rotate()'
|
||||
}
|
||||
})
|
||||
export class SortableDirective {
|
||||
|
||||
constructor() { }
|
||||
|
||||
@Input() sortable: string = '';
|
||||
@Input() direction: string = '';
|
||||
@Output() sort = new EventEmitter<SortEvent>();
|
||||
|
||||
rotate() {
|
||||
this.direction = rotate[this.direction];
|
||||
this.sort.emit({column: this.sortable, direction: this.direction});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user