[879b32]: / qiita_pet / templates / resources.html

Download this file

286 lines (250 with data), 10.7 kB

  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
{% extends sitebase.html %}
{% block head %}
<link rel="stylesheet" href="{% raw qiita_config.portal_dir %}/static/vendor/css/ol.css" type="text/css">
<style type="text/css">
/* Add any custom styles here */
</style>
<script src="{% raw qiita_config.portal_dir %}/static/vendor/js/ol.js"></script>
{% end %}
{% block content %}
<div style="width: 80%; margin: 0 auto; max-width: 1600px;">
<div id="default-message" style="text-align: center; padding: 20px; background-color: #f8f9fa; border-radius: 5px; margin-top: 20px;">
<h3>Please choose software, version, and command to view the data.</h3>
</div>
<form method="POST">
<div class="form-group">
<label for="software">Software:</label>
<select id="software" name="software" class="form-control">
<option value="">Select Software</option>
</select>
</div>
<div class="form-group">
<label for="version">Version:</label>
<select id="version" name="version" class="form-control">
<option value="">Select Version</option>
</select>
</div>
<div class="form-group">
<label for="command">Command:</label>
<select id="command" name="command" class="form-control">
<option value="">Select Command</option>
</select>
</div>
</form>
<div id="data-container">
<div id="time-container" style="text-align: center; padding: 20px; background-color: #f8f9fa; border-radius: 5px; margin-top: 20px;">
<h3>Generated on: {{time}} </h3>
</div>
<table>
<tr>
<th>Memory Allocation</th>
<th>Time Allocation</th>
</tr>
<tr>
<td id="image-mem">
{% if img_mem and img_mem is not None %}
<img height="100%" width="100%" src="{% raw img_mem %}"/>
{% else %}
No memory allocation image available
{% end %}
</td>
<td id="image-time">
{% if img_time and img_time is not None %}
<img height="100%" width="100%" src="{% raw img_time %}"/>
{% else %}
No time allocation image available
{% end %}
</td>
</tr>
<tr>
<td id="mem-data">
<ul>
<li>k: {{ mk }}</li>
<li>a: {{ ma }}</li>
<li>b: {{ mb }}</li>
<li>model: {{ mmodel }}</li>
<li>real: {{ mreal }}</li>
<li>calc: {{ mcalc }}</li>
<li>fail: {{ mfail }}</li>
</ul>
</td>
<td id="time-data">
<ul>
<li>k: {{ tk }}</li>
<li>a: {{ ta }}</li>
<li>b: {{ tb }}</li>
<li>model: {{ tmodel }}</li>
<li>real: {{ treal }}</li>
<li>calc: {{ tcalc }}</li>
<li>fail: {{ tfail }}</li>
</ul>
</td>
</tr>
</table>
</div>
</div>
<script>
function toggleDataVisibility(showData) {
const defaultMessage = document.getElementById('default-message');
const dataContainer = document.getElementById('data-container');
if (showData) {
defaultMessage.style.display = 'none';
dataContainer.style.display = 'block';
} else {
defaultMessage.style.display = 'block';
dataContainer.style.display = 'none';
}
}
// Call this function on initial load
{% if initial_load %}
toggleDataVisibility(false);
{% else %}
toggleDataVisibility(true);
{% end %}
const commandsConst = JSON.parse(`{% raw commands %}`);
const softwareSelect = document.getElementById('software');
const versionSelect = document.getElementById('version');
const commandSelect = document.getElementById('command');
// Populate software options
for (const software in commandsConst) {
const option = document.createElement('option');
option.value = software;
option.textContent = software;
softwareSelect.appendChild(option);
}
// If there's only one software option, select it automatically
function autoSelectIfSingle(selectElem) {
const realOptions = Array.from(selectElem.options).filter(opt => opt.value !== "");
if (realOptions.length === 1) {
selectElem.value = realOptions[0].value;
// Trigger the change event to populate next select
const event = new Event('change', { bubbles: true });
selectElem.dispatchEvent(event);
}
}
function populateVersions(software) {
versionSelect.innerHTML = '<option value="">Select Version</option>';
commandSelect.innerHTML = '<option value="">Select Command</option>';
if (software && commandsConst[software]) {
for (const version in commandsConst[software]) {
const option = document.createElement('option');
option.value = version;
option.textContent = version;
versionSelect.appendChild(option);
}
}
// Auto-select if only one version available
autoSelectIfSingle(versionSelect);
}
function populateCommands(software, version) {
commandSelect.innerHTML = '<option value="">Select Command</option>';
if (software && version && commandsConst[software][version]) {
commandsConst[software][version].forEach(command => {
const option = document.createElement('option');
option.value = command;
option.textContent = command;
commandSelect.appendChild(option);
});
}
// Auto-select if only one command available
autoSelectIfSingle(commandSelect);
}
function sendPostRequest(software, version, command) {
const data = {
software: software,
version: version,
command: command
};
$.post(window.location.href, JSON.stringify(data), function(response, textStatus, jqXHR) {
if (response.status === "success") {
// Toggle visibility based on the response
toggleDataVisibility(true);
// Update the time container
if (response.time) {
$('#time-container').text(`Generated on: ${response.time}`);
} else {
$('#time-container').text('Error: Plot for this command has not been generated');
}
// Update memory image
if (response.img_mem) {
$('#image-mem').html('<img height="100%" width="100%" src="' + response.img_mem + '"/>');
} else {
$('#image-mem').html('No memory allocation image available');
}
// Update time image
if (response.img_time) {
$('#image-time').html('<img height="100%" width="100%" src="' + response.img_time + '"/>');
} else {
$('#image-time').html('No time allocation image available');
}
// Update memory data
if (response.mk && response.ma && response.mb && response.mmodel && response.mreal && response.mcalc && response.mfail) {
$('#mem-data').html(`
<ul>
<li>k: ${response.mk}</li>
<li>a: ${response.ma}</li>
<li>b: ${response.mb}</li>
<li>model: ${response.mmodel}</li>
<li>real: ${response.mreal}</li>
<li>calc: ${response.mcalc}</li>
<li>fail: ${response.mfail}</li>
</ul>
`);
} else {
$('#mem-data').html('No memory allocation data available');
}
// Update time data
if (response.tk && response.ta && response.tb && response.tmodel && response.treal && response.tcalc && response.tfail) {
$('#time-data').html(`
<ul>
<li>k: ${response.tk}</li>
<li>a: ${response.ta}</li>
<li>b: ${response.tb}</li>
<li>model: ${response.tmodel}</li>
<li>real: ${response.treal}</li>
<li>calc: ${response.tcalc}</li>
<li>fail: ${response.tfail}</li>
</ul>
`);
} else {
$('#time-data').html('No time allocation data available');
}
bootstrapAlert("Data updated successfully", "success", 2200);
} else if (response.status === "no_data") {
toggleDataVisibility(false);
$('#default-message').html('<h3>No data available for the selected options.</h3>');
bootstrapAlert("No data available", "info", 2200);
} else {
toggleDataVisibility(false);
bootstrapAlert("Error: " + response.message, "danger", 2200);
}
}, 'json')
.fail(function(jqXHR, textStatus, errorThrown) {
toggleDataVisibility(false);
bootstrapAlert("An error occurred while processing your request", "danger", 2200);
});
}
// Event listener for software select
softwareSelect.addEventListener('change', function() {
const selectedSoftware = this.value;
populateVersions(selectedSoftware);
});
// Event listener for version select
versionSelect.addEventListener('change', function() {
const selectedSoftware = softwareSelect.value;
const selectedVersion = this.value;
populateCommands(selectedSoftware, selectedVersion);
});
// Event listener for command select
commandSelect.addEventListener('change', function() {
const selectedSoftware = softwareSelect.value;
const selectedVersion = versionSelect.value;
const selectedCommand = this.value;
if (selectedSoftware && selectedVersion && selectedCommand) {
sendPostRequest(selectedSoftware, selectedVersion, selectedCommand);
}
});
// Attempt auto-select after initial population of software
autoSelectIfSingle(softwareSelect);
</script>
{% end %}