Skip to content

Commit

Permalink
Add more filtering options for admin, invitees and table types
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiritin committed Mar 5, 2023
1 parent f9919e1 commit dc7de83
Show file tree
Hide file tree
Showing 43 changed files with 1,326 additions and 252 deletions.
13 changes: 7 additions & 6 deletions app/Enums/ApplicationStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

namespace App\Enums;

enum ApplicationStatus
enum ApplicationStatus: string
{
case Open;
case Canceled;
case Accepted;
case TableOffered;
case TableAccepted;
case Canceled = 'canceled';
case Open = 'open';
case Waiting = 'waiting';
case TableOffered = 'table_offered';
case TableAccepted = 'table_accepted';
case CheckedIn = 'checked_in';
}
19 changes: 19 additions & 0 deletions app/Events/ApplicationCancelledEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Events;

use App\Models\Application;
use App\Models\User;
use Illuminate\Foundation\Events\Dispatchable;

class ApplicationCancelledEvent
{
use Dispatchable;

public Application $application;

public function __construct(Application $application)
{
$this->application = $application;
}
}
19 changes: 19 additions & 0 deletions app/Events/ApplicationCreatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Events;

use App\Models\Application;
use App\Models\User;
use Illuminate\Foundation\Events\Dispatchable;

class ApplicationCreatedEvent
{
use Dispatchable;

public Application $application;

public function __construct(Application $application)
{
$this->application = $application;
}
}
19 changes: 19 additions & 0 deletions app/Events/ApplicationUpdatedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Events;

use App\Models\Application;
use App\Models\User;
use Illuminate\Foundation\Events\Dispatchable;

class ApplicationUpdatedEvent
{
use Dispatchable;

public Application $application;

public function __construct(Application $application)
{
$this->application = $application;
}
}
19 changes: 19 additions & 0 deletions app/Events/ChildAddedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Events;

use App\Models\Application;
use App\Models\User;
use Illuminate\Foundation\Events\Dispatchable;

class ChildAddedEvent
{
use Dispatchable;

public Application $child;

public function __construct(Application $child)
{
$this->child = $child;
}
}
19 changes: 19 additions & 0 deletions app/Events/ChildRemovedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Events;

use App\Models\Application;
use App\Models\User;
use Illuminate\Foundation\Events\Dispatchable;

class ChildRemovedEvent
{
use Dispatchable;

public Application $child;

public function __construct(Application $child)
{
$this->child = $child;
}
}
174 changes: 111 additions & 63 deletions app/Filament/Resources/ApplicationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Filament\Resources;

use App\Enums\ApplicationStatus;
use App\Enums\ApplicationType;
use App\Filament\Resources\ApplicationResource\Pages;
use App\Filament\Resources\ApplicationResource\RelationManagers;
use App\Models\Application;
Expand All @@ -17,88 +19,129 @@ class ApplicationResource extends Resource
{
protected static ?string $model = Application::class;

protected static ?string $navigationIcon = 'heroicon-o-collection';

protected static ?string $navigationIcon = 'heroicon-o-folder';
public static function form(Form $form): Form
{
return $form
->columns(3)
->schema([
Forms\Components\TextInput::make('user_id')
->required(),
Forms\Components\TextInput::make('table_type_requested')
->required(),
Forms\Components\TextInput::make('table_type_assigned'),
Forms\Components\TextInput::make('parent'),
Forms\Components\TextInput::make('type')
->required()
->maxLength(255),
Forms\Components\TextInput::make('display_name')
->maxLength(255),
Forms\Components\TextInput::make('website')
->maxLength(255),
Forms\Components\TextInput::make('table_number')
->maxLength(255),
Forms\Components\TextInput::make('invite_code_shares')
->maxLength(255),
Forms\Components\TextInput::make('invite_code_assistants')
->maxLength(255),
Forms\Components\Textarea::make('merchandise')
->maxLength(65535),
Forms\Components\Textarea::make('wanted_neighbors')
->maxLength(65535),
Forms\Components\Textarea::make('unwanted_neighbors')
->maxLength(65535),
Forms\Components\Textarea::make('comment')
->maxLength(65535),
Forms\Components\Toggle::make('is_mature'),
Forms\Components\Toggle::make('is_afterdark'),
Forms\Components\Toggle::make('is_power'),
Forms\Components\Toggle::make('is_wallseat'),
Forms\Components\DateTimePicker::make('canceled_at'),
Forms\Components\DateTimePicker::make('accepted_at'),
Forms\Components\DateTimePicker::make('allocated_at'),
Forms\Components\Group::make()->columnSpan(2)->columns()->schema([
Forms\Components\TextInput::make('display_name')
->maxLength(255),
Forms\Components\TextInput::make('website')
->maxLength(255),

Forms\Components\Grid::make()->columns()->schema([
Forms\Components\TextInput::make('merchandise')
->maxLength(65535),
Forms\Components\Fieldset::make('Checks')->columnSpan(1)->columns(4)->schema([
Forms\Components\Toggle::make('is_mature')->label('Mature'),
Forms\Components\Toggle::make('is_afterdark')->label('Afterdark'),
Forms\Components\Toggle::make('is_power')->label('Power'),
Forms\Components\Toggle::make('is_wallseat')->label('Wallseat'),
]),
]),

Forms\Components\Grid::make()->columns()->schema([
Forms\Components\Textarea::make('wanted_neighbors')
->label('Wanted')
->maxLength(65535),
Forms\Components\Textarea::make('unwanted_neighbors')
->label('Unwanted')
->maxLength(65535),
]),
Forms\Components\Textarea::make('comment')
->columnSpanFull()
->maxLength(65535),
]),

Forms\Components\Group::make()->schema([

Forms\Components\Fieldset::make('Status')->inlineLabel()->columns(1)->schema([
Forms\Components\Select::make('status')->options([
"canceled" => "Canceled",
"open" => "Open",
"waiting" => "Waiting",
"table_offered" => "Table offered",
"table_accepted" => "Table accepted",
"checked_in" => "Checked in (Onsite)"
])->required(),
]),

Forms\Components\Fieldset::make('Relationships')->inlineLabel()->columns(1)->schema([
Forms\Components\Select::make('type')->options(ApplicationType::class)->required(),
Forms\Components\Select::make('user_id')->searchable()->relationship('user', 'name')
->required(),
Forms\Components\Select::make('parent')->searchable()->relationship('parent', 'id')
->getOptionLabelFromRecordUsing(function (?Application $record) {
return $record->user->name;
})
->hidden(function (?Application $record) {
return $record->type === ApplicationType::Dealer;
})
->required(),
Forms\Components\Select::make('table_type_requested')->relationship('requestedTable', 'name')->required(),
Forms\Components\Select::make('table_type_assigned')->relationship('assignedTable', 'name')->nullable(),
Forms\Components\TextInput::make('table_number')
->maxLength(255),
]),

Forms\Components\Fieldset::make('Dates')->inlineLabel()->columns(1)->schema([
Forms\Components\Placeholder::make('offer_sent_at')->content(fn(?Application $record): string => $record?->offer_sent_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('offer_accepted_at')->content(fn(?Application $record): string => $record?->offer_accepted_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('waiting_at')->content(fn(?Application $record): string => $record?->waiting_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('checked_in_at')->content(fn(?Application $record): string => $record?->checked_in_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('canceled_at')->content(fn(?Application $record): string => $record?->canceled_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('updated_at')->content(fn(?Application $record): string => $record?->updated_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('created_at')->content(fn(?Application $record): string => $record?->created_at?->diffForHumans() ?? '-'),
]),
]),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('user_id'),
Tables\Columns\TextColumn::make('table_type_requested'),
Tables\Columns\TextColumn::make('table_type_assigned'),
Tables\Columns\TextColumn::make('parent'),
Tables\Columns\TextColumn::make('type'),
Tables\Columns\TextColumn::make('display_name'),
Tables\Columns\TextColumn::make('website'),
Tables\Columns\TextColumn::make('table_number'),
Tables\Columns\TextColumn::make('invite_code_shares'),
Tables\Columns\TextColumn::make('invite_code_assistants'),
Tables\Columns\TextColumn::make('merchandise'),
Tables\Columns\TextColumn::make('wanted_neighbors'),
Tables\Columns\TextColumn::make('unwanted_neighbors'),
Tables\Columns\TextColumn::make('comment'),
Tables\Columns\TextColumn::make('user.name')->searchable(),
Tables\Columns\BadgeColumn::make('status')->enum(ApplicationStatus::cases())->formatStateUsing(function (Application $record) {
return $record->status->name;
})->colors([
'secondary',
'success' => ApplicationStatus::TableAccepted->value,
'danger' => ApplicationStatus::Canceled->value
]),
Tables\Columns\TextColumn::make('requestedTable.name'),
Tables\Columns\TextColumn::make('assignedTable.name'),
Tables\Columns\TextColumn::make('type')->formatStateUsing(function (string $state) {
return ucfirst($state);
})->sortable(),
Tables\Columns\TextColumn::make('display_name')->searchable(),
Tables\Columns\TextColumn::make('table_number')->sortable()->searchable(),
Tables\Columns\IconColumn::make('wanted_neighbors')->label('N Wanted')->default(false)->boolean(),
Tables\Columns\IconColumn::make('unwanted_neighbors')->label('N Unwanted')->default(false)->boolean(),
Tables\Columns\IconColumn::make('comment')->default(false)->boolean(),
Tables\Columns\IconColumn::make('is_mature')
->label('Mature')
->sortable()
->boolean(),
Tables\Columns\IconColumn::make('is_afterdark')
->label('AD')
->sortable()
->boolean(),
Tables\Columns\IconColumn::make('is_power')
->label('Power')
->sortable()
->boolean(),
Tables\Columns\IconColumn::make('is_wallseat')
->label('Wallseat')
->sortable()
->boolean(),
Tables\Columns\TextColumn::make('canceled_at')
->dateTime(),
Tables\Columns\TextColumn::make('accepted_at')
->dateTime(),
Tables\Columns\TextColumn::make('allocated_at')
->dateTime(),
Tables\Columns\TextColumn::make('created_at')
->dateTime(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime(),
])
->filters([
//
Tables\Filters\Filter::make('parent')->query(fn (Builder $query): Builder => $query->whereNull('parent'))->label('Only Full Dealerships')
])
->actions([
Tables\Actions\EditAction::make(),
Expand All @@ -107,20 +150,25 @@ public static function table(Table $table): Table
Tables\Actions\DeleteBulkAction::make(),
]);
}

public static function getRelations(): array
{
return [
//
RelationManagers\ChildrenRelationManager::class
];
}


protected function shouldPersistTableFiltersInSession(): bool
{
return true;
}

public static function getPages(): array
{
return [
'index' => Pages\ListApplications::route('/'),
'create' => Pages\CreateApplication::route('/create'),
'edit' => Pages\EditApplication::route('/{record}/edit'),
];
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace App\Filament\Resources\ApplicationResource\RelationManagers;

use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class ChildrenRelationManager extends RelationManager
{
protected static string $relationship = 'children';

protected static ?string $title = "Shares and Assistants";
protected static ?string $label = "application";
protected static ?string $recordTitleAttribute = 'user.name';

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('user.name')
->required()
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('user.name'),
])
->filters([
//
])
->headerActions([
])
->actions([
Tables\Actions\Action::make('Show'),
])
->bulkActions([
]);
}
}
Loading

0 comments on commit dc7de83

Please sign in to comment.