mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-23 06:49:37 +02:00
collection days
This commit is contained in:
parent
055290ce3f
commit
c94a4379c7
8 changed files with 101 additions and 5 deletions
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 5.0.7 on 2024-07-27 18:18
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('adventures', '0011_adventure_updated_at'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='collection',
|
||||||
|
name='end_date',
|
||||||
|
field=models.DateField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='collection',
|
||||||
|
name='start_date',
|
||||||
|
field=models.DateField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -56,6 +56,8 @@ class Collection(models.Model):
|
||||||
description = models.TextField(blank=True, null=True)
|
description = models.TextField(blank=True, null=True)
|
||||||
is_public = models.BooleanField(default=False)
|
is_public = models.BooleanField(default=False)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
start_date = models.DateField(blank=True, null=True)
|
||||||
|
end_date = models.DateField(blank=True, null=True)
|
||||||
|
|
||||||
# if connected adventures are private and collection is public, raise an error
|
# if connected adventures are private and collection is public, raise an error
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
|
@ -29,7 +29,7 @@ class CollectionSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Collection
|
model = Collection
|
||||||
# fields are all plus the adventures field
|
# fields are all plus the adventures field
|
||||||
fields = ['id', 'description', 'user_id', 'name', 'is_public', 'adventures']
|
fields = ['id', 'description', 'user_id', 'name', 'is_public', 'adventures', 'created_at', 'start_date', 'end_date']
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,20 @@
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h2 class="card-title overflow-ellipsis">{collection.name}</h2>
|
<h2 class="card-title overflow-ellipsis">{collection.name}</h2>
|
||||||
<p>{collection.adventures.length} Adventures</p>
|
<p>{collection.adventures.length} Adventures</p>
|
||||||
|
{#if collection.start_date && collection.end_date}
|
||||||
|
<p>
|
||||||
|
Dates: {new Date(collection.start_date).toLocaleDateString()} - {new Date(
|
||||||
|
collection.end_date
|
||||||
|
).toLocaleDateString()}
|
||||||
|
</p>
|
||||||
|
<!-- display the duration in days -->
|
||||||
|
<p>
|
||||||
|
Duration: {Math.floor(
|
||||||
|
(new Date(collection.end_date).getTime() - new Date(collection.start_date).getTime()) /
|
||||||
|
(1000 * 60 * 60 * 24)
|
||||||
|
)}{' '}
|
||||||
|
days
|
||||||
|
</p>{/if}
|
||||||
<div class="card-actions justify-end">
|
<div class="card-actions justify-end">
|
||||||
{#if type != 'link'}
|
{#if type != 'link'}
|
||||||
<button on:click={deleteCollection} class="btn btn-secondary"
|
<button on:click={deleteCollection} class="btn btn-secondary"
|
||||||
|
|
|
@ -109,6 +109,7 @@
|
||||||
bind:value={collectionToEdit.description}
|
bind:value={collectionToEdit.description}
|
||||||
class="input input-bordered w-full max-w-xs mt-1 mb-2"
|
class="input input-bordered w-full max-w-xs mt-1 mb-2"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- <button
|
<!-- <button
|
||||||
class="btn btn-neutral ml-2"
|
class="btn btn-neutral ml-2"
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -117,6 +118,28 @@
|
||||||
></iconify-icon>Generate Description</button
|
></iconify-icon>Generate Description</button
|
||||||
> -->
|
> -->
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label for="start_date">Start Date <Calendar class="inline-block mb-1 w-6 h-6" /></label
|
||||||
|
><br />
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
id="start_date"
|
||||||
|
name="start_date"
|
||||||
|
bind:value={collectionToEdit.start_date}
|
||||||
|
class="input input-bordered w-full max-w-xs mt-1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label for="end_date">End Date <Calendar class="inline-block mb-1 w-6 h-6" /></label><br
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
id="end_date"
|
||||||
|
name="end_date"
|
||||||
|
bind:value={collectionToEdit.end_date}
|
||||||
|
class="input input-bordered w-full max-w-xs mt-1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label for="is_public">Public <Earth class="inline-block -mt-1 mb-1 w-6 h-6" /></label><br
|
<label for="is_public">Public <Earth class="inline-block -mt-1 mb-1 w-6 h-6" /></label><br
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
import { enhance } from '$app/forms';
|
import { enhance } from '$app/forms';
|
||||||
import { addToast } from '$lib/toasts';
|
import { addToast } from '$lib/toasts';
|
||||||
|
|
||||||
|
import Calendar from '~icons/mdi/calendar';
|
||||||
|
|
||||||
let newCollection: Collection = {
|
let newCollection: Collection = {
|
||||||
user_id: NaN,
|
user_id: NaN,
|
||||||
id: NaN,
|
id: NaN,
|
||||||
|
@ -104,10 +106,32 @@
|
||||||
class="input input-bordered w-full max-w-xs mt-1 mb-2"
|
class="input input-bordered w-full max-w-xs mt-1 mb-2"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="mb-2">
|
||||||
<div class="mb-2">
|
<label for="start_date">Start Date <Calendar class="inline-block mb-1 w-6 h-6" /></label
|
||||||
<button type="submit" class="btn btn-primary mr-4 mt-4">Create</button>
|
><br />
|
||||||
<button type="button" class="btn mt-4" on:click={close}>Close</button>
|
<input
|
||||||
|
type="date"
|
||||||
|
id="start_date"
|
||||||
|
name="start_date"
|
||||||
|
bind:value={newCollection.start_date}
|
||||||
|
class="input input-bordered w-full max-w-xs mt-1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label for="end_date">End Date <Calendar class="inline-block mb-1 w-6 h-6" /></label><br
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
id="end_date"
|
||||||
|
name="end_date"
|
||||||
|
bind:value={newCollection.end_date}
|
||||||
|
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>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -64,6 +64,8 @@ export type Collection = {
|
||||||
is_public: boolean;
|
is_public: boolean;
|
||||||
adventures: Adventure[];
|
adventures: Adventure[];
|
||||||
created_at?: string;
|
created_at?: string;
|
||||||
|
start_date?: string;
|
||||||
|
end_date?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type OpenStreetMapPlace = {
|
export type OpenStreetMapPlace = {
|
||||||
|
|
|
@ -51,6 +51,8 @@ export const actions: Actions = {
|
||||||
|
|
||||||
const name = formData.get('name') as string;
|
const name = formData.get('name') as string;
|
||||||
const description = formData.get('description') as string | null;
|
const description = formData.get('description') as string | null;
|
||||||
|
const start_date = formData.get('start_date') as string | null;
|
||||||
|
const end_date = formData.get('end_date') as string | null;
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return {
|
return {
|
||||||
|
@ -62,6 +64,8 @@ export const actions: Actions = {
|
||||||
const formDataToSend = new FormData();
|
const formDataToSend = new FormData();
|
||||||
formDataToSend.append('name', name);
|
formDataToSend.append('name', name);
|
||||||
formDataToSend.append('description', description || '');
|
formDataToSend.append('description', description || '');
|
||||||
|
formDataToSend.append('start_date', start_date || '');
|
||||||
|
formDataToSend.append('end_date', end_date || '');
|
||||||
let auth = event.cookies.get('auth');
|
let auth = event.cookies.get('auth');
|
||||||
|
|
||||||
if (!auth) {
|
if (!auth) {
|
||||||
|
@ -136,6 +140,8 @@ export const actions: Actions = {
|
||||||
const name = formData.get('name') as string;
|
const name = formData.get('name') as string;
|
||||||
const description = formData.get('description') as string | null;
|
const description = formData.get('description') as string | null;
|
||||||
let is_public = formData.get('is_public') as string | null | boolean;
|
let is_public = formData.get('is_public') as string | null | boolean;
|
||||||
|
const start_date = formData.get('start_date') as string | null;
|
||||||
|
const end_date = formData.get('end_date') as string | null;
|
||||||
|
|
||||||
if (is_public) {
|
if (is_public) {
|
||||||
is_public = true;
|
is_public = true;
|
||||||
|
@ -154,6 +160,8 @@ export const actions: Actions = {
|
||||||
formDataToSend.append('name', name);
|
formDataToSend.append('name', name);
|
||||||
formDataToSend.append('description', description || '');
|
formDataToSend.append('description', description || '');
|
||||||
formDataToSend.append('is_public', is_public.toString());
|
formDataToSend.append('is_public', is_public.toString());
|
||||||
|
formDataToSend.append('start_date', start_date || '');
|
||||||
|
formDataToSend.append('end_date', end_date || '');
|
||||||
|
|
||||||
let auth = event.cookies.get('auth');
|
let auth = event.cookies.get('auth');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue