From 229cd366cc8cb688fd13406c1b5787ded31a3a7f Mon Sep 17 00:00:00 2001 From: Spitfire Date: Wed, 29 Nov 2023 10:59:12 -0600 Subject: [PATCH] Image and Header Image Bulk edit --- app/Datagrids/Bulks/AbilityBulk.php | 2 + app/Datagrids/Bulks/AttributeTemplateBulk.php | 2 + app/Datagrids/Bulks/Bulk.php | 4 +- app/Datagrids/Bulks/CalendarBulk.php | 2 + app/Datagrids/Bulks/CharacterBulk.php | 2 + app/Datagrids/Bulks/ConversationBulk.php | 2 + app/Datagrids/Bulks/CreatureBulk.php | 2 + app/Datagrids/Bulks/DiceRollBulk.php | 2 + app/Datagrids/Bulks/EventBulk.php | 2 + app/Datagrids/Bulks/FamilyBulk.php | 2 + app/Datagrids/Bulks/ItemBulk.php | 2 + app/Datagrids/Bulks/JournalBulk.php | 2 + app/Datagrids/Bulks/LocationBulk.php | 2 + app/Datagrids/Bulks/MapBulk.php | 2 + app/Datagrids/Bulks/NoteBulk.php | 2 + app/Datagrids/Bulks/OrganisationBulk.php | 4 +- app/Datagrids/Bulks/QuestBulk.php | 2 + app/Datagrids/Bulks/RaceBulk.php | 2 + app/Datagrids/Bulks/TagBulk.php | 2 + app/Datagrids/Bulks/TimelineBulk.php | 2 + app/Services/BulkService.php | 21 ++++++ .../cruds/fields/entity_header.blade.php | 64 +++++++++++------- .../views/cruds/fields/entity_image.blade.php | 66 ++++++++++--------- 23 files changed, 138 insertions(+), 57 deletions(-) diff --git a/app/Datagrids/Bulks/AbilityBulk.php b/app/Datagrids/Bulks/AbilityBulk.php index 9bd3d0496b..1e4a6ddb35 100644 --- a/app/Datagrids/Bulks/AbilityBulk.php +++ b/app/Datagrids/Bulks/AbilityBulk.php @@ -10,5 +10,7 @@ class AbilityBulk extends Bulk 'ability_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/AttributeTemplateBulk.php b/app/Datagrids/Bulks/AttributeTemplateBulk.php index 249df3252b..d8a24bc86b 100644 --- a/app/Datagrids/Bulks/AttributeTemplateBulk.php +++ b/app/Datagrids/Bulks/AttributeTemplateBulk.php @@ -9,5 +9,7 @@ class AttributeTemplateBulk extends Bulk //'attribute_template_id', //'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/Bulk.php b/app/Datagrids/Bulks/Bulk.php index 34e60cf4ce..281384fdca 100644 --- a/app/Datagrids/Bulks/Bulk.php +++ b/app/Datagrids/Bulks/Bulk.php @@ -68,7 +68,9 @@ protected function defaults(): array 'name', 'type', 'tags', - 'private_choice' + 'private_choice', + 'entity_image', + 'entity_header', ]; } } diff --git a/app/Datagrids/Bulks/CalendarBulk.php b/app/Datagrids/Bulks/CalendarBulk.php index 170c5d179b..7c161ce9ca 100644 --- a/app/Datagrids/Bulks/CalendarBulk.php +++ b/app/Datagrids/Bulks/CalendarBulk.php @@ -11,5 +11,7 @@ class CalendarBulk extends Bulk 'tags', 'private_choice', 'format', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/CharacterBulk.php b/app/Datagrids/Bulks/CharacterBulk.php index 399137d9c3..f7c163f1a5 100644 --- a/app/Datagrids/Bulks/CharacterBulk.php +++ b/app/Datagrids/Bulks/CharacterBulk.php @@ -17,6 +17,8 @@ class CharacterBulk extends Bulk 'organisations', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; protected array $booleans = [ diff --git a/app/Datagrids/Bulks/ConversationBulk.php b/app/Datagrids/Bulks/ConversationBulk.php index 8650012b43..3c0f23ddf3 100644 --- a/app/Datagrids/Bulks/ConversationBulk.php +++ b/app/Datagrids/Bulks/ConversationBulk.php @@ -8,5 +8,7 @@ class ConversationBulk extends Bulk 'name', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/CreatureBulk.php b/app/Datagrids/Bulks/CreatureBulk.php index 60ad7ce644..b01c4653a5 100644 --- a/app/Datagrids/Bulks/CreatureBulk.php +++ b/app/Datagrids/Bulks/CreatureBulk.php @@ -10,5 +10,7 @@ class CreatureBulk extends Bulk 'creature_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/DiceRollBulk.php b/app/Datagrids/Bulks/DiceRollBulk.php index 1d523d16ab..7c6ad3d3e4 100644 --- a/app/Datagrids/Bulks/DiceRollBulk.php +++ b/app/Datagrids/Bulks/DiceRollBulk.php @@ -9,5 +9,7 @@ class DiceRollBulk extends Bulk 'character_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/EventBulk.php b/app/Datagrids/Bulks/EventBulk.php index 1d59fd4e7e..4b78e63883 100644 --- a/app/Datagrids/Bulks/EventBulk.php +++ b/app/Datagrids/Bulks/EventBulk.php @@ -11,5 +11,7 @@ class EventBulk extends Bulk 'location_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/FamilyBulk.php b/app/Datagrids/Bulks/FamilyBulk.php index b621017de9..524b7b67d6 100644 --- a/app/Datagrids/Bulks/FamilyBulk.php +++ b/app/Datagrids/Bulks/FamilyBulk.php @@ -11,5 +11,7 @@ class FamilyBulk extends Bulk 'location_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/ItemBulk.php b/app/Datagrids/Bulks/ItemBulk.php index 37b3dd9c38..f4e1792c9e 100644 --- a/app/Datagrids/Bulks/ItemBulk.php +++ b/app/Datagrids/Bulks/ItemBulk.php @@ -14,5 +14,7 @@ class ItemBulk extends Bulk 'character_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/JournalBulk.php b/app/Datagrids/Bulks/JournalBulk.php index bae0fa11ae..4ddb3e290f 100644 --- a/app/Datagrids/Bulks/JournalBulk.php +++ b/app/Datagrids/Bulks/JournalBulk.php @@ -12,5 +12,7 @@ class JournalBulk extends Bulk 'location_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/LocationBulk.php b/app/Datagrids/Bulks/LocationBulk.php index 7cfff7f919..55c6fdd3fa 100644 --- a/app/Datagrids/Bulks/LocationBulk.php +++ b/app/Datagrids/Bulks/LocationBulk.php @@ -10,5 +10,7 @@ class LocationBulk extends Bulk 'location_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/MapBulk.php b/app/Datagrids/Bulks/MapBulk.php index 17211dd923..8ff59eac28 100644 --- a/app/Datagrids/Bulks/MapBulk.php +++ b/app/Datagrids/Bulks/MapBulk.php @@ -10,5 +10,7 @@ class MapBulk extends Bulk 'map_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/NoteBulk.php b/app/Datagrids/Bulks/NoteBulk.php index 9dd545437e..f8ff0378b8 100644 --- a/app/Datagrids/Bulks/NoteBulk.php +++ b/app/Datagrids/Bulks/NoteBulk.php @@ -10,5 +10,7 @@ class NoteBulk extends Bulk 'note_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/OrganisationBulk.php b/app/Datagrids/Bulks/OrganisationBulk.php index 57fc70dd61..30fe6b6574 100644 --- a/app/Datagrids/Bulks/OrganisationBulk.php +++ b/app/Datagrids/Bulks/OrganisationBulk.php @@ -11,7 +11,9 @@ class OrganisationBulk extends Bulk 'organisation_id', 'tags', 'private_choice', - 'defunct_choice' + 'defunct_choice', + 'entity_image', + 'entity_header', ]; protected array $booleans = [ diff --git a/app/Datagrids/Bulks/QuestBulk.php b/app/Datagrids/Bulks/QuestBulk.php index 17c275ce22..b78e052ddd 100644 --- a/app/Datagrids/Bulks/QuestBulk.php +++ b/app/Datagrids/Bulks/QuestBulk.php @@ -12,6 +12,8 @@ class QuestBulk extends Bulk 'completed_choice', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; protected array $booleans = [ diff --git a/app/Datagrids/Bulks/RaceBulk.php b/app/Datagrids/Bulks/RaceBulk.php index 37e3e04107..d2feef01f2 100644 --- a/app/Datagrids/Bulks/RaceBulk.php +++ b/app/Datagrids/Bulks/RaceBulk.php @@ -10,5 +10,7 @@ class RaceBulk extends Bulk 'race_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Datagrids/Bulks/TagBulk.php b/app/Datagrids/Bulks/TagBulk.php index decc834df3..7bafb7391a 100644 --- a/app/Datagrids/Bulks/TagBulk.php +++ b/app/Datagrids/Bulks/TagBulk.php @@ -12,6 +12,8 @@ class TagBulk extends Bulk 'private_choice', 'auto_applied_choice', 'hide_choice', + 'entity_image', + 'entity_header', ]; protected array $booleans = [ diff --git a/app/Datagrids/Bulks/TimelineBulk.php b/app/Datagrids/Bulks/TimelineBulk.php index cd51a2ca40..37006f95d6 100644 --- a/app/Datagrids/Bulks/TimelineBulk.php +++ b/app/Datagrids/Bulks/TimelineBulk.php @@ -10,5 +10,7 @@ class TimelineBulk extends Bulk 'timeline_id', 'tags', 'private_choice', + 'entity_image', + 'entity_header', ]; } diff --git a/app/Services/BulkService.php b/app/Services/BulkService.php index faf6d24a47..efa8ccf4ed 100644 --- a/app/Services/BulkService.php +++ b/app/Services/BulkService.php @@ -273,6 +273,16 @@ public function editing(array $fields, Bulk $bulk): int unset($filledFields['tags']); $tagIds = Arr::get($fields, 'tags', []); + // Handle images differently + if (isset($filledFields['entity_image'])) { + $imageUuid = $filledFields['entity_image']; + unset($filledFields['entity_image']); + } + if (isset($filledFields['entity_header'])) { + $headerUuid = $filledFields['entity_header']; + unset($filledFields['entity_header']); + } + if ($this->entityName === 'relations') { $mirrorOptions = []; $mirrorOptions['unmirror'] = (bool) Arr::get($fields, 'unmirror', '0'); @@ -320,6 +330,17 @@ public function editing(array $fields, Bulk $bulk): int if (!empty($entity->entity)) { $realEntity = $entity->entity; + if (isset($imageUuid)) { + $realEntity->image_uuid = $imageUuid; + // Changed the image, reset the focus + $realEntity->focus_x = null; + $realEntity->focus_y = null; + } + + if (isset($headerUuid)) { + $realEntity->header_uuid = $headerUuid; + } + $realEntity->is_private = $entity->is_private; $realEntity->name = $entity->name; $realEntity->save(); diff --git a/resources/views/cruds/fields/entity_header.blade.php b/resources/views/cruds/fields/entity_header.blade.php index 930db2a4be..003f8dde84 100644 --- a/resources/views/cruds/fields/entity_header.blade.php +++ b/resources/views/cruds/fields/entity_header.blade.php @@ -1,4 +1,14 @@ @php +$name = 'entity_header_uuid'; +$label = __('fields.gallery-header.description'); +$description = __('crud.fields.image'); + +if (isset($bulk)) { + $name = 'entity_header'; + $label = __('fields.header-image.title'); + $description = ''; +} + $preset = null; if (isset($model) && $model->entity && $model->entity->header_uuid) { $preset = $model->entity->header; @@ -6,33 +16,37 @@ $preset = FormCopy::field('header')->entity()->select(); } @endphp - - -
- - -
-
- @if (!empty($model->entity) && !empty($model->entity->header_uuid) && !empty($model->entity->header)) - @include('cruds.fields._image_preview', [ - 'image' => $model->entity->header->getUrl(80, null, 'header_image'), - 'title' => $model->name, - ]) - @endif -
-
-
+@if (isset($bulk) && !$campaign->boosted()) + @include('cruds.fields.helpers.boosted', ['key' => 'fields.header-image.boosted-description']) +@else + + +
+ + +
+
+ @if (!empty($model->entity) && !empty($model->entity->header_uuid) && !empty($model->entity->header)) + @include('cruds.fields._image_preview', [ + 'image' => $model->entity->header->getUrl(80, null, 'header_image'), + 'title' => $model->name, + ]) + @endif +
+
+
+@endif @if (!empty($model->entity) && !empty($model->entity->image_uuid) && empty($model->entity->image)) @endif diff --git a/resources/views/cruds/fields/entity_image.blade.php b/resources/views/cruds/fields/entity_image.blade.php index dfc0c943d8..c81ff60bc0 100644 --- a/resources/views/cruds/fields/entity_image.blade.php +++ b/resources/views/cruds/fields/entity_image.blade.php @@ -1,35 +1,41 @@ - @php - $preset = null; - if (isset($model) && $model->entity && $model->entity->image_uuid) { - $preset = $model->entity->image; - } else { - $preset = FormCopy::field('image')->entity()->select(); - } - @endphp +@php +$preset = null; +$name = 'entity_image_uuid'; +if (isset($bulk)) { + $name = 'entity_image'; +} +if (isset($model) && $model->entity && $model->entity->image_uuid) { + $preset = $model->entity->image; +} else { + $preset = FormCopy::field('image')->entity()->select(); +} +@endphp +@if(!isset($bulk)) {{ __('fields.gallery-image.description') }} - -
- - -
- @if (!empty($model->entity) && !empty($model->entity->image_uuid) && !empty($model->entity->image)) -
- - -
- @endif -
- @if (!empty($model->entity) && !empty($model->entity->image_uuid) && empty($model->entity->image)) - - @endif +@endif + +
+ + +
+ @if (!empty($model->entity) && !empty($model->entity->image_uuid) && !empty($model->entity->image)) +
+ + +
+ @endif +
+@if (!empty($model->entity) && !empty($model->entity->image_uuid) && empty($model->entity->image)) + +@endif