mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-23 23:09:37 +02:00
Fix custom default category
This commit is contained in:
parent
17d8784d8c
commit
ce0b82acb7
10 changed files with 66 additions and 26 deletions
|
@ -19,7 +19,7 @@ class Migration(migrations.Migration):
|
||||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True)),
|
||||||
('name', models.CharField(max_length=200)),
|
('name', models.CharField(max_length=200)),
|
||||||
('display_name', models.CharField(max_length=200)),
|
('display_name', models.CharField(max_length=200)),
|
||||||
('icon', models.CharField(default='🌎', max_length=200)),
|
('icon', models.CharField(default='🌍', max_length=200)),
|
||||||
('user_id', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
('user_id', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
|
|
|
@ -111,7 +111,7 @@ class Adventure(models.Model):
|
||||||
if force_insert and force_update:
|
if force_insert and force_update:
|
||||||
raise ValueError("Cannot force both insert and updating in model saving.")
|
raise ValueError("Cannot force both insert and updating in model saving.")
|
||||||
if not self.category:
|
if not self.category:
|
||||||
self.category = Category.objects.get_or_create(user_id=self.user_id, name='general', display_name='General', icon='🌎')[0]
|
self.category = Category.objects.get_or_create(user_id=self.user_id, name='general', display_name='General', icon='🌍')[0]
|
||||||
return super().save(force_insert, force_update, using, update_fields)
|
return super().save(force_insert, force_update, using, update_fields)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -260,7 +260,7 @@ class Category(models.Model):
|
||||||
User, on_delete=models.CASCADE, default=default_user_id)
|
User, on_delete=models.CASCADE, default=default_user_id)
|
||||||
name = models.CharField(max_length=200)
|
name = models.CharField(max_length=200)
|
||||||
display_name = models.CharField(max_length=200)
|
display_name = models.CharField(max_length=200)
|
||||||
icon = models.CharField(max_length=200, default='🌎')
|
icon = models.CharField(max_length=200, default='🌍')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name_plural = 'Categories'
|
verbose_name_plural = 'Categories'
|
||||||
|
|
|
@ -90,7 +90,7 @@ class AdventureSerializer(CustomModelSerializer):
|
||||||
if isinstance(category_data, dict):
|
if isinstance(category_data, dict):
|
||||||
name = category_data.get('name', '').lower()
|
name = category_data.get('name', '').lower()
|
||||||
display_name = category_data.get('display_name', name)
|
display_name = category_data.get('display_name', name)
|
||||||
icon = category_data.get('icon', '🌎')
|
icon = category_data.get('icon', '<EFBFBD>')
|
||||||
else:
|
else:
|
||||||
name = category_data.name.lower()
|
name = category_data.name.lower()
|
||||||
display_name = category_data.display_name
|
display_name = category_data.display_name
|
||||||
|
|
|
@ -644,7 +644,7 @@ class CategoryViewSet(viewsets.ModelViewSet):
|
||||||
general_category = Category.objects.filter(user_id=request.user, name='general').first()
|
general_category = Category.objects.filter(user_id=request.user, name='general').first()
|
||||||
|
|
||||||
if not general_category:
|
if not general_category:
|
||||||
general_category = Category.objects.create(user_id=request.user, name='general', icon='🌎', display_name='General')
|
general_category = Category.objects.create(user_id=request.user, name='general', icon='🌍', display_name='General')
|
||||||
|
|
||||||
Adventure.objects.filter(category=instance).update(category=general_category)
|
Adventure.objects.filter(category=instance).update(category=general_category)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ export default defineConfig({
|
||||||
title: "AdventureLog",
|
title: "AdventureLog",
|
||||||
description: "The ultimate travel companion.",
|
description: "The ultimate travel companion.",
|
||||||
lang: "en-US",
|
lang: "en-US",
|
||||||
|
// lastUpdated: true,
|
||||||
|
|
||||||
ignoreDeadLinks: [
|
ignoreDeadLinks: [
|
||||||
// ignore exact url "/playground"
|
// ignore exact url "/playground"
|
||||||
|
@ -33,6 +34,10 @@ export default defineConfig({
|
||||||
search: {
|
search: {
|
||||||
provider: "local",
|
provider: "local",
|
||||||
},
|
},
|
||||||
|
editLink: {
|
||||||
|
pattern:
|
||||||
|
"https://github.com/seanmorley15/AdventureLog/edit/main/documentation/:path",
|
||||||
|
},
|
||||||
|
|
||||||
footer: {
|
footer: {
|
||||||
message: "AdventureLog",
|
message: "AdventureLog",
|
||||||
|
|
|
@ -404,6 +404,18 @@
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log(adventure);
|
console.log(adventure);
|
||||||
if (adventure.id === '') {
|
if (adventure.id === '') {
|
||||||
|
console.log(categories);
|
||||||
|
if (categories.some((category) => category.name === 'general')) {
|
||||||
|
adventure.category = categories.find((category) => category.name === 'general') as Category;
|
||||||
|
} else {
|
||||||
|
adventure.category = {
|
||||||
|
id: '',
|
||||||
|
name: 'general',
|
||||||
|
display_name: 'General',
|
||||||
|
icon: '🌍',
|
||||||
|
user_id: ''
|
||||||
|
};
|
||||||
|
}
|
||||||
let res = await fetch('/api/adventures', {
|
let res = await fetch('/api/adventures', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
let category_to_edit: Category | null = null;
|
let category_to_edit: Category | null = null;
|
||||||
|
|
||||||
|
let is_changed: boolean = false;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
modal = document.getElementById('my_modal_1') as HTMLDialogElement;
|
modal = document.getElementById('my_modal_1') as HTMLDialogElement;
|
||||||
if (modal) {
|
if (modal) {
|
||||||
|
@ -39,6 +41,7 @@
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
|
is_changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +63,7 @@
|
||||||
});
|
});
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
categories = categories.filter((c) => c.id !== category.id);
|
categories = categories.filter((c) => c.id !== category.id);
|
||||||
|
is_changed = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -87,21 +91,44 @@
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if category_to_edit}
|
{#if category_to_edit}
|
||||||
<input
|
<h2 class="text-center text-xl font-semibold mt-2 mb-2">Edit Category</h2>
|
||||||
type="text"
|
<div class="flex flex-row space-x-2 form-control">
|
||||||
placeholder="Name"
|
<input
|
||||||
bind:value={category_to_edit.display_name}
|
type="text"
|
||||||
class="input input-bordered w-full max-w-xs"
|
placeholder="Name"
|
||||||
/>
|
bind:value={category_to_edit.display_name}
|
||||||
<input
|
class="input input-bordered w-full max-w-xs"
|
||||||
type="text"
|
/>
|
||||||
placeholder="Icon"
|
|
||||||
bind:value={category_to_edit.icon}
|
<input
|
||||||
class="input input-bordered w-full max-w-xs"
|
type="text"
|
||||||
/>
|
placeholder="Icon"
|
||||||
|
bind:value={category_to_edit.icon}
|
||||||
|
class="input input-bordered w-full max-w-xs"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<button class="btn btn-primary" on:click={saveCategory}>Save</button>
|
<button class="btn btn-primary" on:click={saveCategory}>Save</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<button class="btn btn-primary mt-4" on:click={close}>{$t('about.close')}</button>
|
<button class="btn btn-primary mt-4" on:click={close}>{$t('about.close')}</button>
|
||||||
|
|
||||||
|
{#if is_changed}
|
||||||
|
<div role="alert" class="alert alert-info mt-6">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
fill="none"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
class="h-6 w-6 shrink-0 stroke-current"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
stroke-width="2"
|
||||||
|
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||||
|
></path>
|
||||||
|
</svg>
|
||||||
|
<span>The adventure cards will be updated once you refresh the page.</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
|
@ -361,8 +361,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="divider"></div>
|
<div class="divider"></div>
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<br />
|
<p class="text-lg font-semibold mb-2">{$t('adventures.sources')}</p>
|
||||||
<p class="text-lg font-semibold mt-2 mb-2">{$t('adventures.sources')}</p>
|
|
||||||
<label class="label cursor-pointer">
|
<label class="label cursor-pointer">
|
||||||
<span class="label-text">{$t('adventures.collection_adventures')}</span>
|
<span class="label-text">{$t('adventures.collection_adventures')}</span>
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -265,9 +265,7 @@
|
||||||
<div>
|
<div>
|
||||||
<p class="text-sm text-muted-foreground">{$t('adventures.adventure_type')}</p>
|
<p class="text-sm text-muted-foreground">{$t('adventures.adventure_type')}</p>
|
||||||
<p class="text-base font-medium">
|
<p class="text-base font-medium">
|
||||||
{typeof adventure.category === 'object'
|
{adventure.category?.display_name + ' ' + adventure.category?.icon}
|
||||||
? `${adventure.category.display_name} ${adventure.category.icon}`
|
|
||||||
: ''}
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{#if data.props.collection}
|
{#if data.props.collection}
|
||||||
|
@ -339,8 +337,7 @@
|
||||||
<Popup openOn="click" offset={[0, -10]}>
|
<Popup openOn="click" offset={[0, -10]}>
|
||||||
<div class="text-lg text-black font-bold">{adventure.name}</div>
|
<div class="text-lg text-black font-bold">{adventure.name}</div>
|
||||||
<p class="font-semibold text-black text-md">
|
<p class="font-semibold text-black text-md">
|
||||||
{typeof adventure.category === 'object' && adventure.category.display_name}
|
{adventure.category?.display_name + ' ' + adventure.category?.icon}
|
||||||
{typeof adventure.category === 'object' && adventure.category.icon}
|
|
||||||
</p>
|
</p>
|
||||||
{#if adventure.visits.length > 0}
|
{#if adventure.visits.length > 0}
|
||||||
<p class="text-black text-sm">
|
<p class="text-black text-sm">
|
||||||
|
|
|
@ -126,7 +126,7 @@
|
||||||
on:click={togglePopup}
|
on:click={togglePopup}
|
||||||
>
|
>
|
||||||
<span class="text-xl">
|
<span class="text-xl">
|
||||||
{typeof adventure.category === 'object' ? adventure.category.icon : adventure.category}
|
{adventure.category?.display_name + ' ' + adventure.category?.icon}
|
||||||
</span>
|
</span>
|
||||||
{#if isPopupOpen}
|
{#if isPopupOpen}
|
||||||
<Popup openOn="click" offset={[0, -10]} on:close={() => (isPopupOpen = false)}>
|
<Popup openOn="click" offset={[0, -10]} on:close={() => (isPopupOpen = false)}>
|
||||||
|
@ -138,7 +138,7 @@
|
||||||
{adventure.is_visited ? $t('adventures.visited') : $t('adventures.planned')}
|
{adventure.is_visited ? $t('adventures.visited') : $t('adventures.planned')}
|
||||||
</p>
|
</p>
|
||||||
<p class="font-semibold text-black text-md">
|
<p class="font-semibold text-black text-md">
|
||||||
{adventure.category.display_name + ' ' + adventure.category.icon}
|
{adventure.category?.display_name + ' ' + adventure.category?.icon}
|
||||||
</p>
|
</p>
|
||||||
{#if adventure.visits && adventure.visits.length > 0}
|
{#if adventure.visits && adventure.visits.length > 0}
|
||||||
<p class="text-black text-sm">
|
<p class="text-black text-sm">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue