webroot/templates/setup/initial-setup.run.html.twig

93 lines
2.5 KiB
Twig

{% extends 'base.html.twig' %}
{% block body %}
<script>
const setup_commands = [
{% for cmd in setup_commands %}
{ "url":{{ cmd.url }}, "output": {{ cmd.output }} },
{% endfor %}
];
redirect_error="{{ setup_url }}";
let command_n = 0;
function endCommands(success) {
let button = document.getElementById("commands-finished-button");
element = document.getElementById("command-code");
p = document.createElement("p");
if (success) {
p.innerText = "Commands executed successfully!";
button.onclick = onCommandsSuccess;
} else {
p.innerText = "Executing commands failed!";
button.onclick = onCommandsFailed;
button.innerText = "Return to setup";
}
element.appendChild(p);
console.log("Button Settings");
button.disabled=false;
}
function appendCommand(n) {
element = document.getElementById("command-code");
p = document.createElement("p");
span = document.createElement("span");
span.innerText = setup_commands[n]["output"];
iframe = document.createElement("iframe");
iframe.setAttribute("id","setup-command-" + n);
iframe.setAttribute("onload","onCommandLoaded");
iframe.setAttribute("src",setup_commands[n]["url"]);
p.appendChild(span);
p.appendChild(iframe);
command_n = n;
}
function onCommandLoaded() {
let element = document.getElementById("command-code");
let cmd_iframe = document.getElementById("setup-command-" + n);
let cmd_result = iframe.contentWindow.document.getElementById("command-result");
if (cmd_result === "SUCCESS") {
next = command_n + 1;
if (n < setup_commands.length) {
appendCommand(next);
} else {
endCommands(true);
}
} else {
endCommands(false);
}
}
function onCommandsSuccess()
{
location.replace('{{ success_url }}');
}
function onCommandsFailed()
{
location.replace('{{ setup_url }}');
}
function onCommandInit()
{
if (setup_commands.length > 0) {
appendCommand(0);
} else {
document.getElementById('commands-finished-button').disabled=true;
endCommands(true);
}
}
</script>
<h1>Running Setup</h1>
<div class="command-output">
<code id="command-code" onload="">
<p id="null-command">Running commands...</p>
</code>
</div>
<button id="commands-finished-button" onclick="onCommandsSuccess;">Finish</button>
<script>onCommandInit();</script>
{% endblock %}