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

New filters #1007

Merged
merged 6 commits into from
Feb 6, 2025
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
36 changes: 4 additions & 32 deletions app/Datagrids/Filters/CharacterFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace App\Datagrids\Filters;

use App\Facades\Module;
use App\Models\Family;
use App\Models\Organisation;
use App\Models\Race;

class CharacterFilter extends DatagridFilter
{
Expand Down Expand Up @@ -33,35 +30,10 @@ public function build()
$this
->add('name')
->add('title')
->add([
'field' => 'family_id',
'label' => Module::singular(config('entities.ids.family'), __('entities.family')),
'type' => 'select2',
'route' => route('search-list', [$this->campaign, config('entities.ids.family')]),
'placeholder' => $famPlaceholder,
'model' => Family::class,
'withChildren' => true,
])
->location()
->add([
'field' => 'race_id',
'label' => Module::singular(config('entities.ids.race'), __('entities.race')),
'type' => 'select2',
'route' => route('search-list', [$this->campaign, config('entities.ids.race')]),
'placeholder' => $racePlaceholder,
'model' => Race::class,
'withChildren' => true,
])
->add([
'field' => 'member_id',
'label' => Module::singular(config('entities.ids.organisation'), __('entities.organisation')),
'type' => 'select2',
'route' => route('search-list', [$this->campaign, config('entities.ids.organisation')]),
'placeholder' => $orgPlaceholder,
'model' => Organisation::class,
'withChildren' => true,

])
->families()
->locations()
->races()
->organisations()
->add('type')
->add('age')
->add('sex')
Expand Down
101 changes: 100 additions & 1 deletion app/Datagrids/Filters/DatagridFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

use App\Facades\Module;
use App\Models\Character;
use App\Models\Family;
use App\Models\Journal;
use App\Models\Location;
use App\Models\Organisation;
use App\Models\Race;
use App\Models\Tag;
use App\Traits\CampaignAware;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -68,6 +71,102 @@ protected function location(): self
return $this;
}

/**
* Add the locations filters
* @return $this
*/
protected function locations(): self
{
$name = Module::plural(config('entities.ids.location'));
$placeholder = __('crud.placeholders.multiple');
if (!empty($name)) {
$placeholder = __('crud.placeholders.fallback', ['module' => $name]);
}
$this->filters[] = [
'field' => 'locations',
'label' => Module::plural(config('entities.ids.location'), __('entities.locations')),
'type' => 'selectMultiple',
'route' => route('search-list', [$this->campaign, config('entities.ids.location')]),
'placeholder' => $placeholder,
'model' => Location::class,
'multiple' => true,
'withChildren' => true,
];
return $this;
}

/**
* Add the races filters
* @return $this
*/
protected function races(): self
{
$name = Module::plural(config('entities.ids.race'));
$placeholder = __('crud.placeholders.multiple');
if (!empty($name)) {
$placeholder = __('crud.placeholders.multiple', ['module' => $name]);
}
$this->filters[] = [
'field' => 'races',
'label' => Module::plural(config('entities.ids.race'), __('entities.races')),
'type' => 'selectMultiple',
'route' => route('search-list', [$this->campaign, config('entities.ids.race')]),
'placeholder' => $placeholder,
'model' => Race::class,
'multiple' => true,
'withChildren' => true,
];
return $this;
}

/**
* Add the organisations filters
* @return $this
*/
protected function organisations(): self
{
$name = Module::plural(config('entities.ids.organisation'));
$placeholder = __('crud.placeholders.multiple');
if (!empty($name)) {
$placeholder = __('crud.placeholders.fallback', ['module' => $name]);
}
$this->filters[] = [
'field' => 'organisations',
'label' => Module::plural(config('entities.ids.organisation'), __('entities.organisations')),
'type' => 'selectMultiple',
'route' => route('search-list', [$this->campaign, config('entities.ids.organisation')]),
'placeholder' => $placeholder,
'model' => Organisation::class,
'multiple' => true,
'withChildren' => true,
];
return $this;
}

/**
* Add the families filters
* @return $this
*/
protected function families(): self
{
$name = Module::plural(config('entities.ids.family'));
$placeholder = __('crud.placeholders.multiple');
if (!empty($name)) {
$placeholder = __('crud.placeholders.fallback', ['module' => $name]);
}
$this->filters[] = [
'field' => 'families',
'label' => Module::plural(config('entities.ids.family'), __('entities.families')),
'type' => 'selectMultiple',
'route' => route('search-list', [$this->campaign, config('entities.ids.family')]),
'placeholder' => $placeholder,
'model' => Family::class,
'multiple' => true,
'withChildren' => true,
];
return $this;
}

/**
* Add the character filters
* @return $this
Expand Down Expand Up @@ -125,7 +224,7 @@ protected function tags(): self
}
$this->filters[] = [
'field' => 'tags',
'label' => Module::singular(config('entities.ids.tag'), __('entities.tag')),
'label' => Module::singular(config('entities.ids.tag'), __('entities.tags')),
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
'type' => 'tag',
'route' => route('search-list', [$this->campaign, config('entities.ids.tag')]),
'placeholder' => $placeholder,
Expand Down
4 changes: 4 additions & 0 deletions app/Models/Character.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,10 @@ public function filterableColumns(): array
'sex',
'pronouns',
'location_id',
'locations',
'organisations',
'races',
'families',
'is_dead',
'member_id',
'race_id',
Expand Down
Loading