From a86aaef510a1320544b5ea73a777c54450b7326a Mon Sep 17 00:00:00 2001 From: trivernis Date: Mon, 13 Dec 2021 17:49:52 +0100 Subject: [PATCH] Fix issues with grid key naviation It should only navigate now when focussed. Same logic applies to the gallery. The focus is kept when changing between the gallery and the grid. TG-48 #closed Signed-off-by: trivernis --- .../src/app/components/core/core.component.ts | 5 +-- .../shared/app-common/app-common.module.ts | 3 ++ .../input-receiver.directive.spec.ts | 8 ++++ .../input-receiver.directive.ts | 32 ++++++++++++++ .../file-gallery/file-gallery.component.html | 2 +- .../file-gallery/file-gallery.component.ts | 44 +++++++++++-------- .../file-grid/file-grid.component.html | 4 +- .../file-grid/file-grid.component.ts | 44 +++++++++++-------- .../file-multiview.component.html | 4 +- .../file-multiview.component.ts | 14 +++++- .../src/app/services/file/file.service.ts | 1 - 11 files changed, 113 insertions(+), 48 deletions(-) create mode 100644 mediarepo-ui/src/app/components/shared/app-common/input-receiver/input-receiver.directive.spec.ts create mode 100644 mediarepo-ui/src/app/components/shared/app-common/input-receiver/input-receiver.directive.ts diff --git a/mediarepo-ui/src/app/components/core/core.component.ts b/mediarepo-ui/src/app/components/core/core.component.ts index 37f1409..c24484a 100644 --- a/mediarepo-ui/src/app/components/core/core.component.ts +++ b/mediarepo-ui/src/app/components/core/core.component.ts @@ -43,14 +43,12 @@ export class CoreComponent { this.stateService.state.subscribe(state => { this.appState = state; - console.log("new state", state); if (this.appState.tabs.value.length === 0) { this.addTab(); } state.tabs.subscribe(tabs => { - console.log("new tabs", tabs); this.tabs = tabs; - console.log(tabs); + if (this.tabs.length === 0) { this.addTab(); } @@ -101,7 +99,6 @@ export class CoreComponent { } public async onMouseClickTabLabel(tab: TabState, event: MouseEvent) { - console.log(event); if (event.button === 1) { // middle mouse button await this.closeTab(tab); } diff --git a/mediarepo-ui/src/app/components/shared/app-common/app-common.module.ts b/mediarepo-ui/src/app/components/shared/app-common/app-common.module.ts index 55c6460..6bc8863 100644 --- a/mediarepo-ui/src/app/components/shared/app-common/app-common.module.ts +++ b/mediarepo-ui/src/app/components/shared/app-common/app-common.module.ts @@ -15,6 +15,7 @@ import {MatMenuModule} from "@angular/material/menu"; import { ContentAwareImageComponent } from "./content-aware-image/content-aware-image.component"; +import { InputReceiverDirective } from "./input-receiver/input-receiver.directive"; @NgModule({ @@ -23,12 +24,14 @@ import { BusyIndicatorComponent, ContextMenuComponent, ContentAwareImageComponent, + InputReceiverDirective, ], exports: [ ConfirmDialogComponent, BusyIndicatorComponent, ContextMenuComponent, ContentAwareImageComponent, + InputReceiverDirective, ], imports: [ CommonModule, diff --git a/mediarepo-ui/src/app/components/shared/app-common/input-receiver/input-receiver.directive.spec.ts b/mediarepo-ui/src/app/components/shared/app-common/input-receiver/input-receiver.directive.spec.ts new file mode 100644 index 0000000..37946f5 --- /dev/null +++ b/mediarepo-ui/src/app/components/shared/app-common/input-receiver/input-receiver.directive.spec.ts @@ -0,0 +1,8 @@ +import { InputReceiverDirective } from './input-receiver.directive'; + +describe('InputReceiverDirective', () => { + it('should create an instance', () => { + const directive = new InputReceiverDirective(); + expect(directive).toBeTruthy(); + }); +}); diff --git a/mediarepo-ui/src/app/components/shared/app-common/input-receiver/input-receiver.directive.ts b/mediarepo-ui/src/app/components/shared/app-common/input-receiver/input-receiver.directive.ts new file mode 100644 index 0000000..718296a --- /dev/null +++ b/mediarepo-ui/src/app/components/shared/app-common/input-receiver/input-receiver.directive.ts @@ -0,0 +1,32 @@ +import { + Directive, + EventEmitter, + HostBinding, + HostListener, + Output +} from "@angular/core"; + +@Directive({ + selector: "[appInputReceiver]" +}) +export class InputReceiverDirective { + + constructor() { + } + + @Output() keyDownEvent = new EventEmitter(); + @Output() keyUpEvent = new EventEmitter(); + + @HostBinding("tabindex") tabIndex = 1; + + @HostListener("keydown", ["$event"]) + onKeyDown(event: KeyboardEvent) { + this.keyDownEvent.emit(event); + } + + @HostListener("keyup", ["$event"]) + onKeyUp(event: KeyboardEvent) { + this.keyUpEvent.emit(event); + } + +} diff --git a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.html b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.html index 9a67404..d12f2ee 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.html +++ b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-gallery/file-gallery.component.html @@ -1,4 +1,4 @@ -