add components placeholder and simplify binding process
This commit is contained in:
parent
9782ab68d6
commit
8c4f7eb10e
|
@ -317,6 +317,7 @@ class NewDeviceForm(FlaskForm):
|
||||||
id_device_supplier = StringField('Id Supplier', [validators.Optional()])
|
id_device_supplier = StringField('Id Supplier', [validators.Optional()])
|
||||||
phid = StringField('Placeholder Hardware identity (Phid)', [validators.Optional()])
|
phid = StringField('Placeholder Hardware identity (Phid)', [validators.Optional()])
|
||||||
pallet = StringField('Identity of pallet', [validators.Optional()])
|
pallet = StringField('Identity of pallet', [validators.Optional()])
|
||||||
|
components = TextAreaField('Components', [validators.Optional()])
|
||||||
info = TextAreaField('Info', [validators.Optional()])
|
info = TextAreaField('Info', [validators.Optional()])
|
||||||
serial_number = StringField('Seria Number', [validators.Optional()])
|
serial_number = StringField('Seria Number', [validators.Optional()])
|
||||||
model = StringField('Model', [validators.Optional()])
|
model = StringField('Model', [validators.Optional()])
|
||||||
|
@ -392,6 +393,7 @@ class NewDeviceForm(FlaskForm):
|
||||||
self.phid.data = self._obj.placeholder.phid
|
self.phid.data = self._obj.placeholder.phid
|
||||||
self.pallet.data = self._obj.placeholder.pallet
|
self.pallet.data = self._obj.placeholder.pallet
|
||||||
self.info.data = self._obj.placeholder.info
|
self.info.data = self._obj.placeholder.info
|
||||||
|
self.components.data = self._obj.placeholder.components
|
||||||
self.serial_number.data = self._obj.serial_number
|
self.serial_number.data = self._obj.serial_number
|
||||||
self.model.data = self._obj.model
|
self.model.data = self._obj.model
|
||||||
self.manufacturer.data = self._obj.manufacturer
|
self.manufacturer.data = self._obj.manufacturer
|
||||||
|
@ -420,6 +422,7 @@ class NewDeviceForm(FlaskForm):
|
||||||
self.id_device_supplier.render_kw = disabled
|
self.id_device_supplier.render_kw = disabled
|
||||||
self.pallet.render_kw = disabled
|
self.pallet.render_kw = disabled
|
||||||
self.info.render_kw = disabled
|
self.info.render_kw = disabled
|
||||||
|
self.components.render_kw = disabled
|
||||||
self.serial_number.render_kw = disabled
|
self.serial_number.render_kw = disabled
|
||||||
self.model.render_kw = disabled
|
self.model.render_kw = disabled
|
||||||
self.manufacturer.render_kw = disabled
|
self.manufacturer.render_kw = disabled
|
||||||
|
@ -595,6 +598,7 @@ class NewDeviceForm(FlaskForm):
|
||||||
'phid': self.phid.data or None,
|
'phid': self.phid.data or None,
|
||||||
'id_device_supplier': self.id_device_supplier.data,
|
'id_device_supplier': self.id_device_supplier.data,
|
||||||
'info': self.info.data,
|
'info': self.info.data,
|
||||||
|
'components': self.components.data,
|
||||||
'pallet': self.pallet.data,
|
'pallet': self.pallet.data,
|
||||||
'is_abstract': False,
|
'is_abstract': False,
|
||||||
}
|
}
|
||||||
|
@ -608,6 +612,7 @@ class NewDeviceForm(FlaskForm):
|
||||||
self.id_device_supplier.data or None
|
self.id_device_supplier.data or None
|
||||||
)
|
)
|
||||||
self._obj.placeholder.info = self.info.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.placeholder.pallet = self.pallet.data or None
|
||||||
self._obj.model = self.model.data
|
self._obj.model = self.model.data
|
||||||
self._obj.manufacturer = self.manufacturer.data
|
self._obj.manufacturer = self.manufacturer.data
|
||||||
|
@ -1662,8 +1667,8 @@ class BindingForm(FlaskForm):
|
||||||
self.phid.errors = [txt]
|
self.phid.errors = [txt]
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.device.placeholder:
|
if self.device.is_abstract() != 'Abstract':
|
||||||
txt = "This is not a device Workbench."
|
txt = "This is not a abstract device."
|
||||||
self.phid.errors = [txt]
|
self.phid.errors = [txt]
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -191,6 +191,14 @@ class BindingView(GenericMixin):
|
||||||
.one()
|
.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':
|
if request.method == 'POST':
|
||||||
old_placeholder = device.binding
|
old_placeholder = device.binding
|
||||||
old_device_placeholder = old_placeholder.device
|
old_device_placeholder = old_placeholder.device
|
||||||
|
|
|
@ -667,13 +667,18 @@ class Device(Thing):
|
||||||
action.functionality_range = value
|
action.functionality_range = value
|
||||||
|
|
||||||
def is_abstract(self):
|
def is_abstract(self):
|
||||||
if not self.placeholder:
|
if self.placeholder:
|
||||||
return ''
|
if self.placeholder.is_abstract:
|
||||||
if self.placeholder.is_abstract:
|
return 'Abstract'
|
||||||
return 'Abstract'
|
if self.placeholder.binding:
|
||||||
if self.placeholder.binding:
|
return 'Twin'
|
||||||
|
return 'Real'
|
||||||
|
if self.binding:
|
||||||
|
if self.binding.is_abstract:
|
||||||
|
return 'Abstract'
|
||||||
return 'Twin'
|
return 'Twin'
|
||||||
return 'Real'
|
|
||||||
|
return ''
|
||||||
|
|
||||||
def is_status(self, action):
|
def is_status(self, action):
|
||||||
from ereuse_devicehub.resources.device import states
|
from ereuse_devicehub.resources.device import states
|
||||||
|
@ -878,6 +883,7 @@ class Placeholder(Thing):
|
||||||
phid = Column(Unicode(), nullable=False, default=create_phid)
|
phid = Column(Unicode(), nullable=False, default=create_phid)
|
||||||
pallet.comment = "used for identification where from where is this placeholders"
|
pallet.comment = "used for identification where from where is this placeholders"
|
||||||
info = db.Column(CIText())
|
info = db.Column(CIText())
|
||||||
|
components = Column(CIText())
|
||||||
info.comment = "more info of placeholders"
|
info.comment = "more info of placeholders"
|
||||||
is_abstract = db.Column(Boolean, default=False)
|
is_abstract = db.Column(Boolean, default=False)
|
||||||
id_device_supplier = db.Column(CIText())
|
id_device_supplier = db.Column(CIText())
|
||||||
|
|
|
@ -142,6 +142,19 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</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">
|
<div class="from-group has-validation mb-2" id="Serial_number">
|
||||||
<label for="serialNumber" class="form-label">{{ form.serial_number.label }}</label>
|
<label for="serialNumber" class="form-label">{{ form.serial_number.label }}</label>
|
||||||
{{ form.serial_number(class_="form-control") }}
|
{{ form.serial_number(class_="form-control") }}
|
||||||
|
|
|
@ -62,13 +62,13 @@
|
||||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#components">Components</button>
|
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#components">Components</button>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
{% if device.binding %}
|
{% if device.is_abstract() == 'Abstract' %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#binding">Binding</button>
|
<button class="nav-link" data-bs-toggle="tab" data-bs-target="#binding">Binding</button>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if device.placeholder and placeholder.binding and device.is_abstract() != 'Abstract'%}
|
{% if device.is_abstract() == 'Twin' %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{{ url_for('inventory.unbinding', phid=placeholder.phid) }}">Unbinding</a>
|
<a class="nav-link" href="{{ url_for('inventory.unbinding', phid=placeholder.phid) }}">Unbinding</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -102,17 +102,17 @@
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-3 col-md-4 label">Manufacturer</div>
|
<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>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-3 col-md-4 label">Model</div>
|
<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>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-3 col-md-4 label">Serial Number</div>
|
<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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -222,6 +222,7 @@
|
||||||
|
|
||||||
<div class="tab-pane fade profile-overview" id="components">
|
<div class="tab-pane fade profile-overview" id="components">
|
||||||
<h5 class="card-title">Components Details</h5>
|
<h5 class="card-title">Components Details</h5>
|
||||||
|
{% if device.binding %}
|
||||||
<div class="list-group col-6">
|
<div class="list-group col-6">
|
||||||
{% for component in device.components|sort(attribute='type') %}
|
{% for component in device.components|sort(attribute='type') %}
|
||||||
<div class="list-group-item">
|
<div class="list-group-item">
|
||||||
|
@ -241,8 +242,13 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="col-6">
|
||||||
|
{{ device.placeholder.components or '' }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if placeholder.binding %}
|
{% if device.is_abstract() %}
|
||||||
<div class="tab-pane fade {% if active_binding %}show active{% else %}profile-overview{% endif %}" id="binding">
|
<div class="tab-pane fade {% if active_binding %}show active{% else %}profile-overview{% endif %}" id="binding">
|
||||||
<h5 class="card-title">Binding</h5>
|
<h5 class="card-title">Binding</h5>
|
||||||
<div class="list-group col-6">
|
<div class="list-group col-6">
|
||||||
|
@ -252,7 +258,7 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="list-group col-6">
|
<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 }}
|
{{ form_binding.csrf_token }}
|
||||||
{% for field in form_binding %}
|
{% for field in form_binding %}
|
||||||
{% if field != form_binding.csrf_token %}
|
{% if field != form_binding.csrf_token %}
|
||||||
|
|
Reference in New Issue