diff --git a/apps/assets/api/admin_user.py b/apps/assets/api/admin_user.py index e32bbe02a..968cd6594 100644 --- a/apps/assets/api/admin_user.py +++ b/apps/assets/api/admin_user.py @@ -79,5 +79,5 @@ class AdminUserTestConnectiveApi(generics.RetrieveAPIView): def retrieve(self, request, *args, **kwargs): admin_user = self.get_object() - test_admin_user_connectability_manual.delay(admin_user) - return Response({"msg": "Task created"}) \ No newline at end of file + task = test_admin_user_connectability_manual.delay(admin_user) + return Response({"task": task.id}) diff --git a/apps/assets/api/asset.py b/apps/assets/api/asset.py index 405beaf53..9520ff120 100644 --- a/apps/assets/api/asset.py +++ b/apps/assets/api/asset.py @@ -87,12 +87,8 @@ class AssetRefreshHardwareApi(generics.RetrieveAPIView): def retrieve(self, request, *args, **kwargs): asset_id = kwargs.get('pk') asset = get_object_or_404(Asset, pk=asset_id) - summary = update_asset_hardware_info_manual(asset)[1] - logger.debug("Refresh summary: {}".format(summary)) - if summary.get('dark'): - return Response(summary['dark'].values(), status=501) - else: - return Response({"msg": "ok"}) + task = update_asset_hardware_info_manual.delay(asset) + return Response({"task": task.id}) class AssetAdminUserTestApi(generics.RetrieveAPIView): @@ -105,8 +101,5 @@ class AssetAdminUserTestApi(generics.RetrieveAPIView): def retrieve(self, request, *args, **kwargs): asset_id = kwargs.get('pk') asset = get_object_or_404(Asset, pk=asset_id) - ok, msg = test_asset_connectability_manual(asset) - if ok: - return Response({"msg": "pong"}) - else: - return Response({"error": msg}, status=502) \ No newline at end of file + task = test_asset_connectability_manual.delay(asset) + return Response({"task": task.id}) diff --git a/apps/assets/api/node.py b/apps/assets/api/node.py index 9c002b271..3b61ceb51 100644 --- a/apps/assets/api/node.py +++ b/apps/assets/api/node.py @@ -130,10 +130,9 @@ class RefreshNodeHardwareInfoApi(APIView): node_id = kwargs.get('pk') node = get_object_or_404(self.model, id=node_id) assets = node.assets.all() - # task_name = _("Refresh node assets hardware info: {}".format(node.name)) task_name = _("更新节点资产硬件信息: {}".format(node.name)) - update_assets_hardware_info_util.delay(assets, task_name=task_name) - return Response({"msg": "Task created"}) + task = update_assets_hardware_info_util.delay(assets, task_name=task_name) + return Response({"task": task.id}) class TestNodeConnectiveApi(APIView): @@ -145,6 +144,6 @@ class TestNodeConnectiveApi(APIView): node = get_object_or_404(self.model, id=node_id) assets = node.assets.all() task_name = _("测试节点下资产是否可连接: {}".format(node.name)) - test_asset_connectability_util.delay(assets, task_name=task_name) - return Response({"msg": "Task created"}) + task = test_asset_connectability_util.delay(assets, task_name=task_name) + return Response({"task": task.id}) diff --git a/apps/assets/api/system_user.py b/apps/assets/api/system_user.py index ca2a6b7f0..b4e46cc78 100644 --- a/apps/assets/api/system_user.py +++ b/apps/assets/api/system_user.py @@ -58,8 +58,8 @@ class SystemUserPushApi(generics.RetrieveAPIView): def retrieve(self, request, *args, **kwargs): system_user = self.get_object() - push_system_user_to_assets_manual.delay(system_user) - return Response({"msg": "Task created"}) + task = push_system_user_to_assets_manual.delay(system_user) + return Response({"task": task.id}) class SystemUserTestConnectiveApi(generics.RetrieveAPIView): @@ -71,5 +71,5 @@ class SystemUserTestConnectiveApi(generics.RetrieveAPIView): def retrieve(self, request, *args, **kwargs): system_user = self.get_object() - test_system_user_connectability_manual.delay(system_user) - return Response({"msg": "Task created"}) \ No newline at end of file + task = test_system_user_connectability_manual.delay(system_user) + return Response({"task": task.id}) diff --git a/apps/assets/tasks.py b/apps/assets/tasks.py index bfdafe734..53a54764d 100644 --- a/apps/assets/tasks.py +++ b/apps/assets/tasks.py @@ -215,7 +215,7 @@ def test_admin_user_connectability_period(): def test_admin_user_connectability_manual(admin_user): # task_name = _("Test admin user connectability: {}").format(admin_user.name) task_name = _("测试管理行号可连接性: {}").format(admin_user.name) - return test_admin_user_connectability_util.delay(admin_user, task_name) + return test_admin_user_connectability_util(admin_user, task_name) @shared_task @@ -395,11 +395,12 @@ def get_node_push_system_user_task_name(system_user, node): ) +@shared_task def push_system_user_to_node(system_user, node): logger.info("Start push system user node: {} => {}".format(system_user.name, node.value)) assets = node.get_all_assets() task_name = get_node_push_system_user_task_name(system_user, node) - push_system_user_util.delay([system_user], assets, task_name) + push_system_user_util([system_user], assets, task_name) @shared_task diff --git a/apps/assets/templates/assets/admin_user_assets.html b/apps/assets/templates/assets/admin_user_assets.html index fa72abaa5..80ff0cd5f 100644 --- a/apps/assets/templates/assets/admin_user_assets.html +++ b/apps/assets/templates/assets/admin_user_assets.html @@ -121,14 +121,16 @@ $(document).ready(function () { }) .on('click', '.btn-test-connective', function () { var the_url = "{% url 'api-assets:admin-user-connective' pk=admin_user.id %}"; - var error = function (data) { - alert(data) + var success = function (data) { + var task_id = data.task; + var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id); + window.open(url, '', 'width=800,height=600') }; APIUpdateAttr({ url: the_url, - error: error, method: 'GET', - success_message: "{% trans 'Task has been send, seen left asset status' %}" + success: success, + flash_message: false }); }) diff --git a/apps/assets/templates/assets/asset_detail.html b/apps/assets/templates/assets/asset_detail.html index 9767320a3..fd57d9643 100644 --- a/apps/assets/templates/assets/asset_detail.html +++ b/apps/assets/templates/assets/asset_detail.html @@ -269,16 +269,15 @@ function updateAssetNodes(nodes) { function refreshAssetHardware() { var the_url = "{% url 'api-assets:asset-refresh' pk=asset.id %}"; - var success = function (data) { - location.reload(); - }; - var error = function (data) { - alert(data) + var success = function(data) { + console.log(data); + var task_id = data.task; + var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id); + window.open(url, '', 'width=800,height=600') }; APIUpdateAttr({ url: the_url, success: success, - error: error, method: 'GET' }); } @@ -344,19 +343,20 @@ $(document).ready(function () { var redirect_url = "{% url 'assets:asset-list' %}"; objectDelete($this, name, the_url, redirect_url); }).on('click', '#btn_refresh_asset', function () { - alert('关闭alert, 等待完成, 自动刷新页面'); refreshAssetHardware() }).on('click', '#btn-test-is-alive', function () { var the_url = "{% url 'api-assets:asset-alive-test' pk=asset.id %}"; - var error = function (data) { - alert(data) + + var success = function(data) { + var task_id = data.task; + var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id); + window.open(url, '', 'width=800,height=600') }; - alert('关闭alert, 等待完成'); + APIUpdateAttr({ url: the_url, - error: error, method: 'GET', - success_message: "{% trans "Reachable" %}" + success: success }); }) diff --git a/apps/assets/templates/assets/asset_list.html b/apps/assets/templates/assets/asset_list.html index ec905b119..25e206c0c 100644 --- a/apps/assets/templates/assets/asset_list.html +++ b/apps/assets/templates/assets/asset_list.html @@ -497,14 +497,17 @@ $(document).ready(function(){ } var the_url = url.replace("{{ DEFAULT_PK }}", current_node.id); - function success() { + function success(data) { rMenu.css({"visibility" : "hidden"}); + var task_id = data.task; + var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id); + window.open(url, '', 'width=800,height=600') } APIUpdateAttr({ url: the_url, method: "GET", - success_message: "更新硬件信息任务下发成功", - success: success + success: success, + flash_message: false }); }) @@ -519,14 +522,17 @@ $(document).ready(function(){ } var the_url = url.replace("{{ DEFAULT_PK }}", current_node.id); - function success() { + function success(data) { rMenu.css({"visibility" : "hidden"}); + var task_id = data.task; + var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id); + window.open(url, '', 'width=800,height=600') } APIUpdateAttr({ url: the_url, method: "GET", - success_message: "测试可连接性任务下发成功", - success: success + success: success, + flash_message: false }); }) .on('click', '.btn_asset_delete', function () { diff --git a/apps/assets/templates/assets/system_user_detail.html b/apps/assets/templates/assets/system_user_detail.html index b74b402cf..3572cfd3d 100644 --- a/apps/assets/templates/assets/system_user_detail.html +++ b/apps/assets/templates/assets/system_user_detail.html @@ -293,26 +293,30 @@ $(document).ready(function () { }) .on('click', '.btn-push', function () { var the_url = "{% url 'api-assets:system-user-push' pk=system_user.id %}"; - var error = function (data) { - alert(data) + var success = function (data) { + var task_id = data.task; + var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id); + window.open(url, '', 'width=800,height=600') }; APIUpdateAttr({ url: the_url, - error: error, method: 'GET', - success_message: "{% trans "Task has been send, Go to ops task list seen result" %}" + success: success, + flash_message: false }); }) .on('click', '.btn-test-connective', function () { var the_url = "{% url 'api-assets:system-user-connective' pk=system_user.id %}"; - var error = function (data) { - alert(data) + var success = function (data) { + var task_id = data.task; + var url = '{% url "ops:celery-task-log" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", task_id); + window.open(url, '', 'width=800,height=600') }; APIUpdateAttr({ url: the_url, - error: error, method: 'GET', - success_message: "{% trans "Task has been send, seen left assets status" %}" + success: success, + flash_message: false }); }) diff --git a/apps/ops/templates/ops/task_list.html b/apps/ops/templates/ops/task_list.html index 4dc24e7ba..bd0748695 100644 --- a/apps/ops/templates/ops/task_list.html +++ b/apps/ops/templates/ops/task_list.html @@ -1,8 +1,9 @@ {% extends '_base_list.html' %} {% load i18n %} {% load static %} + {% block content_left_head %} - +
{% trans "Create task" %}
{% endblock %} diff --git a/apps/static/js/jumpserver.js b/apps/static/js/jumpserver.js index c4d18815b..984bdfe9a 100644 --- a/apps/static/js/jumpserver.js +++ b/apps/static/js/jumpserver.js @@ -157,7 +157,7 @@ function APIUpdateAttr(props) { props = props || {}; var success_message = props.success_message || '更新成功!'; var fail_message = props.fail_message || '更新时发生未知错误.'; - var flash_message = true; + var flash_message = props.flash_message || true; if (props.flash_message === false){ flash_message = false; } @@ -170,7 +170,9 @@ function APIUpdateAttr(props) { dataType: props.data_type || "json" }).done(function(data, textStatue, jqXHR) { if (flash_message) { - toastr.success(success_message); + if (send_message) { + toastr.success(success_message); + } } if (typeof props.success === 'function') { return props.success(data);