Skip to content

Commit

Permalink
Merge pull request #808 from owlchester/creatures-is-extinct
Browse files Browse the repository at this point in the history
  • Loading branch information
ilestis authored Jan 31, 2024
2 parents 75580c2 + 8f8bef5 commit b96176f
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/Datagrids/Bulks/CreatureBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ class CreatureBulk extends Bulk
'creature_id',
'tags',
'private_choice',
'extinct_choice',
'entity_image',
'entity_header',
];

protected $booleans = [
'is_extinct'
];
}
1 change: 1 addition & 0 deletions app/Datagrids/Filters/CreatureFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function build()
'model' => Creature::class,
])
->location()
->add('is_extinct')
->isPrivate()
->template()
->hasImage()
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/CreatureResource.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,
'creature_id' => $model->creature_id,
'is_extinct' => (bool) $model->is_extinct,
'locations' => $locationIDs
]);
}
Expand Down
22 changes: 20 additions & 2 deletions app/Models/Creature.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @property Creature[] $creatures
* @property Location|null $location
* @property Collection|Location[] $locations
* @property bool $is_extinct
*/
class Creature extends MiscModel
{
Expand All @@ -47,6 +48,7 @@ class Creature extends MiscModel
'entry',
'is_private',
'creature_id',
'is_extinct',
];

/**
Expand All @@ -56,12 +58,14 @@ class Creature extends MiscModel

protected array $sortableColumns = [
'creature.name',
'is_extinct',
];

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

/**
Expand All @@ -79,6 +83,11 @@ class Creature extends MiscModel
'pivotLocations',
];

protected array $exportFields = [
'base',
'is_extinct',
];

/**
* @return string
*/
Expand Down Expand Up @@ -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'];
}

/**
Expand Down Expand Up @@ -202,7 +211,8 @@ public function filterableColumns(): array
{
return [
'creature_id',
'location_id'
'location_id',
'is_extinct',
];
}

Expand Down Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion app/Observers/CampaignObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion app/Renderers/DatagridRenderer2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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('creatures', function (Blueprint $table) {
$table->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');
});
}
};
6 changes: 6 additions & 0 deletions lang/en/creatures.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
'placeholders' => [
'type' => 'Herbivore, Aquatic, Mythical',
],
'fields' => [
'is_extinct' => 'Extinct',
],
'hints' => [
'is_extinct' => 'This creature is extinct.',
],
];
3 changes: 3 additions & 0 deletions resources/api-docs/1.0/creatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 |
Expand Down
11 changes: 11 additions & 0 deletions resources/views/creatures/_tree.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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
11 changes: 11 additions & 0 deletions resources/views/creatures/datagrid.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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/creatures/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')">
{!! Form::hidden('is_extinct', 0) !!}
<x-checkbox :text="__('creatures.hints.is_extinct')">
{!! Form::checkbox('is_extinct', 1, $model->is_extinct ?? '' )!!}
</x-checkbox>
</x-forms.field>

@include('cruds.fields.tags')
@include('cruds.fields.image')

Expand Down
7 changes: 7 additions & 0 deletions resources/views/cruds/fields/extinct_choice.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<x-forms.field field="extinct" :label="__('creatures.fields.is_extinct')">
<select name="is_extinct" class="w-full">
<option value=""></option>
<option value="0">{{ __('general.no') }}</option>
<option value="1">{{ __('general.yes') }}</option>
</select>
</x-forms.field>
7 changes: 6 additions & 1 deletion resources/views/entities/components/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@
<span class="sr-only">{{ __('organisations.hints.is_defunct') }}</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 "></x-icon>
<span class="sr-only">{{ __('creatures.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

0 comments on commit b96176f

Please sign in to comment.