Begin frontend
Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
parent
0f83fec132
commit
8028d82e94
5 changed files with 97 additions and 0 deletions
0
circuit-laundry-notifier/__init__.py
Normal file
0
circuit-laundry-notifier/__init__.py
Normal file
17
circuit-laundry-notifier/static/siteSelect.js
Normal file
17
circuit-laundry-notifier/static/siteSelect.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
const block = document.getElementById("select_site");
|
||||
const nextButton = document.getElementById("select_site__next_button")
|
||||
const siteIDInput = document.getElementById("select_site__site_id_input")
|
||||
|
||||
nextButton.addEventListener("click", function () {
|
||||
hideErrorIndicator()
|
||||
|
||||
if (siteIDInput.value === "") {
|
||||
showError("Missing site ID")
|
||||
return
|
||||
}
|
||||
|
||||
showWorkingIndicator()
|
||||
hideWorkingIndicator()
|
||||
})
|
||||
}
|
25
circuit-laundry-notifier/static/util.js
Normal file
25
circuit-laundry-notifier/static/util.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
const workingIndicator = document.getElementById("working")
|
||||
|
||||
function showWorkingIndicator() {
|
||||
workingIndicator.style.display = "block";
|
||||
}
|
||||
|
||||
function hideWorkingIndicator() {
|
||||
workingIndicator.style.display = "none";
|
||||
}
|
||||
|
||||
const errorIndicator = document.getElementById("error")
|
||||
const errorIndicatorText = document.getElementById("error_text")
|
||||
|
||||
function showErrorIndicator() {
|
||||
errorIndicator.style.display = "block"
|
||||
}
|
||||
|
||||
function hideErrorIndicator() {
|
||||
errorIndicator.style.display = "none"
|
||||
}
|
||||
|
||||
function showError(text) {
|
||||
errorIndicatorText.innerText = text
|
||||
showErrorIndicator()
|
||||
}
|
50
circuit-laundry-notifier/templates/index.html
Normal file
50
circuit-laundry-notifier/templates/index.html
Normal file
|
@ -0,0 +1,50 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>CircuitBodge</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<span class="navbar-brand mb-0 h1">CircuitBodge</span>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="container pt-4">
|
||||
|
||||
<h2>CircuitBodge</h2>
|
||||
|
||||
<div id="working" style="display:none;">
|
||||
<h4>Working...</h4>
|
||||
</div>
|
||||
|
||||
<div id="error" style="display: none;">
|
||||
<p id="error_text" style="color: red;"></p>
|
||||
</div>
|
||||
|
||||
<div id="select_site" style="display:block;">
|
||||
<div class="mb-3">
|
||||
<label for="select_site__site_id_input" class="form-label">Circuit site ID</label>
|
||||
<input type="text" class="form-control" id="select_site__site_id_input" placeholder="0000">
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" id="select_site__next_button">Next</button>
|
||||
</div>
|
||||
|
||||
<div id="select_machine" style="display:none;">
|
||||
</div>
|
||||
|
||||
<div id="submit" style="display:none;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/static/util.js"></script>
|
||||
<script src="/static/siteSelect.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -12,6 +12,7 @@ from circuit_scraper import CircuitScraper, Machine, ScraperError, MachineState
|
|||
def new(debug=False) -> flask.Flask:
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
app.add_url_rule("/", view_func=_web_get_index, methods=["GET"])
|
||||
app.add_url_rule(
|
||||
"/api/v1/machines/<site_id>", view_func=_api_get_machines, methods=["GET"]
|
||||
)
|
||||
|
@ -32,6 +33,10 @@ def new(debug=False) -> flask.Flask:
|
|||
return app
|
||||
|
||||
|
||||
def _web_get_index() -> Union[any, Tuple[any, int]]:
|
||||
return flask.render_template("index.html")
|
||||
|
||||
|
||||
def _api_get_machines(site_id: str) -> Union[any, Tuple[any, int]]:
|
||||
try:
|
||||
machines = CircuitScraper.get_site_machine_states(site_id)
|
||||
|
|
Reference in a new issue