-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.html
More file actions
123 lines (94 loc) · 3.58 KB
/
Copy pathvalidate.html
File metadata and controls
123 lines (94 loc) · 3.58 KB
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
---
layout: post
title: Validate your data
---
<script src='assets/js/micca-0.6.1.js'></script>
<div class="container">
<div class="intro">
<p class="intro__post"> </p>
</div>
<div id='intro-section'>
<p>
Use this page to check the structure of your data and identify any data that don't conform to the definitions in the data dictionary. This tool runs locally in your web browser and does not transmit data anywhere.
</p>
</div>
<div id='getter-section'>
<p>Step 1: Select MICCA input file:</p>
<input id='input-file' type='file' onchange='onChangeHandler(this.files)'>
</div>
<p></p>
<div id='output-section'>
<p>Step 2: View report of issues with input data</p>
<div id='validation-output'></div>
<!-- Function to handle file input and display results -->
<!-- Extract this to a bundle later -->
<script>
function createReportDescript(problems){
let probDiv = document.createElement("div");
probDiv.setAttribute('class', 'container');
let dl = probDiv.appendChild(document.createElement("dl"));
dl.setAttribute('class','reportout');
let dt,dd,p;
if("headerProblems" in problems){
let hprobs = problems['headerProblems'];
for( const key in hprobs){
dt = dl.appendChild(document.createElement("dt"));
dt.setAttribute('class','reportout');
p = dt.appendChild(document.createElement("p"));
p.setAttribute('class','title');
p.innerHTML = `${key}:`;
dd = dl.appendChild(document.createElement("dd"));
dd.setAttribute('class','reportout');
p = dd.appendChild(document.createElement("p"));
p.innerHTML = hprobs[key].toString();
}
}
if("rowProblems" in problems){
let rprobs = problems['rowProblems'];
for( const key in rprobs){
dt = dl.appendChild(document.createElement("dt"));
dt.setAttribute('class','reportout');
p = dt.appendChild(document.createElement("p"));
p.setAttribute('class','title');
p.innerHTML = `Row ${key}:`;
dd = dl.appendChild(document.createElement("dd"));
dd.setAttribute('class','reportout');
p = dd.appendChild(document.createElement("p"));
p.innerHTML = rprobs[key].toString();
}
}
return(probDiv);
}
function processData(rawText){
let outsec = document.getElementById('validation-output');
//Check validity and get list of problems
let isValid = micca.Validator.validateFile(rawText);
let problems = micca.Marple.reportProblems(rawText);
outP = outsec.appendChild( document.createElement("p") );
outP.innerHTML = "Processing Done";
outVerdict = outsec.appendChild( document.createElement("p") );
outP.innerHTML = `Input file is: ${isValid ? "Valid" : "Invalid"}`;
if(!isValid){
let details = createReportDescript(problems);
outsec.appendChild( details);
}
}
function onChangeHandler(files){
console.log("file changed");
// Clear existing outputs
let outsec = document.getElementById('validation-output');
while(outsec.firstChild){ outsec.removeChild(outsec.firstChild); }
// Read file and update DOM
let file = files[0];
try{
let reader = new FileReader();
// Define what action to take upon loading input file
reader.onload = function(e) { processData(reader.result); }
// Do the read
reader.readAsText(file);
}
catch(err){ console.log(err); }
}
</script>
</div>
</div>