Commit 7fe4e4d1 by Kálmán Viktor

dashboard: add store features

parent a30f9eb3
...@@ -8,32 +8,62 @@ ...@@ -8,32 +8,62 @@
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<ul id="store-list-list"> <div class="list-group" id="store-list-list">
<a href="?directory={{ up_url }}" class="list-group-item store-list-item" data-item-type="D">
<i class="icon-reply store-list-item-icon"></i>
..
<div class="pull-right">
{{ current }}
</div>
</a>
{% for f in root %} {% for f in root %}
<li class="store-list-item"> <a class="list-group-item store-list-item" data-item-type="{{ f.TYPE }}"
href="{% if f.TYPE == "D" %}?directory={{ f.path }}{% else %}
{# url "dashboard.views.store-download" #}?path={{ f.path }}{% endif %}">
<div class="store-list-item-icon"> <div class="store-list-item-icon">
<i class="icon-{% if f.TYPE == "D" %}folder-open-alt{% else %}file-alt{% endif %}"></i> <i class="
icon-{% if f.TYPE == "D" %}folder-open-alt{% else %}file-alt{% endif %}"
></i>
</div> </div>
{{ f.NAME }} {{ f.NAME }}
<div class="store-list-item-size"> <div class="store-list-item-size">
{% if f.TYPE == "D" %}{% trans "directory" %}{% else %}{% bytes_to_megabytes f.SIZE %}MB{% endif %} {{ f.human_readable_size }}
</div> </div>
<div class="clearfix"></div>
</a>
<div class="infos" style="position: relative;">
<a href="{% url "dashboard.views.store-download" %}?path={{ f.path }}"
class="btn btn-primary" style="position: absolute; right: 15px; top: 32px;">
<i class="icon-download"></i>
Download
</a>
<dl class="dl-horizontal" style="margin: 0; padding: 0;">
<dt>Filename</dt>
<dd>{{ f.NAME }}</dd>
<div class="store-list-item-actions"> <dt>Size</dt>
<span title="{% trans "Last modified:" %} {% timestamp_to_date f.MTIME %}" <dd>{{ f.human_readable_size }}</dd>
class="btn btn-default btn-xs">
<i class="icon-time"></i>
</span>
<span class="btn btn-default btn-xs">
<i class="icon-cloud-download"></i>
</span>
</div>
<div class="clearfix"></div> <dt>Latest modification</dt>
</li> <dd>{{ f.human_readable_date }}</dd>
</dl>
</div>
{% empty %}
<a class="list-group-item">
{% trans "This folder is empty." %}
</a>
{% endfor %} {% endfor %}
</ul> <div class="list-group-item">
Upload file to this folder
<form action="" data-action="{% url "dashboard.views.store-upload" %}"
method="POST" enctype="multipart/form-data" class="pull-right">
{% csrf_token %}
<input type="hidden" name="current_dir" value="{{ current }}"></a>
<input type="file" name="data"/>
<input type="submit"/>
</form>
</div>
</div>
</div> </div>
</div> </div>
...@@ -43,36 +73,72 @@ ...@@ -43,36 +73,72 @@
} }
.store-list-item { .store-list-item {
padding: 0 8px 0 8px;
cursor: pointer; cursor: pointer;
line-height: 35px;
height: 35px;
} }
.store-list-item:hover { .store-list-item:hover {
background: rgba(0, 0, 0, 0.1); background: rgba(0, 0, 0, 0.6);
} }
.store-list-item-icon { .store-list-item-icon {
width: 20px; width: 20px;
display: inline-block;
text-align: center; text-align: center;
display: inline-block;
margin-right: 15px;
} }
.store-list-item-size { .store-list-item-size {
display: inline-block;
width: 70px; width: 70px;
text-align: right; text-align: right;
float: right; float: right;
} }
.store-list-item-actions { .infos {
display: inline-block; padding: 20px;
width: 100px; display: none;
text-align: center; border-left: 1px solid #ddd;
float: right; border-right: 1px solid #ddd;
} }
</style> </style>
<script>
$(function() {
$(".store-list-item").click(function() {
if($(this).data("item-type") == "D") return true;
$(this).next(".infos").stop().slideToggle();
return false;
});
/* less js way, but at least works, tho redirection is bad */
$('form input[type="submit"]').click(function() {
var current_dir = $("form").find('[name="current_dir"]').val();
$.get($("form").data("action") + "?current_dir=" + current_dir, function(result) {
$("form").get(0).setAttribute("action", result['url']);
$("form").submit();
});
return false;
});
/* this does not work
$('form input[type="submit"]').click(function() {
var current_dir = $("form").find('[name="current_dir"]').val();
$.get($("form").data("action") + "?current_dir=" + current_dir, function(result) {
$.ajax({
method: "POST",
url: result['url'],
data: $("form").serialize(),
success: function(re) {
console.log(re);
}
});
});
return false;
}); */
});
</script>
{% endblock %} {% endblock %}
......
...@@ -37,7 +37,7 @@ from .views import ( ...@@ -37,7 +37,7 @@ from .views import (
get_vm_screenshot, get_vm_screenshot,
ProfileView, toggle_use_gravatar, UnsubscribeFormView, ProfileView, toggle_use_gravatar, UnsubscribeFormView,
UserKeyDelete, UserKeyDetail, UserKeyCreate, UserKeyDelete, UserKeyDetail, UserKeyCreate,
StoreList StoreList, store_download, store_upload,
) )
urlpatterns = patterns( urlpatterns = patterns(
...@@ -172,5 +172,9 @@ urlpatterns = patterns( ...@@ -172,5 +172,9 @@ urlpatterns = patterns(
name="dashboard.views.userkey-create"), name="dashboard.views.userkey-create"),
url(r"^store/list/$", StoreList.as_view(), url(r"^store/list/$", StoreList.as_view(),
name="dashboard.views.store-list") name="dashboard.views.store-list"),
url(r"^store/download/$", store_download,
name="dashboard.views.store-download"),
url(r"^store/upload/$", store_upload,
name="dashboard.views.store-upload"),
) )
...@@ -2940,8 +2940,54 @@ class StoreList(LoginRequiredMixin, TemplateView): ...@@ -2940,8 +2940,54 @@ class StoreList(LoginRequiredMixin, TemplateView):
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super(StoreList, self).get_context_data(*args, **kwargs) context = super(StoreList, self).get_context_data(*args, **kwargs)
directory = self.request.GET.get("directory", "/")
directory = "/" if not len(directory) else directory
files = store_api.listfolder("test", "/") context['root'] = self.clean_directory_list(directory)
dirs_first = sorted(files, key=lambda k: k['TYPE']) context['up_url'] = self.create_up_directory(directory)
context['root'] = dirs_first context['current'] = directory
return context return context
def create_up_directory(self, directory):
cut = -2 if directory.endswith("/") else -1
return "/".join(directory.split("/")[:cut]) + "/"
def clean_directory_list(self, directory):
from datetime import datetime
from sizefield.utils import filesizeformat
content = store_api.listfolder("test", directory)
for d in content:
d['human_readable_date'] = datetime.fromtimestamp(float(
d['MTIME']))
d['human_readable_size'] = (
"directory" if d['TYPE'] == "D" else
filesizeformat(float(d['SIZE'])))
d['path'] = d['DIR']
if len(d['path']) == 1 and d['path'][0] == ".":
d['path'] = "/"
else:
d['path'] = "/" + d['path'] + "/"
d['path'] += d['NAME']
if d['TYPE'] == "D":
d['path'] += "/"
return sorted(content, key=lambda k: k['TYPE'])
@require_GET
def store_download(request):
path = request.GET.get("path")
url = store_api.requestdownload("test", path)
return redirect(url)
@require_GET
def store_upload(request):
current_dir = request.GET.get("current_dir")
url = store_api.requestupload("test", current_dir)
return HttpResponse(
json.dumps({'url': url}), 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