Skip to content

Commit

Permalink
Merge branch 'develop' into tag-children-add-multiple-entities
Browse files Browse the repository at this point in the history
  • Loading branch information
ilestis authored Dec 5, 2023
2 parents 47a1858 + 463e1b4 commit 0a5428f
Show file tree
Hide file tree
Showing 150 changed files with 880 additions and 5,052 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ yarn-error.log
.phpunit.result.cache
*.sql
package-lock.json
.phpstorm.meta.php

2,931 changes: 0 additions & 2,931 deletions .phpstorm.meta.php

This file was deleted.

78 changes: 0 additions & 78 deletions app/Console/Commands/GenerateTrees.php

This file was deleted.

45 changes: 45 additions & 0 deletions app/Console/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Console\Commands;

use App\Models\EntityType;
use Illuminate\Console\Command;
use Exception;

class InstallCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kanka:install';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Set up Kanka\'s boilerplate';

/**
* Execute the console command.
*/
public function handle()
{
try {
if (EntityType::find(1)) {
$this->error('Kanka has already been installed.');
return;
}
} catch (Exception) {
}
$this->call('key:generate');
$this->call('migrate');
$this->call('db:seed');
$this->call('passport:install');

$this->info('Kanka successfully installed.');
$this->info('Check it out at ' . config('app.url'));
}
}
1 change: 0 additions & 1 deletion app/Http/Controllers/Abilities/AbilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function index(Campaign $campaign, Ability $ability)
Datagrid::layout(\App\Renderers\Layouts\Ability\Ability::class)
->route('abilities.abilities', $options);

// @phpstan-ignore-next-line
$this->rows = $ability
->descendants()
->sort(request()->only(['o', 'k']), ['name' => 'asc'])
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Controllers/Abilities/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ public function store(StoreAbilityEntity $request, Campaign $campaign, Ability $
$redirectUrlOptions['ability_id'] = $ability->id;
}

$ability->attachEntity($request->only('entity_id', 'visibility_id'));
$count = $ability->attachEntity($request->only('entities', 'visibility_id'));

return redirect()->route('abilities.entities', [$campaign, 'ability' => $ability->id])
->with('success', __('abilities.children.create.success', ['name' => $ability->name]));
//->with('success', __('abilities.children.create.success', ['name' => $ability->name]));
->with('success', trans_choice('abilities.children.create.attach_success', $count, ['count' => $count, 'name' => $ability->name]));

}
}
30 changes: 30 additions & 0 deletions app/Http/Controllers/Api/v1/FilterApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Controllers\Api\v1;

use App\Http\Controllers\Controller;
use App\Models\EntityType;
use App\Services\Api\FilterService;

class FilterApiController extends Controller
{
protected FilterService $filterService;

public function __construct(FilterService $filterService)
{
$this->filterService = $filterService;
}

public function index()
{
return response()->json($this->filterService->endpoints());
}
public function show(EntityType $entityType)
{
return response()->json([
'data' => $this->filterService
->entityType($entityType)
->filters()
]);
}
}
13 changes: 9 additions & 4 deletions app/Http/Controllers/CrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Models\Entity;
use App\Models\AttributeTemplate;
use App\Models\Bookmark;
use App\Models\Family;
use App\Models\MiscModel;
use App\Sanitizers\MiscSanitizer;
use App\Services\MultiEditingService;
Expand Down Expand Up @@ -118,9 +119,12 @@ public function crudIndex(Request $request)
$model = new $this->model();
$campaign = $this->campaign;
$this->filterService
->request($request)
->model($model)
->make($this->view);
->request($request);
if (method_exists($model, 'explicitFilters')) {
$this->filterService
->model($model)
->make($this->view);
}
$name = $this->view;
$langKey = $this->langKey ?? $name;
/** @var DatagridFilter|null $filter */
Expand All @@ -144,7 +148,7 @@ public function crudIndex(Request $request)
$parent = null;
if (request()->has('parent_id')) {
// @phpstan-ignore-next-line
$parentKey = $model->getParentIdName();
$parentKey = $model->getParentKeyName();
$base->where([$model->getTable() . '.' . $parentKey => request()->get('parent_id')]);

$parent = $model->where('id', request()->get('parent_id'))->first();
Expand All @@ -153,6 +157,7 @@ public function crudIndex(Request $request)
// Do this to avoid an extra sql query when no filters are selected
if ($this->filterService->hasFilters()) {
$unfilteredCount = $base->count();
// @phpstan-ignore-next-line
$base = $base->filter($this->filterService->filters());

$models = $base->paginate();
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Events/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function index(Campaign $campaign, Event $event)
Datagrid::layout(\App\Renderers\Layouts\Event\Event::class)
->route('events.events', $options);

// @phpstan-ignore-next-line
$this->rows = $event
->descendants()
->sort(request()->only(['o', 'k']), ['name' => 'asc'])
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Front/HelperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Front;

use App\Models\Family;
use App\Models\MiscModel;
use Exception;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -29,6 +30,7 @@ public function apiFilters()
if (!$misc instanceof MiscModel) {
abort(404);
}
// @phpstan-ignore-next-line
$filters = $misc->getFilterableColumns();

return view('helpers.api-filters', compact(
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Locations/CharacterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function index(Campaign $campaign, Location $location)
'location', 'location.entity',
'races', 'families',
])
->filter($filters)
->filteredCharacters()
->paginate();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Locations/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function index(Campaign $campaign, Location $location)
// @phpstan-ignore-next-line
$this->rows = $location
->descendants()
->select(['id', 'image', 'name', 'type', 'location_id', 'is_private'])
->select(['id', 'name', 'type', 'location_id', 'is_private'])
->sort(request()->only(['o', 'k']), ['name' => 'asc'])
->filter($filters)
->with([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function organisations(Campaign $campaign, Organisation $organisation)
Datagrid::layout(\App\Renderers\Layouts\Organisation\Organisation::class)
->route('organisations.organisations', $options);

// @phpstan-ignore-next-line
$this->rows = $organisation
->descendants()
->sort(request()->only(['o', 'k']), ['name' => 'asc'])
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Quests/QuestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function index(Campaign $campaign, Quest $quest)
Datagrid::layout(\App\Renderers\Layouts\Quest\Quest::class)
->route('quests.quests', $options);

// @phpstan-ignore-next-line
$this->rows = $quest
->descendants()
->sort(request()->only(['o', 'k']), ['name' => 'asc'])
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Races/RaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function index(Campaign $campaign, Race $race)
Datagrid::layout(\App\Renderers\Layouts\Race\Race::class)
->route('races.races', $options);

// @phpstan-ignore-next-line
$this->rows = $race
->descendants()
->sort(request()->only(['o', 'k']), ['name' => 'asc'])
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Tags/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function index(Campaign $campaign, Tag $tag)
Datagrid::layout(\App\Renderers\Layouts\Tag\Tag::class)
->route('tags.tags', $options);

// @phpstan-ignore-next-line
$this->rows = $tag
->descendants()
->sort(request()->only(['o', 'k']), ['name' => 'asc'])
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/Timelines/TimelineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function index(Campaign $campaign, Timeline $timeline)
Datagrid::layout(\App\Renderers\Layouts\Timeline\Timeline::class)
->route('timelines.timelines', $options);

// @phpstan-ignore-next-line
$this->rows = $timeline
->descendants()
->sort(request()->only(['o', 'k']), ['name' => 'asc'])
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Timelines/TimelineReorderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Requests\ReorderTimeline;
use App\Models\Campaign;
use App\Models\Timeline;
use App\Models\TimelineEra;
use App\Services\TimelineService;

class TimelineReorderController extends Controller
Expand All @@ -31,6 +32,7 @@ public function index(Campaign $campaign, Timeline $timeline)
->get();

$hasNothing = true;
/** @var TimelineEra $era */
foreach ($eras as $era) {
if (!$era->orderedElements->isEmpty()) {
$hasNothing = false;
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Requests/StoreAbilityEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ public function rules()
{
return [
'ability_id' => 'required|exists:entities,id',
'entity_id' => 'required|exists:entities,id|different:ability_id',
'visibility_id' => 'required|exists:visibilities,id',
'entities' => 'array|required',
'entities.*' => ['different:ability_id|exists:entities,id'],
];
}
}
2 changes: 1 addition & 1 deletion app/Http/Resources/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function toArray($request)
'id' => $model->child->id,
'entity_id' => $model->id,
'name' => $model->name,
'image' => Avatar::entity($model)->thumbnail(),
'image' => Avatar::entity($model)->original(),
'image_thumb' => Avatar::entity($model)->size(40)->thumbnail(),
'has_custom_image' => !empty($model->image_path) && !empty($model->image),

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/EntityAssetResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function toArray($request)
/** @var EntityAsset $asset */
$asset = $this->resource;

$data = $this->entity([
$data = $this->onEntity([
'type_id' => $asset->type_id,
'_file' => $asset->isFile(),
'_link' => $asset->isLink(),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/EntityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function entity(array $prepared = [])

if ($misc->ancestors) {
$ancestors = [];
foreach ($misc->getAncestors(['id']) as $ancestor) {
foreach ($misc->ancestors as $ancestor) {
$ancestors[] = $ancestor->id;
}
$merged['parents'] = $ancestors;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/InventoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function toArray($request)
{
/** @var Inventory $model */
$model = $this->resource;
return $this->entity([
return $this->onEntity([
'item_id' => $model->item_id,
'name' => $model->name,
'position' => $model->position,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function toArray($request)
{
/** @var Post $model */
$model = $this->resource;
return $this->entity([
return $this->onEntity([
'name' => $model->name,
'visibility_id' => (int) $model->visibility_id->value,
'entry' => $model->entry,
Expand Down
Loading

0 comments on commit 0a5428f

Please sign in to comment.