Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added feature key navigation user suite #691

Merged
merged 6 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions web/resources/js/user-suite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2024. The Pycroft Authors. See the AUTHORS file.
* This file is part of the Pycroft project and licensed under the terms of
* the Apache License, Version 2.0. See the LICENSE file for details
*/

function waitForKeyPress(callback: (event: KeyboardEvent) => void): void {
const handleKeyPress = (event: KeyboardEvent) => {
// Call the callback function with the event when a key is pressed
callback(event);

// Remove the event listener after the first key press (if you want it to happen only once)
// document.removeEventListener('keydown', handleKeyPress);
};

// Add the event listener to the document
document.addEventListener('keydown', handleKeyPress);
}
agmes4 marked this conversation as resolved.
Show resolved Hide resolved

// Example of using the function
agmes4 marked this conversation as resolved.
Show resolved Hide resolved
waitForKeyPress((event) => {
console.log(`Key pressed: ${event.key}`);
// Add your logic here based on the key press
agmes4 marked this conversation as resolved.
Show resolved Hide resolved
if (event.key === "ArrowRight" ){
agmes4 marked this conversation as resolved.
Show resolved Hide resolved
const navLinks = document.getElementsByClassName("user-nav-link");
agmes4 marked this conversation as resolved.
Show resolved Hide resolved
for (let i= 0; i < navLinks.length; i++){
const link = navLinks[i] as HTMLLinkElement;
if(link.classList.contains("active")) {
let index = (i + 1)% (navLinks.length - 1);
lukasjuhrich marked this conversation as resolved.
Show resolved Hide resolved
let link2 = navLinks[index] as HTMLLinkElement;
link2.click();
break;
}
}
}

if (event.key === "ArrowLeft" ){
const navLinks = document.getElementsByClassName("user-nav-link");
for (let i= 0; i < navLinks.length; i++){
const link = navLinks[i] as HTMLLinkElement;
if(link.classList.contains("active")) {
let index = i - 1;
if (index < 0) index += (navLinks.length - 1); // Ich hasse JS noch nicht mal mod kann das ordentlich
lukasjuhrich marked this conversation as resolved.
Show resolved Hide resolved
const link2 = navLinks[index] as HTMLLinkElement;
link2.click();
break;
}
}
}
});
3 changes: 2 additions & 1 deletion web/templates/user/user_show.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<ul class="nav nav-tabs">
{% for tab in tabs %}
<li class="nav-item">
<a class="nav-link {{ "active" if tab.id == 'hosts' else "" }}
<a class="nav-link user-nav-link {{ "active" if tab.id == 'hosts' else "" }}
{{ "disabled" if 'disabled' in tab and tab.disabled else "" }}"
{{ 'aria-current="page"' if tab.id == 'hosts' else "" }}
{{ 'aria-disabled="true"' if 'disabled' in tab and tab.disabled else "" }}
Expand Down Expand Up @@ -59,4 +59,5 @@

{% block page_script %}
{{ resources.link_script_file('tab-anchor.js' | require) }}
{{ resources.link_script_file('user-suite.js' | require) }}
{% endblock %}
4 changes: 4 additions & 0 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export default {
import: './js/tab-anchor.ts',
dependOn: 'main',
},
'user-suite': {
import: './js/user-suite.ts',
dependOn: 'main',
},
'rooms-table': {
import: './js/rooms-table.ts',
dependOn: 'main',
Expand Down
Loading