Files
paperless-ngx/src-ui/src/app/directives/sortable.directive.ts
T

56 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-12-15 22:48:16 -08:00
import {
Directive,
EventEmitter,
HostBinding,
HostListener,
Input,
Output,
} from '@angular/core'
2020-11-08 16:58:06 +01:00
export interface SortEvent {
2021-01-04 15:58:26 +01:00
column: string
reverse: boolean
2020-11-08 16:58:06 +01:00
}
@Directive({
2023-09-14 14:03:28 -07:00
selector: 'th[pngxSortable]',
2020-11-08 16:58:06 +01:00
})
export class SortableDirective {
2022-03-11 10:53:32 -08:00
constructor() {}
2020-11-08 16:58:06 +01:00
2021-01-04 15:58:26 +01:00
@Input()
2023-09-14 14:03:28 -07:00
pngxSortable: string = ''
2021-01-04 15:58:26 +01:00
@Input()
2021-01-04 17:08:52 +01:00
currentSortReverse: boolean = false
2021-01-04 15:58:26 +01:00
@Input()
2021-01-04 17:08:52 +01:00
currentSortField: string
2021-01-04 15:58:26 +01:00
2022-03-11 10:53:32 -08:00
@Output() sort = new EventEmitter<SortEvent>()
2020-11-08 16:58:06 +01:00
2022-12-15 22:48:16 -08:00
@HostBinding('class.asc') get asc() {
return (
2023-09-14 14:03:28 -07:00
this.currentSortField === this.pngxSortable && !this.currentSortReverse
2022-12-15 22:48:16 -08:00
)
}
@HostBinding('class.des') get des() {
2023-09-14 14:03:28 -07:00
return (
this.currentSortField === this.pngxSortable && this.currentSortReverse
)
2022-12-15 22:48:16 -08:00
}
@HostListener('click') rotate() {
2023-09-14 14:03:28 -07:00
if (this.currentSortField != this.pngxSortable) {
this.sort.emit({ column: this.pngxSortable, reverse: false })
2022-03-11 10:53:32 -08:00
} else if (
2023-09-14 14:03:28 -07:00
this.currentSortField == this.pngxSortable &&
2022-03-11 10:53:32 -08:00
!this.currentSortReverse
) {
this.sort.emit({ column: this.currentSortField, reverse: true })
2021-01-04 15:58:26 +01:00
} else {
2022-03-11 10:53:32 -08:00
this.sort.emit({ column: null, reverse: false })
2021-01-04 15:58:26 +01:00
}
2020-11-08 16:58:06 +01:00
}
}