Skip to content

Commit eea48c4

Browse files
committed
Add ignoreEscapeKey option.
While this amends the global behaviour of Grafana and should probably be implemented elsewhere, it helps us now to prevent the user to leave the Kiosk mode.
1 parent 88e5bdd commit eea48c4

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
- Add control options `mapFitData` and `mapZoomByRadius`.
3939
- Repaint user interface.
4040
- Refactor machinery and user interface.
41-
- Add options `ignoreEmptyGeohashValues` and `ignoreInvalidGeohashValues`.
41+
- Add options `ignoreEmptyGeohashValues` and `ignoreInvalidGeohashValues`.
42+
- Add `ignoreEscapeKey` option.
4243

4344
## v0.2.0
4445

src/chrome.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,33 @@ export class WorldmapChrome {
4444
});
4545
}
4646

47+
removeEscapeKeyBinding() {
48+
/*
49+
* Prevent navigation
50+
* - https://github.com/grafana/grafana/issues/11636
51+
* - https://github.com/grafana/grafana/issues/13706
52+
*
53+
* Embed entire dashboard
54+
* - https://github.com/grafana/grafana/issues/4757
55+
* - https://github.com/grafana/grafana/issues/10979
56+
* - https://github.com/grafana/grafana/issues/13493
57+
*
58+
* References
59+
* - https://github.com/grafana/grafana/blob/v6.1.6/public/app/core/services/keybindingSrv.ts
60+
* - https://github.com/grafana/grafana/blob/v6.1.6/public/app/plugins/datasource/grafana-azure-monitor-datasource/editor/query_field.tsx
61+
* - https://github.com/daq-tools/grafanimate/blob/0.5.5/grafanimate/grafana-studio.js
62+
*
63+
*/
64+
this.getKeybindingSrv().unbind('esc', 'keydown');
65+
}
66+
67+
restoreEscapeKeyBinding() {
68+
this.getKeybindingSrv().setupGlobal();
69+
}
70+
71+
getKeybindingSrv() {
72+
const app = window['angular'].element('grafana-app');
73+
return app.injector().get('keybindingSrv');
74+
}
75+
4776
}

src/partials/editor.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,12 @@ <h5>Appearance</h5>
347347
<gf-form-switch class="gf-form" label="Mouse Wheel Zoom" label-class="width-10" checked="ctrl.panel.mouseWheelZoom" on-change="ctrl.toggleMouseWheelZoom()"></gf-form-switch>
348348
</div>
349349

350+
<div class="gf-form-group">
351+
<h5>Global options</h5>
352+
<gf-form-switch class="gf-form" label="Ignore escape key" label-class="width-10" checked="ctrl.panel.ignoreEscapeKey" on-change="ctrl.setupGlobal()"></gf-form-switch>
353+
<gf-form-switch class="gf-form" label="Hide time picker" label-class="width-10" checked="ctrl.panel.hideTimepickerNavigation" on-change="ctrl.setupGlobal()"></gf-form-switch>
354+
</div>
355+
350356
</div>
351357

352358
<!-- 2nd column -->

src/worldmap_ctrl.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ const panelDefaults = {
6363
labelField: null,
6464
labelLocationKeyField: null,
6565
linkField: null,
66-
}
66+
},
67+
ignoreEscapeKey: false,
6768
};
6869

6970
export default class WorldmapCtrl extends MetricsPanelCtrl {
@@ -84,8 +85,6 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
8485
$document: any;
8586

8687
settings: any;
87-
dataErrors:Array<any> = [];
88-
locationErrors:Array<any> = [];
8988
core: WorldmapCore;
9089
chrome: WorldmapChrome;
9190
errors: ErrorManager;
@@ -135,9 +134,14 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
135134
/*
136135
* Initialize the plugin.
137136
*/
138-
// TODO: Establish conditions for running this.
139-
//this.removeTimePickerNav();
140-
//this.removeEscapeKeyBinding();
137+
138+
// Optionally ignore the escape key.
139+
if (this.settings.ignoreEscapeKey) {
140+
this.chrome.removeEscapeKeyBinding();
141+
} else {
142+
this.chrome.restoreEscapeKeyBinding();
143+
}
144+
141145
}
142146

143147
setupEvents() {

0 commit comments

Comments
 (0)