Skip to content

Commit

Permalink
Merge pull request #346 from localcontexts/8689u4y5u-fix-large-bounda…
Browse files Browse the repository at this point in the history
…ry-error

#8689u4y5u fix large boundary error
  • Loading branch information
birbjam authored Sep 30, 2024
2 parents bd81787 + c42275b commit 9e960f7
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 42 deletions.
2 changes: 1 addition & 1 deletion helpers/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
path('download/community/support-letter/', views.download_community_support_letter, name="download-community-support-letter"),
path('community-boundary-view/<int:community_id>', views.community_boundary_view, name="community-boundary-view"),
path('project-boundary-view/<int:project_id>', views.project_boundary_view, name="project-boundary-view"),
path('boundary-view/', views.boundary_view, name="boundary-view"),
path('boundary-preview/', views.boundary_preview, name="boundary-preview"),
]
46 changes: 23 additions & 23 deletions helpers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
from institutions.models import Institution
from researchers.models import Researcher


def restricted_view(request, exception=None):
return render(request, '403.html', status=403)


@login_required(login_url='login')
def delete_member_invite(request, pk):
invite = InviteMember.objects.get(id=pk)
Expand Down Expand Up @@ -53,6 +55,7 @@ def download_open_collaborate_notice(request, perm, researcher_id=None, institut

return download_otc_notice(request)


@login_required(login_url='login')
def download_collections_care_notices(request, institution_id, perm):
# perm will be a 1 or 0
Expand All @@ -63,6 +66,7 @@ def download_collections_care_notices(request, institution_id, perm):
NoticeDownloadTracker.objects.create(institution=Institution.objects.get(id=institution_id), user=request.user, collections_care_notices=True)
return download_cc_notices(request)


@login_required(login_url='login')
def download_community_support_letter(request):
try:
Expand All @@ -80,6 +84,9 @@ def download_community_support_letter(request):

@xframe_options_sameorigin
def community_boundary_view(request, community_id):
"""
Uses boundary in community for view
"""
community = Community.objects.filter(id=community_id).first()
if not community:
message = 'Community Does Not Exist'
Expand All @@ -92,32 +99,14 @@ def community_boundary_view(request, community_id):
context = {
'boundary': boundary
}
return render(request, 'boundary/boundary-view.html', context)


@login_required(login_url='login')
def boundary_view(request):
try:
boundary = request.GET.get('boundary')
if boundary:
boundary = json.loads(
boundary.replace('(', '[').replace(')', ']')
)
else:
boundary = []

context = {
'boundary': boundary
}
return render(request, 'boundary/boundary-view.html', context)
except Exception as e:
message = 'Invalid Boundary Format'
print(f'{message}: {e}')
raise Exception(message)
return render(request, 'boundary/boundary-preview.html', context)


@xframe_options_sameorigin
def project_boundary_view(request, project_id):
"""
Uses boundary in project for view
"""
project = Project.objects.filter(id=project_id).first()
if not project:
message = 'Project Does Not Exist'
Expand All @@ -130,4 +119,15 @@ def project_boundary_view(request, project_id):
context = {
'boundary': boundary
}
return render(request, 'boundary/boundary-view.html', context)
return render(request, 'boundary/boundary-preview.html', context)


@login_required(login_url='login')
def boundary_preview(request):
"""
Uses boundary in local storage for preview
"""
context = {
'preview_boundary': True,
}
return render(request, 'boundary/boundary-preview.html', context)
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,53 @@
margin-top: 50px;
padding: 36px;
}
.invisible {
display: none
}
</style>
</head>
<body>
<div id="map"></div>

{% if boundary|length == 0 %}
<div id="no-boundary-container">
<div id="no-boundary">
No boundary Present
</div>
<div id="no-boundary-container">
<div id="no-boundary">
No boundary Present
</div>
</div>

<script>
// when boundary is not present, set default
let boundary = [
[[8.7832, 34.5085]]
]
let setInitialZoom = true

function boundaryExists() {
// when boundary exists, this is run to modify
// the settings
setInitialZoom = false
document.querySelector('#no-boundary').classList.add('invisible')
}
</script>

{% if preview_boundary %}
<script>
// when boundary are not present, set default
const boundary = [
[[8.7832, 34.5085]]
]
const setInitialZoom = true
// get boundary data from Local Storage
if (localStorage.hasOwnProperty('boundary_preview')) {
boundary = JSON.parse(
localStorage.getItem('boundary_preview')
)
boundaryExists()
}
</script>
{% else %}
{% elif boundary|length > 0 %}
<script>
const boundary = {{ boundary }}
const setInitialZoom = false
// Get boundary data from backend
boundary = {{ boundary }}
boundaryExists()
</script>
{% endif %}


<script>
// define map and its initial boundary
const map = L.map('map')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,11 @@
}

function setViewLocationsHref(selectionUnit, boundary) {
// set boundary-preview value in localStorage
localStorage.setItem('boundary_preview', JSON.stringify(boundary))

// set href for view-boundary-location
const href = `{% url 'boundary-view' %}?boundary=${JSON.stringify(boundary)}`
const href = "{% url 'boundary-preview' %}"
selectionUnit.querySelector('.view-boundary-link').setAttribute('href', href)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,11 @@
}

function setViewLocationsHref(selectionUnit, boundary) {
// set href for view-boundary-location
const href = `{% url 'boundary-view' %}?boundary=${JSON.stringify(boundary)}`
// set boundary-preview value in localStorage
localStorage.setItem('boundary_preview', JSON.stringify(boundary))

// set href for view-boundary-location
const href = "{% url 'boundary-preview' %}"
selectionUnit.querySelector('.view-boundary-link').setAttribute('href', href)
}

Expand Down
5 changes: 4 additions & 1 deletion templates/widget_forms/boundary_widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@
return
}

// set boundary-preview value in localStorage
localStorage.setItem('boundary_preview', JSON.stringify(boundary))

// open boundary preview
const url = `{% url 'boundary-view' %}?boundary=[${boundary}]`
const url = "{% url 'boundary-preview' %}"
window.open(url, '_blank');
}
async function uploadShapeFileData(self) {
Expand Down

0 comments on commit 9e960f7

Please sign in to comment.