Skip to content

Commit 5e4b2ca

Browse files
author
Erwin Dondorp
committed
select menu items by keyboard (cmdbox->'c')
1 parent 5deec63 commit 5e4b2ca

3 files changed

Lines changed: 50 additions & 25 deletions

File tree

saltgui/static/scripts/Router.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ export class Router {
7777
/* eslint-enable compat/compat */
7878
}
7979

80-
_registerMenuItem (pParentId, pButtonId, pUrl) {
80+
_registerMenuItem (pParentId, pButtonId, pUrl, pKey) {
81+
82+
// shortcut
83+
84+
if (pKey) {
85+
Utils.setStorageItem("session", "menu_" + pKey, pUrl);
86+
}
8187

8288
// full menu
8389

@@ -177,19 +183,20 @@ export class Router {
177183
/* eslint-enable compat/compat */
178184
});
179185

180-
this._registerMenuItem(null, "minions", "minions");
181-
this._registerMenuItem("minions", "grains", "grains");
182-
this._registerMenuItem("minions", "schedules", "schedules");
183-
this._registerMenuItem("minions", "pillars", "pillars");
184-
this._registerMenuItem("minions", "beacons", "beacons");
185-
this._registerMenuItem("minions", "nodegroups", "nodegroups");
186-
this._registerMenuItem(null, "keys", "keys");
187-
this._registerMenuItem(null, "jobs", "jobs");
188-
this._registerMenuItem("jobs", "highstate", "highstate");
189-
this._registerMenuItem("jobs", "templates", "templates");
190-
this._registerMenuItem(null, "events", "events");
191-
this._registerMenuItem("events", "reactors", "reactors");
192-
this._registerMenuItem(null, "issues", "issues");
186+
this._registerMenuItem(null, "minions", "minions", "m");
187+
this._registerMenuItem("minions", "grains", "grains", "g");
188+
this._registerMenuItem("minions", "schedules", "schedules", "s");
189+
this._registerMenuItem("minions", "pillars", "pillars", "p");
190+
this._registerMenuItem("minions", "beacons", "beacons", "b");
191+
this._registerMenuItem("minions", "nodegroups", "nodegroups", "n");
192+
this._registerMenuItem(null, "keys", "keys", "k");
193+
this._registerMenuItem(null, "jobs", "jobs", "j");
194+
this._registerMenuItem("jobs", "highstate", "highstate", "h");
195+
this._registerMenuItem("jobs", "templates", "templates", "t");
196+
this._registerMenuItem(null, "events", "events", "e");
197+
this._registerMenuItem("events", "reactors", "reactors", "r");
198+
this._registerMenuItem(null, "issues", "issues", "i");
199+
// no shortcut for logout
193200
this._registerMenuItem(null, "logout", "logout");
194201
}
195202

saltgui/static/scripts/Utils.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,13 @@ export class Utils {
663663
if (pKeyUpEvent.isComposing) {
664664
return false;
665665
}
666+
if (pKeyUpEvent.target !== document.body) {
667+
// not when focus is in a text field
668+
return false;
669+
}
666670
if (pKeyUpEvent.key.length > 1) {
667671
// not a simple key
668-
// return false;
672+
return false;
669673
}
670674
return true;
671675
}

saltgui/static/scripts/pages/Page.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* global */
22

33
import {CommandBox} from "../CommandBox.js";
4+
import {Router} from "../Router.js";
45
import {Utils} from "../Utils.js";
56

67
export class Page {
@@ -33,27 +34,23 @@ export class Page {
3334

3435
const body = document.querySelector("body");
3536
body.onkeyup = (keyUpEvent) => {
37+
if (!Utils.isValidKeyUpEvent(keyUpEvent)) {
38+
return;
39+
}
40+
3641
if (this._handleTemplateKey(keyUpEvent)) {
3742
keyUpEvent.stopPropagation();
3843
return;
3944
}
40-
if (Page._handleMenuKey(keyUpEvent)) {
45+
46+
if (this._handleMenuKey(keyUpEvent)) {
4147
keyUpEvent.stopPropagation();
4248
// return;
4349
}
4450
};
4551
}
4652

4753
_handleTemplateKey (keyUpEvent) {
48-
if (!Utils.isValidKeyUpEvent(keyUpEvent)) {
49-
return false;
50-
}
51-
52-
if (keyUpEvent.target !== document.body) {
53-
// not when focus is in a text field
54-
return false;
55-
}
56-
5754
const templateName = Utils.getStorageItem("session", "template_" + keyUpEvent.key, "");
5855
if (templateName === "") {
5956
// key not bound to a template
@@ -66,6 +63,23 @@ export class Page {
6663
return true;
6764
}
6865

66+
_handleMenuKey (keyUpEvent) {
67+
if (keyUpEvent.key === "c") {
68+
CommandBox.showManualRun(this.api);
69+
return true;
70+
}
71+
72+
const pages = Router._getPagesList();
73+
const page = Utils.getStorageItem("session", "menu_" + keyUpEvent.key, "");
74+
// Arrays.includes() is only available from ES7/2016
75+
if (page && (pages.length === 0 || pages.indexOf(page) >= 0)) {
76+
this.router.goTo(page);
77+
return true;
78+
}
79+
80+
return false;
81+
}
82+
6983
addPanel (pPanel) {
7084
pPanel.route = this;
7185
pPanel.router = this.router;

0 commit comments

Comments
 (0)