picluster/web/functions-viewer.html

128 lines
3.9 KiB
HTML
Raw Permalink 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 get_functions() {
if (parent.manage_function && parent.manage_function_uuid) {
var option = '<option value="' + parent.manage_function_uuid + '">' + parent.manage_function + '</option>';
$('#function_list').append(option);
parent.manage_function = '';
parent.manage_function_uuid = '';
} else {
$.get("/nodes?token=" + parent.token, function(data) {
for (var i in data.functions.name) {
if (data.functions.name[i].name) {
option += '<option value="' + data.functions.name[i].uuid + '">' + data.functions.name[i].name + '</option>';
}
}
$('#function_list').append(option);
});
}
}
function exec() {
var function_list = document.getElementById("function_list");
var get_function = function_list.options[function_list.selectedIndex] ? function_list.options[function_list.selectedIndex].value: '';
var command = '';
document.getElementById("function_output").value = 'Fetching.....';
document.getElementById("function_url").value = 'Fetching.....';
if (get_function.length > 1) {
$.get("/nodes?token=" + parent.token, function(data) {
for (var i in data.functions.name) {
if (data.functions.name[i].name.indexOf(get_function) > -1) {
if (data.functions.name[i].name && data.functions.name[i].output) {
document.getElementById("function_output").value = data.functions.name[i].output;
document.getElementById("function_url").value = 'curl \"' + data.function_server + '?token=' + parent.token + '&uuid=' + data.functions.name[i].uuid + '\"';
} else {
document.getElementById("function_output").value = 'No output or function already removed.';
document.getElementById("function_url").value = 'No output or function already removed.';
}
}
}
});
} else {
alert('Error, you did not select a function.')
output_modal.style.display = "none";
modal.style.display = "block";
}
};
</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>View Functions</h2>
</div>
<div class="modal-body">
<fieldset name="functions" id="functions">
<legend><b>Function</b></legend>
<div id="function_list_selector">
<select name="function_list" id="function_list"></select>
</div>
<div id="function_list_submit">
<button id="submit_button">View</button>
</div>
</fieldset>
<fieldset name="options" id="options">
<legend><b>Function Data</b></legend>
<label>Data Retrieval</label>
<input type="text" id="function_url" name="function_url" class="modal_input" value="">
<textarea id="function_output"></textarea>
</fieldset>
</div>
</div>
</div>
<div id="output" class="modal">
<div class="modal-content modal-large">
<div class="modal-header">
<span class="close">&times;</span>
<h2>Command Output</h2>
</div>
<div id="functions-viewer-modal-body" class="modal-body">
Please wait.
</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");
span.onclick = function () {
modal.style.display = "none";
}
output_span.onclick = function () {
output_modal.style.display = "none";
}
submit_button.onclick = function () {
exec();
}
modal.style.display = "block";
get_functions();
</script>
</html>