@@ -67,6 +72,7 @@ onMounted(() => {
ref="input"
class="w-full rounded-md border-0 bg-white dark:bg-gray-900 py-1.5 pl-3 pr-12 text-gray-900 dark:text-gray-300 shadow-sm ring-1 ring-inset ring-gray-300 dark:ring-gray-700 focus:ring-2 focus:ring-inset focus:ring-indigo-500 dark:focus:ring-indigo-600 sm:text-sm sm:leading-6"
:displayValue="(item) => item?.name"
+ :placeholder="placeholder"
@change="query = $event.target.value"
@focus="$event.target.select()"
autocomplete="off"
@@ -96,8 +102,7 @@ onMounted(() => {
@after-leave="query = ''"
>
{
+ return [
+ selectedMaterialTag.value?.id,
+ selectedBrandTag.value?.id,
+ selectedEventTag.value?.id,
+ selectedStateTag.value?.id,
+ selectedContentTag.value?.id,
+ selectedSizeTag.value?.id,
+ ].filter(tag => tag);
+});
const tagNames = computed(() => {
return item.value.tag_ids.map(function (tagId) {
@@ -32,13 +43,17 @@ const tagNames = computed(() => {
});
});
-const addTagToItem = (tag) => {
- if (item.value.tag_ids.find(itemTag => itemTag === tag.id)) {
- return;
- }
+const addTagsToItem = () => {
+ item.value.tag_ids = [...new Set([...item.value.tag_ids, ...selectedTagIds.value])];
- item.value.tag_ids.push(tag.id);
emit('change', item.value);
+
+ selectedMaterialTag.value = null;
+ selectedBrandTag.value = null;
+ selectedEventTag.value = null;
+ selectedStateTag.value = null;
+ selectedContentTag.value = null;
+ selectedSizeTag.value = null;
};
const removeTagFromItem = (tagId) => {
@@ -75,110 +90,63 @@ const copyItem = () => {
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
{
aria-hidden="true">
{{ tag.name }}
-
+
+
+
diff --git a/resources/js/Pages/Photos/Partials/PhotoItem.vue b/resources/js/Pages/Photos/Partials/PhotoItem.vue
index c7859395..dfae199a 100644
--- a/resources/js/Pages/Photos/Partials/PhotoItem.vue
+++ b/resources/js/Pages/Photos/Partials/PhotoItem.vue
@@ -1,5 +1,5 @@
@@ -35,103 +69,57 @@ const selectedSizeTag = ref(props.tags.size[0]);
-
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ Add Selected Tags
+
+
diff --git a/resources/js/Pages/Photos/Show.vue b/resources/js/Pages/Photos/Show.vue
index 343b6687..f41092b7 100644
--- a/resources/js/Pages/Photos/Show.vue
+++ b/resources/js/Pages/Photos/Show.vue
@@ -70,9 +70,9 @@ const copyItem = (photoItemId) => {
});
};
-const addTagToItem = (photoItem, tagId) => {
+const addTagsToItem = (photoItem, tagIds) => {
axios.post(`/photo-items/${photoItem.id}/tags`, {
- tag_id: tagId,
+ tag_ids: tagIds,
}).then(() => {
getPhoto();
});
@@ -206,7 +206,7 @@ const onKeyDown = (event) => {
:item="item"
:tags="tags"
@remove-item="removeItem"
- @add-tag-to-item="addTagToItem"
+ @add-tags-to-item="addTagsToItem"
@remove-tag-from-item="removeTagFromItem"
@copy-item="copyItem"
@toggle-picked-up="toggleItemPickedUp"
diff --git a/tests/Feature/Tagging/AddTagToPhotoItemTest.php b/tests/Feature/Tagging/AddTagToPhotoItemTest.php
index 8dec8508..d8afc5e3 100644
--- a/tests/Feature/Tagging/AddTagToPhotoItemTest.php
+++ b/tests/Feature/Tagging/AddTagToPhotoItemTest.php
@@ -6,22 +6,27 @@
use App\Models\Tag;
use App\Models\User;
-test('a user can add a tag to an item of a photo', function () {
+test('a user can add tags to an item of a photo', function () {
$user = User::factory()->create();
$photo = Photo::factory()->for($user)->create();
$item = Item::factory()->create();
$photoItem = PhotoItem::factory()->for($item)->for($photo)->create();
- $tag = Tag::factory()->create();
+ $tagA = Tag::factory()->create();
+ $tagB = Tag::factory()->create();
$response = $this->actingAs($user)->postJson("/photo-items/{$photoItem->id}/tags", [
- 'tag_id' => $tag->id,
+ 'tag_ids' => [$tagA->id, $tagB->id],
]);
$response->assertOk();
- $this->assertDatabaseCount('photo_item_tag', 1);
+ $this->assertDatabaseCount('photo_item_tag', 2);
+ $this->assertDatabaseHas('photo_item_tag', [
+ 'photo_item_id' => $photoItem->id,
+ 'tag_id' => $tagA->id,
+ ]);
$this->assertDatabaseHas('photo_item_tag', [
'photo_item_id' => $photoItem->id,
- 'tag_id' => $tag->id,
+ 'tag_id' => $tagB->id,
]);
});
@@ -32,11 +37,11 @@
$photoItem = PhotoItem::factory()->for($item)->for($photo)->create();
$response = $this->actingAs($user)->postJson("/photo-items/{$photoItem->id}/tags", [
- 'tag_id' => '12345',
+ 'tag_ids' => ['12345'],
]);
$response->assertStatus(422);
- $response->assertJsonValidationErrors('tag_id');
+ $response->assertJsonValidationErrors('tag_ids.0');
$this->assertDatabaseCount('photo_item_tag', 0);
});
@@ -48,7 +53,7 @@
$tag = Tag::factory()->create();
$response = $this->actingAs($user)->postJson("/photo-items/{$photoItem->id}/tags", [
- 'tag_id' => $tag->id,
+ 'tag_ids' => [$tag->id],
]);
$response->assertNotFound();