BrickTracker/templates/create.html

170 lines
5.5 KiB
HTML

<!DOCTYPE html>
<html data-theme="light" class="has-navbar-fixed-top">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bulma@1.0.0/css/bulma.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.3.1/socket.io.js" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar is-dark is-fixed-top" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="/">
Home
</a>
</div>
<div id="navMenu" class="navbar-menu">
<div class="navbar-start">
</div>
<div class="navbar-end">
</div>
</div>
</nav>
<section class="section">
<div class="container">
<form id="createForm" action="/create" method="post">
<div class="field">
<label class="label" for="inputField">Input:</label>
<div class="control">
<input class="input" type="text" id="inputField" name="inputField">
</div>
</div>
<span id="progress-bar-text" style="left: 50%; font-size: 12px;"></span>
<progress id="progress-bar" class="progress is-large is-primary" value="0" max="100">
</progress>
<div class="field">
<div class="control">
<button id="submitButton" class="button is-primary" type="submit">Submit</button>
</div>
</div>
</form>
</div>
</section>
<button class="js-modal-trigger" data-target="modal-js-example" id="modal-js">
</button>
<div class="modal" id="modal-js-example">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Cannot add set!</p>
<button class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body">
Set number does not exists:
<br>
<b id="error-code"></b>
</section>
<footer class="modal-card-foot">
<div class="buttons">
<button class="button is-primary">OK</button>
</div>
</footer>
</div>
</div>
</body>
<script>
var socket = io.connect(window.location.protocol + '//' + document.domain + ':' + location.port + '/progress', {
transports: ['websocket'],
});
// Event listener for receiving progress updates
socket.on('update_progress', function (msg) {
var progress = msg.progress;
var state = msg.desc;
console.log(progress,state);
// document.getElementById("progress-bar").style.width = progress + "%";
document.getElementById("progress-bar").value = progress;
document.getElementById("progress-bar").innerText = progress + "%";
document.getElementById("progress-bar-text").innerText = state;
});
// Event listener for the form submission
document.getElementById("createForm").addEventListener("submit", function (event) {
event.preventDefault(); // Prevent default form submission
var inputField = document.getElementById("inputField").value;
socket.emit('start_task', { inputField: inputField }); // Emit socket event with inputField value
});
// Event listener for the 'task_completed' event
socket.on('task_completed', function () {
// Redirect to '/'
document.getElementById("progress-bar-text").innerText = '';
window.location.href = '/';
});
socket.on('task_failed', function () {
// Redirect to '/'
var inputField = document.getElementById("inputField").value;
console.log(inputField);
document.getElementById("modal-js").click();
document.getElementById("error-code").innerHTML = inputField;
document.getElementById("inputField").value = "";
// window.location.href = '/create';
});
document.addEventListener('DOMContentLoaded', () => {
// Functions to open and close a modal
function openModal($el) {
$el.classList.add('is-active');
}
function closeModal($el) {
$el.classList.remove('is-active');
}
function closeAllModals() {
(document.querySelectorAll('.modal') || []).forEach(($modal) => {
closeModal($modal);
});
}
// Add a click event on buttons to open a specific modal
(document.querySelectorAll('.js-modal-trigger') || []).forEach(($trigger) => {
const modal = $trigger.dataset.target;
const $target = document.getElementById(modal);
$trigger.addEventListener('click', () => {
openModal($target);
});
});
// Add a click event on various child elements to close the parent modal
(document.querySelectorAll('.modal-background, .modal-close, .modal-card-head .delete, .modal-card-foot .button') || []).forEach(($close) => {
const $target = $close.closest('.modal');
$close.addEventListener('click', () => {
closeModal($target);
});
});
// Add a keyboard event to close all modals
document.addEventListener('keydown', (event) => {
if (event.key === "Escape") {
closeAllModals();
}
});
});
</script>
</html>