From 68a047904818d5e27d06b5fb8829ed27e4195c89 Mon Sep 17 00:00:00 2001 From: Spitfire Date: Wed, 14 Aug 2024 10:22:20 -0600 Subject: [PATCH] Races: Is extinct --- app/Datagrids/Bulks/RaceBulk.php | 5 ++++ app/Datagrids/Filters/RaceFilter.php | 1 + app/Http/Resources/RaceResource.php | 1 + app/Models/Race.php | 28 +++++++++++++++-- ..._14_145655_update_races_add_is_extinct.php | 30 +++++++++++++++++++ lang/en/races.php | 3 ++ resources/api-docs/1.0/races.md | 3 ++ .../entities/components/header.blade.php | 6 ++++ .../entities/pages/print/markdown.blade.php | 3 ++ resources/views/races/datagrid.blade.php | 11 +++++++ resources/views/races/form/_entry.blade.php | 7 +++++ 11 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2024_08_14_145655_update_races_add_is_extinct.php diff --git a/app/Datagrids/Bulks/RaceBulk.php b/app/Datagrids/Bulks/RaceBulk.php index d51f52bb3c..3ba29d01d4 100644 --- a/app/Datagrids/Bulks/RaceBulk.php +++ b/app/Datagrids/Bulks/RaceBulk.php @@ -11,7 +11,12 @@ class RaceBulk extends Bulk 'locations', 'tags', 'private_choice', + 'extinct_choice', 'entity_image', 'entity_header', ]; + + protected $booleans = [ + 'is_extinct', + ]; } diff --git a/app/Datagrids/Filters/RaceFilter.php b/app/Datagrids/Filters/RaceFilter.php index f9f6ce7612..ea86d3cfce 100644 --- a/app/Datagrids/Filters/RaceFilter.php +++ b/app/Datagrids/Filters/RaceFilter.php @@ -23,6 +23,7 @@ public function build() 'model' => Race::class, ]) ->location() + ->add('is_extinct') ->isPrivate() ->template() ->hasImage() diff --git a/app/Http/Resources/RaceResource.php b/app/Http/Resources/RaceResource.php index 9fdf2b5f40..580b9ce5ee 100644 --- a/app/Http/Resources/RaceResource.php +++ b/app/Http/Resources/RaceResource.php @@ -21,6 +21,7 @@ public function toArray($request) return $this->entity([ 'type' => $model->type, 'race_id' => $model->race_id, + 'is_extinct' => $model->isExtinct(), 'locations' => $locationIDs ]); } diff --git a/app/Models/Race.php b/app/Models/Race.php index cd69aacb64..9274948a0f 100644 --- a/app/Models/Race.php +++ b/app/Models/Race.php @@ -26,6 +26,7 @@ * @property Race[]|Collection $descendants * * @property ?int $race_id + * @property bool|int $is_extinct * @property Collection|CharacterRace[] $characterRaces */ class Race extends MiscModel @@ -49,6 +50,7 @@ class Race extends MiscModel 'type', 'entry', 'is_private', + 'is_extinct', 'race_id', ]; @@ -61,6 +63,11 @@ class Race extends MiscModel 'name', 'type', 'parent.name', + 'is_extinct', + ]; + + protected array $sortableColumns = [ + 'is_extinct', ]; /** @@ -71,6 +78,13 @@ class Race extends MiscModel 'race_id', ]; + protected array $exportFields = [ + 'base', + 'is_extinct', + ]; + + protected array $exploreGridFields = ['is_extinct']; + /** * Foreign relations to add to export */ @@ -127,7 +141,7 @@ public function scopePreparedWith(Builder $query): Builder */ public function datagridSelectFields(): array { - return ['race_id']; + return ['race_id', 'is_extinct']; } /** @@ -204,7 +218,8 @@ public function filterableColumns(): array return [ 'race_id', 'location_id', - 'parent' + 'parent', + 'is_extinct', ]; } @@ -225,6 +240,15 @@ public function showProfileInfo(): bool return parent::showProfileInfo(); } + + /** + * Determine if the model is extinct. + */ + public function isExtinct(): bool + { + return (bool) $this->is_extinct; + } + /** * Detach children when moving this entity from one campaign to another */ diff --git a/database/migrations/2024_08_14_145655_update_races_add_is_extinct.php b/database/migrations/2024_08_14_145655_update_races_add_is_extinct.php new file mode 100644 index 0000000000..40ee8b196f --- /dev/null +++ b/database/migrations/2024_08_14_145655_update_races_add_is_extinct.php @@ -0,0 +1,30 @@ +boolean('is_extinct')->default(0); + $table->index('is_extinct'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('races', function (Blueprint $table) { + $table->dropIndex('is_extinct'); + $table->dropColumn('is_extinct'); + }); + } +}; diff --git a/lang/en/races.php b/lang/en/races.php index ea0561302d..3e7e3507f7 100644 --- a/lang/en/races.php +++ b/lang/en/races.php @@ -20,6 +20,9 @@ 'title' => 'New Members', ], ], + 'hints' => [ + 'is_extinct' => 'This race is extinct.', + ], 'placeholders' => [ 'type' => 'Human, Fey, Borg', ], diff --git a/resources/api-docs/1.0/races.md b/resources/api-docs/1.0/races.md index 7dd8f08be0..edde3544e2 100644 --- a/resources/api-docs/1.0/races.md +++ b/resources/api-docs/1.0/races.md @@ -46,6 +46,7 @@ The list of returned entities can be filtered. The available filters are [availa "updated_by": 1, "race_id": 3, "type": null, + "is_extinct": true, "locations": [ 67, 66, @@ -85,6 +86,7 @@ To get the details of a single race, use the following endpoint. "updated_by": 1, "race_id": 3, "type": "Humanoid", + "is_extinct": true, "locations": [ 67, 66, @@ -112,6 +114,7 @@ To create a race, use the following endpoint. | `name` | `string` (Required) | Name of the race | | `entry` | `string` | The html description of the race | | `type` | `string` | The race's type | +| `is_extinct` | `boolean` | If the race is extinct | | `race_id` | `string` | Parent race of the race | | `tags` | `array` | Array of tag ids | | `entity_image_uuid` | `string` | Gallery image UUID for the entity image | diff --git a/resources/views/entities/components/header.blade.php b/resources/views/entities/components/header.blade.php index fc5daaf49c..5011cc2132 100644 --- a/resources/views/entities/components/header.blade.php +++ b/resources/views/entities/components/header.blade.php @@ -144,6 +144,12 @@ {{ __('locations.hints.is_destroyed') }} @endif + @if ($model instanceof \App\Models\Race && $model->isExtinct()) + + + {{ __('races.hints.is_extinct') }} + + @endif @if ($model instanceof \App\Models\Creature && $model->isExtinct()) diff --git a/resources/views/entities/pages/print/markdown.blade.php b/resources/views/entities/pages/print/markdown.blade.php index cab91b1ec1..b87b379213 100644 --- a/resources/views/entities/pages/print/markdown.blade.php +++ b/resources/views/entities/pages/print/markdown.blade.php @@ -22,6 +22,9 @@ @if ($model instanceof \App\Models\Creature && $model->isExtinct()) {{ __('creatures.hints.is_extinct') }} @endif +@if ($model instanceof \App\Models\Race && $model->isExtinct()) +{{ __('races.hints.is_extinct') }} +@endif @if ($model instanceof \App\Models\Creature && $model->isDead()) {{ __('creatures.hints.is_dead') }} @endif diff --git a/resources/views/races/datagrid.blade.php b/resources/views/races/datagrid.blade.php index 84aa14f71d..c8c0f11d48 100644 --- a/resources/views/races/datagrid.blade.php +++ b/resources/views/races/datagrid.blade.php @@ -20,6 +20,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/races/form/_entry.blade.php b/resources/views/races/form/_entry.blade.php index 9fe9e0b3f8..d0c8ba6a73 100644 --- a/resources/views/races/form/_entry.blade.php +++ b/resources/views/races/form/_entry.blade.php @@ -7,6 +7,13 @@ @include('cruds.fields.entry2') + + + + is_extinct ?? $model->is_extinct ?? false)) checked="checked" @endif /> + + + @include('cruds.fields.tags') @include('cruds.fields.image')