Skip to content

Commit

Permalink
families: extinct
Browse files Browse the repository at this point in the history
  • Loading branch information
spitfire305 committed Aug 14, 2024
1 parent 986840e commit 9924cf9
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/Datagrids/Bulks/FamilyBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ class FamilyBulk extends Bulk
'location_id',
'tags',
'private_choice',
'extinct_choice',
'entity_image',
'entity_header',
];

protected $booleans = [
'is_extinct',
];
}
1 change: 1 addition & 0 deletions app/Datagrids/Filters/FamilyFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function build()
])
->location()
->character('member_id')
->add('is_extinct')
->isPrivate()
->template()
->hasImage()
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/FamilyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
]);
}
Expand Down
18 changes: 17 additions & 1 deletion app/Models/Family.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,20 +54,23 @@ class Family extends MiscModel
'family_id',
'is_private',
'type',
'is_extinct',
];

/**
* Fields that can be sorted on
*/
protected array $sortableColumns = [
'location.name',
'is_extinct',
];

protected array $sortable = [
'name',
'type',
'location.name',
'parent.name',
'is_extinct',
];

/**
Expand All @@ -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[]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand All @@ -295,6 +310,7 @@ public function filterableColumns(): array
'location_id',
'family_id',
'member_id',
'is_extinct',
'parent'
];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('families', function (Blueprint $table) {
$table->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');
});
}
};
1 change: 1 addition & 0 deletions lang/en/families.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
3 changes: 3 additions & 0 deletions resources/api-docs/1.0/families.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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) |
Expand Down
6 changes: 6 additions & 0 deletions resources/views/entities/components/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@
<span class="sr-only">{{ __('creatures.hints.is_dead') }}</span>
</span>
@endif
@if ($model instanceof \App\Models\Family && $model->isExtinct())
<span class="entity-name-icon entity-fam-extinct cursor-pointer text-2xl" data-toggle="tooltip" data-title="{{ __('families.hints.is_extinct') }}">
<x-icon class="ra ra-skull entity-icons " />
<span class="sr-only">{{ __('families.hints.is_extinct') }}</span>
</span>
@endif
@if (auth()->check() && auth()->user()->isAdmin())
<span role="button" tabindex="0" class="entity-privacy-icon" data-toggle="dialog" data-url="{{ route('entities.quick-privacy', [$campaign, $model->entity]) }}" data-target="primary-dialog" aria-haspopup="dialog">
<i class="fa-solid fa-lock entity-icons text-2xl" data-title="{{ __('entities/permissions.quick.title') }}" data-toggle="tooltip" aria-hidden="true"></i>
Expand Down
3 changes: 3 additions & 0 deletions resources/views/entities/pages/print/markdown.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
11 changes: 11 additions & 0 deletions resources/views/families/datagrid.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
},
'disableSort' => true,
],
[
'label' => '<i class="ra ra-skull" title="' . __('creatures.fields.is_extinct') . '"></i>',
'field' => 'is_extinct',
'render' => function($model) {
if ($model->isExtinct()) {
return '<i class="ra ra-skull" title="' . __('creatures.fields.is_extinct') . '"></i>';
}
return '';
},
'class' => 'icon'
],
[
'type' => 'is_private',
]
Expand Down
7 changes: 7 additions & 0 deletions resources/views/families/form/_entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
</x-forms.field>
@endif

<x-forms.field field="extinct" :label="__('creatures.fields.is_extinct')">
<input type="hidden" name="is_extinct" value="0" />
<x-checkbox :text="__('families.hints.is_extinct')">
<input type="checkbox" name="is_extinct" value="1" @if (old('is_extinct', $source->is_extinct ?? $model->is_extinct ?? false)) checked="checked" @endif />
</x-checkbox>
</x-forms.field>

@include('cruds.fields.tags')

@include('cruds.fields.image')
Expand Down

0 comments on commit 9924cf9

Please sign in to comment.