From 9924cf902c498080c942b94ac6959e40bf507046 Mon Sep 17 00:00:00 2001 From: Spitfire Date: Wed, 14 Aug 2024 12:43:44 -0600 Subject: [PATCH] families: extinct --- app/Datagrids/Bulks/FamilyBulk.php | 5 ++++ app/Datagrids/Filters/FamilyFilter.php | 1 + app/Http/Resources/FamilyResource.php | 1 + app/Models/Family.php | 18 ++++++++++- ..._164041_update_families_add_is_extinct.php | 30 +++++++++++++++++++ lang/en/families.php | 1 + resources/api-docs/1.0/families.md | 3 ++ .../entities/components/header.blade.php | 6 ++++ .../entities/pages/print/markdown.blade.php | 3 ++ resources/views/families/datagrid.blade.php | 11 +++++++ .../views/families/form/_entry.blade.php | 7 +++++ 11 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2024_08_14_164041_update_families_add_is_extinct.php diff --git a/app/Datagrids/Bulks/FamilyBulk.php b/app/Datagrids/Bulks/FamilyBulk.php index 524b7b67d6..5303674966 100644 --- a/app/Datagrids/Bulks/FamilyBulk.php +++ b/app/Datagrids/Bulks/FamilyBulk.php @@ -11,7 +11,12 @@ class FamilyBulk extends Bulk 'location_id', 'tags', 'private_choice', + 'extinct_choice', 'entity_image', 'entity_header', ]; + + protected $booleans = [ + 'is_extinct', + ]; } diff --git a/app/Datagrids/Filters/FamilyFilter.php b/app/Datagrids/Filters/FamilyFilter.php index ea4d5a8a55..29a3f0c376 100644 --- a/app/Datagrids/Filters/FamilyFilter.php +++ b/app/Datagrids/Filters/FamilyFilter.php @@ -24,6 +24,7 @@ public function build() ]) ->location() ->character('member_id') + ->add('is_extinct') ->isPrivate() ->template() ->hasImage() diff --git a/app/Http/Resources/FamilyResource.php b/app/Http/Resources/FamilyResource.php index 51e8be5534..1854464515 100644 --- a/app/Http/Resources/FamilyResource.php +++ b/app/Http/Resources/FamilyResource.php @@ -19,6 +19,7 @@ public function toArray($request) return $this->entity([ 'type' => $model->type, 'family_id' => $model->family_id, + 'is_extinct' => $model->isExtinct(), 'members' => $model->members()->pluck('character_id')->toArray() ]); } diff --git a/app/Models/Family.php b/app/Models/Family.php index a084e3d51a..4ce81786c9 100644 --- a/app/Models/Family.php +++ b/app/Models/Family.php @@ -25,6 +25,7 @@ * Class Family * @package App\Models * @property ?int $family_id + * @property bool|int $is_extinct * @property Collection|Character[] $members * @property ?FamilyTree $familyTree * @property Collection|Family[] $descendants @@ -53,6 +54,7 @@ class Family extends MiscModel 'family_id', 'is_private', 'type', + 'is_extinct', ]; /** @@ -60,6 +62,7 @@ class Family extends MiscModel */ protected array $sortableColumns = [ 'location.name', + 'is_extinct', ]; protected array $sortable = [ @@ -67,6 +70,7 @@ class Family extends MiscModel 'type', 'location.name', 'parent.name', + 'is_extinct', ]; /** @@ -80,8 +84,11 @@ class Family extends MiscModel 'base', 'family_id', 'location_id', + 'is_extinct', ]; + protected array $exploreGridFields = ['is_extinct']; + /** * Nullable values (foreign keys) * @var string[] @@ -190,7 +197,7 @@ public function scopeMember(Builder $query, string|null $value, FilterOption $fi */ public function datagridSelectFields(): array { - return ['family_id', 'location_id']; + return ['family_id', 'location_id', 'is_extinct']; } public function familyTree(): HasOne @@ -270,6 +277,14 @@ public function entityTypeId(): int return (int) config('entities.ids.family'); } + /** + * Determine if the model is extinct. + */ + public function isExtinct(): bool + { + return (bool) $this->is_extinct; + } + /** * Determine if the model has profile data to be displayed */ @@ -295,6 +310,7 @@ public function filterableColumns(): array 'location_id', 'family_id', 'member_id', + 'is_extinct', 'parent' ]; } diff --git a/database/migrations/2024_08_14_164041_update_families_add_is_extinct.php b/database/migrations/2024_08_14_164041_update_families_add_is_extinct.php new file mode 100644 index 0000000000..90a174e2ef --- /dev/null +++ b/database/migrations/2024_08_14_164041_update_families_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('families', function (Blueprint $table) { + $table->dropIndex('is_extinct'); + $table->dropColumn('is_extinct'); + }); + } +}; diff --git a/lang/en/families.php b/lang/en/families.php index 336b0c7b4b..3ba985ecc6 100644 --- a/lang/en/families.php +++ b/lang/en/families.php @@ -9,6 +9,7 @@ ], 'hints' => [ 'members' => 'Members of a family are listed here. A character can be added to a family by editing the desired character and using the "Family" dropdown.', + 'is_extinct' => 'This family is extinct.', ], 'members' => [ 'create' => [ diff --git a/resources/api-docs/1.0/families.md b/resources/api-docs/1.0/families.md index 20e0406212..edfb4fa085 100644 --- a/resources/api-docs/1.0/families.md +++ b/resources/api-docs/1.0/families.md @@ -49,6 +49,7 @@ The list of returned entities can be filtered. The available filters are [availa "updated_at": "2019-08-29T13:48:54.000000Z", "updated_by": 1, "location_id": 4, + "is_extinct": true, "type": "", "family_id": 2, "members": [ @@ -87,6 +88,7 @@ To get the details of a single family, use the following endpoint. "updated_at": "2019-08-29T13:48:54.000000Z", "updated_by": 1, "location_id": 1, + "is_extinct": true, "type": "", "family_id": 2, "members": [ @@ -119,6 +121,7 @@ To create a family, use the following endpoint. | `type` | `string` | The type of family | | `location_id` | `integer` | The family's location id | | `family_id` | `integer` | The parent family id | +| `is_extinct` | `boolean` | If the family is extinct | | `tags` | `array` | Array of tag ids | | `entity_image_uuid` | `string` | Gallery image UUID for the entity image | | `entity_header_uuid` | `string` | Gallery image UUID for the entity header (limited to premium campaigns) | diff --git a/resources/views/entities/components/header.blade.php b/resources/views/entities/components/header.blade.php index fc5daaf49c..85c15fc29e 100644 --- a/resources/views/entities/components/header.blade.php +++ b/resources/views/entities/components/header.blade.php @@ -156,6 +156,12 @@ {{ __('creatures.hints.is_dead') }} @endif + @if ($model instanceof \App\Models\Family && $model->isExtinct()) + + + {{ __('families.hints.is_extinct') }} + + @endif @if (auth()->check() && auth()->user()->isAdmin()) diff --git a/resources/views/entities/pages/print/markdown.blade.php b/resources/views/entities/pages/print/markdown.blade.php index cab91b1ec1..ef966ca8bc 100644 --- a/resources/views/entities/pages/print/markdown.blade.php +++ b/resources/views/entities/pages/print/markdown.blade.php @@ -25,6 +25,9 @@ @if ($model instanceof \App\Models\Creature && $model->isDead()) {{ __('creatures.hints.is_dead') }} @endif +@if ($model instanceof \App\Models\Family && $model->isExtinct()) +{{ __('families.hints.is_extinct') }} +@endif @if ($model instanceof \App\Models\Character && !empty($model->title)) {{ $model->title }} diff --git a/resources/views/families/datagrid.blade.php b/resources/views/families/datagrid.blade.php index 1b47459db9..aa4dae979f 100644 --- a/resources/views/families/datagrid.blade.php +++ b/resources/views/families/datagrid.blade.php @@ -24,6 +24,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/families/form/_entry.blade.php b/resources/views/families/form/_entry.blade.php index 51e5dde1c2..86f3ff5052 100644 --- a/resources/views/families/form/_entry.blade.php +++ b/resources/views/families/form/_entry.blade.php @@ -19,6 +19,13 @@ @endif + + + + is_extinct ?? $model->is_extinct ?? false)) checked="checked" @endif /> + + + @include('cruds.fields.tags') @include('cruds.fields.image')