Commit a8ed2ccf by Kálmán Viktor

dashboard: refresh disk download percentage via ajax

parent 6693f199
$(function() {
$(".disk-list-disk-percentage").each(function() {
var disk = $(this).data("disk-pk");
var element = $(this);
refreshDisk(disk, element);
});
});
function refreshDisk(disk, element) {
$.get("/dashboard/disk/" + disk + "/status/", function(result) {
if(result.percentage == null || result.failed == "True") {
location.reload();
} else {
var diff = result.percentage - parseInt(element.html());
var refresh = 5 - diff;
refresh = refresh < 1 ? 1 : (result.percentage == 0 ? 1 : refresh);
if(isNaN(refresh)) refresh = 2; // this should not happen
element.html(result.percentage);
setTimeout(function() {refreshDisk(disk, element)}, refresh * 1000);
}
});
}
...@@ -107,10 +107,14 @@ ...@@ -107,10 +107,14 @@
font-weight: bold; font-weight: bold;
} }
</style> </style>
<script> {% endblock %}
$(function() {
$("#hint_id_num_cores, #hint_id_priority, #hint_id_ram_size").hide(); {% block extra_js %}
}); <script>
</script> $(function() {
$("#hint_id_num_cores, #hint_id_priority, #hint_id_ram_size").hide();
});
</script>
<script src="{{ STATIC_URL }}dashboard/disk-list.js"></script>
{% endblock %} {% endblock %}
...@@ -205,4 +205,5 @@ ...@@ -205,4 +205,5 @@
<script src="{{ STATIC_URL }}dashboard/vm-details.js"></script> <script src="{{ STATIC_URL }}dashboard/vm-details.js"></script>
<script src="{{ STATIC_URL }}dashboard/vm-common.js"></script> <script src="{{ STATIC_URL }}dashboard/vm-common.js"></script>
<script src="{{ STATIC_URL }}dashboard/vm-console.js"></script> <script src="{{ STATIC_URL }}dashboard/vm-console.js"></script>
<script src="{{ STATIC_URL }}dashboard/disk-list.js"></script>
{% endblock %} {% endblock %}
...@@ -10,7 +10,7 @@ from .views import ( ...@@ -10,7 +10,7 @@ from .views import (
TemplateDelete, TemplateDetail, TemplateList, TransferOwnershipConfirmView, TemplateDelete, TemplateDetail, TemplateList, TransferOwnershipConfirmView,
TransferOwnershipView, vm_activity, VmCreate, VmDelete, VmDetailView, TransferOwnershipView, vm_activity, VmCreate, VmDelete, VmDetailView,
VmDetailVncTokenView, VmGraphView, VmList, VmMassDelete, VmMigrateView, VmDetailVncTokenView, VmGraphView, VmList, VmMassDelete, VmMigrateView,
VmRenewView, DiskRemoveView VmRenewView, DiskRemoveView, get_disk_download_status,
) )
urlpatterns = patterns( urlpatterns = patterns(
...@@ -97,8 +97,11 @@ urlpatterns = patterns( ...@@ -97,8 +97,11 @@ urlpatterns = patterns(
url(r'^disk/add/$', DiskAddView.as_view(), url(r'^disk/add/$', DiskAddView.as_view(),
name="dashboard.views.disk-add"), name="dashboard.views.disk-add"),
url(r'^profile/$', MyPreferencesView.as_view(),
name="dashboard.views.profile"),
url(r'^disk/(?P<pk>\d+)/remove/$', DiskRemoveView.as_view(), url(r'^disk/(?P<pk>\d+)/remove/$', DiskRemoveView.as_view(),
name="dashboard.views.disk-remove"), name="dashboard.views.disk-remove"),
url(r'^disk/(?P<pk>\d+)/status/$', get_disk_download_status,
name="dashboard.views.disk-status"),
url(r'^profile/$', MyPreferencesView.as_view(),
name="dashboard.views.profile"),
) )
...@@ -2146,3 +2146,18 @@ class DiskRemoveView(DeleteView): ...@@ -2146,3 +2146,18 @@ class DiskRemoveView(DeleteView):
else: else:
messages.success(request, success_message) messages.success(request, success_message)
return HttpResponseRedirect("%s#resources" % success_url) return HttpResponseRedirect("%s#resources" % success_url)
@require_GET
def get_disk_download_status(request, pk):
disk = Disk.objects.get(pk=pk)
if not disk.has_level(request.user, 'owner'):
raise PermissionDenied()
return HttpResponse(
json.dumps({
'percentage': disk.get_download_percentage(),
'failed': disk.failed
}),
content_type="application/json",
)
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 sign in to comment