Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locations: Is destroyed #944

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/Datagrids/Bulks/LocationBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ class LocationBulk extends Bulk
'private_choice',
'entity_image',
'entity_header',
'destroyed_choice'
];

protected $booleans = [
'is_destroyed'
];
}
1 change: 1 addition & 0 deletions app/Datagrids/Filters/LocationFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function build()
'placeholder' => __('crud.placeholders.parent'),
'model' => Location::class,
])
->add('is_destroyed')
->isPrivate()
->template()
->hasImage()
Expand Down
1 change: 1 addition & 0 deletions app/Http/Resources/LocationResource.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,
'location_id' => $model->location_id,
'is_destroyed' => (bool) $this->is_destroyed
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
]);
}
}
1 change: 0 additions & 1 deletion app/Models/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Enums\Visibility;
use App\Facades\CampaignCache;
use App\Facades\Img;
use App\Facades\Mentions;
use App\Models\Concerns\Boosted;
use App\Models\Concerns\CampaignLimit;
Expand Down
1 change: 0 additions & 1 deletion app/Models/CampaignPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;

/**
* Class CampaignPermission
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ public function type(): string

public function cleanCache(): self
{
unset($this->cachedType);
unset($this->cachedPluralName);
unset($this->cachedType, $this->cachedPluralName);

return $this;
}

Expand Down
24 changes: 23 additions & 1 deletion app/Models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @property string $image
* @property ?string $map
* @property bool|int $is_private
* @property bool|int $is_destroyed
* @property bool|int $is_map_private
* @property ?int $location_id
* @property Map[]|Collection $maps
Expand Down Expand Up @@ -60,13 +61,22 @@ class Location extends MiscModel
'location_id',
'campaign_id',
'is_private',
'is_destroyed',
];


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

/**
* Fields that can be sorted on
*/
protected array $sortableColumns = [
'is_destroyed',
];

/**
Expand All @@ -83,8 +93,11 @@ class Location extends MiscModel

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

protected array $exploreGridFields = ['is_destroyed'];

protected array $sanitizable = [
'name',
'type',
Expand Down Expand Up @@ -128,7 +141,7 @@ public function scopePreparedWith(Builder $query): Builder
*/
public function datagridSelectFields(): array
{
return ['location_id'];
return ['location_id', 'is_destroyed'];
}

public function characters(): HasMany
Expand Down Expand Up @@ -268,6 +281,14 @@ public function showProfileInfo(): bool
return !empty($this->type) || !$this->maps->isEmpty() || !$this->entity->elapsedEvents->isEmpty();
}

/**
* Get the value of the is_destroyed variable
*/
public function isDestroyed(): bool
{
return (bool) $this->is_destroyed;
}

/**
* Define the fields unique to this model that can be used on filters
* @return string[]
Expand All @@ -276,6 +297,7 @@ public function filterableColumns(): array
{
return [
'location_id',
'is_destroyed'
];
}
}
1 change: 0 additions & 1 deletion app/Observers/UserObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Jobs\Emails\WelcomeEmailJob;
use App\Jobs\Users\UnsubscribeUser;
use App\Jobs\Users\UpdateEmail;
use App\Facades\Images;
use App\User;
use Exception;
use Illuminate\Support\Facades\Hash;
Expand Down
1 change: 0 additions & 1 deletion app/Services/Campaign/Import/Mappers/EntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ protected function prepareModel(): self
$this->model->$field = $value;
}

$this->model->slug = Str::slug($this->model->name);
$this->model->saveQuietly();
$this->entity();

Expand Down
1 change: 0 additions & 1 deletion app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App;

use App\Facades\Identity;
use App\Facades\Img;
use App\Facades\PostCache;
use App\Facades\SingleUserCache;
use App\Facades\UserCache;
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('locations', function (Blueprint $table) {
$table->boolean('is_destroyed')->default(0);
$table->index('is_destroyed');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('locations', function (Blueprint $table) {
$table->dropIndex('is_destroyed');
$table->dropColumn('is_destroyed');
});
}
};
6 changes: 6 additions & 0 deletions lang/en/locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
'helpers' => [
'characters' => 'View all characters in this location and its children locations, or just those directly located here.',
],
'hints' => [
'is_destroyed' => 'This location is destroyed.',
],
'placeholders' => [
'type' => 'City, Kingdom, Ruin',
],
'fields' => [
'is_destroyed' => 'Destroyed',
]
];
3 changes: 3 additions & 0 deletions resources/api-docs/1.0/locations.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ The list of returned entities can be filtered. The available filters are [availa
"image_full": "{url}",
"image_thumb": "{url}",
"has_custom_image": false,
"is_destroyed": true,
"is_private": true,
"location_id": null,
"entity_id": 5,
Expand Down Expand Up @@ -73,6 +74,7 @@ To get the details of a single location, use the following endpoint.
"image_full": "{url}",
"image_thumb": "{url}",
"has_custom_image": false,
"is_destroyed": true,
"is_private": true,
"location_id": null,
"entity_id": 5,
Expand Down Expand Up @@ -107,6 +109,7 @@ To create a location, use the following endpoint.
| `type` | `string` | Type of location |
| `location_id` | `integer` | The parent location id (where this location is located)|
| `tags` | `array` | Array of tag ids |
| `is_destroyed` | `boolean` | If the location is destroyed |
| `is_private` | `boolean` | If the location is only visible to `admin` members of the campaign |
| `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/cruds/fields/destroyed.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<x-forms.field field="destroyed" :label="__('locations.fields.is_destroyed')">
<input type="hidden" name="is_destroyed" value="0" />
<x-checkbox :text="__('locations.hints.is_destroyed')">
<input type="checkbox" name="is_destroyed" value="1" @if (old('is_destroyed', $model->is_destroyed ?? false)) checked="checked" @endif />
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
</x-checkbox>
</x-forms.field>
7 changes: 7 additions & 0 deletions resources/views/cruds/fields/destroyed_choice.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<x-forms.field field="destroyed" :label="__('locations.fields.is_destroyed')">
<select name="is_destroyed" class="w-full">
<option value=""></option>
<option value="0">{{ __('general.no') }}</option>
<option value="1">{{ __('general.yes') }}</option>
</select>
</x-forms.field>
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 @@ -138,6 +138,12 @@
<span class="sr-only">{{ __('organisations.hints.is_defunct') }}</span>
</span>
@endif
@if ($model instanceof \App\Models\Location && $model->isDestroyed())
<span class="entity-name-icon entity-loc-destroyed cursor-pointer text-2xl" data-toggle="tooltip" data-title="{{ __('locations.hints.is_destroyed') }}">
<x-icon class="fa-solid fa-building-circle-xmark " />
<span class="sr-only">{{ __('locations.hints.is_destroyed') }}</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 @@ -16,6 +16,9 @@
@if ($model instanceof \App\Models\Organisation && $model->isDefunct())
{{ __('organisations.hints.is_defunct') }}
@endif
@if ($model instanceof \App\Models\Location && $model->isDestroyed())
{{ __('locations.hints.is_destroyed') }}
@endif
@if ($model instanceof \App\Models\Creature && $model->isExtinct())
{{ __('creatures.hints.is_extinct') }}
@endif
Expand Down
11 changes: 11 additions & 0 deletions resources/views/locations/datagrid.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
},
'disableSort' => true,
],
[
'label' => '<i class="fa-solid fa-building-circle-xmark" title="' . __('locations.fields.is_destroyed') . '"></i>',
'field' => 'is_destroyed',
'render' => function($model) {
if ($model->isDestroyed()) {
return '<i class="fa-solid fa-building-circle-xmark" title="' . __('locations.fields.is_destroyed') . '"></i>';
}
return '';
},
'class' => 'icon'
],
[
'type' => 'is_private',
]
Expand Down
2 changes: 2 additions & 0 deletions resources/views/locations/form/_entry.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
@include('cruds.fields.location', ['isParent' => true])

@include('cruds.fields.entry2')

@include('cruds.fields.destroyed')

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