From 64fc9b7fd472b0c492e748c20f8482c286e9d359 Mon Sep 17 00:00:00 2001 From: Spitfire Date: Thu, 25 Apr 2024 09:37:15 -0600 Subject: [PATCH] Assets is now its own module --- .../Controllers/Entity/AssetController.php | 9 ++++++ .../Entity/AttributeController.php | 5 ++-- .../Entity/InventoryController.php | 9 ++++++ app/Models/CampaignSetting.php | 1 + app/Models/MiscModel.php | 2 +- ...59_update_campaign_settings_add_assets.php | 28 +++++++++++++++++++ lang/en/campaigns.php | 1 + lang/en/entities.php | 1 + .../views/campaigns/modules/index.blade.php | 3 ++ 9 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2024_04_24_193659_update_campaign_settings_add_assets.php diff --git a/app/Http/Controllers/Entity/AssetController.php b/app/Http/Controllers/Entity/AssetController.php index e8dfcf2727..c886d10d6e 100644 --- a/app/Http/Controllers/Entity/AssetController.php +++ b/app/Http/Controllers/Entity/AssetController.php @@ -21,6 +21,15 @@ class AssetController extends Controller public function index(Campaign $campaign, Entity $entity) { + if (!$campaign->enabled('assets')) { + return redirect()->route('entities.show', [$campaign, $entity])->with( + 'error_raw', + __('campaigns.settings.errors.module-disabled', [ + 'fix' => link_to_route('campaign.modules', __('crud.fix-this-issue'), ['#assets']), + ]) + ); + } + $this->authEntityView($entity); $assets = $entity->assets; diff --git a/app/Http/Controllers/Entity/AttributeController.php b/app/Http/Controllers/Entity/AttributeController.php index add8c5a295..b6b8ad192c 100644 --- a/app/Http/Controllers/Entity/AttributeController.php +++ b/app/Http/Controllers/Entity/AttributeController.php @@ -31,13 +31,14 @@ public function __construct(AttributeService $attributeService, TemplateService public function index(Campaign $campaign, Entity $entity) { if (!$campaign->enabled('entity_attributes')) { - return redirect()->route('dashboard', $campaign)->with( + return redirect()->route('entities.show', [$campaign, $entity])->with( 'error_raw', __('campaigns.settings.errors.module-disabled', [ - 'fix' => link_to_route('campaign.modules', __('crud.fix-this-issue'), ['#entity_attributes']), + 'fix' => link_to_route('campaign.modules', __('crud.fix-this-issue'), ['#assets']), ]) ); } + $this->authEntityView($entity); if (!$entity->accessAttributes()) { diff --git a/app/Http/Controllers/Entity/InventoryController.php b/app/Http/Controllers/Entity/InventoryController.php index aa7baf067d..5d6b184a34 100644 --- a/app/Http/Controllers/Entity/InventoryController.php +++ b/app/Http/Controllers/Entity/InventoryController.php @@ -28,6 +28,15 @@ class InventoryController extends Controller public function index(Campaign $campaign, Entity $entity) { + if (!$campaign->enabled('inventories')) { + return redirect()->route('entities.show', [$campaign, $entity])->with( + 'error_raw', + __('campaigns.settings.errors.module-disabled', [ + 'fix' => link_to_route('campaign.modules', __('crud.fix-this-issue'), ['#inventories']), + ]) + ); + } + $this->authEntityView($entity); $inventory = $entity diff --git a/app/Models/CampaignSetting.php b/app/Models/CampaignSetting.php index 0bb4fd73be..a0826d7210 100644 --- a/app/Models/CampaignSetting.php +++ b/app/Models/CampaignSetting.php @@ -13,6 +13,7 @@ class CampaignSetting extends Model protected $fillable = [ 'abilities', + 'assets', 'campaign_id', 'characters', 'entity_attributes', diff --git a/app/Models/MiscModel.php b/app/Models/MiscModel.php index 310a774b47..309220ce95 100644 --- a/app/Models/MiscModel.php +++ b/app/Models/MiscModel.php @@ -299,7 +299,7 @@ public function menuItems(array $items = []): array // Each entity can have assets - if ($this->entity->hasFiles()) { + if ($campaign->enabled('assets') && $this->entity->hasFiles()) { $items['third']['assets'] = [ 'name' => 'crud.tabs.assets', 'route' => 'entities.entity_assets.index', diff --git a/database/migrations/2024_04_24_193659_update_campaign_settings_add_assets.php b/database/migrations/2024_04_24_193659_update_campaign_settings_add_assets.php new file mode 100644 index 0000000000..3abde3c8da --- /dev/null +++ b/database/migrations/2024_04_24_193659_update_campaign_settings_add_assets.php @@ -0,0 +1,28 @@ +boolean('assets')->default(true); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('campaign_settings', function (Blueprint $table) { + $table->dropColumn('assets'); + }); + } +}; diff --git a/lang/en/campaigns.php b/lang/en/campaigns.php index 047e228f7c..cbbd1ee777 100644 --- a/lang/en/campaigns.php +++ b/lang/en/campaigns.php @@ -371,6 +371,7 @@ ], 'helpers' => [ 'abilities' => 'Create abilities, be it feats, spells, or powers that can be assigned to entities.', + 'assets' => 'Upload files, links and aliases to individual entities.', 'bookmarks' => 'Create bookmarks to entities or filtered lists that appear in the sidebar.', 'calendars' => 'A place to define the calendars of your world.', 'characters' => 'Create and keep track of the people inhabiting the world with characters.', diff --git a/lang/en/entities.php b/lang/en/entities.php index 5ab8f9c127..2058c1332f 100644 --- a/lang/en/entities.php +++ b/lang/en/entities.php @@ -3,6 +3,7 @@ return [ 'abilities' => 'Abilities', 'ability' => 'Ability', + 'assets' => 'Assets', 'attribute_template' => 'Attribute Template', 'attribute_templates' => 'Attribute Templates', 'bookmark' => 'Bookmark', diff --git a/resources/views/campaigns/modules/index.blade.php b/resources/views/campaigns/modules/index.blade.php index 2bf61443a4..d918635689 100644 --- a/resources/views/campaigns/modules/index.blade.php +++ b/resources/views/campaigns/modules/index.blade.php @@ -107,6 +107,9 @@
@include('campaigns.modules.box', ['icon' => 'fa-solid fa-table', 'module' => 'entity_attributes'])
+
+ @include('campaigns.modules.box', ['icon' => 'fa-solid fa-folder', 'module' => 'assets']) +
@endsection