Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: add "last synced" column to tables #11

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/site-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
name: Deploy
runs-on: ubuntu-latest
needs: build
if: github.event != 'pull_request'
if: github.event_name != 'pull_request'
permissions:
pages: write
id-token: write
Expand Down
33 changes: 33 additions & 0 deletions web/assets/live-metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function parseAge(raw) {
var v = parseFloat(raw);
if (v >= 20*24*60*60) { // 20 days
return '<td class="time-muted">a long time ago</td>';
} else if (v >= 24*60*60) { // 24 hours
return '<td class="time-red">' + (v/(24*60*60)).toFixed(1) + " days</td>"
} else if (v >= 19*60*60) { // 19 hours
return '<td class="time-yellow">' + (v/(60*60)).toFixed(1) + " hours</td>"
} else if (v >= 60*60) { // 1 hour
return '<td class="time-green">' + (v/(60*60)).toFixed(1) + " hours</td>"
} else { // less than an hour
return '<td class="time-green">' + (v/60).toFixed(0) + " minutes</td>"
}
}

$(function() {
$.getJSON(
"https://prometheus.voidlinux.org/api/v1/query?query=(time()-repo_origin_time%7Bzone=%22external%22%7D)",
function(data) {
var mirrors = {};
$.each(data["data"]["result"], function(i, val) {
mirrors[val["metric"]["instance"].replace(/current$/, "")] = parseAge(val["value"][1]);
});
console.log(mirrors);
$(".mirrortbl thead tr").append('<th>Last Synced</th>');
$(".mirrortbl tbody tr").each(function() {
var k = $(this).children(":first")[0].innerText.trim().replace(/https?:\/\//, "");
$(this).append(mirrors[k] || '<td class="time-muted">unreachable</td>');
});
}
);
});

55 changes: 40 additions & 15 deletions web/assets/misc.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,52 @@ h1[id], h2[id], h3[id], h4[id], h5[id], h6[id] {
border-color: black;
}

table {
.mirrortbl {
border-collapse: collapse;
overflow-y: auto;
border: 1px #478061 solid;
table-layout: fixed;
}

table td {
.mirrortbl td {
padding: 6px 20px;
}

table thead {
.mirrortbl thead {
background: #478061;
color: #fff;
}

table thead th {
.mirrortbl thead th {
font-weight: 700;
text-align: center;
padding: 6px 20px;
}

thead th:nth-child(1) {
width: 50%;
.mirrortbl tr:nth-child(2n) {
background: #eee;
}

thead th:nth-child(2) {
width: 20%;
.time-muted {
color: #666;
background-color: #ddd;
}

thead th:nth-child(3) {
width: 30%;
.time-red {
color: #fff;
background-color: rgb(227, 46, 66);
}

.time-yellow {
background-color: rgb(234, 184, 57);
}

tbody tr:nth-child(2n) {
background: #fafafa;
.time-green {
background-color: rgb(115, 191, 105);
}

@media (prefers-color-scheme: dark) {
body {
color: #ccc;
color: #ddd;
background-color: #222;
}
h1, h2, h3, h4, h5, h6 { color: #ccc; }
Expand All @@ -94,7 +99,27 @@ tbody tr:nth-child(2n) {
.navbar {
background-color: #295340;
}
tbody tr:nth-child(2n) {
.mirrortbl tbody tr:nth-child(2n) {
background: #2c2c2c;
}

.time-muted {
color: #aaa;
background-color: #444;
}

.time-red {
color: #000;
background-color: #d73c50;
}

.time-yellow {
color: #222;
background-color: rgb(234, 184, 57);
}

.time-green {
color: #222;
background-color: rgb(115, 191, 105);
}
}
2 changes: 1 addition & 1 deletion web/generate-site.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


tabletmpl = """
<table>
<table class="mirrortbl">
<thead>
<tr>
<th>Mirror</th>
Expand Down
6 changes: 3 additions & 3 deletions web/index.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
<link rel="stylesheet" href="/assets/screen.css">
<link rel="stylesheet" href="/assets/misc.css">
<link rel="stylesheet" href="/assets/font-ubuntu.css">

<script src="/assets/jquery.min.js"></script>
<script src="/assets/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-default navbar-inverse navbar-sticky" role="navigation">
Expand Down Expand Up @@ -126,5 +123,8 @@
<p class="text-center">Linux® is a registered trademark of Linus Torvalds (<a href="https://www.linuxfoundation.org/programs/legal/trademark/attribution">info</a>)</p>
</footer>
</div>
<script src="/assets/jquery.min.js"></script>
<script src="/assets/bootstrap.min.js"></script>
<script src="/assets/live-metrics.js"></script>
</body>
</html>