-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_file_listing.peb
150 lines (126 loc) · 3.75 KB
/
test_file_listing.peb
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
<!-- BEGIN: standard Trident submit app templating !-->
<!DOCTYPE html>
<html>
<head>
<title>The slash at the end of the href is important!</title>
<base href="http://localhost:8998/getStatic/" />
<script type="text/javascript">document.domain=document.domain</script>
<script src="jquery-3.2.1.min.js" type="text/javascript"></script>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<div id="jQuery-status" style="color:red; text-align:center;">JQUERY NOT LOADED! SUBMISSION ERRORS WILL OCCUR</div>
<div id="data">
<h3>Required Metadata</h3>
<div id="metadata">
<label for="serial_number">Serial Number</label>
<input type="text" name="serial_number" id="serial_number" placeholder="ex: 8142"><br>
</div>
{% if rawFiles is not empty %}
<h3>Raw Files</h3>
<table id="raw-files">
<tr>
<th>Filepath</th>
<th>Filename</th>
</tr>
{% for file in rawFiles %}
<tr>
<td class="file-path">{{ file.path }}</td>
<td class="file-name">{{ file.name }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% if processedFiles is not empty %}
<h3>Processed Files</h3>
<table id="processed-files">
<tr>
<th>Filepath</th>
<th>Filename</th>
</tr>
{% for file in rawFiles %}
<tr>
<td class="file-path">{{ file.path }}</td>
<td class="file-name">{{ file.name }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
<br>
<input id="btn-form-submit" type="submit" value="Submit">
</div>
<div id="status" style="color:green;"></div>
<script type='text/javascript'>
(function() {
// Clear the warning about jQuery, since jQuery has been successfully loaded
$("#jQuery-status").empty();
function populate_from_table(payload, tableID, isRaw) {
$('#'+ tableID +' > tbody > tr').not(":first").each(function() {
var filepath = null,
filename = null;
$.each($(this).find(".file-path"), function() {
filepath = $(this).html();
});
$.each($(this).find(".file-name"), function() {
filename = $(this).html();
});
if(filepath && filename) {
payload.files.push({ filepath: filepath, filename: filename, is_raw: isRaw });
}
});
};
function prep_submission_data() {
// Build the payload
var payload = {
nifiEndpoint: "{{ server_port_url }}",
actionPathId: "{{ action_path_id }}",
metadata: {},
files: []
};
// Populate the METADATA portion of the payload
$("#metadata input").each(function(index){
payload.metadata[$(this).attr('id')] = $(this).val();
});
// Populate the RAW data files portion of the payload
populate_from_table(payload, 'raw-files', true);
// Populate the PROCESSED data files portion of the payload
populate_from_table(payload, 'processed-files', false);
return payload;
};
$("#btn-form-submit").click(function(e) {
$.ajax({
type: "POST",
url: "http://localhost:8998/formSubmit",
data: JSON.stringify(prep_submission_data()),
dataType: "json",
contentType: "application/json",
crossDomain: true,
// jsonp: false,
// jsonpCallback: 'jsonpCallback',
success: function(res) {
// $("#status").text("success!");
},
error: function (xhr, ajaxOptions, thrownError) {
// $("#status").text(xhr.status);
//$("#status").text(thrownError);
}
})
});
})();
</script>
</body>
</html>