Skip to content

Commit 327d19a

Browse files
committed
Add basic uptime visualisation (wip)
1 parent b2a3f27 commit 327d19a

File tree

7 files changed

+107
-16
lines changed

7 files changed

+107
-16
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ npm-debug.log
3535
.idea/
3636
*.iml
3737
/tmp/
38+
39+
*.swp

assets/css/app.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,10 @@
118118
0% { opacity: 1; }
119119
100% { opacity: 0; }
120120
}
121+
122+
.loading-container {
123+
margin: 20px;
124+
width: 100px;
125+
height: 100px;
126+
position: relative;
127+
}

assets/js/app.js

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// We import the CSS which is extracted to its own file by esbuild.
22
// Remove this line if you add a your own CSS build pipeline (e.g postcss).
3-
import "../css/app.scss"
3+
import "../css/app.scss";
44

55
// If you want to use Phoenix channels, run `mix help phx.gen.channel`
66
// to get started and then uncomment the line below.
@@ -20,26 +20,68 @@ import "../css/app.scss"
2020
//
2121

2222
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
23-
import "phoenix_html"
23+
import "phoenix_html";
2424
// Establish Phoenix Socket and LiveView configuration.
25-
import {Socket} from "phoenix"
26-
import {LiveSocket} from "phoenix_live_view"
27-
import topbar from "../vendor/topbar"
25+
import { Socket } from "phoenix";
26+
import { LiveSocket } from "phoenix_live_view";
27+
import topbar from "../vendor/topbar";
28+
import ProgressBar from "progressbar.js";
2829

29-
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
30-
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
30+
let csrfToken = document
31+
.querySelector("meta[name='csrf-token']")
32+
.getAttribute("content");
33+
let liveSocket = new LiveSocket("/live", Socket, {
34+
params: { _csrf_token: csrfToken },
35+
});
3136

3237
// Show progress bar on live navigation and form submits
33-
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
34-
window.addEventListener("phx:page-loading-start", info => topbar.show())
35-
window.addEventListener("phx:page-loading-stop", info => topbar.hide())
38+
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" });
39+
window.addEventListener("phx:page-loading-start", (info) => topbar.show());
40+
window.addEventListener("phx:page-loading-stop", (info) => topbar.hide());
3641

3742
// connect if there are any LiveViews on the page
38-
liveSocket.connect()
43+
liveSocket.connect();
3944

4045
// expose liveSocket on window for web console debug logs and latency simulation:
4146
// >> liveSocket.enableDebug()
4247
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
4348
// >> liveSocket.disableLatencySim()
44-
window.liveSocket = liveSocket
49+
window.liveSocket = liveSocket;
4550

51+
// progressbar.js@1.0.0 version is used
52+
// Docs: http://progressbarjs.readthedocs.org/en/1.0.0/
53+
54+
window.loadStatusProgressBar = function(divId) {
55+
console.log(`Loading bar for id ${divId}`);
56+
let bar = new ProgressBar.Circle(`#${divId}`, {
57+
color: "#aaa",
58+
// This has to be the same size as the maximum width to
59+
// prevent clipping
60+
strokeWidth: 4,
61+
trailWidth: 1,
62+
easing: "easeInOut",
63+
duration: 1400,
64+
text: {
65+
autoStyleContainer: false,
66+
},
67+
from: { color: "#aaa", width: 1 },
68+
to: { color: "#5cb571", width: 4 }, // #333
69+
70+
// Set default step function for all animate calls
71+
step: function (state, circle) {
72+
circle.path.setAttribute("stroke", state.color);
73+
circle.path.setAttribute("stroke-width", state.width);
74+
75+
var value = Math.round(circle.value() * 100);
76+
if (value === 0) {
77+
circle.setText("");
78+
} else {
79+
circle.setText(value);
80+
}
81+
},
82+
});
83+
bar.text.style.fontFamily = '"Raleway", Helvetica, sans-serif';
84+
bar.text.style.fontSize = "2rem";
85+
86+
bar.animate(1.0); // Number from 0.0 to 1.0
87+
}

assets/package-lock.json

Lines changed: 34 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"font-awesome": "^4.7.0",
99
"phoenix": "file:../deps/phoenix",
1010
"phoenix_html": "file:../deps/phoenix_html",
11-
"phoenix_live_view": "file:../deps/phoenix_live_view"
11+
"phoenix_live_view": "file:../deps/phoenix_live_view",
12+
"progressbar.js": "^1.1.0"
1213
}
1314
}

lib/zout_web/templates/layout/root.html.heex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<meta name="csrf-token" content={csrf_token_value()}>
77
<%= live_title_tag assigns[:page_title] || "Zout", suffix: " · Phoenix Framework" %>
88
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/assets/app.css")}/>
9+
<link href="https://fonts.googleapis.com/css?family=Raleway:400,300,600,800,900" rel="stylesheet" type="text/css">
910
<script defer phx-track-static type="text/javascript" src={Routes.static_path(@conn, "/assets/app.js")}></script>
1011
</head>
1112
<body>

lib/zout_web/templates/project/index.html.heex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<tr>
66
<th>Project</th>
77
<th>Status</th>
8+
<th>Uptime</th>
89
</tr>
910
</thead>
1011
<tbody>
@@ -14,7 +15,13 @@
1415
<td>
1516
<%= render_status(downtime) %>
1617
</td>
18+
<td><div class="loading-container" id={"loading-container-#{ project.id }"}></div></td>
1719
</tr>
20+
<script>
21+
window.addEventListener("load",function(event) {
22+
loadStatusProgressBar("loading-container-<%= project.id %>");
23+
});
24+
</script>
1825
<% end %>
1926
</tbody>
2027
</table>

0 commit comments

Comments
 (0)