Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Dec 14, 2023
1 parent c2eca5a commit f4f7262
Show file tree
Hide file tree
Showing 14 changed files with 297 additions and 68 deletions.
102 changes: 102 additions & 0 deletions app/Filament/Organizations/Resources/CommunityProfileResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

use App\Filament\Organizations\Resources\CommunityProfileResource\Pages;
use App\Models\CommunityProfile;
use App\Models\Service;
use Awcodes\FilamentTableRepeater\Components\TableRepeater;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Resources\Resource;

class CommunityProfileResource extends Resource
Expand Down Expand Up @@ -36,4 +47,95 @@ public static function getPages(): array
'index' => Pages\EditCommunityProfile::route('/'),
];
}

public static function form(Form $form): Form
{
$services = Service::pluck('name', 'id');

return $form
->schema([
Section::make()
->columns(4)
->schema([
Group::make()
->columnSpan(3)
->schema([
TextInput::make('name')
->label(__('community.field.name'))
->placeholder(__('community.placeholder.name'))
->maxLength(200)
->required(),

TableRepeater::make('services')
->relationship()
->reorderable(false)
->hideLabels()
->addActionLabel(__('service.action.create'))
->minItems(1)
->schema([
Hidden::make('model_type')
->default(app(CommunityProfile::class)->getMorphClass()),

Select::make('service_id')
->label(__('community.field.service'))
->options($services)
->required(),

Toggle::make('is_visible')
->label(__('community.field.service_visible')),

Toggle::make('is_available')
->label(__('community.field.service_available')),

]),

Select::make('counties')
->relationship('counties', 'name')
->label(__('community.field.location'))
->placeholder(__('community.placeholder.location'))
->multiple()
->preload(),
]),

RichEditor::make('description')
->label(__('community.field.description'))
->placeholder(__('community.placeholder.description'))
->toolbarButtons([
'bold',
'bulletList',
'italic',
'link',
'orderedList',
'redo',
'strike',
'underline',
'undo',
])
->columnSpanFull(),

SpatieMediaLibraryFileUpload::make('logo')
->label(__('community.field.logo'))
->helperText(__('community.help.logo'))
->image()
->collection('logo')
->conversion('large')
->columnSpanFull(),

TextInput::make('email')
->label(__('community.field.email'))
->placeholder(__('placeholder.email'))
->email(),

TextInput::make('phone')
->label(__('community.field.phone'))
->placeholder(__('placeholder.phone'))
->tel(),

TextInput::make('website')
->label(__('community.field.website'))
->placeholder(__('placeholder.url'))
->url(),
]),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
namespace App\Filament\Organizations\Resources\CommunityProfileResource\Pages;

use App\Filament\Organizations\Resources\CommunityProfileResource;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Pages\EditRecord;

class EditCommunityProfile extends EditRecord
Expand All @@ -26,54 +21,4 @@ public function mount($record = null): void

$this->previousUrl = url()->previous();
}

public function form(Form $form): Form
{
return $form
->schema([
Section::make()
->columns(4)
->schema([
TextInput::make('name')
->label(__('organization.field.name'))
->maxLength(200)
->columnSpan(3)
->required(),

RichEditor::make('description')
->label(__('organization.field.description'))
->toolbarButtons([
'bold',
'bulletList',
'italic',
'link',
'orderedList',
'redo',
'strike',
'underline',
'undo',
])
->columnSpanFull(),

SpatieMediaLibraryFileUpload::make('logo')
->label(__('organization.field.logo'))
->image()
->collection('logo')
->conversion('large')
->columnSpanFull(),

TextInput::make('email')
->label(__('organization.field.email'))
->email(),

TextInput::make('phone')
->label(__('organization.field.phone'))
->tel(),

TextInput::make('website')
->label(__('organization.field.website'))
->url(),
]),
]);
}
}
28 changes: 16 additions & 12 deletions app/Filament/Organizations/Resources/CommunityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Filament\Organizations\Resources\CommunityResource\Pages;
use App\Models\CommunityProfile;
use App\Tables\Columns\ServiceChipsColumn;
use Filament\Infolists\Components\Grid;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Components\SpatieMediaLibraryImageEntry;
Expand All @@ -21,6 +22,7 @@
use Filament\Tables\Enums\FiltersLayout;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;

class CommunityResource extends Resource
Expand All @@ -29,6 +31,8 @@ class CommunityResource extends Resource

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

protected static ?string $recordRouteKeyName = 'slug';

protected static bool $isScopedToTenant = false;

protected static ?string $slug = 'community';
Expand All @@ -45,16 +49,6 @@ public static function getNavigationLabel(): string
return __('navigation.community.network');
}

public static function getModelLabel(): string
{
return __('beneficiary.label.singular');
}

public static function getPluralModelLabel(): string
{
return __('beneficiary.label.plural');
}

public static function infolist(Infolist $infolist): Infolist
{
return $infolist
Expand Down Expand Up @@ -113,6 +107,7 @@ public static function infolist(Infolist $infolist): Infolist
public static function table(Table $table): Table
{
return $table
->modifyQueryUsing(fn (Builder $query) => $query->with('services', 'counties'))
->columns([
Split::make([
Stack::make([
Expand All @@ -125,7 +120,7 @@ public static function table(Table $table): Table
->size('text-3xl')
->weight('normal')
->extraAttributes([
'class' => 'mt-2.5 mb-6',
'class' => '-mt-3.5',
]),

TextColumn::make('description')
Expand All @@ -135,7 +130,12 @@ public static function table(Table $table): Table
->stripTags()
->limit(300, '...')
),

ServiceChipsColumn::make('services'),
])
->extraAttributes([
'class' => 'flex flex-col gap-6',
])
->columnSpan(2),

SpatieMediaLibraryImageColumn::make('logo')
Expand All @@ -150,6 +150,10 @@ public static function table(Table $table): Table
])
->from('md'),
])

->contentGrid([
'default' => 1,
])
->filters([
SelectFilter::make('county')
->relationship('counties', 'name')
Expand All @@ -174,7 +178,7 @@ public static function getPages(): array
{
return [
'index' => Pages\ListCommunityProfiles::route('/'),
'view' => Pages\ViewCommunityProfile::route('/{record}'),
'view' => Pages\ViewCommunityProfile::route('/{record:slug}'),
];
}
}
15 changes: 15 additions & 0 deletions app/Models/CommunityProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace App\Models;

use App\Concerns\HasCounties;
use App\Concerns\HasSlug;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
Expand All @@ -16,10 +18,12 @@ class CommunityProfile extends Model implements HasMedia
{
use HasCounties;
use HasFactory;
use HasSlug;
use InteractsWithMedia;

protected $fillable = [
'name',
'slug',
'description',
'email',
'phone',
Expand All @@ -31,6 +35,12 @@ public function organization(): BelongsTo
return $this->belongsTo(Organization::class);
}

public function services(): HasMany
{
return $this->hasMany(ServicePivot::class, 'model_id')
->where('model_type', $this->getMorphClass());
}

public function registerMediaCollections(): void
{
$this->addMediaCollection('logo')
Expand All @@ -41,4 +51,9 @@ public function registerMediaCollections(): void
->optimize();
});
}

protected function getSlugSource(): string
{
return $this->name;
}
}
36 changes: 36 additions & 0 deletions app/Models/ServicePivot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Pivot;

class ServicePivot extends Pivot
{
public $timestamps = false;

protected $table = 'model_has_services';

protected $fillable = [
'model_type',
'service_id',
'is_visible',
'is_available',
];

protected $casts = [
'is_visible' => 'boolean',
'is_available' => 'boolean',
];

protected $with = [
'service',
];

public function service(): BelongsTo
{
return $this->belongsTo(Service::class);
}
}
32 changes: 32 additions & 0 deletions app/Tables/Columns/ServiceChipsColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace App\Tables\Columns;

use Closure;
use Filament\Tables\Columns\Column;
use Filament\Tables\Columns\Concerns;

class ServiceChipsColumn extends Column
{
use Concerns\HasColor;

protected string $view = 'tables.columns.service-chips-column';

protected string | Closure | null $size = null;

public function size(string | Closure | null $size): static
{
$this->size = $size;

return $this;
}

public function getSize(mixed $state): string | null
{
return $this->evaluate($this->size, [
'state' => $state,
]);
}
}
Loading

0 comments on commit f4f7262

Please sign in to comment.