Skip to content

Commit

Permalink
Issue #650: Added service unit count display for job list view (#652)
Browse files Browse the repository at this point in the history
* added service unit count display for job list view

* added empty line at end of total_service_units_popover.html

* finalized job SU count functionality

* Adjust wording of popup

---------

Co-authored-by: Matthew Li <[email protected]>
  • Loading branch information
Hzaakk and matthew-li authored Feb 5, 2025
1 parent e85cd9f commit 99d70f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions coldfront/core/statistics/templates/job_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ <h1>Job List</h1>
</div>
{% endif %}
<div class="card mb-3 bg-light">
<div class="card-header">
<a class="btn btn-primary" href="{% url 'export-job-list' %}" role="button" style="float: right;">
<div class="card-header" style="display: flex; justify-content: space-between; align-items: center;">
<div>
<b>Total Service Units {% include "total_service_units_popover.html" %}:</b>
{{ total_service_units }}
</div>
<a class="btn btn-primary" href="{% url 'export-job-list' %}" role="button">
<i class="fas fa-download" aria-hidden="true"></i>
Export Job List to CSV
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<a href="#" data-toggle="popover" title="Service Units" data-trigger="hover" data-content=
"The total service units used by the jobs in the list below. The total is only calculated when there are no more than 100,000 jobs. If you exceed this limit, consider adjusting job filters.">
<span class="accessibility-link-text">Total Service Units</span>
<i class="fas fa-info-circle"></i>
</a>

<script>
$(document).ready(function() {
$('[data-toggle="popover"]').popover({html:true});
});
</script>
10 changes: 10 additions & 0 deletions coldfront/core/statistics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import itertools
import logging

from decimal import Decimal
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
Expand Down Expand Up @@ -144,6 +145,15 @@ def get_context_data(self, **kwargs):

context['show_username'] = (self.request.user.is_superuser or self.request.user.has_perm('statistics.view_job')) or is_pi

if self.object_list.count() > 100000:
context['total_service_units'] = 'Too many jobs to calculate'
else:
total_service_units = Decimal('0.00')
for job in self.object_list.iterator():
total_service_units += job.amount
context['total_service_units'] = \
total_service_units.quantize(Decimal('0.01'))

return context


Expand Down

0 comments on commit 99d70f3

Please sign in to comment.