mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-13 22:45:05 +02:00
initial implementation
This commit is contained in:
parent
ecafaa58c9
commit
8a9971ac79
5 changed files with 107 additions and 5 deletions
|
@ -837,6 +837,27 @@ function initializeWidgetOnList(list, parentId) {
|
|||
// If we can update the contact information, it'll be shown again.
|
||||
hideElement(contactList.parentElement);
|
||||
|
||||
let federalPortfolioApi = document.getElementById("federal_and_portfolio_types_from_agency_json_url").value;
|
||||
fetch(`${federalPortfolioApi}?organization_type=${organizationType.value}&agency_name=${selectedText}`)
|
||||
.then(response => {
|
||||
const statusCode = response.status;
|
||||
return response.json().then(data => ({ statusCode, data }));
|
||||
})
|
||||
.then(({ statusCode, data }) => {
|
||||
if (data.error) {
|
||||
console.error("Error in AJAX call: " + data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
let federal_type = data.federal_type;
|
||||
let portfolio_type = data.portfolio_type;
|
||||
console.log("portfolio type: " + portfolio_type);
|
||||
console.log("federal type: " + federal_type);
|
||||
updateFederalType(data.federal_type);
|
||||
updatePortfolioType(data.portfolio_type);
|
||||
})
|
||||
.catch(error => console.error("Error fetching federal and portfolio types: ", error));
|
||||
|
||||
let seniorOfficialApi = document.getElementById("senior_official_from_agency_json_url").value;
|
||||
fetch(`${seniorOfficialApi}?agency_name=${selectedText}`)
|
||||
.then(response => {
|
||||
|
@ -879,6 +900,7 @@ function initializeWidgetOnList(list, parentId) {
|
|||
}
|
||||
})
|
||||
.catch(error => console.error("Error fetching senior official: ", error));
|
||||
|
||||
}
|
||||
|
||||
function handleStateTerritoryChange(stateTerritory, urbanizationField) {
|
||||
|
@ -890,6 +912,35 @@ function initializeWidgetOnList(list, parentId) {
|
|||
}
|
||||
}
|
||||
|
||||
function updatePortfolioType(portfolioType) {
|
||||
console.log("attempting to update portfolioType");
|
||||
// Find the div with class 'field-portfolio_type'
|
||||
const portfolioTypeDiv = document.querySelector('.field-portfolio_type');
|
||||
if (portfolioTypeDiv) {
|
||||
console.log("found portfoliotype");
|
||||
// Find the nested div with class 'readonly' inside 'field-portfolio_type'
|
||||
const readonlyDiv = portfolioTypeDiv.querySelector('.readonly');
|
||||
if (readonlyDiv) {
|
||||
console.log("found readonly div");
|
||||
// Update the text content of the readonly div
|
||||
readonlyDiv.textContent = portfolioType !== null ? portfolioType : '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateFederalType(federalType) {
|
||||
// Find the div with class 'field-federal_type'
|
||||
const federalTypeDiv = document.querySelector('.field-federal_type');
|
||||
if (federalTypeDiv) {
|
||||
// Find the nested div with class 'readonly' inside 'field-federal_type'
|
||||
const readonlyDiv = federalTypeDiv.querySelector('.readonly');
|
||||
if (readonlyDiv) {
|
||||
// Update the text content of the readonly div
|
||||
readonlyDiv.textContent = federalType !== null ? federalType : '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateContactInfo(data) {
|
||||
if (!contactList) return;
|
||||
|
||||
|
|
|
@ -24,7 +24,10 @@ from registrar.views.report_views import (
|
|||
|
||||
from registrar.views.domain_request import Step
|
||||
from registrar.views.domain_requests_json import get_domain_requests_json
|
||||
from registrar.views.utility.api_views import get_senior_official_from_federal_agency_json
|
||||
from registrar.views.utility.api_views import (
|
||||
get_senior_official_from_federal_agency_json,
|
||||
get_federal_and_portfolio_types_from_federal_agency_json
|
||||
)
|
||||
from registrar.views.domains_json import get_domains_json
|
||||
from registrar.views.utility import always_404
|
||||
from api.views import available, get_current_federal, get_current_full
|
||||
|
@ -139,6 +142,11 @@ urlpatterns = [
|
|||
get_senior_official_from_federal_agency_json,
|
||||
name="get-senior-official-from-federal-agency-json",
|
||||
),
|
||||
path(
|
||||
"admin/api/get-federal-and-portfolio-types-from-federal-agency-json/",
|
||||
get_federal_and_portfolio_types_from_federal_agency_json,
|
||||
name="get-federal-and-portfolio-types-from-federal-agency-json",
|
||||
),
|
||||
path("admin/", admin.site.urls),
|
||||
path(
|
||||
"reports/export_data_type_user/",
|
||||
|
|
|
@ -131,9 +131,13 @@ class Portfolio(TimeStampedModel):
|
|||
Returns a combination of organization_type / federal_type, seperated by ' - '.
|
||||
If no federal_type is found, we just return the org type.
|
||||
"""
|
||||
org_type_label = self.OrganizationChoices.get_org_label(self.organization_type)
|
||||
agency_type_label = BranchChoices.get_branch_label(self.federal_type)
|
||||
if self.organization_type == self.OrganizationChoices.FEDERAL and agency_type_label:
|
||||
return self.get_portfolio_type(self.organization_type, self.federal_type)
|
||||
|
||||
@classmethod
|
||||
def get_portfolio_type(cls, organization_type, federal_type):
|
||||
org_type_label = cls.OrganizationChoices.get_org_label(organization_type)
|
||||
agency_type_label = BranchChoices.get_branch_label(federal_type)
|
||||
if organization_type == cls.OrganizationChoices.FEDERAL and agency_type_label:
|
||||
return " - ".join([org_type_label, agency_type_label])
|
||||
else:
|
||||
return org_type_label
|
||||
|
@ -141,8 +145,12 @@ class Portfolio(TimeStampedModel):
|
|||
@property
|
||||
def federal_type(self):
|
||||
"""Returns the federal_type value on the underlying federal_agency field"""
|
||||
return self.federal_agency.federal_type if self.federal_agency else None
|
||||
return self.get_federal_type(self.federal_agency)
|
||||
|
||||
@classmethod
|
||||
def get_federal_type(cls, federal_agency):
|
||||
return federal_agency.federal_type if federal_agency else None
|
||||
|
||||
# == Getters for domains == #
|
||||
def get_domains(self):
|
||||
"""Returns all DomainInformations associated with this portfolio"""
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
{% comment %} Stores the json endpoint in a url for easier access {% endcomment %}
|
||||
{% url 'get-senior-official-from-federal-agency-json' as url %}
|
||||
<input id="senior_official_from_agency_json_url" class="display-none" value="{{url}}" />
|
||||
{% url 'get-federal-and-portfolio-types-from-federal-agency-json' as url %}
|
||||
<input id="federal_and_portfolio_types_from_agency_json_url" class="display-none" value="{{url}}" />
|
||||
{{ block.super }}
|
||||
{% endblock content %}
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@ from registrar.models import FederalAgency, SeniorOfficial
|
|||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from registrar.models.portfolio import Portfolio
|
||||
from registrar.utility.constants import BranchChoices
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -34,3 +37,33 @@ def get_senior_official_from_federal_agency_json(request):
|
|||
return JsonResponse(so_dict)
|
||||
else:
|
||||
return JsonResponse({"error": "Senior Official not found"}, status=404)
|
||||
|
||||
@login_required
|
||||
@staff_member_required
|
||||
def get_federal_and_portfolio_types_from_federal_agency_json(request):
|
||||
"""Returns specific portfolio information as a JSON. Request must have
|
||||
both agency_name and organization_type."""
|
||||
|
||||
# This API is only accessible to admins and analysts
|
||||
superuser_perm = request.user.has_perm("registrar.full_access_permission")
|
||||
analyst_perm = request.user.has_perm("registrar.analyst_access_permission")
|
||||
if not request.user.is_authenticated or not any([analyst_perm, superuser_perm]):
|
||||
return JsonResponse({"error": "You do not have access to this resource"}, status=403)
|
||||
|
||||
federal_type = None
|
||||
portfolio_type = None
|
||||
|
||||
agency_name = request.GET.get("agency_name")
|
||||
organization_type = request.GET.get("organization_type")
|
||||
agency = FederalAgency.objects.filter(agency=agency_name).first()
|
||||
if agency:
|
||||
federal_type = Portfolio.get_federal_type(agency)
|
||||
portfolio_type = Portfolio.get_portfolio_type(organization_type, federal_type)
|
||||
federal_type = BranchChoices.get_branch_label(federal_type) if federal_type else "-"
|
||||
|
||||
response_data = {
|
||||
'portfolio_type': portfolio_type,
|
||||
'federal_type': federal_type,
|
||||
}
|
||||
|
||||
return JsonResponse(response_data)
|
Loading…
Add table
Add a link
Reference in a new issue