Skip to content

fix: shelter attributes actions #96

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

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 25 additions & 3 deletions app/Filament/Admin/Resources/ShelterAttributeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace App\Filament\Admin\Resources;

use App\Filament\Admin\Resources\ShelterAttributeResource\Actions\ListAction;
use App\Filament\Admin\Resources\ShelterAttributeResource\Actions\UnlistAction;
use App\Filament\Admin\Resources\ShelterAttributeResource\Pages;
use App\Forms\Components\TableRepeater;
use App\Models\ShelterAttribute;
Expand Down Expand Up @@ -104,7 +106,11 @@ public static function table(Table $table): Table

TextColumn::make('shelter_variables_count')
->label(__('app.field.variables'))
->counts('shelterVariables'),
->counts('shelterVariables')
->sortable()
->numeric()
->alignRight()
->shrink(),

// TextColumn::make('shelters_count')
// ->label(__('app.field.usage'))
Expand All @@ -113,13 +119,29 @@ public static function table(Table $table): Table

IconColumn::make('is_enabled')
->label(__('app.field.active'))
->boolean(),
->boolean()
->shrink(),

IconColumn::make('is_listed')
->label(__('app.field.is_listed'))
->boolean()
->shrink(),
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\ActionGroup::make([
Tables\Actions\ViewAction::make(),

Tables\Actions\EditAction::make(),

ListAction::make(),

UnlistAction::make(),

Tables\Actions\DeleteAction::make(),
]),
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace App\Filament\Admin\Resources\ShelterAttributeResource\Actions;

use App\Models\ShelterAttribute;
use Filament\Facades\Filament;
use Filament\Tables\Actions\Action;

class ListAction extends Action
{
public static function getDefaultName(): ?string
{
return 'list';
}

protected function setUp(): void
{
parent::setUp();

$this->visible(fn (ShelterAttribute $record) => $record->isUnlisted() && Filament::auth()->user()->can('update', $record));

$this->label(__('app.attribute.actions.list.button'));

$this->color('success');

$this->icon('heroicon-o-eye');

$this->outlined();

$this->requiresConfirmation();

$this->modalHeading(__('app.attribute.actions.list.confirm.title'));

$this->modalDescription(__('app.attribute.actions.list.confirm.description'));

$this->action(function (ShelterAttribute $record) {
$record->list();
$this->success();
});

$this->successNotificationTitle(__('app.attribute.actions.list.confirm.success'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace App\Filament\Admin\Resources\ShelterAttributeResource\Actions;

use App\Models\ShelterAttribute;
use Filament\Facades\Filament;
use Filament\Tables\Actions\Action;

class UnlistAction extends Action
{
public static function getDefaultName(): ?string
{
return 'unlist';
}

protected function setUp(): void
{
parent::setUp();

$this->visible(fn (ShelterAttribute $record) => $record->isListed() && Filament::auth()->user()->can('update', $record));

$this->label(__('app.attribute.actions.unlist.button'));

$this->color('danger');

$this->icon('heroicon-o-eye-slash');

$this->outlined();

$this->requiresConfirmation();

$this->modalHeading(__('app.attribute.actions.unlist.confirm.title'));

$this->modalDescription(__('app.attribute.actions.unlist.confirm.description'));

$this->action(function (ShelterAttribute $record) {
$record->unlist();
$this->success();
});

$this->successNotificationTitle(__('app.attribute.actions.unlist.confirm.success'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public function table(Table $table): Table
fn () => Shelter::query()
->whereListed()
->whereNot('id', Filament::getTenant()->id)
->with('shelterVariables')
->with([
'country',
'location',
'shelterVariables',
])
)
->contentGrid([
'md' => 2,
Expand All @@ -53,9 +57,9 @@ public function table(Table $table): Table
->weight(FontWeight::Bold)
->searchable(),

TextColumn::make('address')
TextColumn::make('full_address')
->color(Color::Gray)
->searchable(),
->searchable('address'),

Split::make([
TextColumn::make('capacity')
Expand Down
6 changes: 5 additions & 1 deletion app/Livewire/RequestPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public function form(Form $form): Form
{
$shelters = Shelter::query()
->whereListed()
->with('shelterVariables')
->with([
'country',
'location',
'shelterVariables',
])
->when(
data_get($this->data, 'filters.variables'),
fn (Builder $query, array $variables) => $query->whereHasShelterVariables($variables)
Expand Down
12 changes: 12 additions & 0 deletions app/Models/Shelter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;

class Shelter extends Model
{
Expand Down Expand Up @@ -116,6 +117,17 @@ public function availableCapacity(): Attribute
);
}

public function fullAddress(): Attribute
{
return Attribute::make(
get: fn (mixed $value) => Str::trim(collect([
$this->address,
$this->location->name,
$this->country->name,
])->filter()->implode(', ')),
);
}

public function isListed(): bool
{
return $this->is_listed;
Expand Down
24 changes: 24 additions & 0 deletions app/Models/ShelterAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,28 @@ public function scopeWhereListed(Builder $query): Builder
->where('is_enabled', true)
->where('is_listed', true);
}

public function isListed(): bool
{
return $this->is_listed;
}

public function isUnlisted(): bool
{
return ! $this->isListed();
}

public function list(): bool
{
return $this->update([
'is_listed' => true,
]);
}

public function unlist(): bool
{
return $this->update([
'is_listed' => false,
]);
}
}
16 changes: 16 additions & 0 deletions lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,22 @@
'success' => 'Attribute deactivated successfully.',
],
],
'list' => [
'button' => 'List attribute',
'confirm' => [
'description' => 'Once a attribute is listed, it will be displayed in the public request form. In order to eliminate the attribute from this lists, it needs to be unlisted.',
'title' => 'List shelter attribute',
'success' => 'Shelter attribute listed successfully.',
],
],
'unlist' => [
'button' => 'Unlist attribute',
'confirm' => [
'description' => 'Once a attribute is unlisted, it will no longer be displayed in the public request form. To include the attribute in this lists again, it needs to be listed.',
'title' => 'Unlist shelter attribute',
'success' => 'Shelter attribute unlisted successfully.',
],
],
],
],
];
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="text-sm leading-6 text-gray-600 dark:text-gray-400">
{{ $shelter->address }}
{{ $shelter->full_address }}
</div>

<dl class="grid grid-cols-2 gap-4">
Expand Down
Loading