changed state visual and ordering

This commit is contained in:
Thomas Nahuel Rusiecki 2024-12-06 19:19:49 -03:00
parent b5d818fdf7
commit ac1d5a3ab0
2 changed files with 58 additions and 10 deletions

View file

@ -37,6 +37,9 @@
<li class="nav-item">
<a href="#details" class="nav-link active" data-bs-toggle="tab" data-bs-target="#details">{% trans 'General details' %}</a>
</li>
<li class="nav-item">
<a href="#states" class="nav-link" data-bs-toggle="tab" data-bs-target="#states">{% trans 'States' %}</a>
</li>
<li class="nav-item">
<a href="#user_properties" class="nav-link" data-bs-toggle="tab" data-bs-target="#user_properties">{% trans 'User properties' %}</a>
</li>
@ -122,14 +125,30 @@
<div class="col-lg-6">
<h5 class="card-title">{% trans 'Current State' %}</h5>
<hr>
<div class="row mb-3">
<div class="col-sm-4 text-muted fw-bold">{% trans 'State' %}</div>
<div class="col-sm-8">{{ device_states.0.state }}</div>
</div>
<div class="row mb-3">
<div class="col-sm-4 text-muted fw-bold">{% trans 'Date' %}</div>
<div class="col-sm-8">{{ device_states.0.date|date:"SHORT_DATETIME_FORMAT" }}</div>
</div>
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead class="table">
<tr>
<th scope="col">{% trans 'State' %}</th>
<th scope="col">{% trans 'User' %}</th>
<th scope="col">{% trans 'Date' %}</th>
</tr>
</thead>
<tbody>
{% if device_states %}
<tr class="table-success">
<td>{{ device_states.0.state }}</td>
<td>{{ device_states.0.user.responsable_person|default:device_states.0.user.username }}</td>
<td>{{ device_states.0.date|date:"SHORT_DATETIME_FORMAT" }}</td>
</tr>
{% else %}
<tr>
<td colspan="3" class="text-center">{% trans 'No state recorded.' %}</td>
</tr>
{% endif %}
</tbody>
</table>
</div>
<!-- TODO: display last note? -->
{% if last_note %}
@ -143,7 +162,36 @@
</div>
<!-- End of Details -->
<!-- States list -->
<div class="tab-pane fade" id="states">
<h5 class="card-title mb-3">{% trans 'History of States' %}</h5>
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead class="table">
<tr>
<th scope="col">{% trans 'Date' %}</th>
<th scope="col">{% trans 'User' %}</th>
<th scope="col">{% trans 'State' %}</th>
</tr>
</thead>
<tbody>
{% for state_change in device_states %}
<tr {% if forloop.first %}class="table-success"{% endif %}>
<td><strong>{{ state_change.state }}</strong></td>
<td>{{ state_change.user.responsable_person|default:state_change.user.username }}</td>
<td>{{ state_change.date|date:"SHORT_DATETIME_FORMAT" }}</td>
</tr>
{% empty %}
<tr>
<td colspan="3" class="text-center">{% trans 'No state changes recorded.' %}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="user_properties">
<div class="btn-group mt-1 mb-3">

View file

@ -116,7 +116,7 @@ class DetailsView(DashboardView, TemplateView):
'snapshot': last_evidence,
'lot_tags': lot_tags,
"state_definitions": StateDefinition.objects.filter(institution=self.request.user.institution).order_by('order'),
"device_states": State.objects.filter(snapshot_uuid=uuid).order_by('date'),
"device_states": State.objects.filter(snapshot_uuid=uuid).order_by('-date'),
})
return context