added current state to device details

This commit is contained in:
Thomas Nahuel Rusiecki 2024-12-06 17:48:06 -03:00
parent a642be2211
commit b3132e5582
3 changed files with 103 additions and 56 deletions

22
action/forms.py Normal file
View file

@ -0,0 +1,22 @@
from django import forms
from .models import State
class AddStateForm(forms.Form):
add_note = forms.BooleanField(required=False)
note = forms.CharField(
required=False,
widget=forms.Textarea(attrs={'rows': 4, 'maxlength': 200, 'placeholder': 'Max 200 characters'}),
)
state_id = forms.IntegerField(required=True, widget=forms.HiddenInput())
snapshot_uuid = forms.UUIDField(required=True, widget=forms.HiddenInput())
def clean(self):
cleaned_data = super().clean()
add_note = cleaned_data.get('add_note')
note = cleaned_data.get('note')
if add_note == True and not note:
self.add_error('note', 'Please enter a note if you checked "Add a note".')
return cleaned_data

View file

@ -58,70 +58,91 @@
</ul>
</div>
</div>
<div class="tab-content pt-2">
<div class="tab-content pt-4">
<div class="tab-pane fade show active" id="details">
<div class="row">
<!-- Device Details -->
<div class="col-lg-6">
<h5 class="card-title">{% trans 'Details' %}</h5>
<hr>
<div class="row mb-3">
<div class="col-lg-3 col-md-4 label">Phid</div>
<div class="col-lg-9 col-md-8">{{ object.id }}</div>
<div class="col-sm-4 text-muted fw-bold">{% trans 'Phid' %}</div>
<div class="col-sm-8">{{ object.id }}</div>
</div>
{% if object.is_eraseserver %}
<div class="row mb-3">
<div class="col-lg-3 col-md-4 label">
{% trans 'Is a erase server' %}
</div>
<div class="col-lg-9 col-md-8"></div>
<div class="col-sm-4 text-muted fw-bold">{% trans 'Is an erase server' %}</div>
<div class="col-sm-8">{% trans 'Yes' %}</div>
</div>
{% endif %}
<div class="row mb-3">
<div class="col-lg-3 col-md-4 label">Type</div>
<div class="col-lg-9 col-md-8">{{ object.type }}</div>
<div class="col-sm-4 text-muted fw-bold">{% trans 'Type' %}</div>
<div class="col-sm-8">{{ object.type }}</div>
</div>
{% if object.is_websnapshot and object.last_user_evidence %}
{% for k, v in object.last_user_evidence %}
{% for k, v in object.last_user_evidence.items %}
<div class="row mb-3">
<div class="col-lg-3 col-md-4 label">{{ k }}</div>
<div class="col-lg-9 col-md-8">{{ v|default:'' }}</div>
<div class="col-sm-4 text-muted fw-bold">{{ k }}</div>
<div class="col-sm-8">{{ v|default:'' }}</div>
</div>
{% endfor %}
{% else %}
<div class="row mb-3">
<div class="col-lg-3 col-md-4 label">
{% trans 'Manufacturer' %}
</div>
<div class="col-lg-9 col-md-8">{{ object.manufacturer|default:'' }}</div>
<div class="col-sm-4 text-muted fw-bold">{% trans 'Manufacturer' %}</div>
<div class="col-sm-8">{{ object.manufacturer|default:'' }}</div>
</div>
<div class="row mb-3">
<div class="col-lg-3 col-md-4 label">
{% trans 'Model' %}
</div>
<div class="col-lg-9 col-md-8">{{ object.model|default:'' }}</div>
<div class="col-sm-4 text-muted fw-bold">{% trans 'Model' %}</div>
<div class="col-sm-8">{{ object.model|default:'' }}</div>
</div>
<div class="row mb-3">
<div class="col-lg-3 col-md-4 label">
{% trans 'Serial Number' %}
</div>
<div class="col-lg-9 col-md-8">{{ object.serial_number|default:'' }}</div>
<div class="col-sm-4 text-muted fw-bold">{% trans 'Serial Number' %}</div>
<div class="col-sm-8">{{ object.serial_number|default:'' }}</div>
</div>
{% endif %}
<div class="row mb-3">
<div class="col-lg-3 col-md-4 label">
{% trans 'Identifiers' %}
</div>
</div>
<div class="col-sm-4 text-muted fw-bold">{% trans 'Identifiers' %}</div>
<div class="col-sm-8">
{% for chid in object.hids %}
<div class="row mb-3">
<div class="col">{{ chid|default:'' }}</div>
</div>
<div>{{ chid|default:'' }}</div>
{% endfor %}
</div>
</div>
</div>
<!-- Device Current State -->
<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>
<!-- TODO: display last note? -->
{% if last_note %}
<div class="row mb-3">
<div class="col-sm-4 text-muted fw-bold">{% trans 'Note' %}</div>
<div class="col-sm-8">{{ object.last_state.note }}</div>
</div>
{% endif %}
</div>
</div>
</div>
</div>
<!-- End of Details -->
<div class="tab-pane fade" id="user_properties">
<div class="btn-group mt-1 mb-3">
@ -169,7 +190,7 @@
</table>
</div>
<!-- pop up modal for delete confirmation -->
<!-- pop up modal for delete confirmation -->
{% for a in object.get_user_properties %}
<div class="modal fade" id="deleteModal{{ a.id }}" tabindex="-1" aria-labelledby="deleteModalLabel{{ a.id }}" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
@ -360,6 +381,7 @@
</div>
<input type="hidden" name="state_id" value="{{ state.id }}">
<input type="hidden" name="snapshot_uuid" value="{{ object.last_uuid }}">
</div>
<div class="modal-footer">

View file

@ -14,7 +14,7 @@ from django.views.generic.edit import (
DeleteView,
)
from django.views.generic.base import TemplateView
from action.models import StateDefinition
from action.models import StateDefinition, State
from dashboard.mixins import DashboardView, Http403
from evidence.models import UserProperty, SystemProperty, Property
from lot.models import LotTag
@ -109,11 +109,14 @@ class DetailsView(DashboardView, TemplateView):
context = super().get_context_data(**kwargs)
self.object.initial()
lot_tags = LotTag.objects.filter(owner=self.request.user.institution)
last_evidence= self.object.get_last_evidence(),
uuid=self.object.last_uuid()
context.update({
'object': self.object,
'snapshot': self.object.get_last_evidence(),
'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'),
})
return context