forked from shado-av/shado-webdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim-test.html
197 lines (166 loc) · 6.62 KB
/
sim-test.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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Favicon -->
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<!-- required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap 4.1.1 libraries -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<!-- Fontawesome Icons -->
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js" integrity="sha384-SlE991lGASHoBfWbelyBPLsUlwY1GwNDJo3jSJO04KZ33K2bwfV9YBauFfnzvynJ" crossorigin="anonymous"></script>
<!-- custom CSS and JavaScript -->
<script src="env.js"></script>
<link rel="stylesheet" href="css/simulator.css">
<!-- title -->
<title>SHADO Test for Developers</title>
</head>
<body>
<!-----------------------------------------
TOP NAVIGATION
------------------------------------------>
<nav class="navbar fixed-top">
<!-- HAL logo and SHADO title -->
<a class="navbar-brand" href="index.html">
<img src="images/hal_light.png" height="38" alt="HAL Logo">
<span id="brand">Simulator of Humans and Automation in Dispatch Operations</span>
<span id="brand-abbr">SHADO</span>
</a>
</nav>
<!-- navigation spacer -->
<div class="spacer"></div>
<div id="shado-sim" class="row">
<div class="col-1"></div>
<div class="col-8">
<div class="row">
<h3 class="col-12 mt-5 mb-5">Simulation by JSON Input file</h3>
<div class="col-12 mb-3">1. Press Choose File to choose your server input file (usually named shadoParamsXXX.json)</div>
<input class="col-12" id="file" type="file" />
<output id="list"></output>
<!-- run sim button -->
<div class="col-12 mt-3 mb-3">
<div class="mb-3">2. Press the Run Simulation button</div>
<button id="submitBtn" class="btn btn-primary btn-sm" type="button">Run Simulation</button>
</div>
<div class="col-12 mb-3" id="downloadBtn" style="display: none">
<div>3. Press button to download output</div>
<div class="divider"></div>
<button id="downloadCSV" class="btn btn-secondary btn-sm" title="">Download CSV</button>
<div class="divider"></div>
<button id="downloadJSON" class="btn btn-secondary btn-sm" title="">Download Output JSON</button>
<div class="divider"></div>
<button id="downloadSummary" class="btn btn-secondary btn-sm" title="">Download Summary</button>
</div>
</div>
</div>
<div class="col-1"></div>
</div>
<script>
$(document).ready(function() {
document.getElementById('file').addEventListener('change', handleFileSelect, false);
$('#submitBtn').prop('disabled', true);
var json;
var sessionId = "";
var sessionQuery = "";
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
console.log('e readAsText = ', e);
console.log('e readAsText target = ', e.target);
try {
json = JSON.parse(e.target.result);
//alert('json global var has been set to parsed json of this file here it is unevaled = \n' + JSON.stringify(json));
//console.log($('#submitBtn').attr('disabled'));
$('#submitBtn').prop("disabled", false);
} catch (ex) {
alert('ex when trying to parse json = ' + ex);
}
}
})(f);
reader.readAsText(f);
}
}
$("#submitBtn").click(function() {
console.log(json);
$('#downloadBtn').hide();
$.ajax({
type: "POST",
url: env.serverUrl + "/shado/runShado",
// The key needs to match your method's input parameter (case-sensitive).
data: JSON.stringify(json),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg);
console.log("response received");
console.log(msg);
alert("PARAMETERS SUBMITTED!");
},
complete: function(msg) {
console.log("response received");
console.log(msg);
var obj = JSON.stringify(msg);
if (msg.status == 500) {
alert("Server Error: Check parameters(maybe not enough tasks)!")
alert(msg.responseText);
}
if (msg.status == 200) {
alert(msg.responseText);
sessionId = msg.responseText.substr(msg.responseText.lastIndexOf(":") + 2);
sessionQuery = "?sessionN=" + sessionId;
showDownloadBtn();
}
document.getElementById("submitBtn").textContent = "Submit Again";
},
failure: function(errMsg) {
alert(errMsg);
}
});
});
$("#downloadCSV").click(function() {
// $.get("http://localhost:8080/shado/getRepDetail");
window.location.href = env.serverUrl + "/shado/getRepDetail" + sessionQuery;
console.log("GET request 'getRepDetail' sent");
});
$("#downloadSummary").click(function() {
var xhttp = new XMLHttpRequest();
window.location.href = env.serverUrl + "/shado/getSummary" + sessionQuery;
console.log("GET request 'getSummary' sent");
});
$("#downloadJSON").click(function() {
window.location.href = env.serverUrl + "/shado/getUtilizationJSON" + sessionQuery;
console.log("GET request 'getUtilizationJSON' sent");
});
$(function() {
$("form").submit(function() {
return false;
});
});
// when tab is selected, focus on the first input
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
var target = e.target.attributes.href.value;
var selectedTab = $(target + ' a.active');
if (selectedTab.length > 0) {
target = selectedTab[0].attributes.href.value;
}
if ($(target + ' input').length > 0)
$(target + ' input')[0].focus();
})
});
function showDownloadBtn() {
document.getElementById("downloadBtn").style.display = "block";
document.getElementById("downloadSummary").style.display = "block";
}
</script>
</body>
</html>