perf: app tree 添加attrs,luna 使用

pull/7995/head
ibuler 2022-03-28 17:06:06 +08:00 committed by 老广
parent e303b4f571
commit a20de3df16
2 changed files with 14 additions and 3 deletions

View File

@ -48,20 +48,24 @@ class SerializeApplicationToTreeNodeMixin:
root_node = self.create_root_node() root_node = self.create_root_node()
tree_nodes.append(root_node) tree_nodes.append(root_node)
organizations = self.filter_organizations(applications) organizations = self.filter_organizations(applications)
for i, org in enumerate(organizations): for i, org in enumerate(organizations):
tree_id = urlencode({'org_id': str(org.id)}) tree_id = urlencode({'org_id': str(org.id)})
apps = applications.filter(org_id=org.id) apps = applications.filter(org_id=org.id)
# 组织节点 # 组织节点
org_node = org.as_tree_node(oid=tree_id, pid=root_node.id) org_node = org.as_tree_node(oid=tree_id, pid=root_node.id)
org_node.name += '({})'.format(apps.count()) org_node.name += '({})'.format(apps.count())
tree_nodes.append(org_node) tree_nodes.append(org_node)
# 类别节点
category_type_nodes = Application.create_category_type_tree_nodes( category_type_nodes = Application.create_category_type_tree_nodes(
apps, tree_id, show_empty=False apps, tree_id, show_empty=False
) )
tree_nodes += category_type_nodes tree_nodes += category_type_nodes
for app in apps: for app in apps:
app_node = app.as_tree_node(tree_id, is_luna=True) app_node = app.as_tree_node(tree_id, k8s_as_tree=True)
tree_nodes.append(app_node) tree_nodes.append(app_node)
return tree_nodes return tree_nodes

View File

@ -20,6 +20,7 @@ class ApplicationTreeNodeMixin:
name: str name: str
type: str type: str
category: str category: str
attrs: dict
@staticmethod @staticmethod
def create_tree_id(pid, type, v): def create_tree_id(pid, type, v):
@ -173,13 +174,18 @@ class ApplicationTreeNodeMixin:
pid = self.create_tree_id(pid, 'type', self.type) pid = self.create_tree_id(pid, 'type', self.type)
return pid return pid
def as_tree_node(self, pid, is_luna=False): def as_tree_node(self, pid, k8s_as_tree=False):
if is_luna and self.type == const.AppType.k8s: if self.type == const.AppType.k8s and k8s_as_tree:
node = KubernetesTree(pid).as_tree_node(self) node = KubernetesTree(pid).as_tree_node(self)
else: else:
node = self._as_tree_node(pid) node = self._as_tree_node(pid)
return node return node
def _attrs_to_tree(self):
if self.category == const.AppCategory.db:
return {'database': self.attrs.get('database')}
return {}
def _as_tree_node(self, pid): def _as_tree_node(self, pid):
icon_skin_category_mapper = { icon_skin_category_mapper = {
'remote_app': 'chrome', 'remote_app': 'chrome',
@ -201,6 +207,7 @@ class ApplicationTreeNodeMixin:
'data': { 'data': {
'category': self.category, 'category': self.category,
'type': self.type, 'type': self.type,
'attrs': self._attrs_to_tree()
} }
} }
}) })