Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

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

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

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

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

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

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

$this->color('success');

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

$this->outlined();

$this->requiresConfirmation();

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

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

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

$this->successNotificationTitle(__('app.shelter.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\OrganizationResource\Actions;

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

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

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

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

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

$this->color('danger');

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

$this->outlined();

$this->requiresConfirmation();

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

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

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

$this->successNotificationTitle(__('app.shelter.actions.unlist.confirm.success'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

namespace App\Filament\Admin\Resources\OrganizationResource\RelationManagers;

use App\Filament\Admin\Resources\OrganizationResource\Actions\ListShelterAction;
use App\Filament\Admin\Resources\OrganizationResource\Actions\UnlistShelterAction;
use App\Filament\Admin\Resources\OrganizationResource\Schemas\SheltersForm;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

Expand All @@ -26,6 +29,11 @@ public function table(Table $table): Table
return $table
->recordTitleAttribute('name')
->columns([
IconColumn::make('is_listed')
->label(__('app.field.is_listed'))
->boolean()
->shrink(),

TextColumn::make('name')
->label(__('app.field.name'))
->searchable()
Expand All @@ -50,7 +58,6 @@ public function table(Table $table): Table
->wrap()
->searchable()
->sortable(),

])
->filters([
//
Expand All @@ -60,9 +67,17 @@ public function table(Table $table): Table
->createAnother(false),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Tables\Actions\ActionGroup::make([
Tables\Actions\ViewAction::make(),

Tables\Actions\EditAction::make(),

ListShelterAction::make(),

UnlistShelterAction::make(),

Tables\Actions\DeleteAction::make(),
]),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function table(Table $table): Table
return $table
->query(
fn () => Shelter::query()
->whereListed()
->whereNot('id', Filament::getTenant()->id)
->with('shelterVariables')
)
Expand Down
1 change: 1 addition & 0 deletions app/Livewire/RequestPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function handle()
public function form(Form $form): Form
{
$shelters = Shelter::query()
->whereListed()
->get(['id', 'name', 'address']);

return $form
Expand Down
36 changes: 36 additions & 0 deletions app/Models/Shelter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Concerns\LogsActivity;
use App\Data\PersonData;
use Database\Factories\ShelterFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -32,13 +33,15 @@ class Shelter extends Model
'address',
'coordinator',
'notes',
'is_listed',
];

protected function casts(): array
{
return [
'capacity' => 'integer',
'coordinator' => PersonData::class,
'is_listed' => 'boolean',
];
}

Expand Down Expand Up @@ -75,6 +78,15 @@ public function shelterVariables(): BelongsToMany
return $this->belongsToMany(ShelterVariable::class);
}

public function scopeWhereListed(Builder $query): Builder
{
return $query
->where('is_listed', true)
->whereHas('organization', function (Builder $query) {
$query->whereActive();
});
}

public function availableCapacity(): Attribute
{
return Attribute::make(
Expand All @@ -83,4 +95,28 @@ public function availableCapacity(): Attribute
->count(),
);
}

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,
]);
}
}
1 change: 1 addition & 0 deletions database/factories/ShelterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function definition(): array
phone: fake()->e164PhoneNumber(),
),
'notes' => fake()->paragraph(),
'is_listed' => fake()->boolean(),
];
}

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

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('shelters', function (Blueprint $table) {
$table->boolean('is_listed')
->default(false)
->after('capacity');
});
}
};
19 changes: 19 additions & 0 deletions lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
'id' => 'ID',
'identifier' => 'Identifier',
'is_indefinite' => 'Indefinite end date',
'is_listed' => 'Listed',
'label' => 'Label',
'latest_stay' => 'Latest stay',
'legal_documents' => 'Legal documents',
Expand Down Expand Up @@ -258,6 +259,24 @@
'plural' => 'shelters',
],
'profile' => 'Profile',
'actions' => [
'list' => [
'button' => 'List shelter',
'confirm' => [
'description' => 'Once a shelter is listed, it will be displayed in the public request form and in the referral process. In order to eliminate the shelter from these lists, it needs to be unlisted.',
'title' => 'List shelter',
'success' => 'Shelter listed successfully.',
],
],
'unlist' => [
'button' => 'Unlist shelter',
'confirm' => [
'description' => 'Once a shelter is unlisted, it will no longer be displayed in the public request form or in the referral process. To include the shelter in these lists again, it needs to be listed.',
'title' => 'Unlist shelter',
'success' => 'Shelter unlisted successfully.',
],
],
],
],
'user' => [
'label' => [
Expand Down
Loading