-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
284 lines (264 loc) · 10.9 KB
/
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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/* globals $, document */
let top_level_data = [];
let second_level_data = [];
const display_names = {
"org_name": "Folder",
"study_name": "Study",
"current_version_passes_validation": "Current Version Passes Validation",
"current_version_loads_successfully": "Current Version Loads Successfully",
"current_version_loaded": "Current Version Loaded",
"previous_version_loaded": "Previous Version Loaded",
"passes_validation": "Passes Validation",
"loads_successfully": "Loads Successfully",
"currently_loaded": "Currently Loaded",
"validation_success": "Validation Success",
"validation_status_code": "Validation Result",
"validation_time_added": "Validation Time Added",
"import_success": "Import Success",
"import_status_code": "Import Result",
"import_time_added": "Import Time Added",
"output": "Output",
"level": "Log Level",
"path": "Path",
"message": "Log Message",
"Validation Results": "Validation Results",
"Import Results": "Import Results"
};
function timeConverter(UNIX_timestamp) {
if (UNIX_timestamp == null) return UNIX_timestamp;
const a = new Date(UNIX_timestamp * 1000);
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const year = a.getFullYear();
const month = months[a.getMonth()];
const date = a.getDate();
const hour = a.getHours();
const min = a.getMinutes();
const sec = a.getSeconds();
return date + ' ' + month + ' ' + year + (' ' + hour).padStart(2, "0") + (':' + min).padStart(2, "0") + (':' + sec).padStart(2, "0")
}
$(document).ready(function () {
const main = $('#main');
const breadcrumbs = $('#breadcrumbs');
let AjaxGet = function (url) {
const result = $.ajax({
type: "GET",
url: url,
param: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
});
return eval(result.responseText)
};
let ElemAjaxGetText = function (elem, url) {
$.ajax({
type: "GET",
url: url,
param: '{}',
contentType: "text/plain; charset=utf-8",
dataType: "text",
async: true,
success: function (data) {
elem.text(data)
}
});
};
top_level_data = AjaxGet("/dashboard/data/top_level.json");
second_level_data = AjaxGet("/dashboard/data/second_level.json");
const second_level_headers = {
//"passes_validation": "bool",
//"loads_successfully": "bool",
//"currently_loaded": "bool",
//"validation_success": "bool",
//"validation_status_code": "exit_code",
//"validation_time_added": "timestamp",
//"import_success": "bool",
//"import_status_code": "exit_code",
"import_time_added": "timestamp",
"Validation Results": "text",
"Import Results": "text"
};
const top_level_headers = {
"study_name": "text",
//"current_version_passes_validation": "bool",
//"current_version_loads_successfully": "bool",
"current_version_loaded": "bool",
"previous_version_loaded": "bool"
};
const bool_key_emotion_if_true = {
"available": "positive",
"current_version_passes_validation": "positive",
"current_version_loads_successfully": "positive",
"passes_validation": "positive",
"loads_successfully": "positive",
"validation_success": "positive",
"import_success": "positive",
"success": "positive"
};
function handle_bool(td, value, property) {
value = (value === null) ? null : (value !== 0);
const emotion = bool_key_emotion_if_true[property];
if (value != null) {
if (emotion != null) {
if (value) td.addClass(emotion === 'positive' ? 'positive' : 'negative');
else td.addClass(emotion === 'positive' ? 'negative' : 'positive');
}
td.append($("<i>").addClass("icon").addClass(value ? "checkmark" : "close"))
}
}
function render_toplevel() {
const table = $('<table>').addClass('ui celled table unstackable');
const thead = $('<thead>');
const tr = $('<tr>');
for (let i in top_level_headers) {
tr.append($('<th>').text(display_names[i]))
}
thead.append(tr);
table.append(thead);
const tbody = $('<tbody>');
top_level_data.forEach(function (row) {
const tr = $('<tr>');
if (row['current_version_loaded'] || row['previous_version_loaded']) tr.addClass('positive');
else if (!(row['current_version_loaded'] == null && row['previous_version_loaded'] == null))
tr.addClass('negative');
for (let property in top_level_headers) {
const value_type = top_level_headers[property];
const value = row[property];
const td = $('<td>').data('label', property);
if (value_type === "bool") {
handle_bool(td, value, property)
}
else if (property === "study_name") {
const link = $('<a>');
link.addClass('secondlevel-link');
link.text(value);
link.attr('href', '#');
link.data('study-id', row['study_id']);
link.data('study-name', row['study_name']);
td.append(link)
} else {
td.text(value)
}
tr.append(td)
}
tbody.append(tr)
});
table.append(tbody);
main.empty();
main.append(table);
$('.secondlevel-link').click(function () {
render_secondlevel($(this).data('study-id'), $(this).data('study-name'))
});
$('#main-breadcrumb').nextAll().remove()
}
const link_info_lookup = {
'Import Results': 'import-link',
'Validation Results': 'validation-link'
};
const othermap = {
'Import Results': 'import_status_code',
'Validation Results': 'validation_status_code'
};
function render_secondlevel(study_id, study_name) {
const table = $('<table>').addClass('ui celled table unstackable');
const thead = $('<thead>');
const tr = $('<tr>');
for (let i in second_level_headers) {
tr.append($('<th>').text(display_names[i]))
}
thead.append(tr);
table.append(thead);
const tbody = $('<tbody>');
second_level_data.forEach(function (row) {
if (!(row.study_id === study_id)) {
return
}
const tr = $('<tr>');
for (let property in second_level_headers) {
const value_type = second_level_headers[property];
const value = row[property];
const td = $('<td>').data('label', property);
if (value_type === "bool") {
handle_bool(td, value, property)
} else if (property === "validation_time_added") {
td.text(timeConverter(value));
} else if (value_type === "exit_code") {
if ([0, 1, 2, 3].includes(value))
td.text(value === 0 ? "SUCCESS" : (value === 3 ? "WARNING" : "ERROR"));
} else if (property === "import_time_added") {
td.text(timeConverter(value));
} else if (["Import Results", "Validation Results"].includes(property)) {
const click_here = $('<td>').data('label', property);
let link = $('<a>');
link.addClass(link_info_lookup[property]);
link.attr('href', '#');
link.data('study-version-id', row['study_version_id']);
link.text(row[othermap[property]] === 0 ? "SUCCESS" : (row[othermap[property]] === 3 ? "WARNING" : "ERROR"));
click_here.append(link);
td.append(click_here);
}
else {
td.text(value)
}
tr.append(td)
}
tbody.append(tr)
}
);
table.append(tbody);
main.empty();
main.append(table);
$('.validation-link').click(function () {
render_validation($(this).data('study-version-id'))
});
$('.import-link').click(function () {
render_import($(this).data('study-version-id'))
});
breadcrumbs.append($('<i>').addClass('right angle icon divider'));
breadcrumbs.append($('<a>').addClass('section').attr('id', 'secondlevel-breadcrumb').text(study_name));
const secondlevel_breadcrumb = $('#secondlevel-breadcrumb');
secondlevel_breadcrumb.click(function () {
render_secondlevel(study_id, study_name)
});
secondlevel_breadcrumb.nextAll().remove()
}
function render_validation(study_version_id) {
const iframe = $('<iframe>')
.attr("height", "100%")
.attr("width", "100%")
.attr("src", "/dashboard/validation/" + study_version_id + ".html")
.attr("frameborder", 0);
main.empty();
main.append(iframe);
breadcrumbs.append($('<i>').addClass('right angle icon divider'));
breadcrumbs.append($('<a>').addClass('section').attr('id', '#validation-breadcrumb').text("study version " + study_version_id + " validation"));
$('#validation-breadcrumb').nextAll().remove()
}
function render_import(study_version_id) {
const table = $('<table>').addClass('ui celled table unstackable');
const thead = $('<thead>');
const tr = $('<tr>');
tr.append($('<th>').text(display_names["output"]))
thead.append(tr);
table.append(thead);
const tbody = $('<tbody>');
const tr_inner = $('<tr>');
const pre = $('<pre>').addClass('pretag-import')
const td = $('<td>').data('label', 'level');
td.append(pre);
tr.append(td);
tbody.append(tr_inner);
table.append(tbody);
main.empty();
main.append(table);
ElemAjaxGetText($('.pretag-import'), '/dashboard/import/' + study_version_id + '.txt');
breadcrumbs.append($('<i>').addClass('right angle icon divider'));
breadcrumbs.append($('<a>').addClass('section').attr('id', '#import-breadcrumb').text("study import " + study_version_id + " output"));
$('#import-breadcrumb').nextAll().remove()
}
render_toplevel();
$("#main-breadcrumb").click(function () {
render_toplevel()
})
})
;