Skip to content

Commit

Permalink
Merge pull request #20 from canyongbs/feature/fdw-case-model-and-fila…
Browse files Browse the repository at this point in the history
…ment-setup

[Feature] Case Model and filament setup
  • Loading branch information
Orrison authored Jul 26, 2023
2 parents 13c564d + e5757cf commit 3d6f3d9
Show file tree
Hide file tree
Showing 38 changed files with 781 additions and 117 deletions.
18 changes: 18 additions & 0 deletions app/Enums/ColumnColorOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Enums;

enum ColumnColorOptions: string
{
case SUCCESS = 'success';

case DANGER = 'danger';

case WARNING = 'warning';

case INFO = 'info';

case PRIMARY = 'primary';

case GRAY = 'gray';
}
80 changes: 80 additions & 0 deletions app/Filament/Resources/CaseItemPriorityResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace App\Filament\Resources;

use Filament\Tables;
use Filament\Forms\Form;
use Filament\Tables\Table;
use App\Models\CaseItemPriority;
use Filament\Resources\Resource;
use Filament\Forms\Components\TextInput;
use App\Filament\Resources\CaseItemPriorityResource\Pages;

class CaseItemPriorityResource extends Resource
{
protected static ?string $model = CaseItemPriority::class;

protected static ?string $navigationGroup = 'Field Settings';

protected static ?int $navigationSort = 3;

protected static ?string $navigationIcon = 'heroicon-o-arrows-up-down';

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->label('Name')
->required(),
TextInput::make('order')
->numeric()
->label('Priority Order')
->required()
->disabledOn('edit'),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->label('Name')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('order')
->label('Priority Order')
->sortable(),
])
->defaultSort('order')
->filters([
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->reorderable('order');
}

public static function getRelations(): array
{
return [
];
}

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

namespace App\Filament\Resources\CaseItemPriorityResource\Pages;

use Filament\Resources\Pages\CreateRecord;
use App\Filament\Resources\CaseItemPriorityResource;

class CreateCaseItemPriority extends CreateRecord
{
protected static string $resource = CaseItemPriorityResource::class;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Filament\Resources\CaseItemPriorityResource\Pages;

use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use App\Filament\Resources\CaseItemPriorityResource;

class EditCaseItemPriority extends EditRecord
{
protected static string $resource = CaseItemPriorityResource::class;

protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\CaseItemPriorityResource\Pages;

use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use App\Filament\Resources\CaseItemPriorityResource;

class ListCaseItemPriorities extends ListRecords
{
protected static string $resource = CaseItemPriorityResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\CaseItemPriorityResource\Pages;

use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
use App\Filament\Resources\CaseItemPriorityResource;

class ViewCaseItemPriority extends ViewRecord
{
protected static string $resource = CaseItemPriorityResource::class;

protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}
128 changes: 128 additions & 0 deletions app/Filament/Resources/CaseItemResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

namespace App\Filament\Resources;

use Filament\Tables;
use App\Models\Student;
use App\Models\CaseItem;
use Filament\Forms\Form;
use Filament\Tables\Table;
use App\Models\CaseItemStatus;
use Filament\Resources\Resource;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Illuminate\Database\Eloquent\Builder;
use Filament\Forms\Components\MorphToSelect;
use App\Filament\Resources\CaseItemResource\Pages;

class CaseItemResource extends Resource
{
protected static ?string $model = CaseItem::class;

protected static ?string $navigationGroup = 'Cases';

protected static ?int $navigationSort = 1;

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

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('casenumber')
->label('Case #')
->required()
->disabledOn('edit'),
MorphToSelect::make('respondent')
->types([
MorphToSelect\Type::make(Student::class)
->getOptionLabelFromRecordUsing(fn (Student $student): string => "{$student->first_name} {$student->middle_name} {$student->last_name}")
->titleAttribute('first_name'),
])
->searchable()
->label('Respondent'),
// TODO: Add Institution input
Select::make('state')
->options(CaseItemStatus::pluck('name', 'id'))
->relationship('state', 'name')
->label('State')
->required(),
// TODO: Add Type input
Select::make('priority')
->relationship(
relationshipName: 'priority',
titleAttribute: 'name',
modifyOptionsQueryUsing: fn (Builder $query) => $query->orderBy('order'),
)
->label('Priority')
->required(),
Select::make('assignedTo')
->relationship(
relationshipName: 'assignedTo',
titleAttribute: 'name',
)
->label('Assigned To')
->required()
->searchable(['name', 'email']),
Textarea::make('close_details')
->label('Close Details/Description')
->nullable(),
Textarea::make('res_details')
->label('Internal Case Details')
->nullable(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('casenumber')
->label('Case #')
->searchable(),
Tables\Columns\TextColumn::make('priority.name')
->label('Priority')
->sortable(query: function (Builder $query, string $direction): Builder {
return $query->orderByPowerJoins('priority.order', $direction);
}),
Tables\Columns\TextColumn::make('state.name')
->label('Status')
->badge()
->color(fn (CaseItem $caseItem) => $caseItem->state->color),
])
->filters([
Tables\Filters\SelectFilter::make('priority')
->relationship('priority', 'name')
->multiple(),
Tables\Filters\SelectFilter::make('state')
->relationship('state', 'name')
->multiple(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListCaseItems::route('/'),
'create' => Pages\CreateCaseItem::route('/create'),
'view' => Pages\ViewCaseItem::route('/{record}'),
'edit' => Pages\EditCaseItem::route('/{record}/edit'),
];
}
}
11 changes: 11 additions & 0 deletions app/Filament/Resources/CaseItemResource/Pages/CreateCaseItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace App\Filament\Resources\CaseItemResource\Pages;

use Filament\Resources\Pages\CreateRecord;
use App\Filament\Resources\CaseItemResource;

class CreateCaseItem extends CreateRecord
{
protected static string $resource = CaseItemResource::class;
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/CaseItemResource/Pages/EditCaseItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\CaseItemResource\Pages;

use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use App\Filament\Resources\CaseItemResource;

class EditCaseItem extends EditRecord
{
protected static string $resource = CaseItemResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/CaseItemResource/Pages/ListCaseItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\CaseItemResource\Pages;

use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use App\Filament\Resources\CaseItemResource;

class ListCaseItems extends ListRecords
{
protected static string $resource = CaseItemResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
17 changes: 17 additions & 0 deletions app/Filament/Resources/CaseItemResource/Pages/ViewCaseItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Filament\Resources\CaseItemResource\Pages;

use Filament\Resources\Pages\ViewRecord;
use App\Filament\Resources\CaseItemResource;

class ViewCaseItem extends ViewRecord
{
protected static string $resource = CaseItemResource::class;

protected function getHeaderActions(): array
{
return [
];
}
}
Loading

0 comments on commit 3d6f3d9

Please sign in to comment.