Skip to content

Commit

Permalink
Image and Header Image Bulk edit
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed Nov 29, 2023
1 parent 4abaf37 commit 229cd36
Show file tree
Hide file tree
Showing 23 changed files with 138 additions and 57 deletions.
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/AbilityBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ class AbilityBulk extends Bulk
'ability_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/AttributeTemplateBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ class AttributeTemplateBulk extends Bulk
//'attribute_template_id',
//'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
4 changes: 3 additions & 1 deletion app/Datagrids/Bulks/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ protected function defaults(): array
'name',
'type',
'tags',
'private_choice'
'private_choice',
'entity_image',
'entity_header',
];
}
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/CalendarBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ class CalendarBulk extends Bulk
'tags',
'private_choice',
'format',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/CharacterBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class CharacterBulk extends Bulk
'organisations',
'tags',
'private_choice',
'entity_image',
'entity_header',
];

protected array $booleans = [
Expand Down
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/ConversationBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ class ConversationBulk extends Bulk
'name',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/CreatureBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ class CreatureBulk extends Bulk
'creature_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/DiceRollBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ class DiceRollBulk extends Bulk
'character_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/EventBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ class EventBulk extends Bulk
'location_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/FamilyBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ class FamilyBulk extends Bulk
'location_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/ItemBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ class ItemBulk extends Bulk
'character_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/JournalBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ class JournalBulk extends Bulk
'location_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/LocationBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ class LocationBulk extends Bulk
'location_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/MapBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ class MapBulk extends Bulk
'map_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/NoteBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ class NoteBulk extends Bulk
'note_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
4 changes: 3 additions & 1 deletion app/Datagrids/Bulks/OrganisationBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class OrganisationBulk extends Bulk
'organisation_id',
'tags',
'private_choice',
'defunct_choice'
'defunct_choice',
'entity_image',
'entity_header',
];

protected array $booleans = [
Expand Down
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/QuestBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class QuestBulk extends Bulk
'completed_choice',
'tags',
'private_choice',
'entity_image',
'entity_header',
];

protected array $booleans = [
Expand Down
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/RaceBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ class RaceBulk extends Bulk
'race_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/TagBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class TagBulk extends Bulk
'private_choice',
'auto_applied_choice',
'hide_choice',
'entity_image',
'entity_header',
];

protected array $booleans = [
Expand Down
2 changes: 2 additions & 0 deletions app/Datagrids/Bulks/TimelineBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ class TimelineBulk extends Bulk
'timeline_id',
'tags',
'private_choice',
'entity_image',
'entity_header',
];
}
21 changes: 21 additions & 0 deletions app/Services/BulkService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
Expand Down
64 changes: 39 additions & 25 deletions resources/views/cruds/fields/entity_header.blade.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
@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;
} else {
$preset = FormCopy::field('header')->entity()->select();
}
@endphp
<x-forms.field
field="header-gallery"
:label="__('fields.gallery-header.description')">
<x-grid type="3/4">
<div class="col-span-3">
<x-forms.foreign
:campaign="$campaign"
name="entity_header_uuid"
:allowClear="true"
:route="route('images.find', $campaign)"
:label="__('crud.fields.image')"
:placeholder="__('fields.gallery.placeholder')"
:selected="$preset">
</x-forms.foreign>
</div>

<div class="preview">
@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
</div>
</x-grid>
</x-forms.field>
@if (isset($bulk) && !$campaign->boosted())
@include('cruds.fields.helpers.boosted', ['key' => 'fields.header-image.boosted-description'])
@else
<x-forms.field
field="header-gallery"
:label="$label">
<x-grid type="3/4">
<div class="col-span-3">
<x-forms.foreign
:campaign="$campaign"
:name="$name"
:allowClear="true"
:route="route('images.find', $campaign)"
:label="$description"
:placeholder="__('fields.gallery.placeholder')"
:selected="$preset">
</x-forms.foreign>
</div>

<div class="preview">
@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
</div>
</x-grid>
</x-forms.field>
@endif
@if (!empty($model->entity) && !empty($model->entity->image_uuid) && empty($model->entity->image))
<input type="hidden" name="entity_image_uuid" value="{{ $model->entity->image_uuid }}" />
@endif
66 changes: 36 additions & 30 deletions resources/views/cruds/fields/entity_image.blade.php
Original file line number Diff line number Diff line change
@@ -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))
<x-helper>
{{ __('fields.gallery-image.description') }}
</x-helper>
<x-grid type="3/4">
<div class="col-span-3">
<x-forms.foreign
:campaign="$campaign"
name="entity_image_uuid"
:allowClear="true"
:route="route('images.find', $campaign)"
:label="__('crud.fields.image')"
:placeholder="__('fields.gallery.placeholder')"
:selected="$preset">
</x-forms.foreign>
</div>
@if (!empty($model->entity) && !empty($model->entity->image_uuid) && !empty($model->entity->image))
<div class="preview-v2">
<a class="h-28 cover-background relative inline-block w-full text-white bg-red-900/50 hover:bg-red-900/90" href="{{ route('campaign.gallery.index', [$campaign, 'folder_id' => $model->entity->image->folder_id]) }}" style="background-image: url('{{ $model->entity->image->getUrl(240,112) }}')" title="{{ $model->name }}">
</a>
</div>
@endif
</x-grid>
@if (!empty($model->entity) && !empty($model->entity->image_uuid) && empty($model->entity->image))
<input type="hidden" name="entity_image_uuid" value="{{ $model->entity->image_uuid }}" />
@endif
@endif
<x-grid type="3/4">
<div class="col-span-3">
<x-forms.foreign
:campaign="$campaign"
:name="$name"
:allowClear="true"
:route="route('images.find', $campaign)"
:label="__('crud.fields.image')"
:placeholder="__('fields.gallery.placeholder')"
:selected="$preset">
</x-forms.foreign>
</div>
@if (!empty($model->entity) && !empty($model->entity->image_uuid) && !empty($model->entity->image))
<div class="preview-v2">
<a class="h-28 cover-background relative inline-block w-full text-white bg-red-900/50 hover:bg-red-900/90" href="{{ route('campaign.gallery.index', [$campaign, 'folder_id' => $model->entity->image->folder_id]) }}" style="background-image: url('{{ $model->entity->image->getUrl(240,112) }}')" title="{{ $model->name }}">
</a>
</div>
@endif
</x-grid>
@if (!empty($model->entity) && !empty($model->entity->image_uuid) && empty($model->entity->image))
<input type="hidden" name="entity_image_uuid" value="{{ $model->entity->image_uuid }}" />
@endif

0 comments on commit 229cd36

Please sign in to comment.