mirror of https://github.com/jumpserver/jumpserver
[Update]优化用户页面的资产标签过滤功能 (#2781)
* [Update] 优化用户页面的资产标签下拉框选项 * [Update]增加用户页面的过滤资产标签功能 * [Update]优化用户页面的资产标签过滤 * [Update]优化用户页面的资产标签过滤代码 * [Update] 优化用户页面的资产标签过滤pull/2785/head
parent
1ba9351957
commit
c300f0b549
|
@ -153,6 +153,10 @@ function initTree() {
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
initTree();
|
initTree();
|
||||||
initTable();
|
initTable();
|
||||||
|
}).on('click', '.labels li', function () {
|
||||||
|
var val = $(this).text();
|
||||||
|
$("#user_assets_table_filter input").val(val);
|
||||||
|
asset_table.search(val).draw();
|
||||||
})
|
})
|
||||||
.on('click', '.asset_detail', function() {
|
.on('click', '.asset_detail', function() {
|
||||||
var data = asset_table.ajax.json();
|
var data = asset_table.ajax.json();
|
||||||
|
|
|
@ -79,6 +79,7 @@ class UserAssetListView(LoginRequiredMixin, TemplateView):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = {
|
context = {
|
||||||
'action': _('My assets'),
|
'action': _('My assets'),
|
||||||
|
'labels': Label.objects.all().order_by('name'),
|
||||||
'system_users': SystemUser.objects.all(),
|
'system_users': SystemUser.objects.all(),
|
||||||
}
|
}
|
||||||
kwargs.update(context)
|
kwargs.update(context)
|
||||||
|
|
|
@ -14,6 +14,7 @@ class AssetsFilterMixin(object):
|
||||||
|
|
||||||
def filter_queryset(self, queryset):
|
def filter_queryset(self, queryset):
|
||||||
queryset = self.search_assets(queryset)
|
queryset = self.search_assets(queryset)
|
||||||
|
queryset = self.filter_labels(queryset)
|
||||||
queryset = self.sort_assets(queryset)
|
queryset = self.sort_assets(queryset)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
@ -40,6 +41,31 @@ class AssetsFilterMixin(object):
|
||||||
queryset = sort_assets(queryset, order_by=order_by, reverse=reverse)
|
queryset = sort_assets(queryset, order_by=order_by, reverse=reverse)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
def filter_labels(self, queryset):
|
||||||
|
from assets.models import Label
|
||||||
|
query_keys = self.request.query_params.keys()
|
||||||
|
all_label_keys = Label.objects.values_list('name', flat=True)
|
||||||
|
valid_keys = set(all_label_keys) & set(query_keys)
|
||||||
|
labels_query = {}
|
||||||
|
for key in valid_keys:
|
||||||
|
labels_query[key] = self.request.query_params.get(key)
|
||||||
|
if not labels_query:
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
labels = set()
|
||||||
|
for k, v in labels_query.items():
|
||||||
|
label = Label.objects.filter(name=k, value=v).first()
|
||||||
|
if not label:
|
||||||
|
continue
|
||||||
|
labels.add(label)
|
||||||
|
|
||||||
|
_queryset = []
|
||||||
|
for asset in queryset:
|
||||||
|
_labels = set(asset.labels.all()) & set(labels)
|
||||||
|
if _labels and len(_labels) == len(set(labels)):
|
||||||
|
_queryset.append(asset)
|
||||||
|
return _queryset
|
||||||
|
|
||||||
|
|
||||||
class RemoteAppFilterMixin(object):
|
class RemoteAppFilterMixin(object):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue