Skip to content

Commit

Permalink
hackgreenville-com-432 - Set admin panel FilamentPHP icon, item sorti…
Browse files Browse the repository at this point in the history
…ng, and fix resource global searching

resolves hackgvl#432
  • Loading branch information
zach2825 committed Nov 5, 2024
1 parent 2737fb8 commit c22c6a7
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 139 deletions.
10 changes: 8 additions & 2 deletions app/Filament/Resources/CategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Filament\Resources\CategoryResource\Pages;
use App\Models\Category;
use Exception;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
Expand All @@ -14,7 +15,9 @@ class CategoryResource extends Resource
{
protected static ?string $model = Category::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = Category::icon;

protected static ?int $navigationSort = 900;

public static function form(Form $form): Form
{
Expand All @@ -26,6 +29,9 @@ public static function form(Form $form): Form
]);
}

/**
* @throws Exception
*/
public static function table(Table $table): Table
{
return $table
Expand All @@ -46,7 +52,7 @@ public static function table(Table $table): Table
->toggleable(isToggledHiddenByDefault: true),
])
->filters([

Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Expand Down
23 changes: 22 additions & 1 deletion app/Filament/Resources/EventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,35 @@
use App\Models\Event;
use App\Models\Org;
use App\Models\Venue;
use Exception;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Malzariey\FilamentDaterangepickerFilter\Filters\DateRangeFilter;

class EventResource extends Resource
{
protected static ?string $model = Event::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = Event::icon;

protected static ?int $navigationSort = 20;

public static function getGloballySearchableAttributes(): array
{
return ['event_name', 'description'];
}

public static function getGlobalSearchResultDetails(Model $record): array
{
return [
'Event Name' => $record->event_name,
'Description' => $record->description,
];
}

public static function form(Form $form): Form
{
Expand Down Expand Up @@ -90,6 +107,9 @@ public static function form(Form $form): Form
]);
}

/**
* @throws Exception
*/
public static function table(Table $table): Table
{
return $table
Expand All @@ -114,6 +134,7 @@ public static function table(Table $table): Table
->sortable(),
])
->filters([
Tables\Filters\TrashedFilter::make(),
DateRangeFilter::make('active_at')
->defaultToday()
->autoApply()
Expand Down
212 changes: 125 additions & 87 deletions app/Filament/Resources/OrgResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
use App\Enums\EventServices;
use App\Enums\OrganizationStatus;
use App\Filament\Resources\OrgResource\Pages;
use App\Filament\Resources\OrgResource\RelationManagers\EventsRelationManager;
use App\Models\Org;
use App\Models\Venue;
use Exception;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class OrgResource extends Resource
{
Expand All @@ -20,131 +25,164 @@ class OrgResource extends Resource

protected static ?string $model = Org::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = Org::icon;

protected static ?int $navigationSort = 10;

public static function getGloballySearchableAttributes(): array
{
return [
'slug',
'title',
'description',
'uri',
'focus_area',
'city',
];
}

public static function getGlobalSearchResultDetails(Venue|Model $record): array
{
return [
'Title' => $record->title,
'Description' => $record->description,
'City' => $record->city,
'Focus Area' => $record->focus_area,
'URI' => $record->uri,
];
}

public static function form(Form $form): Form
{
return $form
->schema([

Forms\Components\Section::make('General')
->columns(2)
->schema([
Forms\Components\TextInput::make('title')
->required()
->columnSpanFull()
->maxLength(255),

Forms\Components\TextInput::make('slug')
->required()
->columnSpanFull()
->maxLength(255),

Forms\Components\Textarea::make('description')
->required()
->columnSpanFull(),

Forms\Components\TextInput::make('focus_area')
->required()
->columnSpanFull(),

Forms\Components\TextInput::make('city')
->required()
->maxLength(255),

Forms\Components\TextInput::make('organization_type')
->datalist(Org::distinct()->pluck('organization_type'))
->required(),

Forms\Components\Select::make('category_id')
->relationship(name: 'category', titleAttribute: 'label')
->required(),

Forms\Components\Select::make('tags')
->multiple()
->relationship('tags', 'name'),

Forms\Components\TextInput::make('uri')
->name('Url')
->url()
->maxLength(255),

Forms\Components\Select::make('status')
->required()
->options(OrganizationStatus::class),

Forms\Components\DateTimePicker::make('established_at')
->required()
->time(false)
->format('m/d/Y'),

Forms\Components\DateTimePicker::make('inactive_at')
->time(false)
->format('m/d/Y'),
]),
->columns(2)
->schema([
Forms\Components\TextInput::make('title')
->required()
->live(onBlur: true)
->afterStateUpdated(fn (Forms\Set $set, ?string $state) => $set('slug', Str::slug($state)))
->maxLength(255),

Forms\Components\TextInput::make('slug')
->disabledOn(
'edit'
)
->live()
->maxLength(255),

Forms\Components\Textarea::make('description')
->required()
->columnSpanFull(),

Forms\Components\TextInput::make('focus_area')
->required()
->columnSpanFull(),

Forms\Components\TextInput::make('city')
->required()
->maxLength(255),

Forms\Components\TextInput::make('organization_type')
->datalist(Org::distinct()->pluck('organization_type'))
->required(),

Forms\Components\Select::make('category_id')
->relationship(name: 'category', titleAttribute: 'label')
->required(),

Forms\Components\Select::make('tags')
->multiple()
->relationship('tags', 'name'),

Forms\Components\TextInput::make('uri')
->name('Url')
->url()
->maxLength(255),

Forms\Components\Select::make('status')
->required()
->options(OrganizationStatus::class),

Forms\Components\DateTimePicker::make('established_at')
->required()
->time(false)
->format('m/d/Y'),

Forms\Components\DateTimePicker::make('inactive_at')
->time(false)
->format('m/d/Y'),
]),

Forms\Components\Section::make('Contacts')
->schema([
Forms\Components\TextInput::make('primary_contact_person')
->maxLength(255),
]),
->schema([
Forms\Components\TextInput::make('primary_contact_person')
->maxLength(255),
]),

Forms\Components\Section::make('Event Service')
->columns(2)
->schema([
Forms\Components\Select::make('service')
->options(EventServices::class),
->columns(2)
->schema([
Forms\Components\Select::make('service')
->options(EventServices::class),

Forms\Components\TextInput::make('service_api_key')
->maxLength(255),
Forms\Components\TextInput::make('service_api_key')
->maxLength(255),

Forms\Components\TextInput::make('event_calendar_uri')
->maxLength(255),
]),
Forms\Components\TextInput::make('event_calendar_uri')
->maxLength(255),
]),
]);
}

/**
* @throws Exception
*/
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('title')
->searchable(),
->searchable(),

Tables\Columns\TextColumn::make('city')
->searchable(),
->searchable(),

Tables\Columns\TextColumn::make('primary_contact_person')
->searchable(),
->searchable(),

Tables\Columns\TextColumn::make('service')
->searchable()
->sortable(),
->toggleable(isToggledHiddenByDefault: true)
->searchable()
->sortable(),

Tables\Columns\TextColumn::make('service_api_key')
->searchable()
->sortable(),
->toggleable(isToggledHiddenByDefault: true)
->searchable()
->sortable(),

Tables\Columns\TextColumn::make('status')
->sortable(),
->sortable(),

Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),

Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),

Tables\Columns\TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([

Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Expand All @@ -161,7 +199,7 @@ public static function table(Table $table): Table
public static function getRelations(): array
{
return [

EventsRelationManager::class,
];
}

Expand Down
4 changes: 3 additions & 1 deletion app/Filament/Resources/StateResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class StateResource extends Resource
{
protected static ?string $model = State::class;

protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = State::icon;

protected static ?int $navigationSort = 1000;

public static function form(Form $form): Form
{
Expand Down
Loading

0 comments on commit c22c6a7

Please sign in to comment.