perf: 添加 category node view

pull/8873/head
ibuler 2022-08-05 19:11:17 +08:00
parent 8dfb8eeb75
commit 698ea3f2ea
2 changed files with 17 additions and 11 deletions

View File

@ -27,6 +27,7 @@ from ..tasks import (
check_node_assets_amount_task
)
from .. import serializers
from ..const import AllTypes
from .mixin import SerializeToTreeNodeMixin
from assets.locks import NodeAddChildrenLock
@ -197,6 +198,14 @@ class NodeChildrenAsTreeApi(SerializeToTreeNodeMixin, NodeChildrenApi):
return self.serialize_assets(assets, self.instance.key)
class CategoryTreeApi(SerializeToTreeNodeMixin, generics.ListAPIView):
def list(self, request, *args, **kwargs):
category_types = AllTypes.category_types()
nodes = self.get_queryset().order_by('value')
nodes = self.serialize_nodes(nodes, with_asset_amount=True)
return Response(data=nodes)
class NodeAssetsApi(generics.ListAPIView):
serializer_class = serializers.AssetSerializer

View File

@ -5,7 +5,7 @@ from common.db.models import IncludesTextChoicesMeta
__all__ = [
'Category', 'HostTypes', 'NetworkTypes', 'DatabaseTypes',
'RemoteAppTypes', 'CloudTypes', 'Protocol', 'AllTypes',
'WebTypes', 'CloudTypes', 'Protocol', 'AllTypes',
]
@ -19,8 +19,8 @@ class Category(PlatformMixin, models.TextChoices):
HOST = 'host', _('Host')
NETWORK = 'network', _("NetworkDevice")
DATABASE = 'database', _("Database")
REMOTE_APP = 'remote_app', _("Remote app")
CLOUD = 'cloud', _("Clouding")
WEB = 'web', _("Web")
@classmethod
def platform_limits(cls):
@ -36,8 +36,8 @@ class Category(PlatformMixin, models.TextChoices):
cls.DATABASE: {
'has_domain': True
},
cls.REMOTE_APP: {
'has_domain': True
cls.WEB: {
'has_domain': False,
},
cls.CLOUD: {
'has_domain': False,
@ -97,11 +97,8 @@ class DatabaseTypes(PlatformMixin, models.TextChoices):
return meta
class RemoteAppTypes(PlatformMixin, models.TextChoices):
CHROME = 'chrome', 'Chrome'
VSPHERE = 'vmware_client', 'vSphere client'
MYSQL_WORKBENCH = 'mysql_workbench', 'MySQL workbench'
GENERAL_REMOTE_APP = 'general_remote_app', _("Custom")
class WebTypes(PlatformMixin, models.TextChoices):
General = 'general', 'General'
class CloudTypes(PlatformMixin, models.TextChoices):
@ -112,7 +109,7 @@ class AllTypes(metaclass=IncludesTextChoicesMeta):
choices: list
includes = [
HostTypes, NetworkTypes, DatabaseTypes,
RemoteAppTypes, CloudTypes
WebTypes, CloudTypes
]
@classmethod
@ -140,7 +137,7 @@ class AllTypes(metaclass=IncludesTextChoicesMeta):
(Category.HOST, HostTypes),
(Category.NETWORK, NetworkTypes),
(Category.DATABASE, DatabaseTypes),
(Category.REMOTE_APP, RemoteAppTypes),
(Category.WEB, WebTypes),
(Category.CLOUD, CloudTypes)
)