diff --git a/apps/applications/api/mixin.py b/apps/applications/api/mixin.py index e17755ea8..35ec0fdb6 100644 --- a/apps/applications/api/mixin.py +++ b/apps/applications/api/mixin.py @@ -48,20 +48,24 @@ class SerializeApplicationToTreeNodeMixin: root_node = self.create_root_node() tree_nodes.append(root_node) organizations = self.filter_organizations(applications) + for i, org in enumerate(organizations): tree_id = urlencode({'org_id': str(org.id)}) apps = applications.filter(org_id=org.id) + # 组织节点 org_node = org.as_tree_node(oid=tree_id, pid=root_node.id) org_node.name += '({})'.format(apps.count()) tree_nodes.append(org_node) + + # 类别节点 category_type_nodes = Application.create_category_type_tree_nodes( apps, tree_id, show_empty=False ) tree_nodes += category_type_nodes 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) return tree_nodes diff --git a/apps/applications/models/application.py b/apps/applications/models/application.py index d9b3efe23..a3c50e960 100644 --- a/apps/applications/models/application.py +++ b/apps/applications/models/application.py @@ -20,6 +20,7 @@ class ApplicationTreeNodeMixin: name: str type: str category: str + attrs: dict @staticmethod def create_tree_id(pid, type, v): @@ -173,13 +174,18 @@ class ApplicationTreeNodeMixin: pid = self.create_tree_id(pid, 'type', self.type) return pid - def as_tree_node(self, pid, is_luna=False): - if is_luna and self.type == const.AppType.k8s: + def as_tree_node(self, pid, k8s_as_tree=False): + if self.type == const.AppType.k8s and k8s_as_tree: node = KubernetesTree(pid).as_tree_node(self) else: node = self._as_tree_node(pid) 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): icon_skin_category_mapper = { 'remote_app': 'chrome', @@ -201,6 +207,7 @@ class ApplicationTreeNodeMixin: 'data': { 'category': self.category, 'type': self.type, + 'attrs': self._attrs_to_tree() } } })