1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#9665 Rack Elevation Sorting Enhancements

This commit is contained in:
Arthur
2022-08-31 14:42:59 -07:00
parent 4dc059fba3
commit 3d4d880110
2 changed files with 21 additions and 7 deletions

View File

@ -590,9 +590,16 @@ class RackElevationListView(generic.ObjectListView):
total_count = racks.count()
# Determine ordering
reverse = bool(request.GET.get('reverse', False))
if reverse:
racks = racks.reverse()
sort = request.GET.get('sort', "name")
if sort:
if sort == 'name':
racks = racks.order_by('name')
elif sort == '-name':
racks = racks.order_by('-name')
elif sort == 'facility':
racks = racks.order_by('facility_id')
elif sort == '-facility':
racks = racks.order_by('-facility_id')
# Pagination
per_page = get_paginate_count(request)
@ -614,7 +621,7 @@ class RackElevationListView(generic.ObjectListView):
'paginator': paginator,
'page': page,
'total_count': total_count,
'reverse': reverse,
'sort': sort,
'rack_face': rack_face,
'filter_form': forms.RackElevationFilterForm(request.GET),
})

View File

@ -18,9 +18,16 @@
<a href="{% url 'dcim:rack_elevation_list' %}{% querystring request face='front' %}" class="btn btn-outline-secondary{% if rack_face == 'front' %} active{% endif %}">Front</a>
<a href="{% url 'dcim:rack_elevation_list' %}{% querystring request face='rear' %}" class="btn btn-outline-secondary{% if rack_face == 'rear' %} active{% endif %}">Rear</a>
</div>
<div class="btn-group btn-group-sm" role="group">
<a href="{% url 'dcim:rack_elevation_list' %}{% querystring request reverse=None %}" class="btn btn-outline-secondary{% if not reverse %} active{% endif %}">Normal</a>
<a href="{% url 'dcim:rack_elevation_list' %}{% querystring request reverse='true' %}" class="btn btn-outline-secondary{% if reverse %} active{% endif %}">Reversed</a>
<div class="dropdown">
<button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="mdi mdi-sort"></i>&nbsp;Sort By ({{ sort }})
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li><a class="dropdown-item{% if sort == 'name' %} active{% endif %}" href="{% url 'dcim:rack_elevation_list' %}{% querystring request sort='name' %}">Name (A-Z)</a></li>
<li><a class="dropdown-item{% if sort == '-name' %} active{% endif %}" href="{% url 'dcim:rack_elevation_list' %}{% querystring request sort='-name' %}">Name (Z-A)</a></li>
<li><a class="dropdown-item{% if sort == 'facility' %} active{% endif %}" href="{% url 'dcim:rack_elevation_list' %}{% querystring request sort='facility' %}">Facility ID (A-Z)</a></li>
<li><a class="dropdown-item{% if sort == '-facility' %} active{% endif %}" href="{% url 'dcim:rack_elevation_list' %}{% querystring request sort='-facility' %}">Facility ID (Z-A)</a></li>
</ul>
</div>
</div>
</div>