Skip to content

Commit

Permalink
Merge pull request #338 from seanmorley15/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
seanmorley15 authored Oct 14, 2024
2 parents 01797bd + 2601b07 commit 3508b3b
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 127 deletions.
18 changes: 18 additions & 0 deletions backend/server/adventures/migrations/0010_collection_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.8 on 2024-10-08 03:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('adventures', '0009_alter_adventure_type'),
]

operations = [
migrations.AddField(
model_name='collection',
name='link',
field=models.URLField(blank=True, max_length=2083, null=True),
),
]
1 change: 1 addition & 0 deletions backend/server/adventures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class Collection(models.Model):
updated_at = models.DateTimeField(auto_now=True)
is_archived = models.BooleanField(default=False)
shared_with = models.ManyToManyField(User, related_name='shared_with', blank=True)
link = models.URLField(blank=True, null=True, max_length=2083)


# if connected adventures are private and collection is public, raise an error
Expand Down
3 changes: 1 addition & 2 deletions backend/server/adventures/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ class CollectionSerializer(serializers.ModelSerializer):

class Meta:
model = Collection
# fields are all plus the adventures field
fields = ['id', 'description', 'user_id', 'name', 'is_public', 'adventures', 'created_at', 'start_date', 'end_date', 'transportations', 'notes', 'updated_at', 'checklists', 'is_archived', 'shared_with']
fields = ['id', 'description', 'user_id', 'name', 'is_public', 'adventures', 'created_at', 'start_date', 'end_date', 'transportations', 'notes', 'updated_at', 'checklists', 'is_archived', 'shared_with', 'link']
read_only_fields = ['id', 'created_at', 'updated_at', 'user_id']

def to_representation(self, instance):
Expand Down
9 changes: 3 additions & 6 deletions backend/server/adventures/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,8 @@ class StatsViewSet(viewsets.ViewSet):

@action(detail=False, methods=['get'])
def counts(self, request):
visited_count = Adventure.objects.filter(
type='visited', user_id=request.user.id).count()
planned_count = Adventure.objects.filter(
type='planned', user_id=request.user.id).count()
adventure_count = Adventure.objects.filter(
user_id=request.user.id).count()
trips_count = Collection.objects.filter(
user_id=request.user.id).count()
visited_region_count = VisitedRegion.objects.filter(
Expand All @@ -524,8 +522,7 @@ def counts(self, request):
user_id=request.user.id).values('region__country').distinct().count()
total_countries = Country.objects.count()
return Response({
'visited_count': visited_count,
'planned_count': planned_count,
'adventure_count': adventure_count,
'trips_count': trips_count,
'visited_region_count': visited_region_count,
'total_regions': total_regions,
Expand Down
49 changes: 2 additions & 47 deletions frontend/src/lib/components/AdventureCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import CollectionLink from './CollectionLink.svelte';
import DotsHorizontal from '~icons/mdi/dots-horizontal';
import DeleteWarning from './DeleteWarning.svelte';
import ImageDisplayModal from './ImageDisplayModal.svelte';
import { isAdventureVisited, typeToString } from '$lib';
import CardCarousel from './CardCarousel.svelte';
export let type: string;
export let user: User | null;
Expand All @@ -28,7 +28,6 @@
let isCollectionModalOpen: boolean = false;
let isWarningModalOpen: boolean = false;
let image_url: string | null = null;
export let adventure: Adventure;
let activityTypes: string[] = [];
Expand Down Expand Up @@ -120,12 +119,6 @@
dispatch('edit', adventure);
}
let currentSlide = 0;
function goToSlide(index: number) {
currentSlide = index;
}
function link() {
dispatch('link', adventure);
}
Expand All @@ -146,48 +139,10 @@
/>
{/if}

{#if image_url}
<ImageDisplayModal image={image_url} on:close={() => (image_url = null)} {adventure} />
{/if}

<div
class="card w-full max-w-xs sm:max-w-sm md:max-w-md lg:max-w-md xl:max-w-md bg-neutral text-neutral-content shadow-xl"
>
<figure>
{#if adventure.images && adventure.images.length > 0}
<div class="carousel w-full">
{#each adventure.images as image, i}
<div
class="carousel-item w-full"
style="display: {i === currentSlide ? 'block' : 'none'}"
>
<!-- svelte-ignore a11y-invalid-attribute -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-missing-attribute -->
<a on:click={() => (image_url = image.image)}
><img src={image.image} class="w-full h-48 object-cover" alt={adventure.name} /></a
>
<div class="flex justify-center w-full py-2 gap-2">
{#each adventure.images as _, i}
<button
on:click={() => goToSlide(i)}
class="btn btn-xs {i === currentSlide ? 'btn-active' : ''}">{i + 1}</button
>
{/each}
</div>
</div>
{/each}
</div>
{:else}
<!-- svelte-ignore a11y-img-redundant-alt -->
<img
src={'https://placehold.co/300?text=No%20Image%20Found&font=roboto'}
alt="No image available"
class="w-full h-48 object-cover"
/>
{/if}
</figure>
<CardCarousel adventures={[adventure]} />

<div class="card-body">
<div class="flex justify-between">
Expand Down
87 changes: 87 additions & 0 deletions frontend/src/lib/components/CardCarousel.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<script lang="ts">
import type { Adventure } from '$lib/types';
import ImageDisplayModal from './ImageDisplayModal.svelte';
export let adventures: Adventure[] = [];
let currentSlide = 0;
let image_url: string | null = null;
$: adventure_images = adventures.flatMap((adventure) =>
adventure.images.map((image) => ({ image: image.image, adventure: adventure }))
);
$: {
if (adventure_images.length > 0) {
currentSlide = 0;
}
}
function changeSlide(direction: string) {
if (direction === 'next' && currentSlide < adventure_images.length - 1) {
currentSlide = currentSlide + 1;
} else if (direction === 'prev' && currentSlide > 0) {
currentSlide = currentSlide - 1;
}
}
</script>

{#if image_url}
<ImageDisplayModal
adventure={adventure_images[currentSlide].adventure}
image={image_url}
on:close={() => (image_url = null)}
/>
{/if}

<figure>
{#if adventure_images && adventure_images.length > 0}
<div class="carousel w-full relative">
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div class="carousel-item w-full block">
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<!-- svelte-ignore a11y-missing-attribute -->
<a
on:click|stopPropagation={() => (image_url = adventure_images[currentSlide].image)}
class="cursor-pointer"
>
<img
src={adventure_images[currentSlide].image}
class="w-full h-48 object-cover"
alt={adventure_images[currentSlide].adventure.name}
/>
</a>

{#if adventure_images.length > 1}
<div class="absolute inset-0 flex items-center justify-between pointer-events-none">
{#if currentSlide > 0}
<button
on:click|stopPropagation={() => changeSlide('prev')}
class="btn btn-circle btn-sm ml-2 pointer-events-auto">❮</button
>
{:else}
<div class="w-12"></div>
{/if}

{#if currentSlide < adventure_images.length - 1}
<button
on:click|stopPropagation={() => changeSlide('next')}
class="btn btn-circle mr-2 btn-sm pointer-events-auto">❯</button
>
{:else}
<div class="w-12"></div>
{/if}
</div>
{/if}
</div>
</div>
{:else}
<!-- svelte-ignore a11y-img-redundant-alt -->
<img
src={'https://placehold.co/300?text=No%20Image%20Found&font=roboto'}
alt="No image available"
class="w-full h-48 object-cover"
/>
{/if}
</figure>
7 changes: 4 additions & 3 deletions frontend/src/lib/components/CollectionCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
import ArchiveArrowUp from '~icons/mdi/archive-arrow-up';
import { goto } from '$app/navigation';
import type { Collection } from '$lib/types';
import type { Adventure, Collection } from '$lib/types';
import { addToast } from '$lib/toasts';
import Plus from '~icons/mdi/plus';
import DotsHorizontal from '~icons/mdi/dots-horizontal';
import TrashCan from '~icons/mdi/trashcan';
import DeleteWarning from './DeleteWarning.svelte';
import ShareModal from './ShareModal.svelte';
import CardCarousel from './CardCarousel.svelte';
const dispatch = createEventDispatcher();
export let type: String | undefined | null;
export let adventures: Adventure[] = [];
let isShareModalOpen: boolean = false;
// export let type: String;
function editAdventure() {
dispatch('edit', collection);
}
Expand Down Expand Up @@ -86,6 +86,7 @@
<div
class="card min-w-max lg:w-96 md:w-80 sm:w-60 xs:w-40 bg-neutral text-neutral-content shadow-xl"
>
<CardCarousel {adventures} />
<div class="card-body">
<div class="flex justify-between">
<button
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/lib/components/EditCollection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@
let originalName = collectionToEdit.name;
let isPointModalOpen: boolean = false;
import MapMarker from '~icons/mdi/map-marker';
import Calendar from '~icons/mdi/calendar';
import Notebook from '~icons/mdi/notebook';
import ClipboardList from '~icons/mdi/clipboard-list';
import Image from '~icons/mdi/image';
import Star from '~icons/mdi/star';
import Attachment from '~icons/mdi/attachment';
import PointSelectionModal from './PointSelectionModal.svelte';
import Earth from '~icons/mdi/earth';
onMount(async () => {
Expand Down Expand Up @@ -156,6 +148,16 @@
class="input input-bordered w-full max-w-xs mt-1"
/>
</div>
<div class="mb-2">
<label for="end_date">Link </label><br />
<input
type="url"
id="link"
name="link"
bind:value={collectionToEdit.link}
class="input input-bordered w-full max-w-xs mt-1"
/>
</div>
</div>
<div class="mb-2">
<label for="is_public">Public <Earth class="inline-block -mt-1 mb-1 w-6 h-6" /></label><br
Expand Down
62 changes: 32 additions & 30 deletions frontend/src/lib/components/ImageDisplayModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import type { Adventure } from '$lib/types';
export let image: string;
export let adventure: Adventure;
export let adventure: Adventure | null = null;
onMount(() => {
modal = document.getElementById('my_modal_1') as HTMLDialogElement;
Expand Down Expand Up @@ -42,34 +42,36 @@
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
<div class="modal-box w-11/12 max-w-5xl" role="dialog" on:keydown={handleKeydown} tabindex="0">
<div class="modal-header flex justify-between items-center mb-4">
<h3 class="font-bold text-2xl">{adventure.name}</h3>
<button class="btn btn-circle btn-neutral" on:click={close}>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
<div
class="flex justify-center items-center"
style="display: flex; justify-content: center; align-items: center;"
>
<img
src={image}
alt={adventure.name}
style="max-width: 100%; max-height: 75vh; object-fit: contain;"
/>
</div>
{#if adventure}
<div class="modal-header flex justify-between items-center mb-4">
<h3 class="font-bold text-2xl">{adventure.name}</h3>
<button class="btn btn-circle btn-neutral" on:click={close}>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
<div
class="flex justify-center items-center"
style="display: flex; justify-content: center; align-items: center;"
>
<img
src={image}
alt={adventure.name}
style="max-width: 100%; max-height: 75vh; object-fit: contain;"
/>
</div>
{/if}
</div>
</dialog>
14 changes: 13 additions & 1 deletion frontend/src/lib/components/NewCollection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
name: '',
description: '',
adventures: [] as Adventure[],
is_public: false
is_public: false,
shared_with: [],
link: ''
};
const dispatch = createEventDispatcher();
Expand Down Expand Up @@ -151,6 +153,16 @@
class="input input-bordered w-full max-w-xs mt-1"
/>
</div>
<div class="mb-2">
<label for="end_date">Link </label><br />
<input
type="url"
id="link"
name="link"
bind:value={newCollection.link}
class="input input-bordered w-full max-w-xs mt-1"
/>
</div>
<div class="mb-2">
<button type="submit" class="btn btn-primary mr-4 mt-4">Create</button>
<button type="button" class="btn mt-4" on:click={close}>Close</button>
Expand Down
Loading

0 comments on commit 3508b3b

Please sign in to comment.