forked from jmandel/csv-to-fhir-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
233 lines (201 loc) · 7.17 KB
/
index.html
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!doctype html>
<html>
<head>
<style>
#submissions {width: 100%; border: 1em solid black; box-sizing: border-box;}
iframe {width: 100%; border: 1em solid yellow; box-sizing: border-box; zoom: 50%}
button {margin-bottom: 2em;}
</style>
</head>
<body>
<!--
CSV File:
<input type="file" id="csv" name="csvfile"/> <br>
-->
Min comment #: <input type="text" id="min-comment" value="1" size="3"/><br>
Max comment #: <input type="text" id="max-comment" value="1" size="3"/><br>
Comment prefix: <input type="text" id="comment-prefix" value="Jan 2015 Ballot Comment #" /><br>
<button id="create">Create issues!</button>
<iframe id="submitter"></iframe>
<script src="jquery-2.1.3.min.js"></script>
<script src="papaparse.js"></script>
<script>
var commentsFile = "january-2015-comments.csv";
var gforge = "http://gforge.hl7.org";
//var gforge = "http://localhost:9999";
var tracker = "/gf/project/fhir/tracker/?action=TrackerItemAdd&tracker_id=";
var tid = "677";
var page = null;
var form = null;
var issues = null;
var loaded = 0;
var processed = 0;
var bodyFields = [
//"Comment Number",
"Vote and Type",
"Existing Wording",
"Proposed Wording",
"Comments",
"In person resolution requested",
"Comment grouping",
"Disposition WG",
//"Tracker Item",
"Priority",
"Grahame's Comments",
"Disposition",
"Disposition Comment",
"Disposition Date",
"Mover / seconder",
"For",
"Against",
"Abstain",
"Retracted / Withdrawn",
"Responsible Person",
"Change Applied",
"Substantive Change",
"Submitted By",
"Organization",
"On behalf of",
"On Behalf of Email",
"Submitter Tracking ID"
];
var structuredFields = [
"Section Number",
"Page or Section URL",
"Owning WG",
"Tracker Category",
"Resource(s)",
"page(s)"
// "Priority", // I don't see what this maps to in GForge
// "Disposition", // I don't see what this maps to in GForge
];
fieldMaps = {
"Section Number": [ FormElementCalled("Section number"), ValFiller ],
"Page or Section URL": [ FormElementCalled("url"), ValFiller ],
"Resource(s)": [ FormElementCalled("Resource(s)"), SelectFiller ],
"page(s)": [ FormElementCalled("HTML Page"), SelectFiller ],
"Owning WG": [ FormElementCalled("Reviewing Work Group(s)"), SelectFiller ],
"Tracker Category": [ FormElementCalled("Category"), SelectFiller ]
};
function processOneIssue(){
//console.log("Processing issue");
$("#submitter").attr("src", "");
iframeBody = $("#submitter").contents().find("body");
iframeBody.empty();
var issue = issues[processed++];
if (!issue) {
$("#submitter").removeAttr("onLoad");
$("button").removeAttr("disabled");
return;
}
var form = populateNewForm(issue);
iframeBody.append(form);
window.formCopy = form;
$("#submitter").attr("onLoad", "processOneIssue()");
form.submit();
}
function populateNewForm(issue){
var blank = form.cloneNode(true);
var newline = "\n"
importantFields = bodyFields.reduce(function(dict, v){
var extra = "";
if (issue[v] && issue[v].trim() !== "") {
extra = newline + "<strong>" + v + "</strong>:" +
newline + issue[v] + newline;
}
return dict + extra;
}, "");
content = importantFields.replace(new RegExp("\n", "g"), "<br>\n");
details = $("textarea[name='details']", blank);
details[0].innerHTML = content;
//console.log("Set deatils as", content, details, details[0].innerHTML);
var comment = $("#comment-prefix").val();
$("input[name='summary']", blank).val(comment + issue["Comment Number"])
if (issue["Tracker Category"] == "Non-Tracker" || !issue["Tracker Category"]){
issue["Tracker Category"] = "None";
}
structuredFields.forEach(function(f){
var val = issue[f];
if (!fieldMaps[f]) return;
var getter = fieldMaps[f][0];
var filler = fieldMaps[f][1];
var field = getter(blank);
filler(field, val);
//console.log("Tried filling", field, val, field.val());
});
// for some reason DOM changes aren't reliable without a clone step
// (e.g. removeAttr("selected") calls don't take effect yet).
return blank.cloneNode(true);
}
function loadOne(){
if (++loaded >= 2)
$("button").removeAttr("disabled");
}
//var source = gforge+tracker+tid;
var source = "gforge-ballot-template.html";
$.ajax(source).done(function(newp){
page = newp;
form = $("form", page)[0].cloneNode(true);
$("input[name='monitor']", form)[0].removeAttribute("checked");
form.setAttribute("action", gforge + form.getAttribute("action"));
$("div", form).remove();
$("script", form).remove();
$("input[name='tracker_id']", form).val(tid);
console.log("got the blank form");
loadOne();
});
Papa.parse(commentsFile, {
header: true,
download: true,
complete: function(results) {
console.log("Parsed");
window.results = results;
loadOne();
}
});
function FormElementCalled(text){
return function(form){
el = $("strong", form).filter(function(i,e){
return $(e).text() == text;
})[0];
//console.log("FEC", text, el);
if (text === "Category")
return $(el).next().next().next();
else
return $(el).next().next();
//while ($(el).text() != "input" && $(el).text() != "select" && $(el).text() != "textarea") el = $(el).next();
//return el;
}
}
function ValFiller(field, value){
//console.log("ValFller", field, value);
field.val(value);
}
function SelectFiller(field, value){
if (!value) return;
$("option", field).each(function(i, o){
var isMatch = o.text.match(new RegExp(value, "i"));
//console.log("Matching for ", value, o.text, isMatch);
if (isMatch){
o.setAttribute("selected", "selected");
} else {
o.removeAttribute("selected");
}
});
}
$("#create").click(function(){
$("button").attr("disabled", "true");
var min = parseInt($("#min-comment").val());
var max = parseInt($("#max-comment").val());
window.issues = results.data.filter(function(i){
var cnum = parseInt(i["Comment Number"]);
var cat = i["Tracker Category"] !== "Non-Tracker";
return cat && cnum >= min && cnum <= max;
});
console.log("Restrictnig from", min, "to", max, "yielded", issues.length, "issues");
processed = 0;
processOneIssue();
});
</script>
</body>
</html>