Skip to content

Commit

Permalink
Farge på sist sett avhengig av tid, forenkler varetellingen
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Sep 14, 2023
1 parent e364e07 commit 84336de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions BookingSystem/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,19 @@ def order_due_date_fmt(self) -> str:
return ''
return parser.parse(self.order_due_date).strftime('%d.%m.%Y')

@property
def last_seen_td_html(self) -> str:
if not self.last_seen:
return ''
parsed = parser.parse(self.last_seen)
# Show last seen within 3hrs as new (color in table)
within_3hrs = 'class="last-seen-new"' if parsed > datetime.now() - timedelta(hours=3) else ''
# 1yr = 1 school year (300 days) (color in table)
over_1yr = 'class="last-seen-old"' if parsed < datetime.now() - timedelta(days=300) else ''
inject_class = f'{within_3hrs}{over_1yr}'
# Construct HTML
return f"<td data-sort=\"{self.last_seen}\"{inject_class}>{parsed.strftime('%d.%m.%Y')}</td>"

@property
def user(self) -> dict:
if self.borrowed_to is None:
Expand Down
2 changes: 1 addition & 1 deletion BookingSystem/templates/inventar.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h3>Her kan du legge til og endre inventaren. Du kan også skrive ut etiketter.<
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.category }}</td>
<td>{{ item.last_seen }}</td>
{{ item.last_seen_td_html | safe }}
<td>
{% if item.available %}
<a href="{{ url_for('app.edit_item', item_id=item.id) }}">Rediger</a>
Expand Down
8 changes: 8 additions & 0 deletions BookingSystem/templates/partials/css.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
color: var(--form-element-color);
}

.last-seen-new {
color: var(--form-element-valid-active-border-color);
}

.last-seen-old {
color: var(--form-element-invalid-active-border-color);
}

/* Use the same max-width as body main */
@media (min-width: 1200px) {
#bulletin-contents {
Expand Down

0 comments on commit 84336de

Please sign in to comment.