mv unique identifiers buttons to device details
This commit is contained in:
parent
b5a738c44a
commit
bdf04061dc
|
@ -137,11 +137,11 @@ class FilterForm(FlaskForm):
|
|||
self.lot = self.lots.filter(Lot.id == self.lot_id).one()
|
||||
device_ids = (d.id for d in self.lot.devices)
|
||||
self.devices = Device.query.filter(Device.id.in_(device_ids)).filter(
|
||||
Device.binding == None
|
||||
Device.binding == None # noqa: E711
|
||||
)
|
||||
else:
|
||||
self.devices = Device.query.filter(Device.owner_id == g.user.id).filter(
|
||||
Device.binding == None
|
||||
Device.binding == None # noqa: E711
|
||||
)
|
||||
if self.only_unassigned:
|
||||
self.devices = self.devices.filter_by(lots=None)
|
||||
|
@ -655,19 +655,30 @@ class NewDeviceForm(FlaskForm):
|
|||
|
||||
|
||||
class TagDeviceForm(FlaskForm):
|
||||
tag = SelectField('Tag', choices=[])
|
||||
device = StringField('Device', [validators.Optional()])
|
||||
tag = SelectField(
|
||||
'Tag',
|
||||
choices=[],
|
||||
render_kw={
|
||||
'class': 'form-control selectpicker',
|
||||
'data-live-search': 'true',
|
||||
},
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
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)
|
||||
|
||||
if self.delete:
|
||||
tags = (
|
||||
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)
|
||||
)
|
||||
else:
|
||||
|
@ -695,20 +706,6 @@ class TagDeviceForm(FlaskForm):
|
|||
self.tag.errors = [("This tag is actualy in use.")]
|
||||
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
|
||||
|
||||
def save(self):
|
||||
|
|
|
@ -80,7 +80,6 @@ class DeviceListMixin(GenericMixin):
|
|||
self.context.update(
|
||||
{
|
||||
'devices': devices,
|
||||
'form_tag_device': TagDeviceForm(),
|
||||
'form_new_action': form_new_action,
|
||||
'form_new_allocate': AllocateForm(lot=lot_id),
|
||||
'form_new_datawipe': DataWipeForm(lot=lot_id),
|
||||
|
@ -148,11 +147,13 @@ class DeviceDetailView(GenericMixin):
|
|||
.one()
|
||||
)
|
||||
|
||||
form_tags = TagDeviceForm(dhid=id)
|
||||
self.context.update(
|
||||
{
|
||||
'device': device,
|
||||
'placeholder': device.binding or device.placeholder,
|
||||
'page_title': 'Device {}'.format(device.devicehub_id),
|
||||
'form_tag_device': form_tags,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -542,12 +543,15 @@ class TagLinkDeviceView(View):
|
|||
methods = ['POST']
|
||||
decorators = [login_required]
|
||||
|
||||
def dispatch_request(self):
|
||||
form = TagDeviceForm()
|
||||
def dispatch_request(self, dhid):
|
||||
form = TagDeviceForm(dhid=dhid)
|
||||
if form.validate_on_submit():
|
||||
tag = form.tag.data
|
||||
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):
|
||||
|
@ -555,19 +559,20 @@ class TagUnlinkDeviceView(GenericMixin):
|
|||
decorators = [login_required]
|
||||
template_name = 'inventory/tag_unlink_device.html'
|
||||
|
||||
def dispatch_request(self, id):
|
||||
def dispatch_request(self, dhid):
|
||||
self.get_context()
|
||||
form = TagDeviceForm(delete=True, device=id)
|
||||
form = TagDeviceForm(delete=True, dhid=dhid)
|
||||
if form.validate_on_submit():
|
||||
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)
|
||||
|
||||
self.context.update(
|
||||
{
|
||||
'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')
|
||||
)
|
||||
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(
|
||||
'/tag/devices/<int:id>/del/',
|
||||
'/tag/devices/<string:dhid>/del/',
|
||||
view_func=TagUnlinkDeviceView.as_view('tag_devices_del'),
|
||||
)
|
||||
devices.add_url_rule(
|
||||
|
|
|
@ -256,6 +256,14 @@
|
|||
</ul>
|
||||
</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>
|
||||
|
||||
</aside><!-- End Sidebar-->
|
||||
|
|
|
@ -7,16 +7,12 @@
|
|||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<form action="{{ url_for('inventory.tag_devices_add') }}" method="post">
|
||||
{{ form_tag_device.csrf_token }}
|
||||
<form action="{{ url_for('inventory.tag_devices_add', dhid=device.devicehub_id) }}" method="post">
|
||||
<div class="modal-body">
|
||||
Please write a name of a unique identifier
|
||||
<select class="form-control selectpicker" id="selectTag" name="tag" data-live-search="true">
|
||||
{% for tag in tags %}
|
||||
<option value="{{ tag.id }}">{{ tag.id }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input class="devicesList" type="hidden" name="device" />
|
||||
{% for f in form_tag_device %}
|
||||
{{ f }}
|
||||
{% endfor %}
|
||||
<p class="text-danger pol">
|
||||
You need select first one device and only one for add this in a unique identifier
|
||||
</p>
|
||||
|
|
|
@ -20,6 +20,28 @@
|
|||
<div class="card-body pt-3">
|
||||
<h3>{{ placeholder.device.devicehub_id }}</h3>
|
||||
<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'] %}
|
||||
<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
|
||||
|
@ -30,6 +52,7 @@
|
|||
</a>
|
||||
{% endif %}
|
||||
<div style="display: block;"></div>
|
||||
|
||||
</div>
|
||||
<!-- Bordered Tabs -->
|
||||
<ul class="nav nav-tabs nav-tabs-bordered">
|
||||
|
@ -237,4 +260,20 @@
|
|||
</div>
|
||||
</div>
|
||||
</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 %}
|
||||
|
|
|
@ -268,42 +268,11 @@
|
|||
</ul>
|
||||
</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="">
|
||||
<button id="btnTags" type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<i class="bi bi-tag"></i>
|
||||
Labels
|
||||
</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">
|
||||
<li>
|
||||
<form id="print_labels" method="post" action="{{ url_for('labels.print_labels') }}">
|
||||
|
@ -610,14 +579,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% include "inventory/addDevicestag.html" %}
|
||||
{% include "inventory/lot_delete_modal.html" %}
|
||||
{% include "inventory/actions.html" %}
|
||||
{% include "inventory/allocate.html" %}
|
||||
{% include "inventory/data_wipe.html" %}
|
||||
{% include "inventory/trade.html" %}
|
||||
{% include "inventory/alert_export_error.html" %}
|
||||
{% include "inventory/alert_unlink_tag_error.html" %}
|
||||
{% include "inventory/alert_lots_changes.html" %}
|
||||
|
||||
<!-- Custom Code -->
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
<input class="devicesList" type="hidden" name="device" />
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</form>
|
||||
|
|
Reference in New Issue