euscanwww: Adding queue position in refresh package alert message
Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
parent
31e3dd66d8
commit
34e966f5de
@ -324,6 +324,13 @@ class RefreshPackageQuery(models.Model):
|
|||||||
priority = models.IntegerField(default=0)
|
priority = models.IntegerField(default=0)
|
||||||
users = models.ManyToManyField(User)
|
users = models.ManyToManyField(User)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def position(self):
|
||||||
|
ordered = RefreshPackageQuery.objects.all().order_by("-priority")
|
||||||
|
for pos, obj in enumerate(ordered, start=1):
|
||||||
|
if obj == self:
|
||||||
|
return pos
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u'[%d] %s' % (self.priority, self.package)
|
return u'[%d] %s' % (self.priority, self.package)
|
||||||
|
|
||||||
|
@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<div class="refresh-alert alert {% if not refreshed %}hide{% endif %}">
|
<div class="refresh-alert alert {% if not refresh_pos %}hide{% endif %}">
|
||||||
A refresh request is in progress, please wait...
|
<p>A refresh request is in progress, please wait...</p>
|
||||||
|
<p>Queue position: <span id="refresh-pos">{{ refresh_pos }}</span></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
@ -34,10 +35,10 @@
|
|||||||
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<span class="pull-right">
|
<span class="pull-right">
|
||||||
<button class="btn refresh-button {% if refreshed %}hide{% endif %}" data-category="{{ package.category }}" data-package="{{ package.name }}">
|
<button class="btn refresh-button {% if refresh_requested %}hide{% endif %}" data-category="{{ package.category }}" data-package="{{ package.name }}">
|
||||||
<img src="{{ STATIC_URL}}/img/refresh-active.png" alt="Refresh" >
|
<img src="{{ STATIC_URL}}/img/refresh-active.png" alt="Refresh" >
|
||||||
</button>
|
</button>
|
||||||
<button class="btn refresh-button-disabled disabled {% if not refreshed %}hide{% endif %}">
|
<button class="btn refresh-button-disabled disabled {% if not refresh_requested %}hide{% endif %}">
|
||||||
<img src="{{ STATIC_URL}}/img/refresh-inactive.png" alt="Refresh" >
|
<img src="{{ STATIC_URL}}/img/refresh-inactive.png" alt="Refresh" >
|
||||||
</button>
|
</button>
|
||||||
<button class="btn favourite-button {% if favourited %}hide{% endif %}" data-url="{% url "favourite_package" package.category package.name %}">
|
<button class="btn favourite-button {% if favourited %}hide{% endif %}" data-url="{% url "favourite_package" package.category package.name %}">
|
||||||
@ -67,9 +68,10 @@
|
|||||||
$(".refresh-button").click(function() {
|
$(".refresh-button").click(function() {
|
||||||
var url = "{% url "refresh_package" "XXX" "YYY" %}";
|
var url = "{% url "refresh_package" "XXX" "YYY" %}";
|
||||||
$.post(url.replace("XXX", $(this).data("category")).replace("YYY", $(this).data("package")),
|
$.post(url.replace("XXX", $(this).data("category")).replace("YYY", $(this).data("package")),
|
||||||
function() {
|
function(data) {
|
||||||
$(".refresh-button").addClass("hide");
|
$(".refresh-button").addClass("hide");
|
||||||
$(".refresh-button-disabled").removeClass("hide");
|
$(".refresh-button-disabled").removeClass("hide");
|
||||||
|
$("#refresh-pos").text(data.position);
|
||||||
$(".refresh-alert").show("slow");
|
$(".refresh-alert").show("slow");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -195,10 +195,13 @@ def package(request, category, package):
|
|||||||
favourited = True
|
favourited = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
refreshed = request.user in \
|
refresh_query = RefreshPackageQuery.objects.get(package=package)
|
||||||
RefreshPackageQuery.objects.get(package=package).users.all()
|
|
||||||
except RefreshPackageQuery.DoesNotExist:
|
except RefreshPackageQuery.DoesNotExist:
|
||||||
refreshed = False
|
refresh_requested = False
|
||||||
|
refresh_pos = None
|
||||||
|
else:
|
||||||
|
refresh_requested = request.user in refresh_query.users.all()
|
||||||
|
refresh_pos = refresh_query.position
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'package': package,
|
'package': package,
|
||||||
@ -209,7 +212,8 @@ def package(request, category, package):
|
|||||||
'msg': log.messages() if log else "",
|
'msg': log.messages() if log else "",
|
||||||
'last_scan': last_scan,
|
'last_scan': last_scan,
|
||||||
'favourited': favourited,
|
'favourited': favourited,
|
||||||
'refreshed': refreshed,
|
'refresh_requested': refresh_requested,
|
||||||
|
'refresh_pos': refresh_pos,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -369,7 +373,8 @@ def refresh_package(request, category, package):
|
|||||||
if not created:
|
if not created:
|
||||||
obj.priority += 1
|
obj.priority += 1
|
||||||
obj.save()
|
obj.save()
|
||||||
return {"result": "success"}
|
|
||||||
|
return {"result": "success", "position": obj.position}
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
Loading…
Reference in New Issue
Block a user