mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
First pass at clearer display of asset list filters
This commit is contained in:
@@ -14,6 +14,48 @@
|
|||||||
<script src="{% static 'js/ajax-bootstrap-select.js' %}"></script>
|
<script src="{% static 'js/ajax-bootstrap-select.js' %}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script>
|
||||||
|
//Get querystring value
|
||||||
|
function getParameterByName(name) {
|
||||||
|
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
||||||
|
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
||||||
|
results = regex.exec(location.search);
|
||||||
|
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||||
|
}
|
||||||
|
//Function used to remove querystring
|
||||||
|
function removeQString(key) {
|
||||||
|
var urlValue=document.location.href;
|
||||||
|
|
||||||
|
//Get query string value
|
||||||
|
var searchUrl=location.search;
|
||||||
|
|
||||||
|
if(key!="") {
|
||||||
|
oldValue = getParameterByName(key);
|
||||||
|
removeVal=key+"="+oldValue;
|
||||||
|
if(searchUrl.indexOf('?'+removeVal+'&')!= "-1") {
|
||||||
|
urlValue=urlValue.replace('?'+removeVal+'&','?');
|
||||||
|
}
|
||||||
|
else if(searchUrl.indexOf('&'+removeVal+'&')!= "-1") {
|
||||||
|
urlValue=urlValue.replace('&'+removeVal+'&','&');
|
||||||
|
}
|
||||||
|
else if(searchUrl.indexOf('?'+removeVal)!= "-1") {
|
||||||
|
urlValue=urlValue.replace('?'+removeVal,'');
|
||||||
|
}
|
||||||
|
else if(searchUrl.indexOf('&'+removeVal)!= "-1") {
|
||||||
|
urlValue=urlValue.replace('&'+removeVal,'');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var searchUrl=location.search;
|
||||||
|
urlValue=urlValue.replace(searchUrl,'');
|
||||||
|
}
|
||||||
|
history.pushState({state:1, rand: Math.random()}, '', urlValue);
|
||||||
|
window.location.reload(true);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
@@ -40,8 +82,18 @@
|
|||||||
{% button 'new' 'asset_create' style="width: 6em" %}
|
{% button 'new' 'asset_create' style="width: 6em" %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row my-2">
|
||||||
|
<div class="col bg-dark rounded pt-3">
|
||||||
|
{# TODO Gotta be a cleaner way to do this... #}
|
||||||
|
<p><span class="ml-2">Active Filters: </span> {% for filter in category_filters %}<span class="badge badge-info mx-1 ">{{filter}}<button type="button" class="btn btn-link p-0 ml-1 align-baseline">
|
||||||
|
<span aria-hidden="true" class="fas fa-times" onclick="removeQString('category', '{{filter.id}}')"></span>
|
||||||
|
</button></span>{%endfor%}{% for filter in status_filters %}<span class="badge badge-info mx-1 ">{{filter}}<button type="button" class="btn btn-link p-0 ml-1 align-baseline">
|
||||||
|
<span aria-hidden="true" class="fas fa-times" onclick="removeQString('status', '{{filter.id}}')"></span>
|
||||||
|
</button></span>{%endfor%}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col px-0">
|
||||||
{% include 'partials/asset_list_table.html' %}
|
{% include 'partials/asset_list_table.html' %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from django.views import generic
|
|||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from versioning import versioning
|
from versioning import versioning
|
||||||
from PyRIGS.views import GenericListView, GenericDetailView, GenericUpdateView, GenericCreateView, ModalURLMixin
|
from PyRIGS.views import GenericListView, GenericDetailView, GenericUpdateView, GenericCreateView, ModalURLMixin
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(csrf_exempt, name='dispatch')
|
@method_decorator(csrf_exempt, name='dispatch')
|
||||||
@@ -64,6 +65,8 @@ class AssetList(LoginRequiredMixin, generic.ListView):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(AssetList, self).get_context_data(**kwargs)
|
context = super(AssetList, self).get_context_data(**kwargs)
|
||||||
context["form"] = self.form
|
context["form"] = self.form
|
||||||
|
context["category_filters"] = self.form.cleaned_data['category']
|
||||||
|
context["status_filters"] = self.form.cleaned_data['status']
|
||||||
context["categories"] = models.AssetCategory.objects.all()
|
context["categories"] = models.AssetCategory.objects.all()
|
||||||
context["statuses"] = models.AssetStatus.objects.all()
|
context["statuses"] = models.AssetStatus.objects.all()
|
||||||
context["page_title"] = "Asset List"
|
context["page_title"] = "Asset List"
|
||||||
|
|||||||
Reference in New Issue
Block a user