-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.6.2b - Proxy Grafana Support for Dark Mode (#52)
Proxy t28 updates the proxy to include a grafana-dark style for PW_STYLE. This is to accommodate placing as iframe in newer Grafana versions (e.g. v9.4.14) while matching the background. See jasonacox/Powerwall-Dashboard#371. Also includes updates to documentation for environmental variable explanations.
- Loading branch information
Showing
5 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use strict' | ||
|
||
// Grafana Dark Theme | ||
// Clear IndexedDB to prevent auth hangup in the proxied Powerwall web app. | ||
try { | ||
window.indexedDB.databases().then((dbs) => { | ||
dbs.forEach(db => { window.indexedDB.deleteDatabase(db.name) }); | ||
}); | ||
} catch (error) { | ||
document.write("Browser blocking indexedDB - Turn off incognito mode."); | ||
} | ||
|
||
function injectScriptAndUse() { | ||
return new Promise((resolve, reject) => { | ||
var body = document.getElementsByTagName("body")[0]; | ||
var script = document.createElement("script"); | ||
script.src = "//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"; | ||
script.onload = function () { | ||
resolve(); | ||
}; | ||
body.appendChild(script); | ||
}); | ||
} | ||
|
||
injectScriptAndUse().then(() => { | ||
console.log("Applying Grafana customization"); | ||
triggerOnMutation(formatPowerwallForGrafana); | ||
}); | ||
|
||
function triggerOnMutation(cb) { | ||
// Create an observer instance | ||
var observer = new MutationObserver(function (mutations) { | ||
mutations.forEach(function (mutation) { | ||
var newNodes = mutation.addedNodes; // DOM NodeList | ||
if (newNodes !== null) { // If there are new nodes added | ||
if (cb) cb(); | ||
} | ||
}); | ||
}); | ||
|
||
// Configuration of the observer: | ||
var config = { | ||
attributes: true, | ||
childList: true, | ||
subtree: true, | ||
}; | ||
|
||
var target = $("#root")[0]; | ||
|
||
// Pass in the target node, as well as the observer options | ||
observer.observe(target, config); | ||
} | ||
|
||
function formatPowerwallForGrafana() { | ||
// Hide elements. | ||
$('.overview-menu, #logout, .footer, .compact-btn-row, .toast-list, .power-flow-header, .btn').hide(); | ||
|
||
// Set alignment | ||
$('.core-layout__viewport').css({ | ||
padding: 0, | ||
margin: 0, | ||
}); | ||
|
||
$('.power-flow-header').css({ | ||
"padding-top": 0, | ||
}); | ||
|
||
$('.power-flow-grid').css({ | ||
width: "100%", | ||
left: 0, | ||
right: 0, | ||
margin: 0, | ||
"padding-top": 0, | ||
"position": "fixed", | ||
}); | ||
|
||
$('.app').css({ | ||
"overflow-y": "hidden", | ||
}); | ||
|
||
// Set colors | ||
$('body').css({ | ||
"background-color": "#111217", | ||
}); | ||
|
||
$('.power-flow-grid.active').css({ | ||
"background-color": "#111217", | ||
}); | ||
} |