mirror of https://github.com/jumpserver/jumpserver
Merge pull request #11264 from jumpserver/pr@dev@fix_recursive_expansion
fix: 解决类型树展开全部时,根节点无限递归展开问题pull/11266/head
commit
7a3a0b2d8e
|
@ -224,7 +224,7 @@ class AllTypes(ChoicesMixin):
|
||||||
return dict(id='ROOT', name=_('All types'), title=_('All types'), open=True, isParent=True)
|
return dict(id='ROOT', name=_('All types'), title=_('All types'), open=True, isParent=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_tree_nodes(cls, resource_platforms, include_asset=False):
|
def get_tree_nodes(cls, resource_platforms, include_asset=False, get_root=True):
|
||||||
from ..models import Platform
|
from ..models import Platform
|
||||||
platform_count = defaultdict(int)
|
platform_count = defaultdict(int)
|
||||||
for platform_id in resource_platforms:
|
for platform_id in resource_platforms:
|
||||||
|
@ -239,10 +239,10 @@ class AllTypes(ChoicesMixin):
|
||||||
category_type_mapper[p.category] += platform_count[p.id]
|
category_type_mapper[p.category] += platform_count[p.id]
|
||||||
tp_platforms[p.category + '_' + p.type].append(p)
|
tp_platforms[p.category + '_' + p.type].append(p)
|
||||||
|
|
||||||
nodes = [cls.get_root_nodes()]
|
nodes = [cls.get_root_nodes()] if get_root else []
|
||||||
for category, type_cls in cls.category_types():
|
for category, type_cls in cls.category_types():
|
||||||
# Category 格式化
|
# Category 格式化
|
||||||
meta = {'type': 'category', 'category': category.value}
|
meta = {'type': 'category', 'category': category.value, '_type': category.value}
|
||||||
category_node = cls.choice_to_node(category, 'ROOT', meta=meta)
|
category_node = cls.choice_to_node(category, 'ROOT', meta=meta)
|
||||||
category_count = category_type_mapper.get(category, 0)
|
category_count = category_type_mapper.get(category, 0)
|
||||||
category_node['name'] += f'({category_count})'
|
category_node['name'] += f'({category_count})'
|
||||||
|
|
|
@ -177,8 +177,10 @@ class UserPermedNodeChildrenWithAssetsAsCategoryTreeApi(
|
||||||
return []
|
return []
|
||||||
pid = f'ROOT_{str(assets[0].category).upper()}_{tp}'
|
pid = f'ROOT_{str(assets[0].category).upper()}_{tp}'
|
||||||
return self.serialize_assets(assets, pid=pid)
|
return self.serialize_assets(assets, pid=pid)
|
||||||
|
params = self.request.query_params
|
||||||
|
get_root = not list(filter(lambda x: params.get(x), ('type', 'n')))
|
||||||
resource_platforms = assets.order_by('id').values_list('platform_id', flat=True)
|
resource_platforms = assets.order_by('id').values_list('platform_id', flat=True)
|
||||||
node_all = AllTypes.get_tree_nodes(resource_platforms)
|
node_all = AllTypes.get_tree_nodes(resource_platforms, get_root=get_root)
|
||||||
pattern = re.compile(r'\(0\)?')
|
pattern = re.compile(r'\(0\)?')
|
||||||
nodes = []
|
nodes = []
|
||||||
for node in node_all:
|
for node in node_all:
|
||||||
|
|
Loading…
Reference in New Issue