Skip to content

Commit

Permalink
Merge pull request #881 from owlchester/refactor/menu-items
Browse files Browse the repository at this point in the history
Refactor menu items
  • Loading branch information
ilestis authored May 22, 2024
2 parents 9fd25ae + cb7d5b0 commit c2e4385
Show file tree
Hide file tree
Showing 41 changed files with 660 additions and 515 deletions.
25 changes: 25 additions & 0 deletions app/Facades/Submenu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Facades;

use Illuminate\Support\Facades\Facade;

/**
* Class Module
* @package App\Facades
*
* @see \App\Services\Submenus\SubmenuService
* @mixin \App\Services\Submenus\SubmenuService
*/
class Submenu extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'submenu';
}
}
19 changes: 0 additions & 19 deletions app/Models/Ability.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Models;

use App\Facades\Mentions;
use App\Facades\Module;
use App\Models\Concerns\Acl;
use App\Models\Concerns\HasFilters;
use App\Models\Concerns\SortableTrait;
Expand Down Expand Up @@ -158,24 +157,6 @@ public function detach(): void
parent::detach();
}

/**
* Menu items for the entity
*/
public function menuItems(array $items = []): array
{
$items['second']['abilities'] = [
'name' => Module::plural($this->entityTypeId(), 'entities.abilities'),
'route' => 'abilities.abilities',
'count' => $this->descendants()->count()
];
$items['second']['entities'] = [
'name' => 'abilities.show.tabs.entities',
'route' => 'abilities.entities',
'count' => $this->entities()->count()
];
return parent::menuItems($items);
}

/**
* Get the entity_type id from the entity_types table
*/
Expand Down
16 changes: 0 additions & 16 deletions app/Models/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,22 +372,6 @@ public function missingDetails(): bool
return count($this->months()) < 1 || count($this->weekdays()) < 2;
}

/**
*
*/
public function menuItems(array $items = []): array
{
$count = $this->calendarEvents()->has('entity')->count();
if ($count > 0) {
$items['second']['events'] = [
'name' => 'crud.tabs.reminders',
'route' => 'calendars.events',
'count' => $count
];
}
return parent::menuItems($items);
}

/**
* Get the entity_type id from the entity_types table
*/
Expand Down
33 changes: 0 additions & 33 deletions app/Models/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace App\Models;

use App\Enums\FilterOption;
use App\Facades\CampaignLocalization;
use App\Facades\Module;
use App\Models\Concerns\Acl;
use App\Models\Concerns\HasFilters;
use App\Models\Concerns\SortableTrait;
Expand Down Expand Up @@ -322,37 +320,6 @@ public function detach(): void
parent::detach();
}

/**
*/
public function menuItems(array $items = []): array
{
$canEdit = auth()->check() && auth()->user()->can('update', $this);
$campaign = CampaignLocalization::getCampaign();

$items['second']['profile'] = [
'name' => 'entities/profile.show.tab_name',
'route' => 'entities.profile',
'entity' => true,

'button' => auth()->check() && auth()->user()->can('update', $this) ? [
'url' => $this->getLink('edit'),
'icon' => 'fa-solid fa-pencil',
'tooltip' => __('crud.edit'),
] : null,
];

$count = $this->organisationMemberships()->has('organisation')->count();
if ($campaign->enabled('organisations') && ($count > 0 || $canEdit)) {
$items['second']['organisations'] = [
'name' => Module::plural(config('entities.ids.organisation'), 'entities.organisations'),
'route' => 'characters.organisations',
'count' => $count
];
}

return parent::menuItems($items);
}

/**
* Tooltip subtitle (character title)
*/
Expand Down
17 changes: 0 additions & 17 deletions app/Models/Creature.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Models;

use App\Enums\FilterOption;
use App\Facades\Module;
use App\Models\Concerns\Acl;
use App\Models\Concerns\HasFilters;
use App\Models\Concerns\SortableTrait;
Expand Down Expand Up @@ -185,22 +184,6 @@ public function creatures()
return $this->hasMany(Creature::class, 'creature_id', 'id');
}

/**
* Menu elements for the rendering
*/
public function menuItems(array $items = []): array
{
$count = $this->descendants()->count();
if ($count > 0) {
$items['second']['creatures'] = [
'name' => Module::plural($this->entityTypeId(), 'entities.creatures'),
'route' => 'creatures.creatures',
'count' => $count
];
}
return parent::menuItems($items);
}

/**
* Get the entity_type id from the entity_types table
*/
Expand Down
14 changes: 0 additions & 14 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Models;

use App\Facades\Module;
use App\Models\Concerns\Acl;
use App\Models\Concerns\HasFilters;
use App\Models\Concerns\SortableTrait;
Expand Down Expand Up @@ -162,19 +161,6 @@ public function getParentKeyName()
return 'event_id';
}

/**
*/
public function menuItems(array $items = []): array
{
$items['second']['events'] = [
'name' => Module::plural($this->entityTypeId(), 'entities.events'),
'route' => 'events.events',
'count' => $this->descendants()->count()
];

return parent::menuItems($items);
}

/**
* Determine if the model has profile data to be displayed
*/
Expand Down
21 changes: 0 additions & 21 deletions app/Models/Family.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Models;

use App\Enums\FilterOption;
use App\Facades\Module;
use App\Models\Concerns\Acl;
use App\Models\Concerns\HasFilters;
use App\Models\Concerns\SortableTrait;
Expand Down Expand Up @@ -250,26 +249,6 @@ public function detach(): void
parent::detach();
}

/**
*/
public function menuItems(array $items = []): array
{
$items['second']['families'] = [
'name' => Module::plural($this->entityTypeId(), 'entities.families'),
'route' => 'families.families',
'count' => $this->descendants()->count()
];

if (config('services.stripe.enabled')) {
$items['second']['tree'] = [
'name' => 'families.show.tabs.tree',
'route' => 'families.family-tree',
];
}

return parent::menuItems($items);
}

/**
* Get the entity_type id from the entity_types table
*/
Expand Down
15 changes: 0 additions & 15 deletions app/Models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,6 @@ public function item()
{
return $this->belongsTo('App\Models\Item', 'item_id', 'id');
}
/**
*/
public function menuItems(array $items = []): array
{
$inventoryCount = $this->inventories()->with('item')->has('entity')->count();
if ($inventoryCount > 0) {
$items['second']['inventories'] = [
'name' => 'items.show.tabs.inventories',
'route' => 'items.inventories',
'count' => $inventoryCount
];
}

return parent::menuItems($items);
}

/**
* Get the entity_type id from the entity_types table
Expand Down
13 changes: 0 additions & 13 deletions app/Models/Journal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Models;

use App\Facades\Module;
use App\Models\Concerns\Acl;
use App\Models\Concerns\HasFilters;
use App\Models\Concerns\SortableTrait;
Expand Down Expand Up @@ -145,18 +144,6 @@ public function datagridSelectFields(): array
return ['journal_id', 'author_id', 'date', 'calendar_id', 'calendar_year', 'calendar_month', 'calendar_day'];
}

/**
*/
public function menuItems(array $items = []): array
{
$items['second']['journals'] = [
'name' => Module::plural($this->entityTypeId(), 'entities.journals'),
'route' => 'journals.journals',
'count' => $this->descendants()->count()
];
return parent::menuItems($items);
}

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
Expand Down
37 changes: 0 additions & 37 deletions app/Models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

namespace App\Models;

use App\Facades\CampaignLocalization;
use App\Models\Concerns\HasFilters;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Facades\Module;
use App\Models\Concerns\Acl;
use App\Models\Concerns\SortableTrait;
use App\Traits\CampaignTrait;
Expand Down Expand Up @@ -278,41 +276,6 @@ public function detach(): void
parent::detach();
}


/**
*/
public function menuItems(array $items = []): array
{
$campaign = CampaignLocalization::getCampaign();

$count = $this->descendants()->has('location')->count();
if ($count > 0) {
$items['second']['locations'] = [
'name' => Module::plural($this->entityTypeId(), 'entities.locations'),
'route' => 'locations.locations',
'count' => $count
];
}

$count = $this->allCharacters()->count();
if ($campaign->enabled('characters') && $count > 0) {
$items['second']['characters'] = [
'name' => Module::plural(config('entities.ids.character'), 'entities.characters'),
'route' => 'locations.characters',
'count' => $count
];
}
/*$count = $this->events()->count();
if ($campaign->enabled('events') && $count > 0) {
$items['second']['events'] = [
'name' => 'locations.show.tabs.events',
'route' => 'locations.events',
'count' => $count
];
}*/
return parent::menuItems($items);
}

/**
* Get the entity_type id from the entity_types table
*/
Expand Down
30 changes: 0 additions & 30 deletions app/Models/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Models;

use App\Facades\CampaignLocalization;
use App\Facades\Module;
use App\Models\Concerns\Acl;
use App\Models\Concerns\HasFilters;
use App\Models\Concerns\SortableTrait;
Expand Down Expand Up @@ -270,35 +269,6 @@ public function detach(): void
parent::detach();
}

/**
*/
public function menuItems(array $items = []): array
{
$items['second']['maps'] = [
'name' => Module::plural($this->entityTypeId(), 'entities.maps'),
'route' => 'maps.maps',
'count' => $this->maps()->count()
];
if (auth()->check() && auth()->user()->can('update', $this)) {
$items['second']['layers'] = [
'name' => 'maps.panels.layers',
'route' => 'maps.map_layers.index',
'count' => $this->layers->count()
];
$items['second']['groups'] = [
'name' => 'maps.panels.groups',
'route' => 'maps.map_groups.index',
'count' => $this->groups->count()
];
$items['second']['markers'] = [
'name' => 'maps.panels.markers',
'route' => 'maps.map_markers.index',
'count' => $this->markers->count()
];
}
return parent::menuItems($items);
}

/**
* Get the entity_type id from the entity_types table
*/
Expand Down
5 changes: 0 additions & 5 deletions app/Models/MapMarker.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,11 +425,6 @@ protected function markerIcon(): string

$iconStyles = [];
$iconStyles[] = 'background-color: ' . $this->backgroundColour();
/*if ($this->entity && $this->icon == 4 && $this->entity->child) {
$entityImage = '<div class="marker-entity" style="background-image: url(' .
$this->entity->child->thumbnail(400) .
');"></div>';
}*/

$iconShape = '<div style="background-color: ' . $this->backgroundColour() . '" class="marker-pin"></div>';

Expand Down
Loading

0 comments on commit c2e4385

Please sign in to comment.