mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
feat(ui): the menu marks the page's section, names Jobs and Administration and counts unfinished jobs
The page's own section was not marked: the active class sat on the list item, which Bootstrap 5 does not style. It now sits on the link with aria-current, underlined (a side bar on a phone). The links are full white on the theme's navbar instead of 55 %. Jobs and Administration carry labels (icons only between 768 and 991px), the menus open aligned to the right, and Jobs shows a badge with the user's queued, running and cancelling jobs. The user menu's disabled 'Language: tr' line is a working language switch. Operation.visible_to replaces the jobs views' _visible, shared with the badge.
This commit is contained in:
parent
f62a62c027
commit
1c8e204c95
13 changed files with 173 additions and 44 deletions
|
|
@ -66,6 +66,11 @@ class Operation(models.Model):
|
|||
ordering = ["-created_at"]
|
||||
constraints = [models.UniqueConstraint(fields=["user", "submission_key"], name="unique_submission")]
|
||||
|
||||
@classmethod
|
||||
def visible_to(cls, user):
|
||||
"""The jobs a user sees: all for a superuser, their own for others."""
|
||||
return cls.objects.all() if user.is_superuser else cls.objects.filter(user=user)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.kind} {self.id}"
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,12 @@ def wrap_at_slash(label):
|
|||
return format_html_join(mark_safe("/<wbr>"), '<span class="text-nowrap">{}</span>', ((part,) for part in label.split("/")))
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def active_job_count(user):
|
||||
"""How many of the jobs the user sees are queued, running or cancelling: the menu's Jobs badge."""
|
||||
return Operation.visible_to(user).filter(state__in=Operation.ACTIVE).count()
|
||||
|
||||
|
||||
@register.inclusion_tag("operations/job_panel_script.html", takes_context=True)
|
||||
def job_panel_script(context, resource):
|
||||
"""The job panel's script for the page of resource."""
|
||||
|
|
|
|||
|
|
@ -24,19 +24,15 @@ from .models import Operation, last_seen, worker_gone
|
|||
from .utils import said, words
|
||||
|
||||
|
||||
def _visible(user):
|
||||
return Operation.objects.all() if user.is_superuser else Operation.objects.filter(user=user)
|
||||
|
||||
|
||||
def _get(user, pk):
|
||||
try:
|
||||
return _visible(user).get(pk=pk)
|
||||
return Operation.visible_to(user).get(pk=pk)
|
||||
except Operation.DoesNotExist:
|
||||
raise Http404 from None
|
||||
|
||||
|
||||
def jobs(request):
|
||||
qs = _visible(request.user)
|
||||
qs = Operation.visible_to(request.user)
|
||||
if request.user.is_superuser:
|
||||
# the host and the user as typed: the start of the host, any part of the name
|
||||
if compute := request.GET.get("compute"):
|
||||
|
|
@ -54,7 +50,7 @@ def jobs(request):
|
|||
seen = last_seen()
|
||||
# a job the worker has to start, run or stop, not one a request runs (job_panel.js uses the same rule)
|
||||
unavailable = (worker_gone(seen)
|
||||
and _visible(request.user).filter(state__in=Operation.ACTIVE)
|
||||
and Operation.visible_to(request.user).filter(state__in=Operation.ACTIVE)
|
||||
.exclude(worker=Operation.REQUEST).exists())
|
||||
return render(request, "operations/jobs.html",
|
||||
{"page": page, "rows": rows, "worker_last_seen": seen, "worker_unavailable": unavailable,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue