-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic uptime visualisation (wip)
- Loading branch information
Showing
7 changed files
with
107 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,5 @@ npm-debug.log | |
.idea/ | ||
*.iml | ||
/tmp/ | ||
|
||
*.swp |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// We import the CSS which is extracted to its own file by esbuild. | ||
// Remove this line if you add a your own CSS build pipeline (e.g postcss). | ||
import "../css/app.scss" | ||
import "../css/app.scss"; | ||
|
||
// If you want to use Phoenix channels, run `mix help phx.gen.channel` | ||
// to get started and then uncomment the line below. | ||
|
@@ -20,26 +20,68 @@ import "../css/app.scss" | |
// | ||
|
||
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons. | ||
import "phoenix_html" | ||
import "phoenix_html"; | ||
// Establish Phoenix Socket and LiveView configuration. | ||
import {Socket} from "phoenix" | ||
import {LiveSocket} from "phoenix_live_view" | ||
import topbar from "../vendor/topbar" | ||
import { Socket } from "phoenix"; | ||
import { LiveSocket } from "phoenix_live_view"; | ||
import topbar from "../vendor/topbar"; | ||
import ProgressBar from "progressbar.js"; | ||
|
||
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") | ||
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}}) | ||
let csrfToken = document | ||
.querySelector("meta[name='csrf-token']") | ||
.getAttribute("content"); | ||
let liveSocket = new LiveSocket("/live", Socket, { | ||
params: { _csrf_token: csrfToken }, | ||
}); | ||
|
||
// Show progress bar on live navigation and form submits | ||
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"}) | ||
window.addEventListener("phx:page-loading-start", info => topbar.show()) | ||
window.addEventListener("phx:page-loading-stop", info => topbar.hide()) | ||
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" }); | ||
window.addEventListener("phx:page-loading-start", (info) => topbar.show()); | ||
window.addEventListener("phx:page-loading-stop", (info) => topbar.hide()); | ||
|
||
// connect if there are any LiveViews on the page | ||
liveSocket.connect() | ||
liveSocket.connect(); | ||
|
||
// expose liveSocket on window for web console debug logs and latency simulation: | ||
// >> liveSocket.enableDebug() | ||
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session | ||
// >> liveSocket.disableLatencySim() | ||
window.liveSocket = liveSocket | ||
window.liveSocket = liveSocket; | ||
|
||
// [email protected] version is used | ||
// Docs: http://progressbarjs.readthedocs.org/en/1.0.0/ | ||
|
||
window.loadStatusProgressBar = function(divId) { | ||
console.log(`Loading bar for id ${divId}`); | ||
let bar = new ProgressBar.Circle(`#${divId}`, { | ||
color: "#aaa", | ||
// This has to be the same size as the maximum width to | ||
// prevent clipping | ||
strokeWidth: 4, | ||
trailWidth: 1, | ||
easing: "easeInOut", | ||
duration: 1400, | ||
text: { | ||
autoStyleContainer: false, | ||
}, | ||
from: { color: "#aaa", width: 1 }, | ||
to: { color: "#5cb571", width: 4 }, // #333 | ||
|
||
// Set default step function for all animate calls | ||
step: function (state, circle) { | ||
circle.path.setAttribute("stroke", state.color); | ||
circle.path.setAttribute("stroke-width", state.width); | ||
|
||
var value = Math.round(circle.value() * 100); | ||
if (value === 0) { | ||
circle.setText(""); | ||
} else { | ||
circle.setText(value); | ||
} | ||
}, | ||
}); | ||
bar.text.style.fontFamily = '"Raleway", Helvetica, sans-serif'; | ||
bar.text.style.fontSize = "2rem"; | ||
|
||
bar.animate(1.0); // Number from 0.0 to 1.0 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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