forked from ahupowerdns/protocol-camel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
camel-main.js
195 lines (167 loc) · 5.58 KB
/
camel-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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
'use strict';
d3.select("#main").text("Calculating..");
var statuses={}
var allsections={};
var allrfcs={};
var dnsrfcentries={};
function tabulate(data, columns) {
d3.select('#table').html("");
var table = d3.select('#table').append('table')
var thead = table.append('thead')
var tbody = table.append('tbody');
// append the header row
thead.append('tr')
.selectAll('th')
.data(columns).enter()
.append('th')
.text(function (column) { return column; });
// create a row for each object in the data
var rows = tbody.selectAll('tr')
.data(data)
.enter()
.append('tr');
// create a cell in each row for each column
var cells = rows.selectAll('td')
.data(function (row) {
return columns.map(function (column) {
return {column: column, value: row[column], url: row["url"]};
});
})
.enter()
.append('td')
.html(function (d) {
switch(d.column) {
case "docID":
return '<span id="link_'+d.value+'">'+d.value+'</span>';
case "obsoleted":
if (Array.isArray(d.value)) {
var arr = [];
for (var a in d.value) {
arr.push('<a href="#link_'+d.value[a]+'">'+d.value[a]+'</a>');
}
return arr.join(', ');
}
return '';
case "title":
return '<a href="'+d.url+'">'+d.value+'</a>';
default:
return d.value;
}
});
return table;
}
function handleStatusClick(e)
{
statuses[e.id]=e.checked;
updateTable();
}
function handleSectionClick(e)
{
allsections[e.id]=e.checked;
updateTable();
}
function createTable()
{
statuses["OBSOLETED"]=0;
statuses["DRAFT"]=0;
var statarr = Object.keys(statuses);
var table = d3.select('#selector').append('table')
var thead = table.append('thead')
var tbody = table.append('tbody');
tbody.append('tr')
.selectAll('td')
.data(statarr).enter()
.append('td')
.html(function (column) {
if(statuses[column])
return '<input type="checkbox" checked id="'+column+'" onclick="handleStatusClick(this);"> <label for="'+column+'">'+column+'</label>';
else
return '<input type="checkbox" id="'+column+'" onclick="handleStatusClick(this);"> <label for="'+column+'">'+column+'</label>';
});
var sectarr = Object.keys(allsections);
tbody.append('tr')
.selectAll('td')
.data(sectarr).enter()
.append('td')
.html(function (column) {
if(allsections[column])
return '<input type="checkbox" checked id="'+column+'" onclick="handleSectionClick(this);"> <label for="'+column+'">'+column+'</label>';
else
return '<input type="checkbox" id="'+column+'" onclick="handleSectionClick(this);"> <label for="'+column+'">'+column+'</label>';
});
}
function updateTable()
{
var arr=[]
var totalPages=0;
for(var e in dnsrfcentries) {
var o = dnsrfcentries[e];
if(statuses[o.currentStatus] && (!o.obsoleted || statuses["OBSOLETED"]) && (!o.draft || statuses["DRAFT"])) {
var doit=false;
for(var l in o.sectionsArray) {
if(allsections[o.sectionsArray[l] ]) {
doit = true;
break;
}
}
if(doit) {
arr.push(o);
totalPages += o.pages;
}
}
}
tabulate(arr, ["docID", "title", "pages", "currentStatus", "obsoleted", "sections"]);
d3.select("#main").text("There are "+Object.keys(dnsrfcentries).length + " RFCs relevant to Mail, of which "+arr.length+" are selected by filter. Total pages selected: "+totalPages);
}
var dnsrfcs={};
var drafts={};
function phaseTwo() {
d3.json("all-rfcs.json", {cache: "force-cache"}).then(function(js) {
allrfcs = js;
for(var a in js) {
var rfc = js[a];
// there must be a way, way better way to do this loop
if(rfc.docID.toLowerCase() in dnsrfcs) {
statuses[rfc.currentStatus]=1;
rfc.url = 'https://tools.ietf.org/html/'+rfc.docID.toLowerCase()+'.txt';
rfc.sections="";
if("sections" in dnsrfcs[rfc.docID.toLowerCase()]) {
rfc.sectionsArray = dnsrfcs[rfc.docID.toLowerCase()].sections;
for(var b in dnsrfcs[rfc.docID.toLowerCase()].sections) {
rfc.sections+= dnsrfcs[rfc.docID.toLowerCase()].sections[b]+" ";
allsections[dnsrfcs[rfc.docID.toLowerCase()].sections[b]] = 1;
}
}
dnsrfcentries[rfc.docID] = rfc;
}
}
statuses["INFORMATIONAL"]=0;
statuses["HISTORIC"]=0;
statuses["EXPERIMENTAL"]=0;
statuses["BEST CURRENT PRACTICE"]=0;
statuses["UNKNOWN"]=0;
d3.json("drafts.json").then(function(js) {
drafts=js;
for(var a in js) {
var o ={};
o.docID="draft"+a;
o.title = js[a].title;
o.pages = js[a].pages;
o.currentStatus = js[a].track;
if(o.currentStatus == "STANDARDS TRACK")
o.currentStatus = "PROPOSED STANDARD";
o.draft=1;
o.url = 'https://tools.ietf.org/id/'+js[a].name;
o.sections=js[a].sections.join(" ");
o.sectionsArray=js[a].sections;
dnsrfcentries[o.docID]=o;
}
});
createTable();
updateTable();
});
}
d3.json("rfc-annotations.json", {cache: "force-cache"}).then(function(js) {
dnsrfcs = js;
phaseTwo();
});