mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-22 06:19:38 +02:00
Region check - frontend
This commit is contained in:
parent
c13d6f4f21
commit
dab6efbe32
2 changed files with 26 additions and 1 deletions
|
@ -54,7 +54,7 @@ class CountryViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
# make a post action that will get all of the users adventures and check if the point is in any of the regions if so make a visited region object for that user if it does not already exist
|
# make a post action that will get all of the users adventures and check if the point is in any of the regions if so make a visited region object for that user if it does not already exist
|
||||||
@action(detail=False, methods=['post'])
|
@action(detail=False, methods=['post'])
|
||||||
def region_check_all_adventures(self, request):
|
def region_check_all_adventures(self, request):
|
||||||
adventures = Adventure.objects.filter(user_id=request.user.id)
|
adventures = Adventure.objects.filter(user_id=request.user.id, type='visited')
|
||||||
count = 0
|
count = 0
|
||||||
for adventure in adventures:
|
for adventure in adventures:
|
||||||
if adventure.latitude is not None and adventure.longitude is not None:
|
if adventure.latitude is not None and adventure.longitude is not None:
|
||||||
|
|
|
@ -44,6 +44,21 @@
|
||||||
a.click();
|
a.click();
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function checkVisitedRegions() {
|
||||||
|
let res = await fetch('/api/countries/region_check_all_adventures/', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let data = await res.json();
|
||||||
|
if (res.ok) {
|
||||||
|
addToast('success', `${data.regions_visited} regions updated`);
|
||||||
|
} else {
|
||||||
|
addToast('error', 'Error updating visited regions');
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1 class="text-center font-extrabold text-4xl mb-6">Settings Page</h1>
|
<h1 class="text-center font-extrabold text-4xl mb-6">Settings Page</h1>
|
||||||
|
@ -157,6 +172,16 @@
|
||||||
<button class="btn btn-neutral mb-4" on:click={exportAdventures}> Export to JSON </button>
|
<button class="btn btn-neutral mb-4" on:click={exportAdventures}> Export to JSON </button>
|
||||||
<p>This may take a few seconds...</p>
|
<p>This may take a few seconds...</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex flex-col items-center">
|
||||||
|
<h1 class="text-center font-extrabold text-xl mt-4 mb-2">Visited Region Check</h1>
|
||||||
|
<p>
|
||||||
|
By selecting this, the server will check all of your visited adventures and mark the regions
|
||||||
|
they are located in as "visited" in world travel.
|
||||||
|
</p>
|
||||||
|
<button class="btn btn-neutral mb-4" on:click={checkVisitedRegions}>Update Visited Regions</button
|
||||||
|
>
|
||||||
|
<p>This may take longer depending on the number of adventures you have.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<small class="text-center"
|
<small class="text-center"
|
||||||
><b>For Debug Use:</b> Server PK={user.pk} | Date Joined: {user.date_joined
|
><b>For Debug Use:</b> Server PK={user.pk} | Date Joined: {user.date_joined
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue