From 8f38ea309199718ee458b37b7dea9799c59bba74 Mon Sep 17 00:00:00 2001 From: Aaron Kitzmiller Date: Tue, 3 Sep 2024 13:10:18 -0400 Subject: [PATCH 1/4] Add js-cookie Set a cookie for year, month, and errors only so that back and forth doesn't require resetting the values Set default to last month when cookies aren't set. --- .../plugins/ifx/calculate_billing_month.html | 38 ++++++++++++++++--- coldfront/templates/common/base.html | 2 + 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/coldfront/plugins/ifx/templates/plugins/ifx/calculate_billing_month.html b/coldfront/plugins/ifx/templates/plugins/ifx/calculate_billing_month.html index de19046f4..f57a75986 100644 --- a/coldfront/plugins/ifx/templates/plugins/ifx/calculate_billing_month.html +++ b/coldfront/plugins/ifx/templates/plugins/ifx/calculate_billing_month.html @@ -3,6 +3,10 @@ {% load crispy_forms_tags %} {% load static %} +{% block ifx_head %} + +{% endblock %} + {% block title %} Calculate Billing Month {% endblock %} @@ -47,6 +51,30 @@ dialog.dialog("close"); }); + + // Get month and year cookie and errorsOnly if it exists using js-cookie + var year = Cookies.get('coldfront-billing-year') || new Date().getFullYear() + var month = Cookies.get('coldfront-billing-month') || new Date().getMonth() - 1 + var errorsOnly = Cookies.get('coldfront-billing-errors-only') || false + $("#year").val(year) + $("#month").val(month) + $("#errorsOnly").prop('checked', errorsOnly) + + // Set month and year cookie when changed + $("#year").change(function() { + Cookies.set('coldfront-billing-year', $(this).val()) + }) + $("#month").change(function() { + Cookies.set('coldfront-billing-month', $(this).val()) + }) + $("#errorsOnly").change(function() { + if ($(this).is(":checked")) { + Cookies.set('coldfront-billing-errors-only', 'true') + } else { + Cookies.remove('coldfront-billing-errors-only') + } + }) + $("#productUsageReload").click((ev) => { ev.preventDefault() if (!$("#year").val() || !$("#month").val()) { @@ -74,7 +102,7 @@ data: function (d) { d.year = $("#year").val() d.month = $("#month").val() - d.errors_only = $("#errors_only").is(":checked") ? 'true' : 'false' + d.errors_only = $("#errorsOnly").is(":checked") ? 'true' : 'false' }, dataSrc: '', error: function (jqXHR, status, error) { @@ -135,11 +163,11 @@
- + - - - + + +
diff --git a/coldfront/templates/common/base.html b/coldfront/templates/common/base.html index f8f88968a..b7299a14a 100644 --- a/coldfront/templates/common/base.html +++ b/coldfront/templates/common/base.html @@ -44,6 +44,8 @@ + {% block ifx_head %}{% endblock %} + {% block title %}FAS Research Computing | HARVARD UNIVERSITY {% endblock %} From 09c8e95b85c769446421861612f549412ed7d176 Mon Sep 17 00:00:00 2001 From: Aaron Kitzmiller Date: Tue, 3 Sep 2024 17:33:03 -0400 Subject: [PATCH 2/4] Updated jquery DataTable with "selectable rows" plugin, "layout" option for element placement Setting year and month by cookie if set; defaults to last month otherwise Errors only also cookie set Selected rows in billing record table can be deleted; can reset a lab when combined with the right search --- .../plugins/ifx/billing_records.html | 103 +++++++++++++++--- .../plugins/ifx/calculate_billing_month.html | 40 +++++-- coldfront/plugins/ifx/views.py | 5 +- 3 files changed, 122 insertions(+), 26 deletions(-) diff --git a/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html b/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html index af59e93eb..4413f75a3 100644 --- a/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html +++ b/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html @@ -3,6 +3,14 @@ {% load crispy_forms_tags %} {% load static %} +{% block ifx_head %} + + + + + +{% endblock %} + {% block title %} Billing Records {% endblock %} @@ -10,15 +18,6 @@ {% block content %}
+

Billing Records

@@ -299,9 +371,9 @@
- + - +
@@ -309,6 +381,9 @@
+
+ +

@@ -316,6 +391,8 @@ + + diff --git a/coldfront/plugins/ifx/templates/plugins/ifx/calculate_billing_month.html b/coldfront/plugins/ifx/templates/plugins/ifx/calculate_billing_month.html index f57a75986..db386b09d 100644 --- a/coldfront/plugins/ifx/templates/plugins/ifx/calculate_billing_month.html +++ b/coldfront/plugins/ifx/templates/plugins/ifx/calculate_billing_month.html @@ -4,7 +4,11 @@ {% load static %} {% block ifx_head %} + + + + {% endblock %} {% block title %} @@ -14,23 +18,20 @@ {% block content %}
+

Calculate Billing Month

@@ -195,7 +211,7 @@

-
Id State User Lab
+
diff --git a/coldfront/plugins/ifx/views.py b/coldfront/plugins/ifx/views.py index 4bdee1be5..97cbffe5a 100644 --- a/coldfront/plugins/ifx/views.py +++ b/coldfront/plugins/ifx/views.py @@ -12,6 +12,7 @@ from django.db import connection from django.conf import settings from django.core.exceptions import PermissionDenied +from django.urls import reverse from django_q.tasks import async_task from rest_framework.decorators import api_view, permission_classes, authentication_classes from rest_framework.response import Response @@ -79,7 +80,9 @@ def billing_records(request): ''' if not request.user.is_superuser: raise PermissionDenied - return render(request, 'plugins/ifx/billing_records.html') + delete_url = reverse('billing-record-detail', kwargs={'pk': 0}) + token = request.user.auth_token.key + return render(request, 'plugins/ifx/billing_records.html', { 'delete_url': delete_url, 'auth_token': token }) @api_view(['GET',]) @authentication_classes([TokenAuthentication, SessionAuthentication, BasicAuthentication]) From 7d5769777d457542203e1bf9a9b4bed59fe8476e Mon Sep 17 00:00:00 2001 From: Aaron Kitzmiller Date: Tue, 3 Sep 2024 17:44:39 -0400 Subject: [PATCH 3/4] Don't enable delete button until some are selected --- .../templates/plugins/ifx/billing_records.html | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html b/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html index 4413f75a3..627aeca0e 100644 --- a/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html +++ b/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html @@ -305,7 +305,6 @@ alert(status + ' ' + error) }, }, - {% comment %} footerCallback: function (row, data, start, end, display) { // THIS DOES NOT WORK because the ajax call is not done yet // Leaving it here, because I'd like to find a fix @@ -338,7 +337,17 @@ api.column(4).footer().innerHTML = '$' + pageTotal + ' ( $' + total + ' total)'; } - } {% endcomment %} + } + }) + billingRecordsTable.on('select', function (e, dt, type, indexes) { + $('#delete-selected').prop('disabled', false) + }) + billingRecordsTable.on('deselect', function (e, dt, type, indexes) { + if (type === 'row' && billingRecordsTable.rows({selected: true}).count() > 0) { + $('#delete-selected').prop('disabled', false) + } else { + $('#delete-selected').prop('disabled', true) + } }) }) @@ -382,7 +391,7 @@

Billing Records

- +
From e79305b097dd6f06f22bbc7e13557e7096b59023 Mon Sep 17 00:00:00 2001 From: Aaron Kitzmiller Date: Tue, 3 Sep 2024 18:32:06 -0400 Subject: [PATCH 4/4] Disabled delete button until selection --- .../plugins/ifx/templates/plugins/ifx/billing_records.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html b/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html index 627aeca0e..156afe1cf 100644 --- a/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html +++ b/coldfront/plugins/ifx/templates/plugins/ifx/billing_records.html @@ -34,6 +34,12 @@ #organizations { width: 400px; } + #delete-selected { + color: red; + } + #delete-selected:disabled { + color: grey; + } .result-header { font-size: 12pt; font-weight: bold; @@ -53,6 +59,7 @@ .righty { position: relative; float: right; + margin-left: 1em; } .dt-input { margin: 0 0 0 1em;
ID