show year selector to admins for logbook
This commit is contained in:
parent
58f8cb14b8
commit
8b0cbe23d1
@ -753,7 +753,7 @@ impl<'r> FromRequest<'r> for AdminUser {
|
|||||||
if user.has_role(db, "admin").await {
|
if user.has_role(db, "admin").await {
|
||||||
Outcome::Success(AdminUser { user })
|
Outcome::Success(AdminUser { user })
|
||||||
} else {
|
} else {
|
||||||
Outcome::Error((Status::Forbidden, LoginError::NotACox))
|
Outcome::Forward(Status::Forbidden)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Outcome::Error(f) => Outcome::Error(f),
|
Outcome::Error(f) => Outcome::Error(f),
|
||||||
|
@ -3,7 +3,16 @@
|
|||||||
{% extends "base" %}
|
{% extends "base" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="max-w-screen-lg w-full">
|
<div class="max-w-screen-lg w-full">
|
||||||
<h1 class="h1">Logbuch</h1>
|
<h1 class="h1">
|
||||||
|
Logbuch
|
||||||
|
{% if "admin" in loggedin_user.roles %}
|
||||||
|
<select id="yearSelect"
|
||||||
|
onchange="changeYear()"
|
||||||
|
style="background: transparent;
|
||||||
|
background-image: none;
|
||||||
|
text-decoration: underline"></select>
|
||||||
|
{% endif %}
|
||||||
|
</h1>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<div class="search-wrapper">
|
<div class="search-wrapper">
|
||||||
<label for="name" class="sr-only">Suche</label>
|
<label for="name" class="sr-only">Suche</label>
|
||||||
@ -17,4 +26,32 @@
|
|||||||
{% for log in logs %}{{ log::show_old(log=log, state="completed", only_ones=false, index=loop.index) }}{% endfor %}
|
{% for log in logs %}{{ log::show_old(log=log, state="completed", only_ones=false, index=loop.index) }}{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<script>
|
||||||
|
function getYearFromURL() {
|
||||||
|
var queryParams = new URLSearchParams(window.location.search);
|
||||||
|
return queryParams.get('year');
|
||||||
|
}
|
||||||
|
|
||||||
|
function populateYears() {
|
||||||
|
var select = document.getElementById('yearSelect');
|
||||||
|
var currentYear = new Date().getFullYear();
|
||||||
|
var selectedYear = getYearFromURL() || currentYear;
|
||||||
|
for (var year = 2019; year <= currentYear; year++) {
|
||||||
|
var option = document.createElement('option');
|
||||||
|
option.value = option.textContent = year;
|
||||||
|
if (year == selectedYear) {
|
||||||
|
option.selected = true;
|
||||||
|
}
|
||||||
|
select.appendChild(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeYear() {
|
||||||
|
var selectedYear = document.getElementById('yearSelect').value;
|
||||||
|
window.location.href = '?year=' + selectedYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call this function when the page loads
|
||||||
|
populateYears();
|
||||||
|
</script>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
Loading…
Reference in New Issue
Block a user