mv unique identifiers buttons to device details

This commit is contained in:
Cayo Puigdefabregas 2022-08-30 13:10:35 +02:00
parent b5a738c44a
commit bdf04061dc
7 changed files with 85 additions and 72 deletions

View File

@ -137,11 +137,11 @@ class FilterForm(FlaskForm):
self.lot = self.lots.filter(Lot.id == self.lot_id).one() self.lot = self.lots.filter(Lot.id == self.lot_id).one()
device_ids = (d.id for d in self.lot.devices) device_ids = (d.id for d in self.lot.devices)
self.devices = Device.query.filter(Device.id.in_(device_ids)).filter( self.devices = Device.query.filter(Device.id.in_(device_ids)).filter(
Device.binding == None Device.binding == None # noqa: E711
) )
else: else:
self.devices = Device.query.filter(Device.owner_id == g.user.id).filter( self.devices = Device.query.filter(Device.owner_id == g.user.id).filter(
Device.binding == None Device.binding == None # noqa: E711
) )
if self.only_unassigned: if self.only_unassigned:
self.devices = self.devices.filter_by(lots=None) self.devices = self.devices.filter_by(lots=None)
@ -655,19 +655,30 @@ class NewDeviceForm(FlaskForm):
class TagDeviceForm(FlaskForm): class TagDeviceForm(FlaskForm):
tag = SelectField('Tag', choices=[]) tag = SelectField(
device = StringField('Device', [validators.Optional()]) 'Tag',
choices=[],
render_kw={
'class': 'form-control selectpicker',
'data-live-search': 'true',
},
)
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.delete = kwargs.pop('delete', None) self.delete = kwargs.pop('delete', None)
self.device_id = kwargs.pop('device', None) self.dhid = kwargs.pop('dhid', None)
self._device = (
Device.query.filter(Device.devicehub_id == self.dhid)
.filter(Device.owner_id == g.user.id)
.one()
)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if self.delete: if self.delete:
tags = ( tags = (
Tag.query.filter(Tag.owner_id == g.user.id) Tag.query.filter(Tag.owner_id == g.user.id)
.filter_by(device_id=self.device_id) .filter_by(device_id=self._device.id)
.order_by(Tag.id) .order_by(Tag.id)
) )
else: else:
@ -695,20 +706,6 @@ class TagDeviceForm(FlaskForm):
self.tag.errors = [("This tag is actualy in use.")] self.tag.errors = [("This tag is actualy in use.")]
return False return False
if self.device.data:
try:
self.device.data = int(self.device.data.split(',')[-1])
except: # noqa: E722
self.device.data = None
if self.device_id or self.device.data:
self.device_id = self.device_id or self.device.data
self._device = (
Device.query.filter(Device.id == self.device_id)
.filter(Device.owner_id == g.user.id)
.one()
)
return True return True
def save(self): def save(self):

View File

@ -80,7 +80,6 @@ class DeviceListMixin(GenericMixin):
self.context.update( self.context.update(
{ {
'devices': devices, 'devices': devices,
'form_tag_device': TagDeviceForm(),
'form_new_action': form_new_action, 'form_new_action': form_new_action,
'form_new_allocate': AllocateForm(lot=lot_id), 'form_new_allocate': AllocateForm(lot=lot_id),
'form_new_datawipe': DataWipeForm(lot=lot_id), 'form_new_datawipe': DataWipeForm(lot=lot_id),
@ -148,11 +147,13 @@ class DeviceDetailView(GenericMixin):
.one() .one()
) )
form_tags = TagDeviceForm(dhid=id)
self.context.update( self.context.update(
{ {
'device': device, 'device': device,
'placeholder': device.binding or device.placeholder, 'placeholder': device.binding or device.placeholder,
'page_title': 'Device {}'.format(device.devicehub_id), 'page_title': 'Device {}'.format(device.devicehub_id),
'form_tag_device': form_tags,
} }
) )
@ -542,12 +543,15 @@ class TagLinkDeviceView(View):
methods = ['POST'] methods = ['POST']
decorators = [login_required] decorators = [login_required]
def dispatch_request(self): def dispatch_request(self, dhid):
form = TagDeviceForm() form = TagDeviceForm(dhid=dhid)
if form.validate_on_submit(): if form.validate_on_submit():
tag = form.tag.data
form.save() form.save()
return flask.redirect(request.referrer) next_url = url_for('inventory.device_details', id=dhid)
messages.success('Tag {} was linked successfully!'.format(tag))
return flask.redirect(next_url)
class TagUnlinkDeviceView(GenericMixin): class TagUnlinkDeviceView(GenericMixin):
@ -555,19 +559,20 @@ class TagUnlinkDeviceView(GenericMixin):
decorators = [login_required] decorators = [login_required]
template_name = 'inventory/tag_unlink_device.html' template_name = 'inventory/tag_unlink_device.html'
def dispatch_request(self, id): def dispatch_request(self, dhid):
self.get_context() self.get_context()
form = TagDeviceForm(delete=True, device=id) form = TagDeviceForm(delete=True, dhid=dhid)
if form.validate_on_submit(): if form.validate_on_submit():
form.remove() form.remove()
next_url = url_for('inventory.devicelist') next_url = url_for('inventory.device_details', id=dhid)
messages.success('Tag {} was unlinked successfully!'.format(form.tag.data))
return flask.redirect(next_url) return flask.redirect(next_url)
self.context.update( self.context.update(
{ {
'form': form, 'form': form,
'referrer': request.referrer, 'dhid': dhid,
} }
) )
@ -1211,10 +1216,11 @@ devices.add_url_rule(
'/device/edit/<string:id>/', view_func=DeviceEditView.as_view('device_edit') '/device/edit/<string:id>/', view_func=DeviceEditView.as_view('device_edit')
) )
devices.add_url_rule( devices.add_url_rule(
'/tag/devices/add/', view_func=TagLinkDeviceView.as_view('tag_devices_add') '/tag/devices/<string:dhid>/add/',
view_func=TagLinkDeviceView.as_view('tag_devices_add'),
) )
devices.add_url_rule( devices.add_url_rule(
'/tag/devices/<int:id>/del/', '/tag/devices/<string:dhid>/del/',
view_func=TagUnlinkDeviceView.as_view('tag_devices_del'), view_func=TagUnlinkDeviceView.as_view('tag_devices_del'),
) )
devices.add_url_rule( devices.add_url_rule(

View File

@ -256,6 +256,14 @@
</ul> </ul>
</li><!-- End Temporal Lots Nav --> </li><!-- End Temporal Lots Nav -->
<li class="nav-heading">Unique Identifiers (Tags)</li>
<li class="nav-item">
<a class="nav-link collapsed" href="{{ url_for('labels.label_list') }}">
<i class="bi bi-tag"></i><span>UI Management</span>
</a>
</li><!-- End Unique Identifiers -->
</ul> </ul>
</aside><!-- End Sidebar--> </aside><!-- End Sidebar-->

View File

@ -7,16 +7,12 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<form action="{{ url_for('inventory.tag_devices_add') }}" method="post"> <form action="{{ url_for('inventory.tag_devices_add', dhid=device.devicehub_id) }}" method="post">
{{ form_tag_device.csrf_token }}
<div class="modal-body"> <div class="modal-body">
Please write a name of a unique identifier Please write a name of a unique identifier
<select class="form-control selectpicker" id="selectTag" name="tag" data-live-search="true"> {% for f in form_tag_device %}
{% for tag in tags %} {{ f }}
<option value="{{ tag.id }}">{{ tag.id }}</option> {% endfor %}
{% endfor %}
</select>
<input class="devicesList" type="hidden" name="device" />
<p class="text-danger pol"> <p class="text-danger pol">
You need select first one device and only one for add this in a unique identifier You need select first one device and only one for add this in a unique identifier
</p> </p>

View File

@ -20,6 +20,28 @@
<div class="card-body pt-3"> <div class="card-body pt-3">
<h3>{{ placeholder.device.devicehub_id }}</h3> <h3>{{ placeholder.device.devicehub_id }}</h3>
<div class="tab-pane active show mb-5"> <div class="tab-pane active show mb-5">
<div class="btn-group dropdown" uib-dropdown="" style="float: right; margin-right: 15px;">
<button id="btnUniqueID" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-tag"></i>
Unique Identifiers (Tags)
</button>
<span class="d-none" id="unlinkTagAlertModal" data-bs-toggle="modal" data-bs-target="#unlinkTagErrorModal"></span>
<span class="d-none" id="addTagAlertModal" data-bs-toggle="modal" data-bs-target="#addingTagModal"></span>
<ul class="dropdown-menu" aria-labelledby="btnUniqueID">
<li>
<a href="javascript:addTag()" class="dropdown-item">
<i class="bi bi-plus"></i>
Add Unique Identifier
</a>
</li>
<li>
<a href="{{ url_for('inventory.tag_devices_del', dhid=placeholder.device.devicehub_id) }}" class="dropdown-item">
<i class="bi bi-x"></i>
Remove Unique Identifier
</a>
</li>
</ul>
</div>
{% if placeholder.status in ['Abstract', 'Real'] %} {% if placeholder.status in ['Abstract', 'Real'] %}
<a type="button" href="{{ url_for('inventory.binding_search', dhid=placeholder.device.devicehub_id) }}" class="btn btn-primary" style="float: right; margin-right: 15px;"> <a type="button" href="{{ url_for('inventory.binding_search', dhid=placeholder.device.devicehub_id) }}" class="btn btn-primary" style="float: right; margin-right: 15px;">
Binding Binding
@ -30,6 +52,7 @@
</a> </a>
{% endif %} {% endif %}
<div style="display: block;"></div> <div style="display: block;"></div>
</div> </div>
<!-- Bordered Tabs --> <!-- Bordered Tabs -->
<ul class="nav nav-tabs nav-tabs-bordered"> <ul class="nav nav-tabs nav-tabs-bordered">
@ -237,4 +260,20 @@
</div> </div>
</div> </div>
</section> </section>
<script>
function addTag() {
const devices_id = [{{ placeholder.device.id }}];
if (devices_id.length == 1) {
$("#addingTagModal .pol").hide();
$("#addingTagModal .btn-primary").show();
} else {
$("#addingTagModal .pol").show();
$("#addingTagModal .btn-primary").hide();
}
$("#addTagAlertModal").click();
}
</script>
{% include "inventory/addDevicestag.html" %}
{% endblock main %} {% endblock main %}

View File

@ -268,42 +268,11 @@
</ul> </ul>
</div> </div>
<div class="btn-group dropdown m-1" uib-dropdown="">
<button id="btnUniqueID" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-tag"></i>
Unique Identifiers (Tags)
</button>
<span class="d-none" id="unlinkTagAlertModal" data-bs-toggle="modal" data-bs-target="#unlinkTagErrorModal"></span>
<span class="d-none" id="addTagAlertModal" data-bs-toggle="modal" data-bs-target="#addingTagModal"></span>
<ul class="dropdown-menu" aria-labelledby="btnUniqueID">
<li>
<a href="javascript:addTag()" class="dropdown-item">
<i class="bi bi-plus"></i>
Add Unique Identifier to selected Device
</a>
</li>
<li>
<a href="javascript:removeTag()" class="dropdown-item">
<i class="bi bi-x"></i>
Remove Unique Identifier from selected Device
</a>
</li>
<li>
<a class="dropdown-item" href="{{ url_for('labels.label_list')}}">
<i class="bi bi-tools"></i>
Unique Identifier Management
</a>
</li>
</ul>
</div>
<div class="btn-group dropdown m-1" uib-dropdown=""> <div class="btn-group dropdown m-1" uib-dropdown="">
<button id="btnTags" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"> <button id="btnTags" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-tag"></i> <i class="bi bi-tag"></i>
Labels Labels
</button> </button>
<span class="d-none" id="unlinkTagAlertModal" data-bs-toggle="modal" data-bs-target="#unlinkTagErrorModal"></span>
<span class="d-none" id="addTagAlertModal" data-bs-toggle="modal" data-bs-target="#addingTagModal"></span>
<ul class="dropdown-menu" aria-labelledby="btnTags"> <ul class="dropdown-menu" aria-labelledby="btnTags">
<li> <li>
<form id="print_labels" method="post" action="{{ url_for('labels.print_labels') }}"> <form id="print_labels" method="post" action="{{ url_for('labels.print_labels') }}">
@ -610,14 +579,12 @@
</div> </div>
</div> </div>
</section> </section>
{% include "inventory/addDevicestag.html" %}
{% include "inventory/lot_delete_modal.html" %} {% include "inventory/lot_delete_modal.html" %}
{% include "inventory/actions.html" %} {% include "inventory/actions.html" %}
{% include "inventory/allocate.html" %} {% include "inventory/allocate.html" %}
{% include "inventory/data_wipe.html" %} {% include "inventory/data_wipe.html" %}
{% include "inventory/trade.html" %} {% include "inventory/trade.html" %}
{% include "inventory/alert_export_error.html" %} {% include "inventory/alert_export_error.html" %}
{% include "inventory/alert_unlink_tag_error.html" %}
{% include "inventory/alert_lots_changes.html" %} {% include "inventory/alert_lots_changes.html" %}
<!-- Custom Code --> <!-- Custom Code -->

View File

@ -49,7 +49,7 @@
<input class="devicesList" type="hidden" name="device" /> <input class="devicesList" type="hidden" name="device" />
<div> <div>
<a href="{{ referrer }}" class="btn btn-danger">Cancel</a> <a href="{{ url_for('inventory.device_details', id=dhid) }}" class="btn btn-danger">Cancel</a>
<button class="btn btn-primary" type="submit">Unlink</button> <button class="btn btn-primary" type="submit">Unlink</button>
</div> </div>
</form> </form>