From 158678c2dbbf277c9c92acae7e72b9393ed41edb Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 28 Dec 2017 18:01:15 +0800 Subject: [PATCH] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E6=94=B9bug=EF=BC=8C?= =?UTF-8?q?=E6=98=BE=E7=A4=BAcluster?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/serializers.py | 6 ++++++ apps/assets/templates/assets/asset_list.html | 9 +++++---- apps/assets/templates/assets/cluster_assets.html | 2 +- apps/assets/templates/assets/system_user_asset.html | 2 +- apps/assets/templates/assets/system_user_detail.html | 2 +- apps/perms/templates/perms/asset_permission_detail.html | 2 +- apps/users/templates/users/user_detail.html | 2 +- apps/users/templates/users/user_group_detail.html | 2 +- 8 files changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/assets/serializers.py b/apps/assets/serializers.py index f13f7837d..49ea18313 100644 --- a/apps/assets/serializers.py +++ b/apps/assets/serializers.py @@ -151,6 +151,8 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer): """ 资产的数据结构 """ + cluster_name = serializers.SerializerMethodField() + class Meta(object): model = Asset list_serializer_class = BulkListSerializer @@ -165,6 +167,10 @@ class AssetSerializer(BulkSerializerMixin, serializers.ModelSerializer): ]) return fields + @staticmethod + def get_cluster_name(obj): + return obj.cluster.name + class AssetGrantedSerializer(serializers.ModelSerializer): """ diff --git a/apps/assets/templates/assets/asset_list.html b/apps/assets/templates/assets/asset_list.html index fa7638879..fc1cc5428 100644 --- a/apps/assets/templates/assets/asset_list.html +++ b/apps/assets/templates/assets/asset_list.html @@ -30,6 +30,7 @@ {% trans 'Hostname' %} {% trans 'IP' %} {% trans 'Port' %} + {% trans 'Cluster' %} {% trans 'Type' %} {% trans 'Env' %} {% trans 'Hardware' %} @@ -74,14 +75,14 @@ function initTable() { var detail_btn = '' + cellData + ''; $(td).html(detail_btn.replace('{{ DEFAULT_PK }}', rowData.id)); }}, - {targets: 7, createdCell: function (td, cellData) { + {targets: 8, createdCell: function (td, cellData) { if (!cellData) { $(td).html('') } else { $(td).html('') } }}, - {targets: 8, createdCell: function (td, cellData) { + {targets: 9, createdCell: function (td, cellData) { if (cellData == 'Unknown'){ $(td).html('') } else if (!cellData) { @@ -90,14 +91,14 @@ function initTable() { $(td).html('') } }}, - {targets: 9, createdCell: function (td, cellData, rowData) { + {targets: 10, createdCell: function (td, cellData, rowData) { var update_btn = '{% trans "Update" %}'.replace("{{ DEFAULT_PK }}", cellData); var del_btn = '{% trans "Delete" %}'.replace('{{ DEFAULT_PK }}', cellData); $(td).html(update_btn + del_btn) }} ], ajax_url: '{% url "api-assets:asset-list" %}', - columns: [{data: "id"}, {data: "hostname" }, {data: "ip" }, {data: "port" }, + columns: [{data: "id"}, {data: "hostname" }, {data: "ip" }, {data: "port" }, {data: "cluster_name"}, {data: "get_type_display" }, {data: "get_env_display"}, {data: "hardware_info"}, {data: "is_active" }, {data: "is_connective"}, {data: "id" }], op_html: $('#actions').html() diff --git a/apps/assets/templates/assets/cluster_assets.html b/apps/assets/templates/assets/cluster_assets.html index e3a3ab769..408b870b7 100644 --- a/apps/assets/templates/assets/cluster_assets.html +++ b/apps/assets/templates/assets/cluster_assets.html @@ -181,7 +181,7 @@ function initTable() { } $(document).ready(function () { - $('.select2').select2(); + $('.select2').select2() .on("select2:select", function (evt) { var data = evt.params.data; jumpserver.assets_selected[data.id] = data.text; diff --git a/apps/assets/templates/assets/system_user_asset.html b/apps/assets/templates/assets/system_user_asset.html index 92b5a664d..75e1b264d 100644 --- a/apps/assets/templates/assets/system_user_asset.html +++ b/apps/assets/templates/assets/system_user_asset.html @@ -125,7 +125,7 @@ function initAssetsTable() { } $(document).ready(function () { - $('.select2').select2(); + $('.select2').select2() .on("select2:select", function (evt) { var data = evt.params.data; jumpserver.assets_selected[data.id] = data.text; diff --git a/apps/assets/templates/assets/system_user_detail.html b/apps/assets/templates/assets/system_user_detail.html index 7df486f60..c4ee49443 100644 --- a/apps/assets/templates/assets/system_user_detail.html +++ b/apps/assets/templates/assets/system_user_detail.html @@ -212,7 +212,7 @@ function updateSystemUserCluster(clusters) { } jumpserver.cluster_selected = {}; $(document).ready(function () { - $('.select2').select2(); + $('.select2').select2() .on('select2:select', function(evt) { var data = evt.params.data; jumpserver.cluster_selected[data.id] = data.text; diff --git a/apps/perms/templates/perms/asset_permission_detail.html b/apps/perms/templates/perms/asset_permission_detail.html index 6444dbbe4..5b945a900 100644 --- a/apps/perms/templates/perms/asset_permission_detail.html +++ b/apps/perms/templates/perms/asset_permission_detail.html @@ -190,7 +190,7 @@ function updateSystemUser(system_users) { } $(document).ready(function () { - $('.select2').select2(); + $('.select2').select2() .on('select2:select', function(evt) { var data = evt.params.data; jumpserver.system_users_selected[data.id] = data.text; diff --git a/apps/users/templates/users/user_detail.html b/apps/users/templates/users/user_detail.html index 5a013adc1..f87c2c0c8 100644 --- a/apps/users/templates/users/user_detail.html +++ b/apps/users/templates/users/user_detail.html @@ -253,7 +253,7 @@ function updateUserGroups(groups) { } $(document).ready(function() { - $('.select2').select2(); + $('.select2').select2() .on('select2:select', function(evt) { var data = evt.params.data; jumpserver.groups_selected[data.id] = data.text; diff --git a/apps/users/templates/users/user_group_detail.html b/apps/users/templates/users/user_group_detail.html index 8b19272a2..c471b5f21 100644 --- a/apps/users/templates/users/user_group_detail.html +++ b/apps/users/templates/users/user_group_detail.html @@ -150,7 +150,7 @@ function updateGroupMember(users) { } $(document).ready(function () { - $('.select2').select2(); + $('.select2').select2() .on('select2:select', function(evt) { var data = evt.params.data; jumpserver.users_selected[data.id] = data.text;