add: whitelist
This commit is contained in:
@@ -15,7 +15,10 @@ CREATE TABLE IF NOT EXISTS items (
|
||||
time TEXT NOT NULL
|
||||
)
|
||||
""")
|
||||
|
||||
try:
|
||||
cursor.execute("ALTER TABLE items ADD COLUMN noshutdown INTEGER DEFAULT 0")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@@ -37,6 +40,7 @@ def mainpage():
|
||||
def submit():
|
||||
value = request.form.get("query")
|
||||
time_value = request.form.get("time")
|
||||
noshutdown = request.form.get("noshutdown")
|
||||
if not value or not time_value:
|
||||
return redirect(url_for("mainpage"))
|
||||
conn = get_db_connection()
|
||||
@@ -47,8 +51,8 @@ def submit():
|
||||
conn.close()
|
||||
return redirect(url_for("mainpage"))
|
||||
cursor.execute(
|
||||
"INSERT INTO items (name, time) VALUES (?, ?)",
|
||||
(value, time_value)
|
||||
"INSERT INTO items (name, time, noshutdown) VALUES (?, ?)",
|
||||
(value, time_value, noshutdown)
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
@@ -79,13 +83,13 @@ def lookup():
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT name, time FROM items WHERE name = ?",
|
||||
"SELECT name, time, noshutdown FROM items WHERE name = ?",
|
||||
(name,)
|
||||
)
|
||||
item = cursor.fetchone()
|
||||
conn.close()
|
||||
|
||||
if item:
|
||||
return jsonify({"name": item["name"], "time": item["time"]}), 200
|
||||
return jsonify({"name": item["name"], "noshutdown": item["noshutdown"], "time": item["time"]}), 200
|
||||
else:
|
||||
return jsonify({"error": "Not found"}), 404
|
||||
@@ -35,7 +35,7 @@
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="{{ url_for('mainpage') }}">BG Shutdown</a>
|
||||
<a class="navbar-brand" href="{{ url_for('mainpage') }}">BS Shutdown</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
@@ -13,9 +13,16 @@
|
||||
class="form-control bg-dark text-white"
|
||||
placeholder="Nom de la machine">
|
||||
</div>
|
||||
|
||||
<div class="col-md-2">
|
||||
<select name="time" class="form-select bg-dark text-white">
|
||||
<div class="form-check text-white">
|
||||
<input class="form-check-input" type="checkbox" name="noshutdown" id="noshutdown">
|
||||
<label class="form-check-label" for="noshutdown">
|
||||
Whitelist shutdown
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<select name="time" class="form-select bg-dark text-white" id="time-select">
|
||||
{% for hour in range(0, 24) %}
|
||||
<option value="{{ '%02d:00'|format(hour) }}">{{ '%02d:00'|format(hour) }}</option>
|
||||
<option value="{{ '%02d:30'|format(hour) }}">{{ '%02d:30'|format(hour) }}</option>
|
||||
@@ -38,9 +45,12 @@
|
||||
{% for item in items %}
|
||||
<div class="d-flex justify-content-between align-items-center py-2">
|
||||
<span class="text-white">{{ item.name }}</span>
|
||||
|
||||
{% if item.noshutdown %}
|
||||
<span class="text-green">OUI</span>
|
||||
{% else %}
|
||||
<span class="text-red">NON</span>
|
||||
<span class="text-white">{{ item.time }}</span>
|
||||
|
||||
{% endif %}
|
||||
<form method="post" action="/delete" class="m-0 p-0">
|
||||
<input type="hidden" name="item_name" value="{{ item.name }}">
|
||||
<button type="submit" class="btn btn-sm btn-danger">×</button>
|
||||
@@ -55,4 +65,15 @@
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const tickCheckbox = document.getElementById('tick'); // script pr desactiver la selection de l'heure si whitelist
|
||||
const timeSelect = document.getElementById('time-select');
|
||||
|
||||
timeSelect.disabled = tickCheckbox.checked;
|
||||
|
||||
tickCheckbox.addEventListener('change', function() {
|
||||
timeSelect.disabled = this.checked;
|
||||
});
|
||||
</script>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user