Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Commit 7502e5c

Browse files
authored
Merge pull request #117 from hjacobs/dashboard-mode
#108 add `renderer` UI option to disable WebGL
2 parents 10fbfe2 + ee0cf9b commit 7502e5c

File tree

3 files changed

+45
-23
lines changed

3 files changed

+45
-23
lines changed

app/src/app.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,26 @@ import SelectBox from './selectbox'
55
import { Theme, ALL_THEMES} from './themes.js'
66
import { DESATURATION_FILTER } from './filters.js'
77
import { JSON_delta } from './vendor/json_delta.js'
8+
import Config from './config.js'
89

910
const PIXI = require('pixi.js')
1011

1112
const addWheelListener = require('./vendor/addWheelListener')
1213

13-
const TRUTHY_VALUES = new Set(['1', 'true'])
14-
1514

1615
export default class App {
1716

1817
constructor() {
1918
const params = this.parseLocationHash()
20-
this.dashboardMode = TRUTHY_VALUES.has(params.get('dashboard'))
21-
this.reloadIntervalSeconds = parseInt(params.get('reload')) || 0
19+
this.config = Config.fromParams(params)
2220
this.filterString = params.get('q') || ''
2321
this.selectedClusters = new Set((params.get('clusters') || '').split(',').filter(x => x))
24-
this.initialScale = parseFloat(params.get('scale')) || 1.0
2522
this.seenPods = new Set()
2623
this.sorterFn = ''
2724
this.theme = Theme.get(localStorage.getItem('theme'))
2825
this.eventSource = null
2926
this.connectTime = null
3027
this.keepAliveTimer = null
31-
// make sure we got activity at least every 20 seconds
32-
this.keepAliveSeconds = 20
33-
// always reconnect after 5 minutes
34-
this.maxConnectionLifetimeSeconds = 300
35-
// consider cluster data older than 1 minute outdated
36-
this.maxDataAgeSeconds = 60
3728
this.clusters = new Map()
3829
this.clusterStatuses = new Map()
3930
this.viewContainerTargetPosition = new PIXI.Point()
@@ -104,8 +95,9 @@ export default class App {
10495
initialize() {
10596
App.current = this
10697

107-
//Create the renderer
108-
const renderer = PIXI.autoDetectRenderer(256, 256, {resolution: 2})
98+
// create the renderer
99+
const noWebGL = this.config.renderer === 'canvas'
100+
const renderer = PIXI.autoDetectRenderer(256, 256, {resolution: 2}, noWebGL)
109101
renderer.view.style.display = 'block'
110102
renderer.autoResize = true
111103
renderer.resize(window.innerWidth, window.innerHeight)
@@ -124,8 +116,8 @@ export default class App {
124116
this.registerEventListeners()
125117
setInterval(this.pruneUnavailableClusters.bind(this), 5 * 1000)
126118

127-
if (this.reloadIntervalSeconds) {
128-
setTimeout(function() { location.reload(false) }, this.reloadIntervalSeconds * 1000)
119+
if (this.config.reloadIntervalSeconds) {
120+
setTimeout(function() { location.reload(false) }, this.config.reloadIntervalSeconds * 1000)
129121
}
130122
}
131123

@@ -152,7 +144,7 @@ export default class App {
152144
}
153145
else if (event.key == 'Home') {
154146
this.viewContainerTargetPosition.x = 20
155-
this.viewContainerTargetPosition.y = this.dashboardMode ? 20 : 40
147+
this.viewContainerTargetPosition.y = this.config.dashboardMode ? 20 : 40
156148
}
157149
else if (event.key && event.key.length == 1 && !event.ctrlKey && !event.metaKey) {
158150
this.filterString += event.key
@@ -334,14 +326,14 @@ export default class App {
334326
this.theme.apply(this.stage)
335327

336328
const viewContainer = new PIXI.Container()
337-
viewContainer.scale.set(this.initialScale)
329+
viewContainer.scale.set(this.config.initialScale)
338330
viewContainer.x = 20
339-
viewContainer.y = this.dashboardMode ? 20 : 40
331+
viewContainer.y = this.config.dashboardMode ? 20 : 40
340332
this.viewContainerTargetPosition.x = viewContainer.x
341333
this.viewContainerTargetPosition.y = viewContainer.y
342334
this.stage.addChild(viewContainer)
343335

344-
if (!this.dashboardMode) {
336+
if (!this.config.dashboardMode) {
345337
this.drawMenuBar()
346338
}
347339

@@ -550,10 +542,10 @@ export default class App {
550542
if (this.keepAliveTimer != null) {
551543
clearTimeout(this.keepAliveTimer)
552544
}
553-
this.keepAliveTimer = setTimeout(this.connect.bind(this), this.keepAliveSeconds * 1000)
545+
this.keepAliveTimer = setTimeout(this.connect.bind(this), this.config.keepAliveSeconds * 1000)
554546
if (this.connectTime != null) {
555547
const now = Date.now()
556-
if (now - this.connectTime > this.maxConnectionLifetimeSeconds * 1000) {
548+
if (now - this.connectTime > this.config.maxConnectionLifetimeSeconds * 1000) {
557549
// maximum connection lifetime exceeded => reconnect
558550
this.connect()
559551
}
@@ -565,7 +557,7 @@ export default class App {
565557
const nowSeconds = Date.now() / 1000
566558
for (const [clusterId, statusObj] of this.clusterStatuses.entries()) {
567559
const lastQueryTime = statusObj.last_query_time || 0
568-
if (lastQueryTime < nowSeconds - this.maxDataAgeSeconds) {
560+
if (lastQueryTime < nowSeconds - this.config.maxDataAgeSeconds) {
569561
this.clusters.delete(clusterId)
570562
updateNeeded = true
571563
} else if (lastQueryTime < nowSeconds - 20) {
@@ -622,7 +614,7 @@ export default class App {
622614
const cluster = JSON.parse(event.data)
623615
const status = that.clusterStatuses.get(cluster.id)
624616
const nowSeconds = Date.now() / 1000
625-
if (status && status.last_query_time < nowSeconds - that.maxDataAgeSeconds) {
617+
if (status && status.last_query_time < nowSeconds - that.config.maxDataAgeSeconds) {
626618
// outdated data => ignore
627619
} else {
628620
that.clusters.set(cluster.id, cluster)

app/src/config.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const TRUTHY_VALUES = new Set(['1', 'true'])
2+
3+
export default class Config {
4+
5+
constructor() {
6+
this.dashboardMode = false
7+
this.reloadIntervalSeconds = 0
8+
this.initialScale = 1.0
9+
this.renderer = 'auto'
10+
// make sure we got activity at least every 20 seconds
11+
this.keepAliveSeconds = 20
12+
// always reconnect after 5 minutes
13+
this.maxConnectionLifetimeSeconds = 300
14+
// consider cluster data older than 1 minute outdated
15+
this.maxDataAgeSeconds = 60
16+
}
17+
18+
static fromParams(params) {
19+
const config = new Config()
20+
config.dashboardMode = TRUTHY_VALUES.has(params.get('dashboard'))
21+
config.reloadIntervalSeconds = parseInt(params.get('reload')) || 0
22+
config.initialScale = parseFloat(params.get('scale')) || 1.0
23+
config.renderer = params.get('renderer') || 'auto'
24+
return config
25+
}
26+
27+
28+
}

docs/ui-options.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ Example URL: ``https://kube-ops-view.example.org/#dashboard=true;reload=600``
1414
Enable dashboard mode which hides the menu bar.
1515
``reload``
1616
Reload the whole page after X seconds. This is useful for unattended TV screens running 24x7 to mitigate JavaScript memory leaks and browser crashes.
17+
``renderer``
18+
Forces the fallback canvas renderer (instead of WebGL) when set to "canvas".
1719
``scale``
1820
Set the initial view scale (``1.0`` is 100%).

0 commit comments

Comments
 (0)