aind-data-transfer-service 1.17.0__py3-none-any.whl → 1.17.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aind_data_transfer_service/__init__.py +1 -1
- aind_data_transfer_service/hpc/client.py +28 -25
- aind_data_transfer_service/server.py +68 -57
- {aind_data_transfer_service-1.17.0.dist-info → aind_data_transfer_service-1.17.2.dist-info}/METADATA +1 -1
- aind_data_transfer_service-1.17.2.dist-info/RECORD +18 -0
- aind_data_transfer_service/templates/admin.html +0 -45
- aind_data_transfer_service/templates/index.html +0 -258
- aind_data_transfer_service/templates/job_params.html +0 -405
- aind_data_transfer_service/templates/job_status.html +0 -324
- aind_data_transfer_service/templates/job_tasks_table.html +0 -146
- aind_data_transfer_service/templates/task_logs.html +0 -31
- aind_data_transfer_service-1.17.0.dist-info/RECORD +0 -24
- {aind_data_transfer_service-1.17.0.dist-info → aind_data_transfer_service-1.17.2.dist-info}/WHEEL +0 -0
- {aind_data_transfer_service-1.17.0.dist-info → aind_data_transfer_service-1.17.2.dist-info}/licenses/LICENSE +0 -0
- {aind_data_transfer_service-1.17.0.dist-info → aind_data_transfer_service-1.17.2.dist-info}/top_level.txt +0 -0
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<title>{% block title %} {% endblock %} AIND Data Transfer Service</title>
|
|
7
|
-
<style>
|
|
8
|
-
body {
|
|
9
|
-
margin: 20px;
|
|
10
|
-
font-family: arial, sans-serif;
|
|
11
|
-
}
|
|
12
|
-
fieldset {
|
|
13
|
-
display:inline
|
|
14
|
-
}
|
|
15
|
-
table {
|
|
16
|
-
border-collapse: collapse;
|
|
17
|
-
width: 75%;
|
|
18
|
-
}
|
|
19
|
-
td, th {
|
|
20
|
-
border: 1px solid #dddddd;
|
|
21
|
-
text-align: left;
|
|
22
|
-
padding: 8px;
|
|
23
|
-
}
|
|
24
|
-
th, tr:hover {
|
|
25
|
-
background-color: #E8EAF6;
|
|
26
|
-
color: #3F51B5;
|
|
27
|
-
}
|
|
28
|
-
#submit {
|
|
29
|
-
border: none;
|
|
30
|
-
border-radius: 6px;
|
|
31
|
-
color: #ffffff;
|
|
32
|
-
padding: 8px;
|
|
33
|
-
width: 80px;
|
|
34
|
-
font-size: medium;
|
|
35
|
-
background-color: #5065df;
|
|
36
|
-
&:hover { background-color: #3f51b5; }
|
|
37
|
-
}
|
|
38
|
-
#message {
|
|
39
|
-
margin-top: 20px;
|
|
40
|
-
&.success { color: green; }
|
|
41
|
-
&.error { color: red; }
|
|
42
|
-
}
|
|
43
|
-
</style>
|
|
44
|
-
</head>
|
|
45
|
-
<body>
|
|
46
|
-
<nav>
|
|
47
|
-
<a href="/">Submit Jobs</a> |
|
|
48
|
-
<a href="/jobs">Job Status</a> |
|
|
49
|
-
<a href="/job_params">Job Parameters</a> |
|
|
50
|
-
<a title="Download job template as .xslx" href= "/api/job_upload_template" download>Job Submit Template</a> |
|
|
51
|
-
<a title="List of project names" href= "{{ project_names_url }}" target="_blank" >Project Names</a> |
|
|
52
|
-
<a title="For more information click here" href="https://aind-data-transfer-service.readthedocs.io" target="_blank" >Help</a> |
|
|
53
|
-
<a href="/admin">Admin</a>
|
|
54
|
-
</nav>
|
|
55
|
-
<br>
|
|
56
|
-
<div>
|
|
57
|
-
<p1>For instructions on how to submit jobs click on the Help tab</p1>
|
|
58
|
-
</div>
|
|
59
|
-
<h2>Submit Jobs</h2>
|
|
60
|
-
<div>
|
|
61
|
-
<fieldset>
|
|
62
|
-
<legend>Mail Notifications (optional)</legend><br>
|
|
63
|
-
<div>
|
|
64
|
-
<label for="email" title="Optionally provide an allen institute email address to receive upload job status notifications">Allen Institute email:</label>
|
|
65
|
-
<input type="email" id="email" pattern=".+@alleninstitute\.org" size="30" placeholder="@alleninstitute.org" /><br><br>
|
|
66
|
-
</div>
|
|
67
|
-
<div>
|
|
68
|
-
<input type="checkbox" id="begin" name="begin" />
|
|
69
|
-
<label for="begin">BEGIN</label> |
|
|
70
|
-
<input type="checkbox" id="end" name="end" />
|
|
71
|
-
<label for="end">END</label> |
|
|
72
|
-
<input type="checkbox" id="fail" name="fail" checked />
|
|
73
|
-
<label for="fail">FAIL</label> |
|
|
74
|
-
<input type="checkbox" id="retry" name="retry" />
|
|
75
|
-
<label for="retry">RETRY</label> |
|
|
76
|
-
<input type="checkbox" id="all" name="all" />
|
|
77
|
-
<label for="all">ALL</label>
|
|
78
|
-
</div>
|
|
79
|
-
</fieldset>
|
|
80
|
-
</div><br><br>
|
|
81
|
-
<form id="file_form" method="post" enctype="multipart/form-data">
|
|
82
|
-
<label for="file">Please select a .csv or .xlsx file:</label>
|
|
83
|
-
<input type="file" id="file" name="file" accept=".csv,.xlsx" onchange="validateJobs(this)" onclick="this.value=null"><br><br>
|
|
84
|
-
</form>
|
|
85
|
-
<button id="submit" type="button" onclick="submitJobs()">Submit</button>
|
|
86
|
-
<div id="message"></div><br>
|
|
87
|
-
<div id="response"></div>
|
|
88
|
-
<script>
|
|
89
|
-
var jobs = []
|
|
90
|
-
var parsing_errors = []
|
|
91
|
-
const msgTypes = {
|
|
92
|
-
"validatePending": "Validating...",
|
|
93
|
-
"validateSuccess": "Successfully validated jobs from file.",
|
|
94
|
-
"validateError": "Error validating jobs from file.",
|
|
95
|
-
"submitPending": "Submitting jobs. Please do not refresh or re-submit...",
|
|
96
|
-
"submitSuccess": "Successfully submitted jobs.",
|
|
97
|
-
"submitError": "Error submitting jobs."
|
|
98
|
-
}
|
|
99
|
-
setMessage = function(msgType) {
|
|
100
|
-
$("#message").removeClass("success");
|
|
101
|
-
$("#message").removeClass("error");
|
|
102
|
-
$("#message").html(msgType);
|
|
103
|
-
if (msgType == msgTypes.validateSuccess || msgType == msgTypes.submitSuccess) {
|
|
104
|
-
$("#message").addClass("success");
|
|
105
|
-
} else if (msgType == msgTypes.validateError || msgType == msgTypes.submitError) {
|
|
106
|
-
$("#message").addClass("error");
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
addTableRow = function(data, table, tr, td, isHeader) {
|
|
110
|
-
tr = document.createElement('tr');
|
|
111
|
-
for (var d of data) {
|
|
112
|
-
td = document.createElement(isHeader ? 'th' : 'td');
|
|
113
|
-
td.innerHTML = d.value ?? d;
|
|
114
|
-
if (d.rowspan) {
|
|
115
|
-
td.setAttribute("rowspan", d.rowspan);
|
|
116
|
-
}
|
|
117
|
-
tr.append(td);
|
|
118
|
-
}
|
|
119
|
-
table.appendChild(tr);
|
|
120
|
-
};
|
|
121
|
-
validateJobs = function(fileElement) {
|
|
122
|
-
if (fileElement.files.length != 1) {
|
|
123
|
-
// File attach was cancelled by user
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (![".csv", ".xlsx"].some(ext => fileElement.files[0].name.endsWith(ext))) {
|
|
127
|
-
fileElement.value = null;
|
|
128
|
-
alert("Invalid file type. Please attach a .csv or .xlsx file.");
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
var formData = new FormData(document.getElementById("file_form"));
|
|
132
|
-
$.ajax({
|
|
133
|
-
url: "/api/v2/validate_csv",
|
|
134
|
-
type: "POST",
|
|
135
|
-
data: formData,
|
|
136
|
-
cache: false,
|
|
137
|
-
contentType: false,
|
|
138
|
-
processData: false,
|
|
139
|
-
beforeSend: function() {
|
|
140
|
-
setMessage(msgTypes.validatePending);
|
|
141
|
-
$("#response").html("");
|
|
142
|
-
},
|
|
143
|
-
success: function(data) {
|
|
144
|
-
setMessage(msgTypes.validateSuccess);
|
|
145
|
-
jobs = data["data"]["jobs"];
|
|
146
|
-
parsing_errors = []
|
|
147
|
-
let jobsLength = jobs.length;
|
|
148
|
-
var table = document.createElement('table'), tr, td, row;
|
|
149
|
-
addTableRow(
|
|
150
|
-
[ "job_type", "project_name", "s3_bucket", "platform", "subject_id", "acq_datetime", "metadata_dir", "modality", "modality.input_source" ],
|
|
151
|
-
table, tr, td, true
|
|
152
|
-
);
|
|
153
|
-
for (row = 0; row < jobsLength; row++) {
|
|
154
|
-
let job = jobs[row];
|
|
155
|
-
let modalities = job.tasks?.modality_transformation_settings;
|
|
156
|
-
if (modalities) {
|
|
157
|
-
modalities = Object.entries(modalities).map(([key, value]) => ({
|
|
158
|
-
abbreviation: key,
|
|
159
|
-
input_source: value.job_settings?.input_source
|
|
160
|
-
}))
|
|
161
|
-
}
|
|
162
|
-
let modalitiesLength = modalities ? modalities.length: 0;
|
|
163
|
-
let metadata_dir = job.tasks?.gather_preliminary_metadata?.job_settings?.metadata_dir
|
|
164
|
-
addTableRow(
|
|
165
|
-
[
|
|
166
|
-
{ value: job.job_type, rowspan: modalitiesLength },
|
|
167
|
-
{ value: job.project_name, rowspan: modalitiesLength },
|
|
168
|
-
{ value: job.s3_bucket, rowspan: modalitiesLength },
|
|
169
|
-
{ value: job.platform.abbreviation, rowspan: modalitiesLength },
|
|
170
|
-
{ value: job.subject_id, rowspan: modalitiesLength },
|
|
171
|
-
{ value: job.acq_datetime, rowspan: modalitiesLength },
|
|
172
|
-
{ value: metadata_dir ?? "", rowspan: modalitiesLength },
|
|
173
|
-
modalities ? modalities[0].abbreviation : "",
|
|
174
|
-
modalities ? modalities[0].input_source : ""
|
|
175
|
-
], table, tr, td, false
|
|
176
|
-
);
|
|
177
|
-
for (mRow = 1; mRow < modalitiesLength; mRow++) {
|
|
178
|
-
let modality = modalities[mRow]
|
|
179
|
-
addTableRow(
|
|
180
|
-
[ modality.abbreviation, modality.input_source ],
|
|
181
|
-
table, tr, td, false
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
$("#response").html(table);
|
|
186
|
-
},
|
|
187
|
-
error: function(data) {
|
|
188
|
-
jobs = []
|
|
189
|
-
parsing_errors = data.responseJSON["data"]["errors"]
|
|
190
|
-
setMessage(msgTypes.validateError);
|
|
191
|
-
$("#response").html(parsing_errors.map((err) => {
|
|
192
|
-
return `<li>${err}</li>`
|
|
193
|
-
}));
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
|
-
submitJobs = function() {
|
|
198
|
-
if(jobs.length > 0 && parsing_errors.length == 0){
|
|
199
|
-
let job_settings = {};
|
|
200
|
-
let mail_user = $("#email").val();
|
|
201
|
-
if (mail_user !== "" && mail_user !== undefined) {
|
|
202
|
-
job_settings["user_email"] = mail_user;
|
|
203
|
-
};
|
|
204
|
-
let mail_type = [];
|
|
205
|
-
if ($("#all").is(":checked")) {
|
|
206
|
-
mail_type = ["all"];
|
|
207
|
-
};
|
|
208
|
-
if ($("#begin").is(":checked")) {
|
|
209
|
-
mail_type.push("begin");
|
|
210
|
-
};
|
|
211
|
-
if ($("#end").is(":checked")) {
|
|
212
|
-
mail_type.push("end");
|
|
213
|
-
};
|
|
214
|
-
if ($("#fail").is(":checked")) {
|
|
215
|
-
mail_type.push("fail");
|
|
216
|
-
};
|
|
217
|
-
if ($("#retry").is(":checked")) {
|
|
218
|
-
mail_type.push("retry");
|
|
219
|
-
};
|
|
220
|
-
job_settings["email_notification_types"] = mail_type
|
|
221
|
-
job_settings["upload_jobs"] = jobs
|
|
222
|
-
$.ajax({
|
|
223
|
-
url: "/api/v2/submit_jobs",
|
|
224
|
-
type: "POST",
|
|
225
|
-
data: JSON.stringify(job_settings),
|
|
226
|
-
contentType: 'application/json; charset=utf-8',
|
|
227
|
-
beforeSend: function() {
|
|
228
|
-
setMessage(msgTypes.submitPending);
|
|
229
|
-
$("#response").html("");
|
|
230
|
-
},
|
|
231
|
-
success: function (data) {
|
|
232
|
-
jobs = []
|
|
233
|
-
parsing_errors = []
|
|
234
|
-
setMessage(msgTypes.submitSuccess);
|
|
235
|
-
$("#response").html(data);
|
|
236
|
-
},
|
|
237
|
-
error: function(data) {
|
|
238
|
-
jobs = []
|
|
239
|
-
setMessage(msgTypes.submitError);
|
|
240
|
-
let errors = data.responseJSON["data"]["errors"];
|
|
241
|
-
try {
|
|
242
|
-
parsing_errors = JSON.parse(errors).map((err) => JSON.stringify(err));
|
|
243
|
-
} catch (e) {
|
|
244
|
-
parsing_errors = (typeof errors == "string") ? [errors] : errors;
|
|
245
|
-
}
|
|
246
|
-
$("#response").html(parsing_errors.map((errStr) => {
|
|
247
|
-
return `<li>${errStr}</li>`
|
|
248
|
-
}));
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
} else if (jobs.length == 0) {
|
|
252
|
-
alert("No valid jobs to submit. Please attach a .csv or .xlsx file with valid jobs.");
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
</script>
|
|
257
|
-
</body>
|
|
258
|
-
</html>
|
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
6
|
-
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.8.1/font/bootstrap-icons.min.css" rel="stylesheet">
|
|
7
|
-
<link rel="stylesheet" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.css" />
|
|
8
|
-
<link rel="stylesheet" href="https://cdn.datatables.net/searchpanes/2.3.3/css/searchPanes.dataTables.css" />
|
|
9
|
-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
10
|
-
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.3/moment.min.js"></script>
|
|
11
|
-
<script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
|
|
12
|
-
<script src="https://cdn.datatables.net/2.1.8/js/dataTables.js"></script>
|
|
13
|
-
<script src="https://cdn.datatables.net/searchpanes/2.3.3/js/dataTables.searchPanes.js"></script>
|
|
14
|
-
<script src="https://cdn.datatables.net/select/3.0.0/js/dataTables.select.js"></script>
|
|
15
|
-
<title>{% block title %} {% endblock %} AIND Data Transfer Service Job Parameters</title>
|
|
16
|
-
<style>
|
|
17
|
-
body {
|
|
18
|
-
margin: 20px;
|
|
19
|
-
font-family: arial, sans-serif;
|
|
20
|
-
}
|
|
21
|
-
nav {
|
|
22
|
-
height: 40px;
|
|
23
|
-
}
|
|
24
|
-
.modal-body {
|
|
25
|
-
max-height: calc(100vh - 200px);
|
|
26
|
-
overflow: auto;
|
|
27
|
-
}
|
|
28
|
-
</style>
|
|
29
|
-
</head>
|
|
30
|
-
<body>
|
|
31
|
-
<nav>
|
|
32
|
-
<a href="/">Submit Jobs</a> |
|
|
33
|
-
<a href="/jobs">Job Status</a> |
|
|
34
|
-
<a href="/job_params">Job Parameters</a> |
|
|
35
|
-
<a title="Download job template as .xslx" href= "/api/job_upload_template" download>Job Submit Template</a> |
|
|
36
|
-
<a title="List of project names" href= "{{ project_names_url }}" target="_blank" >Project Names</a> |
|
|
37
|
-
<a title="For more information click here" href="https://aind-data-transfer-service.readthedocs.io" target="_blank" >Help</a> |
|
|
38
|
-
<a href="/admin">Admin</a>
|
|
39
|
-
{% if user_signed_in %}
|
|
40
|
-
<a href="/logout" class="float-end">Log out</a>
|
|
41
|
-
{% else %}
|
|
42
|
-
<a href="/login" class="float-end">Log in</a>
|
|
43
|
-
{% endif %}
|
|
44
|
-
</nav>
|
|
45
|
-
<div class="content">
|
|
46
|
-
<h4 class="mb-2">
|
|
47
|
-
<!-- dropdown to switch version -->
|
|
48
|
-
<div id="version-dropdown" class="btn-group mb-2">
|
|
49
|
-
<button id="version-button" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown">
|
|
50
|
-
{{default_version}}
|
|
51
|
-
</button>
|
|
52
|
-
<ul class="dropdown-menu">
|
|
53
|
-
{% for v in versions %}
|
|
54
|
-
<button class="dropdown-item" type="button">{{ v }}</button>
|
|
55
|
-
{% endfor %}
|
|
56
|
-
</ul>
|
|
57
|
-
</div>
|
|
58
|
-
<span>Job Parameters</span>
|
|
59
|
-
</h4>
|
|
60
|
-
<!-- button and modal for adding new parameters-->
|
|
61
|
-
{% if user_signed_in %}
|
|
62
|
-
<div class="mb-2">
|
|
63
|
-
<button type="button" class="btn btn-success btn-sm" data-bs-toggle="modal" data-bs-target="#param-modal" data-bs-action="new">
|
|
64
|
-
<i class="bi bi-plus-circle"></i> Add New Parameter
|
|
65
|
-
</button>
|
|
66
|
-
</div>
|
|
67
|
-
{% endif %}
|
|
68
|
-
<!-- job params table -->
|
|
69
|
-
<div>
|
|
70
|
-
<table id="job-params-table" class="display compact table table-bordered table-sm" style="font-size: small">
|
|
71
|
-
<thead>
|
|
72
|
-
<tr>
|
|
73
|
-
<th>Job Type</th>
|
|
74
|
-
<th>Task ID</th>
|
|
75
|
-
<th>Modality</th>
|
|
76
|
-
<th>Parameter Name</th>
|
|
77
|
-
<th>Last Modified</th>
|
|
78
|
-
</tr>
|
|
79
|
-
</thead>
|
|
80
|
-
</table>
|
|
81
|
-
<!-- modal for displaying param value as json -->
|
|
82
|
-
<!-- if user is signed in, the textarea will be editable and the footer will display the Submit button -->
|
|
83
|
-
<div class="modal fade" id="param-modal" tabindex="-1" aria-labelledby="param-modal-label" aria-hidden="true">
|
|
84
|
-
<div class="modal-dialog modal-xl">
|
|
85
|
-
<div class="modal-content">
|
|
86
|
-
<div class="modal-header">
|
|
87
|
-
<h5 class="modal-title" id="param-modal-label"></h5>
|
|
88
|
-
<span class="badge bg-primary ms-2" id="param-modal-version"></span>
|
|
89
|
-
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
90
|
-
</div>
|
|
91
|
-
<div class="modal-body">
|
|
92
|
-
<!-- dropdowns for Add New Parameter -->
|
|
93
|
-
<div class="row mb-2" id="param-modal-dropdowns" style="display:none;">
|
|
94
|
-
<div class="col-md-4">
|
|
95
|
-
<label for="param-modal-job-type-select" class="form-label">Job Type</label>
|
|
96
|
-
<select id="param-modal-job-type-select" class="form-select form-select-sm mb-1"></select>
|
|
97
|
-
<input type="text" id="param-modal-job-type-input" class="form-control form-control-sm mt-1" placeholder="Enter new Job Type" style="display:none;" />
|
|
98
|
-
</div>
|
|
99
|
-
<div class="col-md-4">
|
|
100
|
-
<label for="param-modal-task-id-select" class="form-label">Task ID</label>
|
|
101
|
-
<select id="param-modal-task-id-select" class="form-select form-select-sm"></select>
|
|
102
|
-
<input type="text" id="param-modal-task-id-input" class="form-control form-control-sm mt-1" placeholder="Enter new Task ID" style="display:none;" />
|
|
103
|
-
</div>
|
|
104
|
-
<div class="col-md-4" style="display:none;">
|
|
105
|
-
<label for="param-modal-modality-select" class="form-label">Modality</label>
|
|
106
|
-
<select id="param-modal-modality-select" class="form-select form-select-sm">
|
|
107
|
-
<option value="">Select Modality</option>
|
|
108
|
-
{% for modality in modalities %}
|
|
109
|
-
<option value="{{ modality }}">{{ modality }}</option>
|
|
110
|
-
{% endfor %}
|
|
111
|
-
</select>
|
|
112
|
-
</div>
|
|
113
|
-
</div>
|
|
114
|
-
<!-- textarea for parameter value -->
|
|
115
|
-
<textarea
|
|
116
|
-
id="param-modal-content" class="bg-light form-control form-control-sm font-monospace" rows="15"
|
|
117
|
-
placeholder='{"skip_task": false}' {% if not user_signed_in %}readonly{% endif %}
|
|
118
|
-
></textarea>
|
|
119
|
-
<!-- message if parameter already exists -->
|
|
120
|
-
<div id="param-modal-param-exists-alert" class="alert alert-info" role="alert" style="display:none;">
|
|
121
|
-
This parameter already exists! To edit, please click on the parameter from the Job Parameters table.
|
|
122
|
-
</div>
|
|
123
|
-
</div>
|
|
124
|
-
{% if user_signed_in %}
|
|
125
|
-
<div class="modal-footer">
|
|
126
|
-
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
127
|
-
<button type="button" class="btn btn-secondary" id="param-modal-reset-btn">Reset</button>
|
|
128
|
-
<button type="button" class="btn btn-primary" id="param-modal-submit-btn">Submit</button>
|
|
129
|
-
</div>
|
|
130
|
-
{% endif %}
|
|
131
|
-
</div>
|
|
132
|
-
</div>
|
|
133
|
-
</div>
|
|
134
|
-
</div>
|
|
135
|
-
</div>
|
|
136
|
-
<script>
|
|
137
|
-
const MODALITY_TASKS = {{ modality_tasks | tojson }}; // from Jinja context
|
|
138
|
-
const MODAL_ID = 'param-modal';
|
|
139
|
-
$(document).ready(function() {
|
|
140
|
-
createJobParamsTable();
|
|
141
|
-
// Event listeners for modal to display/edit params
|
|
142
|
-
$(`#${MODAL_ID}`).on('show.bs.modal', function(event) {
|
|
143
|
-
// Add New Parameter: set label and dropdown options
|
|
144
|
-
// Edit Existing Parameter: set label and load intital value
|
|
145
|
-
const eventTarget = $(event.relatedTarget);
|
|
146
|
-
const action = eventTarget.data('bs-action');
|
|
147
|
-
const modal = $(`#${MODAL_ID}`);
|
|
148
|
-
modal.data('bs-action', action); // save action type
|
|
149
|
-
const isNew = action === 'new';
|
|
150
|
-
modal.find(`#${MODAL_ID}-label`).text(isNew ? 'Add New Parameter' : eventTarget.data('bs-param-name'));
|
|
151
|
-
modal.find(`#${MODAL_ID}-version`).text(getCurrentVersion()).toggle(isNew);
|
|
152
|
-
modal.find(`#${MODAL_ID}-dropdowns`).toggle(isNew);
|
|
153
|
-
if (isNew) {
|
|
154
|
-
['Job Type', 'Task ID'].forEach(field => {
|
|
155
|
-
const select = modal.find(`#${MODAL_ID}-${field.toLowerCase().replace(' ', '-')}-select`);
|
|
156
|
-
select.empty()
|
|
157
|
-
.append(`<option value="">Select ${field}</option>`)
|
|
158
|
-
.append(getUniqueColumnValues(field).map(val => `<option value="${val}">${val}</option>`))
|
|
159
|
-
.append(`<option value="__new__">Create new ${field}</option>`);
|
|
160
|
-
});
|
|
161
|
-
} else {
|
|
162
|
-
loadParameterValue(getParamUrlFromParamName(eventTarget.data('bs-param-name')));
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
$(`#${MODAL_ID}`).on('hidden.bs.modal', function() {
|
|
166
|
-
onResetModal();
|
|
167
|
-
});
|
|
168
|
-
$(`#${MODAL_ID}`).on('click', `#${MODAL_ID}-reset-btn`, function() {
|
|
169
|
-
onResetModal(true);
|
|
170
|
-
});
|
|
171
|
-
$(`#${MODAL_ID}`).on('click', `#${MODAL_ID}-submit-btn`, function() {
|
|
172
|
-
const modal = $(`#${MODAL_ID}`);
|
|
173
|
-
const action = modal.data('bs-action');
|
|
174
|
-
let url;
|
|
175
|
-
if (action === "new") {
|
|
176
|
-
const version = getCurrentVersion();
|
|
177
|
-
const jobType = getValidatedInputValue('Job Type', modal);
|
|
178
|
-
const taskId = getValidatedInputValue('Task ID', modal);
|
|
179
|
-
const modality = MODALITY_TASKS.includes(taskId) ? getValidatedInputValue('Modality', modal) : null;
|
|
180
|
-
url = getParamUrlFromParamInfo(version, jobType, taskId, modality);
|
|
181
|
-
} else {
|
|
182
|
-
const paramName = modal.find(`#${MODAL_ID}-label`).text();
|
|
183
|
-
url = getParamUrlFromParamName(paramName);
|
|
184
|
-
}
|
|
185
|
-
const paramValue = modal.find(`#${MODAL_ID}-content`).val();
|
|
186
|
-
submitParameterValue(url, paramValue);
|
|
187
|
-
});
|
|
188
|
-
$(`#${MODAL_ID}-job-type-select`).on('change', function() {
|
|
189
|
-
$(`#${MODAL_ID}-job-type-input`).toggle($(this).val() === '__new__').focus();
|
|
190
|
-
handleExistingParam();
|
|
191
|
-
});
|
|
192
|
-
$(`#${MODAL_ID}-task-id-select`).on('change', function() {
|
|
193
|
-
$(`#${MODAL_ID}-task-id-input`).toggle($(this).val() === '__new__').focus();
|
|
194
|
-
$(`#${MODAL_ID}-modality-select`).val('').parent().toggle(MODALITY_TASKS.includes($(this).val()));
|
|
195
|
-
handleExistingParam();
|
|
196
|
-
});
|
|
197
|
-
$(`#${MODAL_ID}-modality-select`).on('change', function() {
|
|
198
|
-
handleExistingParam();
|
|
199
|
-
});
|
|
200
|
-
// Event listener for version dropdown
|
|
201
|
-
$('#version-dropdown .dropdown-item').on('click', function() {
|
|
202
|
-
var version = $(this).text();
|
|
203
|
-
if (version != getCurrentVersion()) {
|
|
204
|
-
$('#version-button').text(version);
|
|
205
|
-
$('#job-params-table').DataTable().ajax.url(`/api/${version}/parameters`).load();
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
// Create DataTable for job params table
|
|
210
|
-
function createJobParamsTable() {
|
|
211
|
-
$('#job-params-table').DataTable({
|
|
212
|
-
ajax: {
|
|
213
|
-
url: "/api/{{default_version}}/parameters",
|
|
214
|
-
dataSrc: 'data'
|
|
215
|
-
},
|
|
216
|
-
processing: true,
|
|
217
|
-
columns: [
|
|
218
|
-
{ data: 'job_type', searchPanes: {show: true} },
|
|
219
|
-
{ data: 'task_id', searchPanes: {show: true} },
|
|
220
|
-
{ data: 'modality', searchPanes: {show: false} },
|
|
221
|
-
{ data: 'name', render: renderParameterButton },
|
|
222
|
-
{ data: 'last_modified', render: renderDatetime },
|
|
223
|
-
],
|
|
224
|
-
order: [0, 'asc'],
|
|
225
|
-
// preselect "default" job_type
|
|
226
|
-
searchPanes: {
|
|
227
|
-
preSelect: [ { rows: ['default'], column: 0 } ],
|
|
228
|
-
},
|
|
229
|
-
// options to match default jobs table
|
|
230
|
-
pageLength: 25,
|
|
231
|
-
layout: {
|
|
232
|
-
topStart: null,
|
|
233
|
-
topEnd: null,
|
|
234
|
-
bottomStart: null,
|
|
235
|
-
bottomEnd: null,
|
|
236
|
-
top1Start: "searchPanes",
|
|
237
|
-
top: [
|
|
238
|
-
'pageLength',
|
|
239
|
-
'info',
|
|
240
|
-
{ paging: { numbers: false } }
|
|
241
|
-
],
|
|
242
|
-
},
|
|
243
|
-
language: {
|
|
244
|
-
info: "_START_ to _END_ of _TOTAL_",
|
|
245
|
-
infoEmpty: "0 to 0 of 0",
|
|
246
|
-
entries: { _: "parameters", 1: "parameter" },
|
|
247
|
-
paginate: {
|
|
248
|
-
first: '« First',
|
|
249
|
-
previous: '‹ Prev',
|
|
250
|
-
next: 'Next ›',
|
|
251
|
-
last: 'Last »'
|
|
252
|
-
},
|
|
253
|
-
},
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
function renderDatetime(data, type, row) {
|
|
257
|
-
return (type === 'display') ? moment.utc(data).local().format('YYYY-MM-DD h:mm:ss a') : data;
|
|
258
|
-
}
|
|
259
|
-
function renderParameterButton(data, type, row) {
|
|
260
|
-
if (type == 'display') {
|
|
261
|
-
return (
|
|
262
|
-
`<button type="button" class="btn btn-link btn-sm"
|
|
263
|
-
data-bs-toggle="modal"
|
|
264
|
-
data-bs-target="#${MODAL_ID}"
|
|
265
|
-
data-bs-action="edit"
|
|
266
|
-
data-bs-param-name=${data}
|
|
267
|
-
data-bs-job-type=${row.job_type}
|
|
268
|
-
data-bs-task-id=${row.task_id}
|
|
269
|
-
data-bs-modality=${row.modality}
|
|
270
|
-
>${data}
|
|
271
|
-
</button>`
|
|
272
|
-
);
|
|
273
|
-
}
|
|
274
|
-
return data;
|
|
275
|
-
}
|
|
276
|
-
// Methods to load/submit param values in the modal
|
|
277
|
-
function getParamUrlFromParamInfo(version, jobType, taskId, modality) {
|
|
278
|
-
var baseUrl = `/api/${version}/parameters/job_types/${jobType}/tasks/${taskId}`;
|
|
279
|
-
return modality ? `${baseUrl}/${modality}` : baseUrl;
|
|
280
|
-
}
|
|
281
|
-
function getParamUrlFromParamName(paramName) {
|
|
282
|
-
const match = paramName.match(/job_types\/(v\d+)?\/?(.*)/);
|
|
283
|
-
const version = match && match[1] ? match[1] : 'v1';
|
|
284
|
-
const cleanedParamName = match ? match[2] : paramName;
|
|
285
|
-
return `/api/${version}/parameters/job_types/${cleanedParamName}`;
|
|
286
|
-
}
|
|
287
|
-
function loadParameterValue(paramUrl) {
|
|
288
|
-
const modal = $(`#${MODAL_ID}`);
|
|
289
|
-
$.ajax({
|
|
290
|
-
url: paramUrl,
|
|
291
|
-
type: 'GET',
|
|
292
|
-
success: function (response) {
|
|
293
|
-
jsonStr = JSON.stringify(response.data, null, 3);
|
|
294
|
-
modal.find(`#${MODAL_ID}-content`).val(jsonStr);
|
|
295
|
-
},
|
|
296
|
-
error: function (xhr, status, error) {
|
|
297
|
-
console.error(`Error fetching ${paramUrl}: ${error}`);
|
|
298
|
-
modal.find(`#${MODAL_ID}-content`).val(error);
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
function submitParameterValue(paramUrl, paramValue) {
|
|
303
|
-
try {
|
|
304
|
-
JSON.parse(paramValue);
|
|
305
|
-
} catch (e) {
|
|
306
|
-
alert('Parameter value must be valid JSON:\n' + e.message);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
$.ajax({
|
|
310
|
-
url: paramUrl,
|
|
311
|
-
type: 'PUT',
|
|
312
|
-
contentType: 'application/json',
|
|
313
|
-
data: paramValue,
|
|
314
|
-
success: function (response) {
|
|
315
|
-
alert('Parameter updated successfully');
|
|
316
|
-
// reload the content to verify and reformat changes
|
|
317
|
-
loadParameterValue(paramUrl);
|
|
318
|
-
},
|
|
319
|
-
error: function (xhr, status, error) {
|
|
320
|
-
var msg = `Error submitting parameter: ${error}`;
|
|
321
|
-
try {
|
|
322
|
-
msg += `\n\n${JSON.stringify(JSON.parse(xhr.responseText), null, 3)}`;
|
|
323
|
-
} catch (e) {
|
|
324
|
-
console.error('Failed to parse error response:', e.message);
|
|
325
|
-
}
|
|
326
|
-
console.error(msg);
|
|
327
|
-
alert(msg);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
// Methods for param modal updates
|
|
332
|
-
function toggleParamTextArea(isEnabled){
|
|
333
|
-
const modal = $(`#${MODAL_ID}`);
|
|
334
|
-
modal.find(`#${MODAL_ID}-content`).toggle(isEnabled);
|
|
335
|
-
modal.find(`#${MODAL_ID}-param-exists-alert`).toggle(!isEnabled);
|
|
336
|
-
modal.find(`#${MODAL_ID}-submit-btn`).prop('disabled', !isEnabled);
|
|
337
|
-
}
|
|
338
|
-
function handleExistingParam() {
|
|
339
|
-
let exists = false;
|
|
340
|
-
const modal = $(`#${MODAL_ID}`);
|
|
341
|
-
const version = getCurrentVersion();
|
|
342
|
-
const jobType = getInputValues('Job Type', modal).input;
|
|
343
|
-
const taskId = getInputValues('Task ID', modal).input;
|
|
344
|
-
const modality = MODALITY_TASKS.includes(taskId) ? getInputValues('Modality', modal).input : null;
|
|
345
|
-
if (jobType && taskId && (!MODALITY_TASKS.includes(taskId) || modality)) {
|
|
346
|
-
const table = $('#job-params-table').DataTable();
|
|
347
|
-
const searchStr = `/${jobType}/tasks/${taskId}` + (modality ? `/${modality}` : '');
|
|
348
|
-
exists = table.column('Parameter Name:title').data().toArray().some(val => val.endsWith(searchStr));
|
|
349
|
-
}
|
|
350
|
-
toggleParamTextArea(!exists);
|
|
351
|
-
}
|
|
352
|
-
function onResetModal(reload = false) {
|
|
353
|
-
const modal = $(`#${MODAL_ID}`);
|
|
354
|
-
const action = modal.data('bs-action');
|
|
355
|
-
if (action === "new") {
|
|
356
|
-
modal.find(`#${MODAL_ID}-dropdowns input`).val('').hide();
|
|
357
|
-
modal.find(`#${MODAL_ID}-dropdowns select`).val('');
|
|
358
|
-
modal.find(`#${MODAL_ID}-modality-select`).parent().hide();
|
|
359
|
-
modal.find(`#${MODAL_ID}-content`).val('');
|
|
360
|
-
toggleParamTextArea(true);
|
|
361
|
-
} else if (action === "edit") {
|
|
362
|
-
if (reload) {
|
|
363
|
-
const paramName = modal.find(`#${MODAL_ID}-label`).text();
|
|
364
|
-
loadParameterValue(getParamUrlFromParamName(paramName));
|
|
365
|
-
} else {
|
|
366
|
-
modal.find(`#${MODAL_ID}-label, #${MODAL_ID}-content`).text('').val('');
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
// Helper methods to get current values
|
|
371
|
-
function getCurrentVersion() {
|
|
372
|
-
return $('#version-button').text().trim();
|
|
373
|
-
}
|
|
374
|
-
function getUniqueColumnValues(columnTitle) {
|
|
375
|
-
return Array.from(new Set($('#job-params-table').DataTable().column(`${columnTitle}:title`).data().toArray()));
|
|
376
|
-
}
|
|
377
|
-
function getInputValues(inputField, modal) {
|
|
378
|
-
const selector = `#${MODAL_ID}-${inputField.toLowerCase().replace(' ', '-')}`;
|
|
379
|
-
const dropdown = modal.find(`${selector}-select`).val()?.trim() || '';
|
|
380
|
-
const input = (dropdown === '__new__') ? (modal.find(`${selector}-input`).val()?.trim() || '') : dropdown;
|
|
381
|
-
return { dropdown, input };
|
|
382
|
-
}
|
|
383
|
-
function getValidatedInputValue(inputField, modal) {
|
|
384
|
-
// Check for empty string, spaces, slashes, or existing values
|
|
385
|
-
const { dropdown, input } = getInputValues(inputField, modal);
|
|
386
|
-
var error = false;
|
|
387
|
-
if (!input) {
|
|
388
|
-
error = `${inputField} cannot be empty`;
|
|
389
|
-
} else if (input.includes(' ') || input.includes('/')) {
|
|
390
|
-
error = `${inputField} cannot contain spaces or slashes`;
|
|
391
|
-
} else if (
|
|
392
|
-
dropdown === '__new__' &&
|
|
393
|
-
getUniqueColumnValues(inputField).some(val => val.toLowerCase() === input.toLowerCase())
|
|
394
|
-
) {
|
|
395
|
-
error = `${inputField} "${input}" already exists. Please select it from the dropdown.`;
|
|
396
|
-
}
|
|
397
|
-
if (error) {
|
|
398
|
-
alert(error);
|
|
399
|
-
throw new Error(error);
|
|
400
|
-
}
|
|
401
|
-
return input;
|
|
402
|
-
}
|
|
403
|
-
</script>
|
|
404
|
-
</body>
|
|
405
|
-
</html>
|