Skip to content

Commit

Permalink
Add ignoreEscapeKey option.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amotl committed May 5, 2019
1 parent 88e5bdd commit eea48c4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
- Add control options `mapFitData` and `mapZoomByRadius`.
- Repaint user interface.
- Refactor machinery and user interface.
- Add options `ignoreEmptyGeohashValues` and `ignoreInvalidGeohashValues`.
- Add options `ignoreEmptyGeohashValues` and `ignoreInvalidGeohashValues`.
- Add `ignoreEscapeKey` option.

## v0.2.0

Expand Down
29 changes: 29 additions & 0 deletions src/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,33 @@ export class WorldmapChrome {
});
}

removeEscapeKeyBinding() {
/*
* Prevent navigation
* - https://github.com/grafana/grafana/issues/11636
* - https://github.com/grafana/grafana/issues/13706
*
* Embed entire dashboard
* - https://github.com/grafana/grafana/issues/4757
* - https://github.com/grafana/grafana/issues/10979
* - https://github.com/grafana/grafana/issues/13493
*
* References
* - https://github.com/grafana/grafana/blob/v6.1.6/public/app/core/services/keybindingSrv.ts
* - https://github.com/grafana/grafana/blob/v6.1.6/public/app/plugins/datasource/grafana-azure-monitor-datasource/editor/query_field.tsx
* - https://github.com/daq-tools/grafanimate/blob/0.5.5/grafanimate/grafana-studio.js
*
*/
this.getKeybindingSrv().unbind('esc', 'keydown');
}

restoreEscapeKeyBinding() {
this.getKeybindingSrv().setupGlobal();
}

getKeybindingSrv() {
const app = window['angular'].element('grafana-app');
return app.injector().get('keybindingSrv');
}

}
6 changes: 6 additions & 0 deletions src/partials/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ <h5>Appearance</h5>
<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>
</div>

<div class="gf-form-group">
<h5>Global options</h5>
<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>
<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>
</div>

</div>

<!-- 2nd column -->
Expand Down
16 changes: 10 additions & 6 deletions src/worldmap_ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const panelDefaults = {
labelField: null,
labelLocationKeyField: null,
linkField: null,
}
},
ignoreEscapeKey: false,
};

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

settings: any;
dataErrors:Array<any> = [];
locationErrors:Array<any> = [];
core: WorldmapCore;
chrome: WorldmapChrome;
errors: ErrorManager;
Expand Down Expand Up @@ -135,9 +134,14 @@ export default class WorldmapCtrl extends MetricsPanelCtrl {
/*
* Initialize the plugin.
*/
// TODO: Establish conditions for running this.
//this.removeTimePickerNav();
//this.removeEscapeKeyBinding();

// Optionally ignore the escape key.
if (this.settings.ignoreEscapeKey) {
this.chrome.removeEscapeKeyBinding();
} else {
this.chrome.restoreEscapeKeyBinding();
}

}

setupEvents() {
Expand Down

0 comments on commit eea48c4

Please sign in to comment.