98 lines
4.0 KiB
HTML
98 lines
4.0 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="sv">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>Admin – Hantera nycklar</title>
|
||
<link rel="stylesheet" href="{{ url_for('static', filename='admin.css') }}">
|
||
</head>
|
||
<body>
|
||
{% if error %}
|
||
<div style="background-color:#f8d7da; color:#721c24; padding:1rem; border:1px solid #f5c6cb; border-radius:6px; margin-bottom:2rem;">
|
||
<strong>Fel:</strong> {{ error }}
|
||
</div>
|
||
{% endif %}
|
||
|
||
<h1>Adminpanel: Hantera åtkomstnycklar</h1>
|
||
|
||
<div class="card">
|
||
<h3>Skapa flera nycklar med tidsfönster</h3>
|
||
<form id="bulkForm" method="post" action="{{ url_for('admin.admin_panel') }}">
|
||
<input type="hidden" name="action" value="bulk_add_full">
|
||
<label>Nycklar och etiketter (en per rad, format: <code>nyckel,etikett</code>):</label><br>
|
||
<textarea name="bulk_keys" rows="10" required>{{ form_data.get("bulk_keys", "") }}</textarea>
|
||
|
||
<h4>Tidsfönster</h4>
|
||
<div id="timeSlotsContainer"></div>
|
||
<button type="button" onclick="addTimeSlot()">➕ Lägg till tidsfönster</button>
|
||
|
||
<br><br>
|
||
<button type="submit">Skapa nycklar och fönster</button>
|
||
</form>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h3>Lägg till tidsfönster för existerande nyckel</h3>
|
||
<form method="post" action="{{ url_for('admin.admin_panel') }}">
|
||
<input type="hidden" name="action" value="add_window">
|
||
<label>Nyckel:<br>
|
||
<input name="key" required value="{{ form_data.get('key', '') }}">
|
||
</label><br>
|
||
<label>Start (ISO):<br>
|
||
<input type="datetime-local" name="start_datetime" required value="{{ form_data.get('start_datetime', '') }}">
|
||
</label><br>
|
||
<label>Slut (ISO):<br>
|
||
<input type="datetime-local" name="end_datetime" required value="{{ form_data.get('end_datetime', '') }}">
|
||
</label><br>
|
||
<button type="submit">Lägg till tidsfönster</button>
|
||
</form>
|
||
</div>
|
||
|
||
<div class="card">
|
||
<h3>Aktuella nycklar och deras tidsfönster</h3>
|
||
{% for key in keys %}
|
||
<h4>{{ key.key }} – {{ key.label }}<br>
|
||
<small>Totalt tokens: {{ key.tokens_total }} (input: {{ key.tokens_input }}, output: {{ key.tokens_output }})</small>
|
||
</h4>
|
||
|
||
<form method="post" style="display:inline;">
|
||
<input type="hidden" name="action" value="delete_key">
|
||
<input type="hidden" name="key" value="{{ key.key }}">
|
||
<button class="delete-button">❌ Ta bort nyckel</button>
|
||
</form>
|
||
|
||
<table>
|
||
<tr><th>Start</th><th>Slut</th><th>Ta bort</th></tr>
|
||
{% for window in key.windows %}
|
||
<tr>
|
||
<td>{{ window.start_datetime }}</td>
|
||
<td>{{ window.end_datetime }}</td>
|
||
<td>
|
||
<form method="post" style="display:inline;">
|
||
<input type="hidden" name="action" value="delete_window">
|
||
<input type="hidden" name="window_id" value="{{ window.id }}">
|
||
<button class="delete-button">❌</button>
|
||
</form>
|
||
</td>
|
||
</tr>
|
||
{% endfor %}
|
||
</table>
|
||
{% endfor %}
|
||
</div>
|
||
|
||
<script>
|
||
let slotIndex = 0;
|
||
function addTimeSlot() {
|
||
const container = document.getElementById("timeSlotsContainer");
|
||
const div = document.createElement("div");
|
||
div.innerHTML = `
|
||
<label>Start: <input type="datetime-local" name="slots[${slotIndex}][start]" required></label>
|
||
<label>Slut: <input type="datetime-local" name="slots[${slotIndex}][end]" required></label>
|
||
<button type="button" class="delete-button" onclick="this.parentElement.remove()">❌</button>
|
||
`;
|
||
container.appendChild(div);
|
||
slotIndex++;
|
||
}
|
||
</script>
|
||
</body>
|
||
</html>
|