forked from silverstripe/supported-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
87 lines (77 loc) · 3.02 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var no_status = 'https://raw.githubusercontent.com/silverstripe/supported-modules/gh-pages/gha-no-status.svg';
$.ajax({
"url": "modules.json",
"dataType": "json"
}).then(function(modules) {
var rows = [];
modules.forEach(function(module) {
var row = "<tr>";
if (module.addons) {
row += "<td><a href='https://addons.silverstripe.org/add-ons/" + module.composer + "'>" + module.composer + "</a></td>";
} else {
if (module.github) {
row += "<td><a href='/~https://github.com/" + module.github + "'>" + module.composer + "</a></td>";
} else if (module.gitlab) {
row += "<td><a href='https://gitlab.cwp.govt.nz/" + module.gitlab + "'>" + module.composer + "</a></td>";
} else {
row += "<td>" + module.composer + "</td>";
}
}
if (module.type === "supported-module") {
row += "<td>" + "Supported module" + "</td>";
} else {
row += "<td>" + "Supported dependency" + "</td>";
}
if (module.github) {
row += [
"<td class='progress first'>",
"<a href='/~https://github.com/" + module.github + "'>",
"<img src='" + no_status + "' class='noci' />",
"</a>",
"<a href='/~https://github.com/" + module.github + "/actions/workflows/ci.yml' style='visibility:hidden;'>",
"<img src='/~https://github.com/" + module.github + "/actions/workflows/ci.yml/badge.svg' class='ci' />",
"</a>",
"</td>"
].join('');
} else if (module.gitlab) {
row += "<td colspan='3'>Module on Gitlab</td>";
} else {
row += "<td colspan='3'>Module definition incomplete</td>";
}
row += "</tr>";
rows.push(row);
});
$("tbody").html(rows.join(""));
});
// this script is to replace the "missing image" placeholder with a "no status" ci badge
var c = 0;
var interval = setInterval(function() {
var els = document.querySelectorAll('.progress');
els.forEach(function(el) {
var noci = el.querySelector('.noci');
if (!noci) {
return;
}
var ci = el.querySelector('.ci');
var style = getComputedStyle(ci);
// ci badge has loaded
// using 50 because the "missing image" browser placeholder actually has a computed width
if (style.width.replace('px', '') > 50) {
el.removeChild(noci.parentNode);
ci.parentNode.style.removeProperty('visibility');
}
});
// give it 10 seconds to fetch status badges
if (c++ >= 4 * 10) {
// delete missing ci elements
els.forEach(function(el) {
var noci = el.querySelector('.noci');
if (!noci) {
return;
}
var ci = el.querySelector('.ci');
el.removeChild(ci.parentNode);
});
clearInterval(interval);
}
}, 250);