picluster/web/exec.html

153 lines
4.1 KiB
HTML
Raw Normal View History

2021-08-25 08:44:55 -06:00
<html>
<head>
<script src="/assets/jquery.min.js"></script>
<link rel="stylesheet" href="/assets/jquery-ui.css">
<script src="/assets/jquery-ui.js"></script>
<script src="/assets/distLogo.js"></script>
<link rel="stylesheet" href="/assets/picluster-iframe.css">
<script>
function exec() {
var node_list = document.getElementById("node_list");
var command_list = document.getElementById("command_list");
var path = '/exec';
var node = node_list.options[node_list.selectedIndex].value;
var saved_command = command_list.options[command_list.selectedIndex].value;
var command = '';
// FIXME: refactor ternary into a variable assignment ternary
(saved_command.indexOf('Choose') > -1) ? command = $("#command_entry").val() : command = saved_command;
if (!command) {
output_modal.style.display = "none";
modal.style.display = "block";
} else {
$.post(path, {
token: parent.token,
command: command,
node: node
}, function(data) {
$('#exec_output').val($('#exec_output').val() + '\n' + data + '\n');
});
}
}
</script>
</head>
<body>
<div id="modal_container" class="modal">
<div class="modal-content modal-small">
<div class="modal-header">
<span class="close">&times;</span>
<h2>Run Commands on the Cluster</h2>
</div>
<div class="modal-body">
<fieldset class="">
<legend><b>Node</b></legend>
<select name="node_list" id="node_list"></select>
</fieldset>
<fieldset>
<legend><b>Command</b></legend>
<input type="text" size="30" id="command_entry" name="command_entry" class="modal_input" value="">
<hr>
<div>
<label id="windowfont" for="command_list">Saved Commands</label>
<select name="command_list" id="command_list" class="modal_input"></select>
</div>
<div id="submit_button_div">
<button id="submit_button">Submit</button>
</div>
</fieldset>
<script>
$(function () {
var option = '';
$.get("/nodes?token=" + parent.token, function (data) {
for (var i in data.nodes) {
option += '<option value="' + data.nodes[i] + '">' + data.nodes[i] + '</option>';
}
option += '<option value="' + '*' + '">' + '*' + '</option>';
$('#node_list').append(option);
});
});
$(function () {
var option = '';
$.post('/listcommands', {
token: parent.token
}, function (data) {
option += '<option value="' + 'Choose' + '">' + 'Choose' + '</option>';
if (data) {
data = JSON.parse(data);
for (var i = 0; i < data.length; i++) {
for (var key in data[i]) {
if (data[i].hasOwnProperty(key)) {
option += '<option value="' + data[i][key] + '">' + key + '</option>';
}
}
}
}
$('#command_list').append(option);
});
});
</script>
</div>
</div>
</div>
<div id="output" class="modal">
<div class="modal-content modal-large">
<div class="modal-header">
<span class="close">&times;</span>
<h2>PiCluster Terminal</h2>
</div>
<div class="modal-body">
<textarea id="exec_output" name="exec_output" value="" enctype="application/json"></textarea>
<div id="rerun_div">
<br>
<button id="rerun_button">Run Again</button>
</div>
</div>
</div>
</div>
<script>
var modal = document.getElementById('modal_container');
var span = document.getElementsByClassName("close")[0];
var output_modal = document.getElementById('output');
var output_span = document.getElementsByClassName("close")[1];
var submit_button = document.getElementById("submit_button");
var rerun_button = document.getElementById("rerun_button");
span.onclick = function () {
modal.style.display = "none";
}
output_span.onclick = function () {
output_modal.style.display = "none";
}
submit_button.onclick = function () {
modal.style.display = "none";
output_modal.style.display = "block";
exec();
}
rerun_button.onclick = function () {
$('#exec_output').val('');
exec();
}
modal.style.display = "block";
</script>
</html>