From 8b8c176b0cb0ef398708226db9e6acc9f2b3bf23 Mon Sep 17 00:00:00 2001 From: Rebecca Hsieh Date: Tue, 1 Oct 2024 07:27:19 -0700 Subject: [PATCH 01/29] Biz logic --- src/registrar/assets/js/get-gov.js | 28 ++ src/registrar/config/urls.py | 6 + src/registrar/models/user.py | 13 + .../includes/domain_requests_table.html | 364 +++++++++--------- src/registrar/utility/csv_export.py | 99 +++++ src/registrar/views/report_views.py | 11 + 6 files changed, 335 insertions(+), 186 deletions(-) diff --git a/src/registrar/assets/js/get-gov.js b/src/registrar/assets/js/get-gov.js index 027ef4344..9d5432259 100644 --- a/src/registrar/assets/js/get-gov.js +++ b/src/registrar/assets/js/get-gov.js @@ -1498,12 +1498,36 @@ class DomainsTable extends LoadTableBase { } } +function showExportElement(element) { + console.log(`Showing element: ${element.id}`); + element.style.display = 'block'; +} + +function hideExportElement(element) { + console.log(`Hiding element: ${element.id}`); + element.style.display = 'none'; +} class DomainRequestsTable extends LoadTableBase { constructor() { super('.domain-requests__table', '.domain-requests__table-wrapper', '#domain-requests__search-field', '#domain-requests__search-field-submit', '.domain-requests__reset-search', '.domain-requests__reset-filters', '.domain-requests__no-data', '.domain-requests__no-search-results'); } + + toggleExportButton(requests) { + console.log("Toggling Export Button Visibility"); + const exportButton = document.getElementById('export-csv-button'); + if (exportButton) { + console.log(`Current requests length: ${requests.length}`); + if (requests.length > 0) { + showExportElement(exportButton); + } else { + hideExportElement(exportButton); + } + console.log(exportButton); + } +} + /** * Loads rows in the domains list, as well as updates pagination around the domains list * based on the supplied attributes. @@ -1517,6 +1541,7 @@ class DomainRequestsTable extends LoadTableBase { */ loadTable(page, sortBy = this.currentSortBy, order = this.currentOrder, scroll = this.scrollToTable, status = this.currentStatus, searchTerm = this.currentSearchTerm, portfolio = this.portfolioValue) { let baseUrl = document.getElementById("get_domain_requests_json_url"); + if (!baseUrl) { return; } @@ -1548,6 +1573,9 @@ class DomainRequestsTable extends LoadTableBase { return; } + // Call toggleExportButton to manage button visibility + this.toggleExportButton(data.domain_requests); + // handle the display of proper messaging in the event that no requests exist in the list or search returns no results this.updateDisplay(data, this.tableWrapper, this.noTableWrapper, this.noSearchResultsWrapper, this.currentSearchTerm); diff --git a/src/registrar/config/urls.py b/src/registrar/config/urls.py index 76c77955f..d4612f9a8 100644 --- a/src/registrar/config/urls.py +++ b/src/registrar/config/urls.py @@ -20,6 +20,7 @@ from registrar.views.report_views import ( AnalyticsView, ExportDomainRequestDataFull, ExportDataTypeUser, + ExportDataTypeRequests, ) from registrar.views.domain_request import Step @@ -165,6 +166,11 @@ urlpatterns = [ ExportDataTypeUser.as_view(), name="export_data_type_user", ), + path( + "reports/export_data_type_requests/", + ExportDataTypeRequests.as_view(), + name="export_data_type_requests", + ), path( "domain-request//edit/", views.DomainRequestWizard.as_view(), diff --git a/src/registrar/models/user.py b/src/registrar/models/user.py index ae76d648b..60b08ddcd 100644 --- a/src/registrar/models/user.py +++ b/src/registrar/models/user.py @@ -229,6 +229,10 @@ class User(AbstractUser): """Determines if the current user can view all available domains in a given portfolio""" return self._has_portfolio_permission(portfolio, UserPortfolioPermissionChoices.VIEW_ALL_DOMAINS) + def has_view_all_domain_requests_portfolio_permission(self, portfolio): + """Determines if the current user can view all available domains in a given portfolio""" + return self._has_portfolio_permission(portfolio, UserPortfolioPermissionChoices.VIEW_ALL_REQUESTS) + def has_any_requests_portfolio_permission(self, portfolio): # BEGIN # Note code below is to add organization_request feature @@ -458,3 +462,12 @@ class User(AbstractUser): return DomainInformation.objects.filter(portfolio=portfolio).values_list("domain_id", flat=True) else: return UserDomainRole.objects.filter(user=self).values_list("domain_id", flat=True) + + def get_user_domain_request_ids(self, request): + """Returns either the domain request ids associated with this user on UserDomainRole or Portfolio""" + portfolio = request.session.get("portfolio") + + if self.is_org_user(request) and self.has_view_all_domain_requests_portfolio_permission(portfolio): + return DomainRequest.objects.filter(portfolio=portfolio).values_list("id", flat=True) + else: + return UserDomainRole.objects.filter(user=self).values_list("domain_request_id", flat=True) diff --git a/src/registrar/templates/includes/domain_requests_table.html b/src/registrar/templates/includes/domain_requests_table.html index 375e0229c..2e0211811 100644 --- a/src/registrar/templates/includes/domain_requests_table.html +++ b/src/registrar/templates/includes/domain_requests_table.html @@ -3,208 +3,200 @@ {% comment %} Stores the json endpoint in a url for easier access {% endcomment %} {% url 'get_domain_requests_json' as url %} +
- {% if not portfolio %} + {% if not portfolio %}
-

Domain requests

+

Domain requests

{% else %} - {% endif %} -
-
- -
-
+ {% endif %} + +
+
+ +
+ +
+ + + Export as CSV + +
+
+ {% if portfolio %}
- Filter by -
-
- +
+
+

Status

+
+ Select to apply status filter +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ -
-
-

Status

-
- Select to apply status filter -
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
-
- - + {% endif %} + + + -
- +

No results found

+ + + +