-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimport.html
576 lines (567 loc) · 32.1 KB
/
import.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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<!DOCTYPE html>
<!--
Facilitates import / upload of new graphs and covers.
-->
<html>
<head>
<title>OCD - Import</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="CSS/layout.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//npmcdn.com/[email protected]/dist/js/tether.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="JS/contentHandler.js"></script>
<script src="node_modules/js-base64/base64.js"></script>
<script src="JS/ServiceAPI/moduleHelper.js"></script>
<script src="JS/ServiceAPI/serviceAPI.js"></script>
<script src="JS/requestHandler.js"></script>
<script src="node_modules/tablesorter/dist/js/jquery.tablesorter.min.js"></script>
<script src="JS/graphTableHandler.js"></script>
<script type="text/javascript">
/* Names of all input formats */
var inputFormatNames;
/* Creator/creation type of a graph / cover */
var creatorTypes;
/* Defaul select option value */
var selectOptionVal = "SELECT";
/* Graphs displayed per page (for cover upload) */
var GRAPHS_PER_PAGE = 20;
/* Current graph page number */
var pageNumber = 0;
/* Default select option code */
var selectOptionStr = '<option value=' + selectOptionVal + '>--SELECT--</option>';
/* Executed after page loading */
$(document).ready(function() {
/* Import form initialization */
$("#objectType").append(
selectOptionStr
+ '<option value="graph">Graph</option>'
+ '<option value="cover">Cover</option>'
+ '<option value="centrality">Centrality</option>'
);
/*
* Import form listener.
*/
$('#importForm').submit(function(){
/*
* Verifies input
*/
if($("#objectType").val() === selectOptionVal) {
showErrorMessage('Please select an import option.');
return;
}
else if($("#objectFormat").val() === selectOptionVal) {
showErrorMessage('Please select an import format.');
return;
}
else if($("#objectName").val() === "") {
showErrorMessage('Please define a name.');
return;
}
if($("#objectType").val() === "cover") {
if($("#objectCreator").val() === selectOptionVal) {
showErrorMessage('Please select an Algorithm.');
return;
}
var graphId = $("input[name='graphSelect']:checked").val();
if(typeof graphId === 'undefined') {
showErrorMessage('Please select a graph.');
return;
}
}
else if($("#objectType").val() === "graph") {
if($("#objectCreator").val() === selectOptionVal) {
showErrorMessage('Please select a Benchmark.');
return;
}
if($("#objectFormat").val() === 'XML' || $("#objectFormat").val() === 'NODE_CONTENT_EDGE_LIST' || $("#objectFormat").val() === 'LMS_TRIPLESTORE'){
if($("#startDate").val() === ""){
showErrorMessage('Please enter Start Date.');
return;
}
if($("#endDate").val() === ""){
showErrorMessage('Please enter End Date.');
return;
}
}
}
else if($("#objectType").val() === "centrality") {
if($("#objectCreator").val() === selectOptionVal) {
showErrorMessage('Please select a Creation Method');
return;
}
var graphId = $("input[name='graphSelect']:checked").val();
if(typeof graphId === 'undefined') {
showErrorMessage('Please select a graph.');
return;
}
}
else {
/* Should not happen */
showErrorMessage('Client Error.');
return;
}
/*
* Verifies browser compatibility
*/
if (window.File && window.FileReader && window.FileList && window.Blob) {
var file = $("#objectFile").get(0).files[0];
buttonSubmitStart("submitButton");
if(file) {
/* Reads input file */
var reader = new FileReader();
reader.onload = function(e) {
var content = e.target.result;
if($("#objectType").val() === "graph") {
/* Requests graph import */
postGraph(content);
}
else if($("#objectType").val() === "cover") {
/* Requests cover import */
postCover(content);
}
else if($("#objectType").val() === "centrality") {
/* Requests centrality import */
postCentrality(content);
}
else {
showErrorMessage("Client Error");
}
};
reader.readAsText(file);
}
else if($("#objectFormat").val() === 'LMS_TRIPLESTORE') {
if($("#objectType").val() === "graph") {
/* Requests graph import */
postGraph("");
}
}
else {
buttonSubmitEnd("submitButton");
showErrorMessage('File could not be loaded.');
}
/*
* Browser not compatible
*/
} else {
showErrorMessage('Your Browser does not support html file input.');
}
});
/*
* Object type select listener
*/
$("#objectType").change(function() {
/* Form initialization */
$("#objectFormat").empty();
$("#objectCreator").empty();
$(".selectorWrapper").css("display", "none");
$(".graphOptionsRow").css("display", "none");
$("#objectType option:selected").each(function() {
if($(this).val() !== selectOptionVal) {
/* Requests input format names and adds them to the form */
getInputFormats(function() {
$("#objectFormat").append(selectOptionStr);
$(inputFormatNames).find('Name').each(function() {
$("#objectFormat").append(
'<option value="' + $(this).text()
+ '">' + $(this).attr("displayName") + '</option>');
});
});
/* Loads and displays graph table to select a corresponding graph */
if($(this).val() === "cover" || $(this).val() === "centrality") {
loadGraphTable();
$(".selectorWrapper").css("display", "block");
}
/* Displays graph import options */
else if($(this).val() === "graph") {
$(".graphOptionsRow").css("display", "block");
}
else {
showErrorMessage("Client Error");
}
/* Loads and displays creator types */
getCreatorTypes(function() {
$("#objectCreator").append(selectOptionStr);
$(creatorTypes).find('Name').each(function() {
$("#objectCreator").append(
'<option value="' + $(this).text()
+ '">' + $(this).attr("displayName") + '</option>');
});
});
$("#objectCreatorRow").css("display", "block");
}
else {
$("#objectCreatorRow").css("display", "none");
}
});
});
$("#objectFormat").change(function() {
if($("#objectFormat").val() === 'XML' || $("#objectFormat").val() === 'NODE_CONTENT_EDGE_LIST' || $("#objectFormat").val() === 'LMS_TRIPLESTORE') {
$("#startDatetr").removeClass('hidden');
$("#endDatetr").removeClass('hidden');
$("#objectFileDiv").removeClass('hidden');
if($("#objectFormat").val() === 'LMS_TRIPLESTORE') {
$("#showUserNamestr").removeClass('hidden');
$("#involvedUserURIstr").removeClass('hidden');
$("#objectFileDiv").addClass('hidden');
}
}
// !!This Code can only be used when webOCD supports edge types!!
// } else if($("#objectFormat").val() === 'XGMML') {
// $("#startDatetr").addClass('hidden');
// $("#endDatetr").addClass('hidden');
// $("#keytr").removeClass('hidden');
// $("#type1tr").removeClass('hidden');
// $("#type2tr").removeClass('hidden');
// $("#type3tr").removeClass('hidden');
else {
$("#startDatetr").addClass('hidden');
$("#endDatetr").addClass('hidden');
$("#showUserNamestr").addClass('hidden');
$("#involvedUserURIstr").addClass('hidden');
$("#objectFileDiv").removeClass('hidden');
}
});
});
/* Requests a graph import */
function postGraph(content) {
var doMakeUndirected = $('#doMakeUndirected').prop('checked');
var restUrl = "graphs?name=" + $("#objectName").val() +
"&creationType=" + $("#objectCreator").val()
+ "&inputFormat=" + $("#objectFormat").val()
+ "&doMakeUndirected=" + doMakeUndirected;
if($("#objectFormat").val() === 'XML' || $("#objectFormat").val() === 'NODE_CONTENT_EDGE_LIST' || $("#objectFormat").val() === 'LMS_TRIPLESTORE'){
restUrl = restUrl + "&startDate=" + $("#startDate").val() + "&endDate=" + $("#endDate").val();
if($("#objectFormat").val() === 'LMS_TRIPLESTORE') {
if($("#showUserNames").val() !== "") {
restUrl = restUrl + "&showUserNames=" + $("#showUserNames").val();
}
if($("#involvedUserURIs").val() !== "") {
restUrl = restUrl + "&involvedUserURIs=" + $("#involvedUserURIs").val();
}
}
}
// !!This Code can only be used when webOCD supports edge types!!
// if($("#objectFormat").val() === 'XGMML') {
// restUrl = restUrl + "&key=" + $("#key").val() + "&type1=" + $("#type1").val() + "&type2=" + $("#type2").val() + "&type3=" + $("#type3").val()
// }
sendRequest("post", restUrl, content,
/* Response handler */
function(response) {
window.location.href = 'graphs.html';
},
/* Error handler */
function(errorData) {
/*
* Request failed
*/
showConnectionErrorMessage("Graph could not be sent.", errorData);
});
}
/* Requests a cover import */
function postCover(filecontent) {
var graphId = $("input[name='graphSelect']:checked").val();
sendRequest("post", "covers/graphs/" + graphId + "?name=" + $("#objectName").val() + "&creationType=" +
$("#objectCreator").val() + "&inputFormat=" + $("#objectFormat").val(), filecontent,
/* Response handler */
function(response) {
window.location.href = 'covers.html';
},
/* Error handler */
function(errorData) {
/*
* Request failed
*/
showConnectionErrorMessage("Cover could not be sent.", errorData);
});
}
/* Requests a centrality import */
function postCentrality(filecontent) {
var graphId = $("input[name='graphSelect']:checked").val();
sendRequest("post", "centrality/graphs/" + graphId + "?name=" + $("#objectName").val() + "&creationType=" +
$("#objectCreator").val() + "&inputFormat=" + $("#objectFormat").val(), filecontent,
/* Response handler */
function(response) {
window.location.href = 'centralities.html';
},
/* Error handler */
function(errorData) {
/*
* Request failed
*/
showConnectionErrorMessage("Centrality could not be sent.", errorData);
});
}
/* Requests input format names.
* Then executes a callback function. */
function getInputFormats(callback) {
const typeSpecifier = $("#objectType").val() !== "centrality" ? $("#objectType").val() + "s" : "centralities";
sendRequest("get", typeSpecifier + "/formats/input", "",
/* Response handler */
function(response) {
inputFormatNames = response;
if(typeof callback !== 'undefined') {
callback();
}
},
/* Error handler */
function(errorData) {
/*
* Request failed
*/
showConnectionErrorMessage("Input format names were not received.", errorData);
});
}
/* Requests creator type names.
* Then executes a callback function. */
function getCreatorTypes(callback) {
const typeSpecifier = $("#objectType").val() !== "centrality" ? $("#objectType").val() + "s" : "centralities";
sendRequest("get", typeSpecifier + "/creationtypes", "",
/* Response handler */
function(response) {
creatorTypes = response;
if(typeof callback !== 'undefined') {
callback();
}
},
/* Error handler */
function(errorData) {
/*
* Request failed
*/
var errString;
if($("#objectType").val() === "graph") {
errString = "Graph creation methods were not received.";
showConnectionErrorMessage(errString, errorData);
}
else if($("#objectType").val() === "cover") {
errString = "Cover creation methods were not received.";
showConnectionErrorMessage(errString, errorData);
}
else {
// Should not happen.
errString = "Client Error";
showErrorMessage(errString);
}
});
}
/* Requests graph information and displays a graph table */
function loadGraphTable() {
/* Table initialization */
$('#graphTable tbody').empty();
$('.pageNumWrapper').empty();
$('.pageNumWrapper').append(pageNumber);
var firstIndex = GRAPHS_PER_PAGE * pageNumber;
/* Identifiers for the graph information to be displayed */
var cells = ["Name", "NodeCount", "EdgeCount", "D", "W", "Z", "N", "L", "Select"];
/* Requests the graph information */
sendRequest("get", "graphs?executionStatuses=COMPLETED&includeMeta=TRUE&firstIndex=" + firstIndex + "&length=" + GRAPHS_PER_PAGE , "",
/* Response handler */
function(graphMetasXml) {
/*
* GraphMetas request succeeded
*/
if($(graphMetasXml).find("Id").length === 0 && pageNumber > 0) {
pageNumber--;
loadGraphTable();
}
/* Adds graph information to the table */
$(graphMetasXml).find("Graph").each(function() {
appendGraphRow($('#graphTable'), $(this), cells);
});
/*
* Sort Table
*/
try {
$("#graphTable").tablesorter({sortList: [[0,0]],
headers: { 4: { sorter: false}, 5: {sorter: false}, 6: {sorter: false}, 7: {sorter: false},
8: {sorter: false}, 9: {sorter: false}}});
$("#graphTable").trigger('update');
} catch(err) { /* table empty */ }
},
function(errorData) {
/*
* GraphIds request failed
*/
showConnectionErrorMessage("Graphs metas were not received.", errorData);
});
/* Listeners for table page control */
$('.pageLeft').click(function(){
if(pageNumber > 0) {
pageNumber--;
loadGraphTable();
}
});
$('.pageRight').click(function(){
pageNumber++;
loadGraphTable();
});
}
</script>
</head>
<body>
<div>
<div id="wrapper">
<div id="contentWrapper">
<div id="content">
<!-- Container for displaying error messages -->
<div id="errorMessageWrapper">
<div id="errorMessage"></div>
</div>
<!-- Page Header -->
<div class="page-header graphColor">
<h3>Importing</h3>
</div>
<!-- Import form -->
<div class="container-fluid">
<form id="importForm" action="javascript:void(0); return false;">
<div class="">
<!-- Import object type, i.e. cover or graph -->
<div class="form-group">
<label for="objectType" class="col-form-label">Import</label>
<select id="objectType" class="form-control custom-select"></select>
</div>
<!-- Input format -->
<div class="form-group">
<label for="objectFormat" class="col-form-label">Format</label>
<select id="objectFormat" class="form-control custom-select"></select>
</div>
<!-- Input file -->
<div id="objectFileDiv" class="form-group">
<label for="objectFile" class="form-label">File</label>
<input id="objectFile" type="file" class="form-control-file">
</div>
<!-- Input Start Date -->
<div id="startDatetr" class="hidden">
<label for="startDate" class="col-form-label">Start Date:</label>
<input id="startDate" type="text" placeholder="YYYY-MM-DD">
</div>
<!-- Input End Date -->
<div id="endDatetr" class="hidden">
<label for="endDate" class="col-form-label">End Date:</label>
<input id="endDate" type="text" placeholder="YYYY-MM-DD">
</div>
<div id="showUserNamestr" class="hidden">
<label for="showUserNames" class="col-form-label">Show Usernames:</label>
<input id="showUserNames" type="text" placeholder="false">
</div>
<div id="involvedUserURIstr" class="hidden">
<label for="involvedUserURIs" class="col-form-label">Involved User URIs:</label>
<input id="involvedUserURIs" type="text" style="width:240px" placeholder="Comma separated uri list">
</div>
<!-- !!!These parts can only be used once edge types are really supported in webOCD!!!
<div id="keytr" class="hidden">
<label for="key" class="col-form-label">Key:</label>
<input id="key" type="text" value="" placeholder="empty">
</div>
<div id="type1tr" class="hidden">
<label for="type1" class="col-form-label">Type 1:</label>
<input id="type1" type="text" value="" placeholder="empty">
</div>
<div id="type2tr" class="hidden">
<label for="type2" class="col-form-label">Type 2:</label>
<input id="type2" type="text" value="" placeholder="empty">
</div>
<div id="type3tr" class="hidden">
<label for="type3" class="col-form-label">Type 3:</label>
<input id="type3" type="text" value="" placeholder="empty">
</div> -->
<!-- Name for imported object -->
<div class="form-group">
<label for="objectName" class="col-form-label">Name</label>
<input id="objectName" type="text" class="form-control">
</div>
<!-- Object creator type -->
<div id="objectCreatorRow" class="form-group hidden">
<label for="objectCreator" class="col-form-label">Creation Method</label>
<select id="objectCreator" class="form-control custom-select"></select>
</div>
<!-- Graph import options (i.e. making graphs undirected) -->
<div class="form-check graphOptionsRow hidden">
<label for="doMakeUndirected" class="form-check-label">
<input type="checkbox" class="form-check-input" id="doMakeUndirected">
make undirected
</label>
</div>
<!-- Form submit -->
<div class="submitWrapper form-group">
<button id="submitButton" type="submit" name="submit" class="btn btn-primary">
<span class="submitText">Submit</span>
<span class="submitSpinner spinner-border spinner-border-sm" role="status" aria-hidden="true" hidden></span>
</button>
</div>
</div>
<!-- Graph selector for choosing a corresponding graph for cover import -->
<div class="selectorWrapper hidden">
<div class="selectorTitle">
Select a Graph
</div>
<div class="selectorContent">
<!-- Graph table page control -->
<div class = "card">
<div class="pageControl">
<div class="pageLeftWrapper">
<img class="icon iconBtn pageLeft" src="IMG/open-iconic/svg/chevron-left.svg" alt="r">
</div>
<div class = "pageNumWrapper">
</div>
<div class="pageRightWrapper">
<img class="icon iconBtn pageRight" src="IMG/open-iconic/svg/chevron-right.svg" alt="r">
</div>
</div>
</div>
<!-- Graph table -->
<div class="tableWrapper">
<table id="graphTable">
<thead>
<tr>
<th class="hidden" title="Id"></th>
<th width="300" title="Graph Name" class="sortable">
Name
<img class="icon iconBtn" src="IMG/open-iconic/svg/sort-ascending.svg" alt="d">
</th>
<th width="120" title="Node Count" class="sortable">
Nodes
<img class="icon iconBtn" src="IMG/open-iconic/svg/sort-ascending.svg" alt="d">
</th>
<th width="120" title="Edge Count" class="sortable">
Edges
<img class="icon iconBtn" src="IMG/open-iconic/svg/sort-ascending.svg" alt="d">
</th>
<th width="20" title="Has Directed Edges">
D
</th>
<th width="20" title="Has Weighted Edges">
W
</th>
<th width="20" title="Has Zero Edge Weights">
Z
</th>
<th width="20" title="Has Negative Edge Weights">
N
</th>
<th width="20" title="Has Self Loops">
L
</th>
<th width="20" title="Select Graph">
Select
</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>