Commit 0a2066bb by Dányi Bence

store: ajax quota

parent 606f3842
...@@ -33,4 +33,5 @@ urlpatterns = patterns('', ...@@ -33,4 +33,5 @@ urlpatterns = patterns('',
url(r'^ajax/store/upload$', 'store.views.ajax_upload', name='store_ajax_upload'), url(r'^ajax/store/upload$', 'store.views.ajax_upload', name='store_ajax_upload'),
url(r'^ajax/store/delete$', 'store.views.ajax_delete', name='store_ajax_delete'), url(r'^ajax/store/delete$', 'store.views.ajax_delete', name='store_ajax_delete'),
url(r'^ajax/store/newFolder$', 'store.views.ajax_new_folder', name='store_ajax_new_folder'), url(r'^ajax/store/newFolder$', 'store.views.ajax_new_folder', name='store_ajax_new_folder'),
url(r'^ajax/store/quota$', 'store.views.ajax_quota', name='store_ajax_quota'),
) )
...@@ -83,6 +83,12 @@ ...@@ -83,6 +83,12 @@
height: 100%; height: 100%;
.used{ .used{
height: 100%; height: 100%;
position: absolute;
}
.softLimit{
height: 100%;
position: absolute;
border-left: 1px solid red;
} }
} }
.summary{ .summary{
......
...@@ -69,7 +69,7 @@ $(function() { ...@@ -69,7 +69,7 @@ $(function() {
}) })
$('#modal').show(); $('#modal').show();
}); });
$('#old-upload').click(function(e){ $('#old-upload').click(function(e) {
e.preventDefault(); e.preventDefault();
$(this).parent().hide().next('div').show(); $(this).parent().hide().next('div').show();
return false; return false;
...@@ -236,8 +236,8 @@ $(function() { ...@@ -236,8 +236,8 @@ $(function() {
function readfiles(files) { function readfiles(files) {
var formData = tests.formdata ? new FormData() : null; var formData = tests.formdata ? new FormData() : null;
for (var i = 0; i < files.length; i++) { for(var i = 0; i < files.length; i++) {
if (tests.formdata) formData.append('data', files[i]); if(tests.formdata) formData.append('data', files[i]);
} }
// now post a new XHR request // now post a new XHR request
if(tests.formdata) { if(tests.formdata) {
...@@ -254,7 +254,7 @@ $(function() { ...@@ -254,7 +254,7 @@ $(function() {
if(event.lengthComputable) { if(event.lengthComputable) {
var complete = (event.loaded / event.total * 100 | 0); var complete = (event.loaded / event.total * 100 | 0);
//progress.value = progress.innerHTML = complete; //progress.value = progress.innerHTML = complete;
self.uploadProgress(parseInt(complete)+'%'); self.uploadProgress(parseInt(complete) + '%');
} }
} }
} }
...@@ -270,6 +270,31 @@ $(function() { ...@@ -270,6 +270,31 @@ $(function() {
readfiles(e.dataTransfer.files); readfiles(e.dataTransfer.files);
return false; return false;
}); });
self.quota = {
used: ko.observable(),
soft: ko.observable(),
hard: ko.observable()
};
self.quota.usedBar = ko.computed(function() {
return(self.quota.used() / self.quota.hard() * 100).toFixed(0) + '%';
}, self);
self.quota.softPos = ko.computed(function() {
return(self.quota.soft() / self.quota.hard() * 100).toFixed(0) + '%';
}, self)
function refreshQuota() {
$.ajax({
'type': 'GET',
'url': '/ajax/store/quota',
dataType: 'json',
success: function(data) {
self.quota.used(parseInt(data.Used));
self.quota.soft(parseInt(data.Soft));
self.quota.hard(parseInt(data.Hard));
}
})
}
refreshQuota();
loadFolder(self.currentPath()); loadFolder(self.currentPath());
} }
var model = new Model(); var model = new Model();
......
...@@ -97,9 +97,10 @@ ...@@ -97,9 +97,10 @@
<li class="wm small"> <li class="wm small">
<div class="summary"> <div class="summary">
<div class="quota"> <div class="quota">
<div class="used" style="background-color: rgba(0,255,0,0.2); width: 2%"></div> <div class="used" style="background-color: rgba(0,255,0,0.2)" data-bind="style: {width: quota.usedBar}"></div>
<div class="softLimit" data-bind="style: {left: quota.softPos}"></div>
</div> </div>
<div class="name">Kvóta: 20MB/2GB</div> <div class="name">Kvóta: <span data-bind="text: quota.used"></span>/<span data-bind="text: quota.hard"></span></div>
<div class="clear"></div> <div class="clear"></div>
</div> </div>
</li> </li>
......
...@@ -98,6 +98,14 @@ def ajax_listfolder(request): ...@@ -98,6 +98,14 @@ def ajax_listfolder(request):
return HttpResponse(json.dumps(file_list)) return HttpResponse(json.dumps(file_list))
@login_required @login_required
def ajax_quota(request):
user = request.user.username
if StoreApi.userexist(user) != True:
estabilish_store_user(user)
#return HttpResponse(json.dumps(StoreApi.requestquota(user)))
return HttpResponse(json.dumps({'Used':20,'Soft':160,'Hard':200}))
@login_required
def ajax_download(request): def ajax_download(request):
user = request.user.username user = request.user.username
try: try:
......
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