mirror of https://github.com/jumpserver/jumpserver
[Bugfix] 修复首页无法显示数据的bug
parent
cd9000e7e9
commit
40d2934de0
|
@ -178,7 +178,7 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" class="no-borders">
|
||||
<button type="button" class="btn btn-info btn-sm" id="btn-add-to-cluster">{% trans 'Confirm' %}</button>
|
||||
<button type="button" class="btn btn-info btn-sm" id="btn-add-to-node">{% trans 'Confirm' %}</button>
|
||||
</td>
|
||||
</tr>
|
||||
</form>
|
||||
|
@ -187,7 +187,7 @@
|
|||
<tr>
|
||||
<td ><b class="bdg_node" data-gid={{ node.id }}>{{ node.name }}</b></td>
|
||||
<td>
|
||||
<button class="btn btn-danger pull-right btn-xs btn-remove-from-cluster" type="button"><i class="fa fa-minus"></i></button>
|
||||
<button class="btn btn-danger pull-right btn-xs btn-remove-from-node" type="button"><i class="fa fa-minus"></i></button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@ -204,27 +204,27 @@
|
|||
{% endblock %}
|
||||
{% block custom_foot_js %}
|
||||
<script>
|
||||
function updateSystemUserCluster(clusters) {
|
||||
function updateSystemUserCluster(nodes) {
|
||||
var the_url = "{% url 'api-assets:system-user-detail' pk=system_user.id %}";
|
||||
var body = {
|
||||
cluster: Object.assign([], clusters)
|
||||
nodes: Object.assign([], nodes)
|
||||
};
|
||||
var success = function(data) {
|
||||
// remove all the selected groups from select > option and rendered ul element;
|
||||
$('.select2-selection__rendered').empty();
|
||||
$('#cluster_selected').val('');
|
||||
$.map(jumpserver.cluster_selected, function(cluster_name, index) {
|
||||
$.map(jumpserver.nodes_selected, function(cluster_name, index) {
|
||||
$('#opt_' + index).remove();
|
||||
// change tr html of user groups.
|
||||
$('.cluster_edit tbody').append(
|
||||
'<tr>' +
|
||||
'<td><b class="bdg_node" data-gid="' + index + '">' + cluster_name + '</b></td>' +
|
||||
'<td><button class="btn btn-danger btn-xs pull-right btn-remove-from-cluster" type="button"><i class="fa fa-minus"></i></button></td>' +
|
||||
'<td><button class="btn btn-danger btn-xs pull-right btn-remove-from-node" type="button"><i class="fa fa-minus"></i></button></td>' +
|
||||
'</tr>'
|
||||
)
|
||||
});
|
||||
// clear jumpserver.groups_selected
|
||||
jumpserver.cluster_selected = {};
|
||||
jumpserver.nodes_selected = {};
|
||||
};
|
||||
APIUpdateAttr({
|
||||
url: the_url,
|
||||
|
@ -232,16 +232,16 @@ function updateSystemUserCluster(clusters) {
|
|||
success: success
|
||||
});
|
||||
}
|
||||
jumpserver.cluster_selected = {};
|
||||
jumpserver.nodes_selected = {};
|
||||
$(document).ready(function () {
|
||||
$('.select2').select2()
|
||||
.on('select2:select', function(evt) {
|
||||
var data = evt.params.data;
|
||||
jumpserver.cluster_selected[data.id] = data.text;
|
||||
jumpserver.nodes_selected[data.id] = data.text;
|
||||
})
|
||||
.on('select2:unselect', function(evt) {
|
||||
var data = evt.params.data;
|
||||
delete jumpserver.cluster_selected[data.id];
|
||||
delete jumpserver.nodes_selected[data.id];
|
||||
});
|
||||
})
|
||||
.on('click', '#btn-auto-push', function () {
|
||||
|
@ -255,26 +255,26 @@ $(document).ready(function () {
|
|||
body: JSON.stringify(body)
|
||||
});
|
||||
})
|
||||
.on('click', '#btn-add-to-cluster', function() {
|
||||
if (Object.keys(jumpserver.cluster_selected).length === 0) {
|
||||
.on('click', '#btn-add-to-node', function() {
|
||||
if (Object.keys(jumpserver.nodes_selected).length === 0) {
|
||||
return false;
|
||||
}
|
||||
var clusters = $('.bdg_node').map(function() {
|
||||
var nodes = $('.bdg_node').map(function() {
|
||||
return $(this).data('gid');
|
||||
}).get();
|
||||
$.map(jumpserver.cluster_selected, function(value, index) {
|
||||
clusters.push(index);
|
||||
$.map(jumpserver.nodes_selected, function(value, index) {
|
||||
nodes.push(index);
|
||||
});
|
||||
updateSystemUserCluster(clusters);
|
||||
updateSystemUserCluster(nodes);
|
||||
})
|
||||
.on('click', '.btn-remove-from-cluster', function() {
|
||||
.on('click', '.btn-remove-from-node', function() {
|
||||
var $this = $(this);
|
||||
var $tr = $this.closest('tr');
|
||||
var $badge = $tr.find('.bdg_node');
|
||||
var gid = $badge.data('gid');
|
||||
var cluster_name = $badge.html() || $badge.text();
|
||||
var node_name = $badge.html() || $badge.text();
|
||||
$('#groups_selected').append(
|
||||
'<option value="' + gid + '" id="opt_' + gid + '">' + cluster_name + '</option>'
|
||||
'<option value="' + gid + '" id="opt_' + gid + '">' + node_name + '</option>'
|
||||
);
|
||||
$tr.remove();
|
||||
var clusters = $('.bdg_node').map(function () {
|
||||
|
|
|
@ -97,6 +97,9 @@ class LDAPTestingAPI(APIView):
|
|||
|
||||
class DjangoSettingsAPI(APIView):
|
||||
def get(self, request):
|
||||
if not settings.DEBUG:
|
||||
return Response('Only debug mode support')
|
||||
|
||||
configs = {}
|
||||
for i in dir(settings):
|
||||
if i.isupper():
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import datetime
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic import TemplateView, View
|
||||
from django.utils import timezone
|
||||
|
@ -54,8 +56,14 @@ class IndexView(LoginRequiredMixin, TemplateView):
|
|||
return month_str
|
||||
|
||||
def get_month_login_metrics(self):
|
||||
return [self.session_month.filter(date_start__date=d).count()
|
||||
for d in self.session_month_dates]
|
||||
data = []
|
||||
time_min = datetime.datetime.min.time()
|
||||
time_max = datetime.datetime.max.time()
|
||||
for d in self.session_month_dates:
|
||||
ds = datetime.datetime.combine(d, time_min).replace(tzinfo=timezone.get_current_timezone())
|
||||
de = datetime.datetime.combine(d, time_max).replace(tzinfo=timezone.get_current_timezone())
|
||||
data.append(self.session_month.filter(date_start__range=(ds, de)).count())
|
||||
return data
|
||||
|
||||
def get_month_active_user_metrics(self):
|
||||
if self.session_month_dates_archive:
|
||||
|
@ -121,10 +129,18 @@ class IndexView(LoginRequiredMixin, TemplateView):
|
|||
self.session_week = Session.objects.filter(date_start__gt=week_ago)
|
||||
self.session_month = Session.objects.filter(date_start__gt=month_ago)
|
||||
self.session_month_dates = self.session_month.dates('date_start', 'day')
|
||||
self.session_month_dates_archive = [
|
||||
self.session_month.filter(date_start__date=d)
|
||||
for d in self.session_month_dates
|
||||
]
|
||||
|
||||
self.session_month_dates_archive = []
|
||||
time_min = datetime.datetime.min.time()
|
||||
time_max = datetime.datetime.max.time()
|
||||
|
||||
for d in self.session_month_dates:
|
||||
ds = datetime.datetime.combine(d, time_min).replace(
|
||||
tzinfo=timezone.get_current_timezone())
|
||||
de = datetime.datetime.combine(d, time_max).replace(
|
||||
tzinfo=timezone.get_current_timezone())
|
||||
self.session_month_dates_archive.append(
|
||||
self.session_month.filter(date_start__range=(ds, de)))
|
||||
|
||||
context = {
|
||||
'assets_count': self.get_asset_count(),
|
||||
|
|
|
@ -186,7 +186,7 @@ function initTree() {
|
|||
{#if (value["key"] === "0") {#}
|
||||
value["open"] = true;
|
||||
{# }#}
|
||||
value["name"] = value["value"] + ' (' + value['assets_amount'] + ')'
|
||||
value["name"] = value["value"]
|
||||
});
|
||||
zNodes = data;
|
||||
$.fn.zTree.init($("#assetTree"), setting, zNodes);
|
||||
|
|
|
@ -129,7 +129,7 @@ class Session(models.Model):
|
|||
has_command = models.BooleanField(default=False, verbose_name=_("Command"))
|
||||
terminal = models.ForeignKey(Terminal, null=True, on_delete=models.CASCADE)
|
||||
date_last_active = models.DateTimeField(verbose_name=_("Date last active"), default=timezone.now)
|
||||
date_start = models.DateTimeField(verbose_name=_("Date start"))
|
||||
date_start = models.DateTimeField(verbose_name=_("Date start"), db_index=True)
|
||||
date_end = models.DateTimeField(verbose_name=_("Date end"), null=True)
|
||||
|
||||
class Meta:
|
||||
|
|
Loading…
Reference in New Issue