Skip to content

Commit

Permalink
Display overdue in index
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Aug 4, 2023
1 parent 56aee7b commit b2e49eb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion BookingSystem/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def unauthorized(e) -> flask.Response:
@login_required()
def index() -> str:
if flask.session.get("user").is_admin:
return flask.render_template('index_admin.html')
return flask.render_template('index_admin.html', overdue_items=inventory.get_all_overdue())
return flask.render_template('index_student.html', all_groups=groups.get_all())


Expand Down
8 changes: 8 additions & 0 deletions BookingSystem/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ def get_all_unavailable() -> list[Item]:
return items


def get_all_overdue() -> list[Item]:
"""Return a JSON list of all overdue items in the database."""
con = sqlite3.connect(DATABASE)
items = [Item(*row) for row in con.execute(read_sql_query('get_all_overdue.sql'))]
con.close()
return items


def _update_last_seen(item_id: str) -> None:
"""Update the last_seen column of the item with the given ID."""
con = sqlite3.connect(DATABASE)
Expand Down
52 changes: 52 additions & 0 deletions BookingSystem/templates/index_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,56 @@ <h3>Velkommen! Her kan du <a href="{{ url_for('innlevering') }}">levere inn</a>
<button>Administrere utstyr</button>
</a>

{% if overdue_items %}
<br><br>
<center>
<h4>
Overskredet utstyr:
</h4>
</center>
<table id="active">
<thead>
<tr>
<th>Løpenummer</th>
<th>Utstyr</th>
<th>Utlånt til</th>
<th>Frist for levering</th>
</thead>
<tbody>
{% for item in overdue_items %}
<tr class="item-row item-row--overdue">
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.borrowed_to }}</td>
<td>{{ item.order_due_date|strftime }}</td>
</tr>
{% endfor %}
</table>
{% endif %}

<script>
$(document).ready(function () {
let lang = {
"lengthMenu": "Vis _MENU_ rader per side",
"zeroRecords": "Ingen treff",
"info": "Viser side _PAGE_ av _PAGES_",
"infoEmpty": "Ingen rader tilgjengelig",
"infoFiltered": "(filtrert fra _MAX_ rader totalt)",
"search": "Søk:",
"paginate": {
"first": "Første",
"last": "Siste",
"next": "Neste",
"previous": "Forrige"
}
};
$('#active').DataTable({
"language": lang,
"order": [[3, "asc"]],
"pageLength": 25,
"lengthMenu": [[25, 50, -1], [25, 50, "Alle"]],
});
});
</script>

{% endblock %}

0 comments on commit b2e49eb

Please sign in to comment.