add components placeholder and simplify binding process

This commit is contained in:
Cayo Puigdefabregas 2022-08-09 10:49:56 +02:00
parent 9782ab68d6
commit 8c4f7eb10e
5 changed files with 53 additions and 15 deletions

View File

@ -317,6 +317,7 @@ class NewDeviceForm(FlaskForm):
id_device_supplier = StringField('Id Supplier', [validators.Optional()])
phid = StringField('Placeholder Hardware identity (Phid)', [validators.Optional()])
pallet = StringField('Identity of pallet', [validators.Optional()])
components = TextAreaField('Components', [validators.Optional()])
info = TextAreaField('Info', [validators.Optional()])
serial_number = StringField('Seria Number', [validators.Optional()])
model = StringField('Model', [validators.Optional()])
@ -392,6 +393,7 @@ class NewDeviceForm(FlaskForm):
self.phid.data = self._obj.placeholder.phid
self.pallet.data = self._obj.placeholder.pallet
self.info.data = self._obj.placeholder.info
self.components.data = self._obj.placeholder.components
self.serial_number.data = self._obj.serial_number
self.model.data = self._obj.model
self.manufacturer.data = self._obj.manufacturer
@ -420,6 +422,7 @@ class NewDeviceForm(FlaskForm):
self.id_device_supplier.render_kw = disabled
self.pallet.render_kw = disabled
self.info.render_kw = disabled
self.components.render_kw = disabled
self.serial_number.render_kw = disabled
self.model.render_kw = disabled
self.manufacturer.render_kw = disabled
@ -595,6 +598,7 @@ class NewDeviceForm(FlaskForm):
'phid': self.phid.data or None,
'id_device_supplier': self.id_device_supplier.data,
'info': self.info.data,
'components': self.components.data,
'pallet': self.pallet.data,
'is_abstract': False,
}
@ -608,6 +612,7 @@ class NewDeviceForm(FlaskForm):
self.id_device_supplier.data or None
)
self._obj.placeholder.info = self.info.data or None
self._obj.placeholder.components = self.components.data or None
self._obj.placeholder.pallet = self.pallet.data or None
self._obj.model = self.model.data
self._obj.manufacturer = self.manufacturer.data
@ -1662,8 +1667,8 @@ class BindingForm(FlaskForm):
self.phid.errors = [txt]
return False
if self.device.placeholder:
txt = "This is not a device Workbench."
if self.device.is_abstract() != 'Abstract':
txt = "This is not a abstract device."
self.phid.errors = [txt]
return False

View File

@ -191,6 +191,14 @@ class BindingView(GenericMixin):
.one()
)
if device.is_abstract() != 'Abstract':
next_url = url_for('inventory.device_details', id=dhid)
messages.error('Device "{}" not is a Abstract device!'.format(dhid))
return flask.redirect(next_url)
if device.placeholder:
device = device.placeholder.binding
if request.method == 'POST':
old_placeholder = device.binding
old_device_placeholder = old_placeholder.device

View File

@ -667,13 +667,18 @@ class Device(Thing):
action.functionality_range = value
def is_abstract(self):
if not self.placeholder:
return ''
if self.placeholder.is_abstract:
return 'Abstract'
if self.placeholder.binding:
if self.placeholder:
if self.placeholder.is_abstract:
return 'Abstract'
if self.placeholder.binding:
return 'Twin'
return 'Real'
if self.binding:
if self.binding.is_abstract:
return 'Abstract'
return 'Twin'
return 'Real'
return ''
def is_status(self, action):
from ereuse_devicehub.resources.device import states
@ -878,6 +883,7 @@ class Placeholder(Thing):
phid = Column(Unicode(), nullable=False, default=create_phid)
pallet.comment = "used for identification where from where is this placeholders"
info = db.Column(CIText())
components = Column(CIText())
info.comment = "more info of placeholders"
is_abstract = db.Column(Boolean, default=False)
id_device_supplier = db.Column(CIText())

View File

@ -142,6 +142,19 @@
{% endif %}
</div>
<div class="form-group mb-2">
<label for="label" class="form-label">{{ form.components.label }}</label>
{{ form.components(class_="form-control") }}
<small class="text-muted form-text">Description of components</small>
{% if form.components.errors %}
<p class="text-danger">
{% for error in form.components.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
<div class="from-group has-validation mb-2" id="Serial_number">
<label for="serialNumber" class="form-label">{{ form.serial_number.label }}</label>
{{ form.serial_number(class_="form-control") }}

View File

@ -62,13 +62,13 @@
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#components">Components</button>
</li>
{% if device.binding %}
{% if device.is_abstract() == 'Abstract' %}
<li class="nav-item">
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#binding">Binding</button>
</li>
{% endif %}
{% if device.placeholder and placeholder.binding and device.is_abstract() != 'Abstract'%}
{% if device.is_abstract() == 'Twin' %}
<li class="nav-item">
<a class="nav-link" href="{{ url_for('inventory.unbinding', phid=placeholder.phid) }}">Unbinding</a>
</li>
@ -102,17 +102,17 @@
<div class="row">
<div class="col-lg-3 col-md-4 label">Manufacturer</div>
<div class="col-lg-9 col-md-8">{{ device.manufacturer }}</div>
<div class="col-lg-9 col-md-8">{{ device.manufacturer or ''}}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Model</div>
<div class="col-lg-9 col-md-8">{{ device.model }}</div>
<div class="col-lg-9 col-md-8">{{ device.model or ''}}</div>
</div>
<div class="row">
<div class="col-lg-3 col-md-4 label">Serial Number</div>
<div class="col-lg-9 col-md-8">{{ device.serial_number }}</div>
<div class="col-lg-9 col-md-8">{{ device.serial_number or ''}}</div>
</div>
</div>
@ -222,6 +222,7 @@
<div class="tab-pane fade profile-overview" id="components">
<h5 class="card-title">Components Details</h5>
{% if device.binding %}
<div class="list-group col-6">
{% for component in device.components|sort(attribute='type') %}
<div class="list-group-item">
@ -241,8 +242,13 @@
</div>
{% endfor %}
</div>
{% else %}
<div class="col-6">
{{ device.placeholder.components or '' }}
</div>
{% endif %}
</div>
{% if placeholder.binding %}
{% if device.is_abstract() %}
<div class="tab-pane fade {% if active_binding %}show active{% else %}profile-overview{% endif %}" id="binding">
<h5 class="card-title">Binding</h5>
<div class="list-group col-6">
@ -252,7 +258,7 @@
</p>
</div>
<div class="list-group col-6">
<form action="{{ url_for('inventory.device_details', id=placeholder.binding.devicehub_id) }}" method="post">
<form action="{{ url_for('inventory.device_details', id=device.devicehub_id) }}" method="post">
{{ form_binding.csrf_token }}
{% for field in form_binding %}
{% if field != form_binding.csrf_token %}