-
Notifications
You must be signed in to change notification settings - Fork 17
/
camel-main.js
188 lines (159 loc) · 5.44 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
'use strict';
document.title = specific.toUpperCase() + " Camel";
d3.select('#welcome').text(specific.toUpperCase());
d3.select("#main").text("Calculating..");
var statuses={}
var allsections={};
var allrfcs={};
var specificrfcentries={};
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) {
if(d.column != "title")
return d.value;
else
return '<a href="'+d.url+'">'+d.value+'</a>';
});
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 specificrfcentries) {
var o = specificrfcentries[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(specificrfcentries).length + " RFCs relevant to " + specific.toUpperCase() + ", of which "+arr.length+" are selected by filter. Total pages selected: "+totalPages);
}
var specificrfcs={};
var drafts={};
function phaseTwo() {
d3.json("data/all-" + specific + "-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 specificrfcs) {
statuses[rfc.currentStatus]=1;
rfc.url = 'https://tools.ietf.org/html/'+rfc.docID.toLowerCase()+'.txt';
rfc.sections="";
if("sections" in specificrfcs[rfc.docID.toLowerCase()]) {
rfc.sectionsArray = specificrfcs[rfc.docID.toLowerCase()].sections;
for(var b in specificrfcs[rfc.docID.toLowerCase()].sections) {
rfc.sections+= specificrfcs[rfc.docID.toLowerCase()].sections[b]+" ";
allsections[specificrfcs[rfc.docID.toLowerCase()].sections[b]] = 1;
}
}
specificrfcentries[rfc.docID] = rfc;
}
}
statuses["INFORMATIONAL"]=0;
statuses["EXPERIMENTAL"]=0;
statuses["BEST CURRENT PRACTICE"]=0;
statuses["UNKNOWN"]=0;
statuses["HISTORIC"] = 0
statuses["BEST_CURRENT_PRACTICE"] = 0
d3.json(specific + "-drafts.json").then(function(js) {
drafts=js;
for(var a in js) {
var o ={};
o.docID="draft"+a;
o.docID = js[a].name;
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.obsoleted=0;
o.draft=1;
o.url = 'https://tools.ietf.org/id/'+js[a].name;
o.sections="core";
o.sectionsArray=["core"];
specificrfcentries[o.docID]=o;
}
createTable();
updateTable();
});
});
}
d3.json(specific + "-rfc-annotations.json", {cache: "force-cache"}).then(function(js) {
specificrfcs = js;
phaseTwo();
});