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