mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-16 00:36:22 +00:00
Feature: global search, keyboard shortcuts / hotkey support (#6449)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="modal-basic-title">{{title}}</h4>
|
||||
<button type="button" class="btn-close" aria-label="Close" (click)="close()"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<table class="table">
|
||||
<tbody>
|
||||
@for (key of hotkeys.entries(); track key[0]) {
|
||||
<tr>
|
||||
<td>{{ key[1] }}</td>
|
||||
<td class="d-flex justify-content-end">
|
||||
<kbd [innerHTML]="formatKey(key[0])"></kbd>
|
||||
@if (key[0].includes('control')) {
|
||||
(macOS <kbd [innerHTML]="formatKey(key[0], true)"></kbd>)
|
||||
}
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
</div>
|
@@ -0,0 +1,35 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
|
||||
import { HotkeyDialogComponent } from './hotkey-dialog.component'
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
|
||||
describe('HotkeyDialogComponent', () => {
|
||||
let component: HotkeyDialogComponent
|
||||
let fixture: ComponentFixture<HotkeyDialogComponent>
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [HotkeyDialogComponent],
|
||||
providers: [NgbActiveModal],
|
||||
}).compileComponents()
|
||||
|
||||
fixture = TestBed.createComponent(HotkeyDialogComponent)
|
||||
component = fixture.componentInstance
|
||||
fixture.detectChanges()
|
||||
})
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy()
|
||||
})
|
||||
|
||||
it('should support close', () => {
|
||||
const closeSpy = jest.spyOn(component.activeModal, 'close')
|
||||
component.close()
|
||||
expect(closeSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should format keys', () => {
|
||||
expect(component.formatKey('control.a')).toEqual('⌃ + a') // ⌃ + a
|
||||
expect(component.formatKey('control.a', true)).toEqual('⌘ + a') // ⌘ + a
|
||||
})
|
||||
})
|
@@ -0,0 +1,38 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
|
||||
const SYMBOLS = {
|
||||
meta: '⌘', // ⌘
|
||||
control: '⌃', // ⌃
|
||||
shift: '⇧', // ⇧
|
||||
left: '←', // ←
|
||||
right: '→', // →
|
||||
up: '↑', // ↑
|
||||
down: '↓', // ↓
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'pngx-hotkey-dialog',
|
||||
templateUrl: './hotkey-dialog.component.html',
|
||||
styleUrl: './hotkey-dialog.component.scss',
|
||||
})
|
||||
export class HotkeyDialogComponent {
|
||||
public title: string = $localize`Keyboard shortcuts`
|
||||
public hotkeys: Map<string, string> = new Map()
|
||||
|
||||
constructor(public activeModal: NgbActiveModal) {}
|
||||
|
||||
public close(): void {
|
||||
this.activeModal.close()
|
||||
}
|
||||
|
||||
public formatKey(key: string, macOS: boolean = false): string {
|
||||
if (macOS) {
|
||||
key = key.replace('control', 'meta')
|
||||
}
|
||||
return key
|
||||
.split('.')
|
||||
.map((k) => SYMBOLS[k] || k)
|
||||
.join(' + ')
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user