Skip to content

Commit

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

protected $booleans = [
'is_extinct',
];
}
1 change: 1 addition & 0 deletions app/Datagrids/Filters/RaceFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function build()
'model' => Race::class,
])
->location()
->add('is_extinct')
->isPrivate()
->template()
->hasImage()
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/RaceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);
}
Expand Down
28 changes: 26 additions & 2 deletions app/Models/Race.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,6 +50,7 @@ class Race extends MiscModel
'type',
'entry',
'is_private',
'is_extinct',
'race_id',
];

Expand All @@ -61,6 +63,11 @@ class Race extends MiscModel
'name',
'type',
'parent.name',
'is_extinct',
];

protected array $sortableColumns = [
'is_extinct',
];

/**
Expand All @@ -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
*/
Expand Down Expand Up @@ -127,7 +141,7 @@ public function scopePreparedWith(Builder $query): Builder
*/
public function datagridSelectFields(): array
{
return ['race_id'];
return ['race_id', 'is_extinct'];
}

/**
Expand Down Expand Up @@ -204,7 +218,8 @@ public function filterableColumns(): array
return [
'race_id',
'location_id',
'parent'
'parent',
'is_extinct',
];
}

Expand All @@ -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
*/
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('races', function (Blueprint $table) {
$table->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');
});
}
};
3 changes: 3 additions & 0 deletions lang/en/races.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
'title' => 'New Members',
],
],
'hints' => [
'is_extinct' => 'This race is extinct.',
],
'placeholders' => [
'type' => 'Human, Fey, Borg',
],
Expand Down
3 changes: 3 additions & 0 deletions resources/api-docs/1.0/races.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 |
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 @@ -144,6 +144,12 @@
<span class="sr-only">{{ __('locations.hints.is_destroyed') }}</span>
</span>
@endif
@if ($model instanceof \App\Models\Race && $model->isExtinct())
<span class="entity-name-icon entity-rac-extinct cursor-pointer text-2xl" data-toggle="tooltip" data-title="{{ __('races.hints.is_extinct') }}">
<x-icon class="fa-solid fa-skull-cow entity-icons " />
<span class="sr-only">{{ __('races.hints.is_extinct') }}</span>
</span>
@endif
@if ($model instanceof \App\Models\Creature && $model->isExtinct())
<span class="entity-name-icon entity-cre-extinct cursor-pointer text-2xl" data-toggle="tooltip" data-title="{{ __('creatures.hints.is_extinct') }}">
<x-icon class="fa-solid fa-skull-cow entity-icons " />
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 @@ -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
Expand Down
11 changes: 11 additions & 0 deletions resources/views/races/datagrid.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
},
'disableSort' => true,
],
[
'label' => '<i class="fa-solid fa-skull-cow" title="' . __('creatures.fields.is_extinct') . '"></i>',
'field' => 'is_extinct',
'render' => function($model) {
if ($model->isExtinct()) {
return '<i class="fa-solid fa-skull-cow" title="' . __('creatures.fields.is_extinct') . '"></i>';
}
return '';
},
'class' => 'icon'
],
[
'type' => 'is_private',
]
Expand Down
7 changes: 7 additions & 0 deletions resources/views/races/form/_entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

@include('cruds.fields.entry2')

<x-forms.field field="extinct" :label="__('creatures.fields.is_extinct')">
<input type="hidden" name="is_extinct" value="0" />
<x-checkbox :text="__('races.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')
</x-grid>

0 comments on commit 68a0479

Please sign in to comment.