Skip to content

Commit

Permalink
Merge pull request #136 from seanmorley15/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
seanmorley15 authored Jul 22, 2024
2 parents 7c33b9e + fe05e5c commit 58a40f1
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 68 deletions.
10 changes: 9 additions & 1 deletion backend/server/adventures/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,24 @@ def image_display(self, obj):
return mark_safe(f'<img src="{public_url}/media/{obj.profile_pic.name}" width="100px" height="100px"')
else:
return

class CollectionAdmin(admin.ModelAdmin):
def adventure_count(self, obj):
return obj.adventure_set.count()

adventure_count.short_description = 'Adventure Count'

list_display = ('name', 'user_id', 'adventure_count', 'is_public')

admin.site.register(CustomUser, CustomUserAdmin)



admin.site.register(Adventure, AdventureAdmin)
admin.site.register(Collection, CollectionAdmin)
admin.site.register(Country, CountryAdmin)
admin.site.register(Region, RegionAdmin)
admin.site.register(VisitedRegion)
admin.site.register(Collection)

admin.site.site_header = 'AdventureLog Admin'
admin.site.site_title = 'AdventureLog Admin Site'
Expand Down
2 changes: 1 addition & 1 deletion backend/server/adventures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ def clean(self):
raise ValidationError('Public collections cannot be associated with private adventures. Collection: ' + self.name + ' Adventure: ' + adventure.name)

def __str__(self):
return self.name
return self.name
4 changes: 2 additions & 2 deletions backend/server/adventures/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ def search(self, request):
(Q(user_id=request.user.id) | Q(is_public=True))
)
queryset = self.apply_sorting(queryset)
adventures = self.paginate_and_respond(queryset, request)
return adventures
serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)

def paginate_and_respond(self, queryset, request):
paginator = self.pagination_class()
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# For backwards compatibility for Django 1.8
MIDDLEWARE_CLASSES = MIDDLEWARE

ROOT_URLCONF = 'demo.urls'
ROOT_URLCONF = 'main.urls'

# WSGI_APPLICATION = 'demo.wsgi.application'

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion backend/server/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings")

from django.core.management import execute_from_command_line

Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/components/AdventureCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
});
if (res.ok) {
console.log('Adventure type changed');
dispatch('typeChange', adventure.id);
addToast('info', 'Adventure type changed successfully!');
adventure.type = newType;
} else {
Expand Down
78 changes: 40 additions & 38 deletions frontend/src/lib/components/Navbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,6 @@
<li>
<button on:click={() => goto('/map')}>Map</button>
</li>
<form class="flex gap-2">
<label class="input input-bordered flex items-center gap-2">
<input type="text" bind:value={query} class="grow" placeholder="Search" />

<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="h-4 w-4 opacity-70"
>
<path
fill-rule="evenodd"
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z"
clip-rule="evenodd"
/>
</svg>
</label>
<button on:click={searchGo} type="submit" class="btn btn-neutral">Search</button>
</form>
{/if}

{#if !data.user}
Expand All @@ -112,6 +93,26 @@
<button class="btn btn-primary" on:click={() => goto('/signup')}>Signup</button>
</li>
{/if}

<form class="flex gap-2">
<label class="input input-bordered flex items-center gap-2">
<input type="text" bind:value={query} class="grow" placeholder="Search" />

<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="h-4 w-4 opacity-70"
>
<path
fill-rule="evenodd"
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z"
clip-rule="evenodd"
/>
</svg>
</label>
<button on:click={searchGo} type="submit" class="btn btn-neutral">Search</button>
</form>
</ul>
</div>
<a class="btn btn-ghost text-xl" href="/"
Expand All @@ -134,25 +135,6 @@
<li>
<button class="btn btn-neutral" on:click={() => goto('/map')}>Map</button>
</li>
<form class="flex gap-2">
<label class="input input-bordered flex items-center gap-2">
<input type="text" bind:value={query} class="grow" placeholder="Search" />

<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="h-4 w-4 opacity-70"
>
<path
fill-rule="evenodd"
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z"
clip-rule="evenodd"
/>
</svg>
</label>
<button on:click={searchGo} type="submit" class="btn btn-neutral">Search</button>
</form>
{/if}

{#if !data.user}
Expand All @@ -163,6 +145,26 @@
<button class="btn btn-primary" on:click={() => goto('/signup')}>Signup</button>
</li>
{/if}

<form class="flex gap-2">
<label class="input input-bordered flex items-center gap-2">
<input type="text" bind:value={query} class="grow" placeholder="Search" />

<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="h-4 w-4 opacity-70"
>
<path
fill-rule="evenodd"
d="M9.965 11.026a5 5 0 1 1 1.06-1.06l2.755 2.754a.75.75 0 1 1-1.06 1.06l-2.755-2.754ZM10.5 7a3.5 3.5 0 1 1-7 0 3.5 3.5 0 0 1 7 0Z"
clip-rule="evenodd"
/>
</svg>
</label>
<button on:click={searchGo} type="submit" class="btn btn-neutral">Search</button>
</form>
</ul>
</div>
<div class="navbar-end">
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/components/NewAdventure.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
user_id: NaN,
latitude: null,
longitude: null,
is_public: false
is_public: false,
collection: null
};
let image: File;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export let appVersion = 'Web v0.4.0';
export let versionChangelog = 'https://github.com/seanmorley15/AdventureLog/releases/tag/v0.4.0';
export let appVersion = 'Web v0.4.1';
export let versionChangelog = 'https://github.com/seanmorley15/AdventureLog/releases/tag/v0.4.1';
export let appTitle = 'AdventureLog';
export let copyrightYear = '2024';
2 changes: 0 additions & 2 deletions frontend/src/routes/adventures/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
let resultsPerPage: number = 10;
let currentView: string = 'cards';
let next: string | null = data.props.next || null;
let previous: string | null = data.props.previous || null;
let count = data.props.count || 0;
Expand Down
26 changes: 24 additions & 2 deletions frontend/src/routes/collections/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
import AdventureCard from '$lib/components/AdventureCard.svelte';
import AdventureLink from '$lib/components/AdventureLink.svelte';
import EditAdventure from '$lib/components/EditAdventure.svelte';
import NotFound from '$lib/components/NotFound.svelte';
export let data: PageData;
let collection: Collection;
let adventures: Adventure[] = [];
let numVisited: number = adventures.filter((a) => a.type == 'visited').length;
let numVisited: number = 0;
$: {
numVisited = adventures.filter((a) => a.type === 'visited').length;
}
let notFound: boolean = false;
let isShowingCreateModal: boolean = false;
Expand Down Expand Up @@ -56,6 +61,19 @@
}
}
function changeType(event: CustomEvent<number>) {
adventures = adventures.map((adventure) => {
if (adventure.id == event.detail) {
if (adventure.type == 'visited') {
adventure.type = 'planned';
} else {
adventure.type = 'visited';
}
}
return adventure;
});
}
let adventureToEdit: Adventure;
let isEditModalOpen: boolean = false;
Expand Down Expand Up @@ -157,7 +175,7 @@
<div class="flex items-center justify-center mb-4">
<div class="stats shadow bg-base-300">
<div class="stat">
<div class="stat-title">Region Stats</div>
<div class="stat-title">Collection Stats</div>
<div class="stat-value">{numVisited}/{adventures.length} Visited</div>
{#if numVisited === adventures.length}
<div class="stat-desc">You've completed this collection! 🎉!</div>
Expand All @@ -169,6 +187,9 @@
</div>
{/if}
<h1 class="text-center font-semibold text-2xl mt-4 mb-2">Linked Adventures</h1>
{#if adventures.length == 0}
<NotFound error={undefined} />
{/if}
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
{#each adventures as adventure}
<AdventureCard
Expand All @@ -177,6 +198,7 @@
on:delete={deleteAdventure}
type={adventure.type}
{adventure}
on:typeChange={changeType}
/>
{/each}
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/map/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const load = (async (event) => {
.map((adventure) => {
return {
lngLat: [adventure.longitude, adventure.latitude] as [number, number],
name: adventure.name
name: adventure.name,
type: adventure.type
};
});
return {
Expand Down
56 changes: 47 additions & 9 deletions frontend/src/routes/map/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script>
// @ts-nocheck
import { DefaultMarker, MapEvents, MapLibre, Popup } from 'svelte-maplibre';
import { DefaultMarker, MapEvents, MapLibre, Popup, Marker } from 'svelte-maplibre';
export let data;
let clickedName = '';
let markers = data.props.markers;
console.log(markers);
</script>
Expand All @@ -13,14 +15,50 @@
class="relative aspect-[9/16] max-h-[70vh] w-full sm:aspect-video sm:max-h-full"
standardControls
>
{#each data.props.markers as { lngLat, name }}
<!-- Unlike the custom marker example, default markers do not have mouse events,
and popups only support the default openOn="click" behavior -->
<DefaultMarker {lngLat}>
<Popup offset={[0, -10]}>
<div class="text-lg font-bold">{name}</div>
</Popup>
</DefaultMarker>
{#each data.props.markers as { lngLat, name, type }}
{#if type == 'visited'}
<Marker
{lngLat}
on:click={() => (clickedName = name)}
class="grid h-8 w-8 place-items-center rounded-full border border-gray-200 bg-red-300 text-black shadow-2xl focus:outline-2 focus:outline-black"
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="12" cy="12" r="10" stroke="red" stroke-width="2" fill="red" />
</svg>
<Popup openOn="click" offset={[0, -10]}>
<div class="text-lg font-bold">{name}</div>
<p class="font-semibold text-md">Visited</p>
</Popup>
</Marker>
{/if}

{#if type == 'planned'}
<Marker
{lngLat}
on:click={() => (clickedName = name)}
class="grid h-8 w-8 place-items-center rounded-full border border-gray-200 bg-blue-300 text-black shadow-2xl focus:outline-2 focus:outline-black"
>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="12" cy="12" r="10" stroke="blue" stroke-width="2" fill="blue" />
</svg>
<Popup openOn="click" offset={[0, -10]}>
<div class="text-lg font-bold">{name}</div>
<p class="font-semibold text-md">Planned</p>
</Popup>
</Marker>
{/if}
{/each}
</MapLibre>

Expand Down
5 changes: 1 addition & 4 deletions frontend/src/routes/search/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export const load = (async (event) => {

return {
props: {
adventures: data.results as Adventure[],
nextPage: data.next,
prevPage: data.previous,
total: data.count,
adventures: data,
query
}
};
Expand Down
Loading

0 comments on commit 58a40f1

Please sign in to comment.