diff --git a/app/Datagrids/Bulks/CreatureBulk.php b/app/Datagrids/Bulks/CreatureBulk.php index b01c4653a5..4fbfb1c6bf 100644 --- a/app/Datagrids/Bulks/CreatureBulk.php +++ b/app/Datagrids/Bulks/CreatureBulk.php @@ -10,7 +10,12 @@ class CreatureBulk extends Bulk 'creature_id', 'tags', 'private_choice', + 'extinct_choice', 'entity_image', 'entity_header', ]; + + protected $booleans = [ + 'is_extinct' + ]; } diff --git a/app/Datagrids/Filters/CreatureFilter.php b/app/Datagrids/Filters/CreatureFilter.php index 2f167b6a64..45ac6e0ebd 100644 --- a/app/Datagrids/Filters/CreatureFilter.php +++ b/app/Datagrids/Filters/CreatureFilter.php @@ -23,6 +23,7 @@ public function build() 'model' => Creature::class, ]) ->location() + ->add('is_extinct') ->isPrivate() ->template() ->hasImage() diff --git a/app/Http/Resources/CreatureResource.php b/app/Http/Resources/CreatureResource.php index aec6231e31..8c4fc0c778 100644 --- a/app/Http/Resources/CreatureResource.php +++ b/app/Http/Resources/CreatureResource.php @@ -21,6 +21,7 @@ public function toArray($request) return $this->entity([ 'type' => $model->type, 'creature_id' => $model->creature_id, + 'is_extinct' => (bool) $model->is_extinct, 'locations' => $locationIDs ]); } diff --git a/app/Models/Creature.php b/app/Models/Creature.php index c43cc51742..3f1698461d 100644 --- a/app/Models/Creature.php +++ b/app/Models/Creature.php @@ -26,6 +26,7 @@ * @property Creature[] $creatures * @property Location|null $location * @property Collection|Location[] $locations + * @property bool $is_extinct */ class Creature extends MiscModel { @@ -47,6 +48,7 @@ class Creature extends MiscModel 'entry', 'is_private', 'creature_id', + 'is_extinct', ]; /** @@ -56,12 +58,14 @@ class Creature extends MiscModel protected array $sortableColumns = [ 'creature.name', + 'is_extinct', ]; protected array $sortable = [ 'name', 'type', 'creature.name', + 'is_extinct', ]; /** @@ -79,6 +83,11 @@ class Creature extends MiscModel 'pivotLocations', ]; + protected array $exportFields = [ + 'base', + 'is_extinct', + ]; + /** * @return string */ @@ -151,7 +160,7 @@ public function scopeLocation(Builder $query, int|null $location, FilterOption $ */ public function datagridSelectFields(): array { - return ['creature_id']; + return ['creature_id', 'is_extinct']; } /** @@ -202,7 +211,8 @@ public function filterableColumns(): array { return [ 'creature_id', - 'location_id' + 'location_id', + 'is_extinct', ]; } @@ -230,4 +240,12 @@ public function showProfileInfo(): bool return parent::showProfileInfo(); } + + /** + * Determine if the model is extinct. + */ + public function isExtinct(): bool + { + return (bool) $this->is_extinct; + } } diff --git a/app/Observers/CampaignObserver.php b/app/Observers/CampaignObserver.php index 2f15d9f5d2..95f36278be 100644 --- a/app/Observers/CampaignObserver.php +++ b/app/Observers/CampaignObserver.php @@ -53,7 +53,7 @@ public function saving(Campaign $campaign) $isPublic = request()->get('is_public', null); if (!empty($isPublic) && $previousVisibility == Campaign::VISIBILITY_PRIVATE) { $campaign->visibility_id = Campaign::VISIBILITY_PUBLIC; - // Default to public for now. Later will have REVIEW mode. + // Default to public for now. Later will have REVIEW mode. } elseif (empty($isPublic) && $previousVisibility != Campaign::VISIBILITY_PRIVATE) { $campaign->visibility_id = Campaign::VISIBILITY_PRIVATE; } diff --git a/app/Renderers/DatagridRenderer2.php b/app/Renderers/DatagridRenderer2.php index d475ea333a..3e9ccc320c 100644 --- a/app/Renderers/DatagridRenderer2.php +++ b/app/Renderers/DatagridRenderer2.php @@ -158,7 +158,7 @@ public function bulks(): array } continue; } - // More specific use cases? + // More specific use cases? } elseif ($bulk === Layout::ACTION_DELETE) { if (auth()->check() && auth()->user()->isAdmin()) { $this->bulks[] = $bulk; diff --git a/database/migrations/2024_01_25_192113_update_creatures_add_is_extinct.php b/database/migrations/2024_01_25_192113_update_creatures_add_is_extinct.php new file mode 100644 index 0000000000..c7f13a98a9 --- /dev/null +++ b/database/migrations/2024_01_25_192113_update_creatures_add_is_extinct.php @@ -0,0 +1,29 @@ +boolean('is_extinct')->default(0); + $table->index('is_extinct'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('creatures', function (Blueprint $table) { + $table->dropIndex(['is_extinct']); + $table->dropColumn('is_extinct'); + }); + } +}; diff --git a/lang/en/creatures.php b/lang/en/creatures.php index 0abb6bddb0..879f01380b 100644 --- a/lang/en/creatures.php +++ b/lang/en/creatures.php @@ -10,4 +10,10 @@ 'placeholders' => [ 'type' => 'Herbivore, Aquatic, Mythical', ], + 'fields' => [ + 'is_extinct' => 'Extinct', + ], + 'hints' => [ + 'is_extinct' => 'This creature is extinct.', + ], ]; diff --git a/resources/api-docs/1.0/creatures.md b/resources/api-docs/1.0/creatures.md index 88a98ff9ed..72dbbdf1e3 100644 --- a/resources/api-docs/1.0/creatures.md +++ b/resources/api-docs/1.0/creatures.md @@ -46,6 +46,7 @@ The list of returned creatures can be filtered. The available filters are availa "updated_by": 1, "creature_id": null, "type": "Bird", + "is_extinct": true, "locations": [ 67, 66, @@ -85,6 +86,7 @@ To get the details of a single creature, use the following endpoint. "updated_by": 1, "creature_id": null, "type": "Bird", + "is_extinct": true, "locations": [ 67, 66, @@ -116,6 +118,7 @@ To create a creature, use the following endpoint. | `tags` | `array` | Array of tag ids | | `locations` | `array` | Array of location ids | | `image_url` | `string` | URL to a picture to be used for the creature | +| `is_extinct` | `boolean` | If the creature is extinct | | `entity_image_uuid` | `string` | Gallery image UUID for the entity image (limited to superboosted campaigns) | | `entity_header_uuid` | `string` | Gallery image UUID for the entity header (limited to superboosted campaigns) | | `is_private` | `boolean` | If the creature is only visible to `admin` members of the campaign | diff --git a/resources/views/creatures/_tree.blade.php b/resources/views/creatures/_tree.blade.php index e399415e3e..d54e67130c 100644 --- a/resources/views/creatures/_tree.blade.php +++ b/resources/views/creatures/_tree.blade.php @@ -31,6 +31,17 @@ }, 'disableSort' => true, ], + [ + 'label' => '', + 'field' => 'is_extinct', + 'render' => function($model) { + if ($model->isExtinct()) { + return ''; + } + return ''; + }, + 'class' => 'icon' + ], [ 'type' => 'is_private', ] diff --git a/resources/views/creatures/datagrid.blade.php b/resources/views/creatures/datagrid.blade.php index 847416509e..a3c2f623b2 100644 --- a/resources/views/creatures/datagrid.blade.php +++ b/resources/views/creatures/datagrid.blade.php @@ -30,6 +30,17 @@ }, 'disableSort' => true, ], + [ + 'label' => '', + 'field' => 'is_extinct', + 'render' => function($model) { + if ($model->isExtinct()) { + return ''; + } + return ''; + }, + 'class' => 'icon' + ], [ 'type' => 'is_private', ] diff --git a/resources/views/creatures/form/_entry.blade.php b/resources/views/creatures/form/_entry.blade.php index 9b4a50a451..03f9733e0e 100644 --- a/resources/views/creatures/form/_entry.blade.php +++ b/resources/views/creatures/form/_entry.blade.php @@ -7,6 +7,13 @@ @include('cruds.fields.entry2') + + {!! Form::hidden('is_extinct', 0) !!} + + {!! Form::checkbox('is_extinct', 1, $model->is_extinct ?? '' )!!} + + + @include('cruds.fields.tags') @include('cruds.fields.image') diff --git a/resources/views/cruds/fields/extinct_choice.blade.php b/resources/views/cruds/fields/extinct_choice.blade.php new file mode 100644 index 0000000000..625f19f714 --- /dev/null +++ b/resources/views/cruds/fields/extinct_choice.blade.php @@ -0,0 +1,7 @@ + + + diff --git a/resources/views/entities/components/header.blade.php b/resources/views/entities/components/header.blade.php index afaa693c9f..68ad182936 100644 --- a/resources/views/entities/components/header.blade.php +++ b/resources/views/entities/components/header.blade.php @@ -138,7 +138,12 @@ {{ __('organisations.hints.is_defunct') }} @endif - + @if ($model instanceof \App\Models\Creature && $model->isExtinct()) + + + {{ __('creatures.hints.is_extinct') }} + + @endif @if (auth()->check() && auth()->user()->isAdmin())