mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-12 00:19:48 +00:00
Feature: global search, keyboard shortcuts / hotkey support (#6449)
This commit is contained in:
@@ -12,8 +12,12 @@ import {
|
||||
} from '@angular/core/testing'
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
||||
import { By } from '@angular/platform-browser'
|
||||
import { Router, ActivatedRoute, convertToParamMap } from '@angular/router'
|
||||
import { RouterTestingModule } from '@angular/router/testing'
|
||||
import {
|
||||
Router,
|
||||
ActivatedRoute,
|
||||
convertToParamMap,
|
||||
RouterModule,
|
||||
} from '@angular/router'
|
||||
import {
|
||||
NgbModal,
|
||||
NgbModule,
|
||||
@@ -253,7 +257,7 @@ describe('DocumentDetailComponent', () => {
|
||||
DatePipe,
|
||||
],
|
||||
imports: [
|
||||
RouterTestingModule.withRoutes(routes),
|
||||
RouterModule.forRoot(routes),
|
||||
HttpClientTestingModule,
|
||||
NgbModule,
|
||||
NgSelectModule,
|
||||
@@ -1126,6 +1130,35 @@ describe('DocumentDetailComponent', () => {
|
||||
req.flush(true)
|
||||
})
|
||||
|
||||
it('should support keyboard shortcuts', () => {
|
||||
initNormally()
|
||||
|
||||
jest.spyOn(component, 'hasNext').mockReturnValue(true)
|
||||
const nextSpy = jest.spyOn(component, 'nextDoc')
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 'arrowright', ctrlKey: true })
|
||||
)
|
||||
expect(nextSpy).toHaveBeenCalled()
|
||||
|
||||
jest.spyOn(component, 'hasPrevious').mockReturnValue(true)
|
||||
const prevSpy = jest.spyOn(component, 'previousDoc')
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 'arrowleft', ctrlKey: true })
|
||||
)
|
||||
expect(prevSpy).toHaveBeenCalled()
|
||||
|
||||
jest.spyOn(openDocumentsService, 'isDirty').mockReturnValue(true)
|
||||
const saveSpy = jest.spyOn(component, 'save')
|
||||
document.dispatchEvent(
|
||||
new KeyboardEvent('keydown', { key: 's', ctrlKey: true })
|
||||
)
|
||||
expect(saveSpy).toHaveBeenCalled()
|
||||
|
||||
const closeSpy = jest.spyOn(component, 'close')
|
||||
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'escape' }))
|
||||
expect(closeSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
function initNormally() {
|
||||
jest
|
||||
.spyOn(activatedRoute, 'paramMap', 'get')
|
||||
|
@@ -69,6 +69,7 @@ import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service
|
||||
import { PDFDocumentProxy } from '../common/pdf-viewer/typings'
|
||||
import { SplitConfirmDialogComponent } from '../common/confirm-dialog/split-confirm-dialog/split-confirm-dialog.component'
|
||||
import { RotateConfirmDialogComponent } from '../common/confirm-dialog/rotate-confirm-dialog/rotate-confirm-dialog.component'
|
||||
import { HotKeyService } from 'src/app/services/hot-key.service'
|
||||
|
||||
enum DocumentDetailNavIDs {
|
||||
Details = 1,
|
||||
@@ -201,7 +202,8 @@ export class DocumentDetailComponent
|
||||
private permissionsService: PermissionsService,
|
||||
private userService: UserService,
|
||||
private customFieldsService: CustomFieldsService,
|
||||
private http: HttpClient
|
||||
private http: HttpClient,
|
||||
private hotKeyService: HotKeyService
|
||||
) {
|
||||
super()
|
||||
}
|
||||
@@ -455,6 +457,40 @@ export class DocumentDetailComponent
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
this.hotKeyService
|
||||
.addShortcut({
|
||||
keys: 'control.arrowright',
|
||||
description: $localize`Next document`,
|
||||
})
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
if (this.hasNext()) this.nextDoc()
|
||||
})
|
||||
|
||||
this.hotKeyService
|
||||
.addShortcut({
|
||||
keys: 'control.arrowleft',
|
||||
description: $localize`Previous document`,
|
||||
})
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
if (this.hasPrevious()) this.previousDoc()
|
||||
})
|
||||
|
||||
this.hotKeyService
|
||||
.addShortcut({ keys: 'escape', description: $localize`Close document` })
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
this.close()
|
||||
})
|
||||
|
||||
this.hotKeyService
|
||||
.addShortcut({ keys: 'control.s', description: $localize`Save document` })
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
if (this.openDocumentService.isDirty(this.document)) this.save()
|
||||
})
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
|
Reference in New Issue
Block a user