-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
66 lines (53 loc) · 1.8 KB
/
main.ts
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
$(() => {
var logger = new Logger();
$('#runTestsBtn').click(() => {
var testRunner = new TestRunner(logger);
testRunner.runTests();
});
function handleFileSelect(evt) {
evt.stopPropagation();
evt.preventDefault();
$('#drop_zone').removeClass('dragging');
logger.clear();
var files = evt.dataTransfer.files; // FileList object.
var f = files[0];
getFileData(f, (csvStr) => {
if (!csvStr.trim()) {
logger.logFailure('no data found in file');
return;
}
try {
var csvData = $.csv.toObjects(csvStr);
} catch (e) {
logger.logFailure('Unable to read file. It should be a csv file.');
return;
}
logger.logFailure(f.name + ': read ' + csvData.length + ' rows');
var v = new Validator(logger);
v.validate(csvData);
});
}
function getFileData(f, go) {
var r = new FileReader();
r.onload = function (e: any) {
var contents = e.target.result;
go(contents);
}
r.readAsText(f);
}
function handleDragOver(evt) {
evt.stopPropagation();
evt.preventDefault();
$('#drop_zone').addClass('dragging');
evt.dataTransfer.dropEffect = 'copy';
}
function handleDragLeave(evt) {
evt.stopPropagation();
evt.preventDefault();
$('#drop_zone').removeClass('dragging');
}
var dropZone = document.getElementById('drop_zone');
dropZone.addEventListener('dragover', handleDragOver, false);
dropZone.addEventListener('dragleave', handleDragLeave, false);
dropZone.addEventListener('drop', handleFileSelect, false);
});