-
Notifications
You must be signed in to change notification settings - Fork 9
/
report.js
130 lines (121 loc) · 7.18 KB
/
report.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
const now = new Date();
const upcoming = d => new Date(d) < monthFromNow(4);
const upcoming6 = d => new Date(d) < monthFromNow(6);
const outdated = d => new Date(d) < now;
const monthFromNow = (n) => new Date(new Date().setMonth(now.getMonth() + n));
const last = a => a[a.length - 1];
const specLink = (spec) => {
const li = document.createElement("li");
const a = document.createElement("a");
a.href = spec.shortlink;
a.textContent = spec.title;
li.appendChild(a);
return li;
}
const listMilestoneTest = (id, milestone, test) => {
return (milestoneData, specData, groupname) => {
const el = document.querySelector("#" + id + " ol");
if (!el) return console.error("Invalid id " + id);
el.setAttribute("data-sort", "span,a")
Object.keys(milestoneData || {}).forEach(s => {
Object.keys(milestoneData[s]).filter(m => m === milestone || milestone === "*").forEach(m => {
if (test(milestoneData[s][m])) {
const spec = extractSpecData(s, specData);
if (spec) {
const li = specLink(spec);
const date = document.createElement("span");
date.appendChild(document.createTextNode(milestoneData[s][m]));
if (outdated(milestoneData[s][m])) date.className='outdated';
li.appendChild(document.createTextNode(" (" + groupname + ") : "));
li.appendChild(date);
el.appendChild(li);
} else {
console.error("Could not find data on " + s);
}
}
});
});
};
};
const fetchJSON = path => fetch(path).then(r => r.json()).catch(e => { console.error(`Loading JSON from ${path} failed with`); console.error(e);});
const schemeLess = url => url.split(':').slice(1).join(':');
const extractSpecData = (shortlink, specs) => specs.filter(s => schemeLess(s.shortlink) === schemeLess(shortlink))[0];
fetchJSON("groups.json")
.then(groups => {
return Promise.all(Object.keys(groups).map(gid => {
const specDataPromise = fetchJSON("./pergroup/" + gid + ".json");
const milestoneDataPromise = fetchJSON("./pergroup/" + gid + "-milestones.json");
const repoDataPromise = fetchJSON("./pergroup/" + gid + "-repo.json");
const groupnamePromise = new Promise((res) => res(groups[gid].name));
return Promise.all([specDataPromise, milestoneDataPromise, repoDataPromise, groupnamePromise])
.then(([specData, milestoneData, repoData, groupname]) => {
const count = document.getElementById('count');
const reccount = document.getElementById('reccount');
count.textContent = parseInt(count.textContent, 10) + specData.length;
reccount.textContent = parseInt(reccount.textContent, 10) + specData.filter(s => s.versions[0]["rec-track"]).length;
listMilestoneTest("upcomingwr", "WR/LC", upcoming)(milestoneData, specData, groupname);
listMilestoneTest("upcomingcr", "CR", upcoming)(milestoneData, specData, groupname);
listMilestoneTest("upcomingpr", "PR", upcoming6)(milestoneData, specData, groupname);
listMilestoneTest("beyondcharter", "*", d => d > groups[gid].end)(milestoneData, specData, groupname);
var abandoned = document.querySelector("#abandoned ol");
abandoned.setAttribute("data-sort", "span,a");
var longRunning = document.querySelector("#longrunning ol");
longRunning.setAttribute("data-sort", "span,a");
var noRepo = document.querySelector("#norepo ol");
norepo.setAttribute("data-sort", "a");
var noEd = document.querySelector("#noed ol");
noEd.setAttribute("data-sort", "a");
Object.keys(specData).filter(s => specData[s].versions[0]["rec-track"]).forEach(s => {
const spec = specData[s];
if (new Date(spec.versions[0].date) < monthFromNow(-36)) {
const li = specLink(spec);
const date = document.createElement("span");
date.appendChild(document.createTextNode(spec.versions[0].date));
li.appendChild(document.createTextNode(": "));
li.appendChild(date);
abandoned.appendChild(li);
}
if (new Date(last(spec.versions).date) < monthFromNow(-60)) {
const li = specLink(spec);
const date = document.createElement("span");
date.appendChild(document.createTextNode(last(spec.versions).date));
li.appendChild(document.createTextNode(": "));
li.appendChild(date);
longRunning.appendChild(li);
}
if (!repoData[spec.shortlink]) {
const li = specLink(spec);
li.appendChild(document.createTextNode(": "));
if (spec.editorsdraft) {
const edDraft = document.createElement("a");
edDraft.href = spec.editorsdraft;
edDraft.textContent = "editors draft on " + edDraft.hostname;
li.appendChild(edDraft);
noRepo.appendChild(li);
} else {
li.appendChild(document.createTextNode("No editors draft known"));
noEd.appendChild(li);
}
}
});
});
}))
}, console.error.bind(console))
.then(() => {
// Sort lists as appropriate
[...document.querySelectorAll("ol[data-sort]")].forEach(ol => {
const sortSelectors = ol.dataset.sort.split(',');
const items = [...ol.children];
items.sort((li1, li2) => {
for (i = 0 ; i < sortSelectors.length; i++) {
const comp = li1.querySelector(sortSelectors[i]).textContent.localeCompare(li2.querySelector(sortSelectors[i]).textContent);
if (comp !== 0) return comp;
}
return 0;
});
ol.innerHTML = "";
items.forEach(li => ol.appendChild(li));
});
});
}