Commit 95ffcdb5 by Kálmán Viktor

dashboard: store display quota on index

parent 4c9dd092
$(function() { $(function() {
$("#store-list-container").on("click", ".store-list-item", function() { $("#store-list-container").on("click", ".store-list-item", function() {
if($(this).data("item-type") == "D") { if($(this).data("item-type") == "D") {
$("#store-list-up-icon").removeClass("fa-reply").addClass("fa-refresh fa-spin");
var url = $(this).prop("href"); var url = $(this).prop("href");
$.get(url, function(result) { $.get(url, function(result) {
$("#store-list-container").html(result); $("#store-list-container").html(result);
......
...@@ -47,7 +47,7 @@ class Store(object): ...@@ -47,7 +47,7 @@ class Store(object):
url = urljoin(self.store_url, url) url = urljoin(self.store_url, url)
if timeout is None: if timeout is None:
timeout = self.default_timeout timeout = self.default_timeout
payload = json.dumps(kwargs) payload = json.dumps(kwargs) if kwargs else None
try: try:
headers = {'content-type': 'application/json'} headers = {'content-type': 'application/json'}
response = method(url, data=payload, headers=headers, response = method(url, data=payload, headers=headers,
...@@ -84,7 +84,7 @@ class Store(object): ...@@ -84,7 +84,7 @@ class Store(object):
return result return result
def request_download(self, path): def request_download(self, path):
r = self._request_cmd("DOWNLOAD", PATH=path, timeout=5) r = self._request_cmd("DOWNLOAD", PATH=path, timeout=10)
return r.json()['LINK'] return r.json()['LINK']
def request_upload(self, path): def request_upload(self, path):
...@@ -102,7 +102,13 @@ class Store(object): ...@@ -102,7 +102,13 @@ class Store(object):
def get_quota(self): # no CMD? :o def get_quota(self): # no CMD? :o
r = self._request(self.username) r = self._request(self.username)
return r.json() quota = r.json()
quota.update({
'readable_used': filesizeformat(float(quota['Used'])),
'readable_soft': filesizeformat(float(quota['Soft'])),
'readable_hard': filesizeformat(float(quota['Hard'])),
})
return quota
def set_quota(self, quota): def set_quota(self, quota):
self._request("/quota/" + self.username, post, QUOTA=quota) self._request("/quota/" + self.username, post, QUOTA=quota)
......
...@@ -68,12 +68,12 @@ ...@@ -68,12 +68,12 @@
class="list-group-item store-list-item" data-item-type="D"> class="list-group-item store-list-item" data-item-type="D">
{% if current == "/" %} {% if current == "/" %}
<div class="store-list-item-icon"> <div class="store-list-item-icon">
<i class="fa fa-refresh"></i> <i class="fa fa-refresh" id="store-list-up-icon"></i>
</div> </div>
{% trans "Refresh" %} {% trans "Refresh" %}
{% else %} {% else %}
<div class="store-list-item-icon"> <div class="store-list-item-icon">
<i class="fa fa-reply"></i> <i class="fa fa-reply" id="store-list-up-icon"></i>
</div> </div>
.. ..
{% endif %} {% endif %}
......
...@@ -2,15 +2,22 @@ ...@@ -2,15 +2,22 @@
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<span class="btn btn-default btn-xs infobtn pull-right" <span class="btn btn-default btn-xs infobtn pull-right store-action-button"
title="A list of your most recent files!"> title="{% trans "A list of your most recent files." %}">
<i class="fa fa-info-circle"></i> <i class="fa fa-info-circle"></i>
</span> </span>
<h3 class="no-margin"><i class="icon-briefcase"></i> Files <span class="btn btn-default btn-xs infobtn pull-right"
title="
{% blocktrans with used=files.quota.readable_used soft=files.quota.readable_soft hard=files.quota.readable_hard %}
You are currently using {{ used }}, your soft limit is {{ soft }}, your hard limit is {{ hard }}.
{% endblocktrans %}">
<i class="fa fa-adjust"></i>
</span>
<h3 class="no-margin"><i class="fa fa-briefcase"></i> {% trans "Files" %}
</h3> </h3>
</div> </div>
<div class="list-group" id="dashboard-files-toplist"> <div class="list-group" id="dashboard-files-toplist">
{% for t in toplist %} {% for t in files.toplist %}
{% if t.TYPE == "F" %} {% if t.TYPE == "F" %}
<div class="list-group-item"> <div class="list-group-item">
<i class="fa fa-{{ t.icon }} dashboard-toplist-icon"></i> <i class="fa fa-{{ t.icon }} dashboard-toplist-icon"></i>
...@@ -46,10 +53,10 @@ ...@@ -46,10 +53,10 @@
</button> </button>
</form> </form>
<a href="{% url "dashboard.views.store-list" %}" class="btn btn-primary btn-xs"> <a href="{% url "dashboard.views.store-list" %}" class="btn btn-primary btn-xs">
<i class="fa fa-chevron-circle-right"></i> {% trans "show my files" %} <i class="fa fa-chevron-circle-right"></i> {% trans "show my files" %}
</a> </a>
<a href="{% url "dashboard.views.store-upload" %}" class="btn btn-success btn-xs"> <a href="{% url "dashboard.views.store-upload" %}" class="btn btn-success btn-xs">
<i class="fa fa-cloud-upload"></i> {% trans "upload" %} <i class="fa fa-cloud-upload"></i> {% trans "upload" %}
</a> </a>
</div> </div>
</div> </div>
......
...@@ -227,19 +227,22 @@ class IndexView(LoginRequiredMixin, TemplateView): ...@@ -227,19 +227,22 @@ class IndexView(LoginRequiredMixin, TemplateView):
# toplist # toplist
if settings.STORE_URL: if settings.STORE_URL:
cache_key = "toplist-%d" % self.request.user.pk cache_key = "files-%d" % self.request.user.pk
cache = get_cache("default") cache = get_cache("default")
toplist = cache.get(cache_key) files = cache.get(cache_key)
if not toplist: if not files:
try: try:
toplist = Store(self.request.user).toplist() store = Store(self.request.user)
toplist = store.toplist()
quota = store.get_quota()
files = {'toplist': toplist, 'quota': quota}
except Exception: except Exception:
logger.exception("Unable to get tolist for %s", logger.exception("Unable to get tolist for %s",
unicode(self.request.user)) unicode(self.request.user))
toplist = [] files = {'toplist': []}
cache.set(cache_key, toplist, 300) cache.set(cache_key, files, 300)
context['toplist'] = toplist context['files'] = files
else: else:
context['no_store'] = True context['no_store'] = True
...@@ -3232,13 +3235,16 @@ def store_new_directory(request): ...@@ -3232,13 +3235,16 @@ def store_new_directory(request):
@require_POST @require_POST
@login_required @login_required
def store_refresh_toplist(request): def store_refresh_toplist(request):
cache_key = "toplist-%d" % request.user.pk cache_key = "files-%d" % request.user.pk
cache = get_cache("default") cache = get_cache("default")
try: try:
toplist = Store(request.user).toplist() store = Store(request.user)
toplist = store.toplist()
quota = store.get_quota()
files = {'toplist': toplist, 'quota': quota}
except Exception: except Exception:
logger.exception("Can't get toplist of %s", unicode(request.user)) logger.exception("Can't get toplist of %s", unicode(request.user))
toplist = [] files = {'toplist': []}
cache.set(cache_key, toplist, 300) cache.set(cache_key, files, 300)
return redirect(reverse("dashboard.index")) return redirect(reverse("dashboard.index"))
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