Unverified Commit 8ed3bb85 authored by 老广's avatar 老广 Committed by GitHub

Bugfix (#2980)

* [Update] 修改排序,去掉标签

* [Update] 修改批量更新后刷新页面

* [Update] 修改面包屑

* [Update] 修改用户排序

* [Update] 处理未登录主机显示为负数

* [Update] 支持单个资产的搜索
parent 40de7d64
......@@ -70,8 +70,6 @@ $(document).ready(function () {
{% endif %}
var form = $("form");
var data = form.serializeObject();
console.log($("#id_private_key").data("file"));
data["private_key"] = $("#id_private_key").data('file');
var props = {
......
......@@ -346,8 +346,8 @@ $(document).ready(function(){
var data = {
'resources': id_list
};
function refreshTag() {
$('#asset_list_table').DataTable().ajax.reload();
function refreshPage() {
setTimeout( function () {window.location.reload();}, 300);
}
function doDeactive() {
......@@ -356,15 +356,11 @@ $(document).ready(function(){
var obj = {"pk": object_id, "is_active": false};
data.push(obj);
});
function success() {
setTimeout( function () {
window.location.reload();}, 500);
}
requestApi({
url: the_url,
method: 'PATCH',
body: JSON.stringify(data),
success: success
success: refreshPage
});
}
function doActive() {
......@@ -373,15 +369,11 @@ $(document).ready(function(){
var obj = {"pk": object_id, "is_active": true};
data.push(obj);
});
function success() {
setTimeout( function () {
window.location.reload();}, 300);
}
requestApi({
url: the_url,
method: 'PATCH',
body: JSON.stringify(data),
success: success
success: refreshPage
});
}
function doDelete() {
......@@ -400,7 +392,7 @@ $(document).ready(function(){
requestApi({
url:url,
method:'DELETE',
success:refreshTag,
success:refreshPage,
flash_message:false,
});
var msg = "{% trans 'Asset Deleted.' %}";
......
......@@ -78,43 +78,9 @@ function initTable() {
var detail_btn = '<a href="{% url "assets:system-user-detail" pk=DEFAULT_PK %}">' + cellData + '</a>';
$(td).html(detail_btn.replace('{{ DEFAULT_PK }}', rowData.id));
}},
{#{targets: 6, createdCell: function (td, cellData) {#}
{# var innerHtml = "";#}
{# var data = cellData.reachable;#}
{# if (data !== 0) {#}
{# innerHtml = "<span class='text-navy'>" + data + "</span>";#}
{# } else {#}
{# innerHtml = "<span>" + data + "</span>";#}
{# }#}
{# $(td).html(innerHtml)#}
{#}},#}
{#{targets: 7, createdCell: function (td, cellData) {#}
{# var data = cellData.unreachable;#}
{# var innerHtml = "";#}
{# if (data !== 0) {#}
{# innerHtml = "<span class='text-danger'>" + data + "</span>";#}
{# } else {#}
{# innerHtml = "<span>" + data + "</span>";#}
{# }#}
{# $(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + data + '">' + innerHtml + '</span>');#}
{#}},#}
{#{targets: 8, createdCell: function (td, cellData, rowData) {#}
{# var val = 0;#}
{# var innerHtml = "";#}
{# var total = rowData.assets_amount;#}
{# var reachable = cellData.reachable;#}
{# if (total && total !== 0) {#}
{# val = reachable/total * 100;#}
{# }#}
{##}
{# if (val === 100) {#}
{# innerHtml = "<span class='text-navy'>" + val + "% </span>";#}
{# } else {#}
{# var num = new Number(val);#}
{# innerHtml = "<span class='text-danger'>" + num.toFixed(1) + "% </span>";#}
{# }#}
{# $(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</span>');#}
{#}},#}
{targets: 4, createdCell: function (td, cellData, rowData) {
$(td).html(rowData.login_mode_display);
}},
{targets: 7, createdCell: function (td, cellData, rowData) {
var update_btn = '<a href="{% url "assets:system-user-update" pk=DEFAULT_PK %}" class="btn btn-xs m-l-xs btn-info">{% trans "Update" %}</a>'.replace('{{ DEFAULT_PK }}', cellData);
var del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_admin_user_delete" data-uid="{{ DEFAULT_PK }}">{% trans "Delete" %}</a>'.replace('{{ DEFAULT_PK }}', cellData);
......@@ -123,8 +89,9 @@ function initTable() {
],
ajax_url: '{% url "api-assets:system-user-list" %}',
columns: [
{data: "id" }, {data: "name" }, {data: "username" }, {data: "protocol"}, {data: "login_mode_display"}, {data: "assets_amount" },
{data: "comment" }, {data: "id" }
{data: "id" }, {data: "name" }, {data: "username" }, {data: "protocol"},
{data: "login_mode"}, {data: "assets_amount", orderable: false },
{data: "comment" }, {data: "id", orderable: false }
],
op_html: $('#actions').html()
};
......
......@@ -100,13 +100,19 @@ class IndexView(PermissionsMixin, TemplateView):
return self.session_month.values('user').distinct().count()
def get_month_inactive_user_total(self):
return current_org.get_org_users().count() - self.get_month_active_user_total()
count = current_org.get_org_users().count() - self.get_month_active_user_total()
if count < 0:
count = 0
return count
def get_month_active_asset_total(self):
return self.session_month.values('asset').distinct().count()
def get_month_inactive_asset_total(self):
return Asset.objects.all().count() - self.get_month_active_asset_total()
count = Asset.objects.all().count() - self.get_month_active_asset_total()
if count < 0:
count = 0
return count
@staticmethod
def get_user_disabled_total():
......@@ -180,6 +186,7 @@ class IndexView(PermissionsMixin, TemplateView):
'week_asset_hot_ten': self.get_week_top10_asset(),
'last_login_ten': self.get_last10_sessions(),
'week_user_hot_ten': self.get_week_top10_user(),
'app': _("Dashboard"),
}
kwargs.update(context)
......
# -*- coding: utf-8 -*-
#
from functools import reduce
import uuid
from hashlib import md5
from django.core.cache import cache
from django.db.models import Q
......@@ -186,6 +186,20 @@ class GrantAssetsMixin(LabelFilterMixin):
data = self.get_serializer_queryset(queryset_list)
return super().get_serializer(data, many=True)
def filter_queryset_by_id(self, assets_items):
i = self.request.query_params.get("id")
if not i:
return assets_items
try:
pk = uuid.UUID(i)
except ValueError:
return assets_items
assets_map = {asset['id']: asset for asset in assets_items}
if pk in assets_map:
return [assets_map.get(pk)]
else:
return []
def search_queryset(self, assets_items):
search = self.request.query_params.get("search")
if not search:
......@@ -221,7 +235,8 @@ class GrantAssetsMixin(LabelFilterMixin):
return [assets_map.get(asset_id) for asset_id in assets_ids_search]
def filter_queryset(self, assets_items):
assets_items = self.filter_queryset_by_id(assets_items)
assets_items = self.search_queryset(assets_items)
assets_items = self.filter_queryset_by_label(assets_items)
assets_items = self.sort_queryset(assets_items)
return assets_items
\ No newline at end of file
return assets_items
# -*- coding: utf-8 -*-
#
import time
import traceback
from functools import reduce
import uuid
from django.db.models import Q
from django.shortcuts import get_object_or_404
from rest_framework.views import APIView, Response
from rest_framework.generics import (
......
......@@ -110,9 +110,6 @@
<div class="col-sm-10">
<h2></h2>
<ol class="breadcrumb">
<li>
<a href="">{% trans 'Dashboard' %}</a>
</li>
{% if app %}
<li>
<a>{{ app }}</a>
......
......@@ -12,11 +12,11 @@
</div>
<div class="col-lg-9 animated fadeInRight">
<div class="mail-box-header">
<div class="btn-group" style="float: right">
<button data-toggle="dropdown" class="btn btn-default btn-sm labels dropdown-toggle">{% trans 'Label' %} <span class="caret"></span></button>
<ul class="dropdown-menu labels-menu">
</ul>
</div>
{# <div class="btn-group" style="float: right">#}
{# <button data-toggle="dropdown" class="btn btn-default btn-sm labels dropdown-toggle">{% trans 'Label' %} <span class="caret"></span></button>#}
{# <ul class="dropdown-menu labels-menu">#}
{# </ul>#}
{# </div>#}
<table class="table table-striped table-bordered table-hover" id="user_assets_table" >
<thead>
<tr>
......
......@@ -76,10 +76,16 @@ function initTable() {
var detail_btn = '<a href="{% url "users:user-detail" pk=DEFAULT_PK %}">' + cellData + '</a>';
$(td).html(detail_btn.replace("{{ DEFAULT_PK }}", rowData.id));
}},
{targets: 3, createdCell: function (td, cellData, rowData) {
$(td).html(rowData.role_display);
}},
{targets: 4, createdCell: function (td, cellData) {
var innerHtml = cellData.length > 20 ? cellData.substring(0, 20) + '...': cellData;
$(td).html('<span href="javascript:void(0);" data-toggle="tooltip" title="' + cellData + '">' + innerHtml + '</span>');
}},
{targets: 5, createdCell: function (td, cellData, rowData) {
$(td).html(rowData.source_display);
}},
{targets: 6, createdCell: function (td, cellData, rowData) {
if (cellData) {
$(td).html('<i class="fa fa-check text-navy"></i>')
......@@ -114,9 +120,9 @@ function initTable() {
ajax_url: '{% url "api-users:user-list" %}',
columns: [
{data: "id"}, {data: "name" }, {data: "username" },
{data: "role_display", orderable: false},
{data: "role"},
{data: "groups_display", orderable: false},
{data: "source_display", orderable: false},
{data: "source"},
{data: "is_valid", orderable: false},
{data: "id", orderable: false}
],
......@@ -209,8 +215,8 @@ $(document).ready(function(){
var data = {
'resources': id_list
};
function refreshTag() {
$('#user_list_table').DataTable().ajax.reload()
function reloadPage() {
setTimeout( function () {window.location.reload();}, 300);
}
function doDeactive() {
var data = [];
......@@ -218,15 +224,11 @@ $(document).ready(function(){
var obj = {"pk": object_id, "is_active": false};
data.push(obj);
});
function success() {
setTimeout( function () {
window.location.reload();}, 300);
}
requestApi({
url: the_url,
method: 'PATCH',
body: JSON.stringify(data),
success: success
success: reloadPage
});
}
function doActive() {
......@@ -235,15 +237,11 @@ $(document).ready(function(){
var obj = {"pk": object_id, "is_active": true};
data.push(obj);
});
function success() {
setTimeout( function () {
window.location.reload();}, 300);
}
requestApi({
url: the_url,
method: 'PATCH',
body: JSON.stringify(data),
success: success
success: reloadPage
});
}
function doDelete() {
......@@ -262,7 +260,7 @@ $(document).ready(function(){
requestApi({
url:url,
method:'DELETE',
success:refreshTag,
success:reloadPage,
flash_message:false,
});
var msg = "{% trans 'User Deleted.' %}";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment