mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-20 13:29:37 +02:00
commit
31aefff74e
4 changed files with 30 additions and 19 deletions
|
@ -175,6 +175,10 @@ class CollectionViewSet(viewsets.ModelViewSet):
|
||||||
permission_classes = [IsOwnerOrReadOnly, IsPublicReadOnly]
|
permission_classes = [IsOwnerOrReadOnly, IsPublicReadOnly]
|
||||||
pagination_class = StandardResultsSetPagination
|
pagination_class = StandardResultsSetPagination
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
print(self.request.user.id)
|
||||||
|
return Collection.objects.filter(user_id=self.request.user.id)
|
||||||
|
|
||||||
def apply_sorting(self, queryset):
|
def apply_sorting(self, queryset):
|
||||||
order_by = self.request.query_params.get('order_by', 'name')
|
order_by = self.request.query_params.get('order_by', 'name')
|
||||||
order_direction = self.request.query_params.get('order_direction', 'asc')
|
order_direction = self.request.query_params.get('order_direction', 'asc')
|
||||||
|
@ -255,9 +259,19 @@ class CollectionViewSet(viewsets.ModelViewSet):
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
collections = Collection.objects.filter(
|
|
||||||
|
adventures = None
|
||||||
|
|
||||||
|
if self.action == 'retrieve':
|
||||||
|
# For individual collection retrieval, include public collections
|
||||||
|
adventures = Collection.objects.filter(
|
||||||
Q(is_public=True) | Q(user_id=self.request.user.id)
|
Q(is_public=True) | Q(user_id=self.request.user.id)
|
||||||
).prefetch_related(
|
)
|
||||||
|
else:
|
||||||
|
# For other actions, only include user's own collections
|
||||||
|
adventures = Collection.objects.filter(user_id=self.request.user.id)
|
||||||
|
|
||||||
|
adventures = adventures.prefetch_related(
|
||||||
Prefetch('adventure_set', queryset=Adventure.objects.filter(
|
Prefetch('adventure_set', queryset=Adventure.objects.filter(
|
||||||
Q(is_public=True) | Q(user_id=self.request.user.id)
|
Q(is_public=True) | Q(user_id=self.request.user.id)
|
||||||
))
|
))
|
||||||
|
@ -266,7 +280,7 @@ class CollectionViewSet(viewsets.ModelViewSet):
|
||||||
Q(is_public=True) | Q(user_id=self.request.user.id)
|
Q(is_public=True) | Q(user_id=self.request.user.id)
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
return self.apply_sorting(collections)
|
return self.apply_sorting(adventures)
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
serializer.save(user_id=self.request.user)
|
serializer.save(user_id=self.request.user)
|
||||||
|
|
|
@ -8,6 +8,9 @@ services:
|
||||||
- PUBLIC_SERVER_URL=http://server:8000
|
- PUBLIC_SERVER_URL=http://server:8000
|
||||||
- ORIGIN=http://localhost:8080
|
- ORIGIN=http://localhost:8080
|
||||||
- BODY_SIZE_LIMIT=Infinity
|
- BODY_SIZE_LIMIT=Infinity
|
||||||
|
# Analytics can be configured here using Umami (https://umami.is)
|
||||||
|
- ENABLE_ANALYTICS=false
|
||||||
|
#- UNAMI_KEY=''
|
||||||
ports:
|
ports:
|
||||||
- "8080:3000"
|
- "8080:3000"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|
|
@ -3,8 +3,17 @@
|
||||||
import Toast from '$lib/components/Toast.svelte';
|
import Toast from '$lib/components/Toast.svelte';
|
||||||
import 'tailwindcss/tailwind.css';
|
import 'tailwindcss/tailwind.css';
|
||||||
export let data;
|
export let data;
|
||||||
|
|
||||||
|
const enableAnalytics = process.env['ENABLE_ANALYTICS'] || 'false';
|
||||||
|
const unamiKey = process.env['UNAMI_KEY'] || '';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
{#if enableAnalytics === 'true' && unamiKey}
|
||||||
|
<script defer src="https://cloud.umami.is/script.js" data-website-id={unamiKey}></script>
|
||||||
|
{/if}
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<Navbar {data} />
|
<Navbar {data} />
|
||||||
<Toast />
|
<Toast />
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
let showVisited = true;
|
let showVisited = true;
|
||||||
let showPlanned = true;
|
let showPlanned = true;
|
||||||
let showCollectionAdventures = false;
|
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (!showVisited) {
|
if (!showVisited) {
|
||||||
|
@ -34,12 +33,6 @@
|
||||||
const plannedMarkers = data.props.markers.filter((marker) => marker.type === 'planned');
|
const plannedMarkers = data.props.markers.filter((marker) => marker.type === 'planned');
|
||||||
markers = [...markers, ...plannedMarkers];
|
markers = [...markers, ...plannedMarkers];
|
||||||
}
|
}
|
||||||
if (!showCollectionAdventures) {
|
|
||||||
markers = markers.filter((marker) => marker.collection === null);
|
|
||||||
} else {
|
|
||||||
const collectionMarkers = data.props.markers.filter((marker) => marker.collection !== null);
|
|
||||||
markers = [...markers, ...collectionMarkers];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let newMarker = [];
|
let newMarker = [];
|
||||||
|
@ -124,14 +117,6 @@
|
||||||
<span class="label-text">Planned</span>
|
<span class="label-text">Planned</span>
|
||||||
<input type="checkbox" bind:checked={showPlanned} class="checkbox checkbox-primary" />
|
<input type="checkbox" bind:checked={showPlanned} class="checkbox checkbox-primary" />
|
||||||
</label>
|
</label>
|
||||||
<label class="label cursor-pointer">
|
|
||||||
<span class="label-text">Collection Adventures</span>
|
|
||||||
<input
|
|
||||||
type="checkbox"
|
|
||||||
bind:checked={showCollectionAdventures}
|
|
||||||
class="checkbox checkbox-primary"
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
{#if newMarker.length > 0}
|
{#if newMarker.length > 0}
|
||||||
<button type="button" class="btn btn-primary mb-2" on:click={() => (createModalOpen = true)}
|
<button type="button" class="btn btn-primary mb-2" on:click={() => (createModalOpen = true)}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue