Skip to content

Commit

Permalink
add bcr project resource in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 23, 2023
1 parent 582d9b7 commit 7fdd703
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 35 deletions.
2 changes: 0 additions & 2 deletions app/Enums/BadgeRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ enum BadgeRules: string
case SHARING_FIRST_SHARE = 'sharing_first_share';
case SHARING_FIVE_SHARES = 'sharing_five_shares';



public function labelKeyPrefix(): string
{
return 'badge.types';
Expand Down
193 changes: 193 additions & 0 deletions app/Filament/Resources/BCRProjectResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Filament\Resources\BCRProjectResource\Pages;
use App\Models\BCRProject;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Actions\DeleteAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Actions\ViewAction;
use Filament\Tables\Columns\TextColumn;

class BCRProjectResource extends Resource
{
protected static ?string $model = BCRProject::class;

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

protected static ?int $navigationSort = 7;

public static function getPluralLabel(): ?string
{
return __('bcr-project.label.plural');
}

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

protected static function getNavigationGroup(): ?string
{
return __('navigation.group.manage');
}

protected static function getNavigationBadge(): ?string
{
return (string) BCRProject::count();
}

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->label(__('bcr-project.labels.title'))
->inlineLabel()
->columnSpanFull()
->required(),

Select::make('category_id')
->label(__('bcr-project.labels.category'))
->relationship('category', 'name')
->inlineLabel()
->columnSpanFull()
->required(),

Select::make('county_id')
->label(__('bcr-project.labels.county'))
->relationship('county', 'name')
->inlineLabel()
->columnSpanFull()
->required(),

Textarea::make('description')
->label(__('bcr-project.labels.description'))
->inlineLabel()
->columnSpanFull()
->required(),

DatePicker::make('start_date')
->label(__('bcr-project.labels.start_date'))
->inlineLabel()
->columnSpanFull()
->required(),

DatePicker::make('end_date')
->label(__('bcr-project.labels.end_date'))
->inlineLabel()
->columnSpanFull()
->required(),

TextInput::make('facebook_link')
->label(__('bcr-project.labels.facebook_link'))
->inlineLabel()
->columnSpanFull()
->required(),

SpatieMediaLibraryFileUpload::make('preview')
->collection('preview')
->label(__('project.labels.preview_image'))
->mediaName('preview')
->image()
->maxFiles(1)
->inlineLabel()
->columnSpanFull(),

SpatieMediaLibraryFileUpload::make('gallery')
->collection('gallery')
->label(__('project.labels.gallery'))
->image()
->multiple()
->maxFiles(20)
->inlineLabel()
->columnSpanFull(),

Repeater::make('external_links')
->schema([
TextInput::make('title')
->label(__('bcr-project.labels.external_links.title'))
->inlineLabel()
->columnSpanFull()
->required(),
TextInput::make('link')->label(__('bcr-project.labels.external_links.link'))
->inlineLabel()
->columnSpanFull()
->required(),
])
->label(__('bcr-project.labels.external_links.label'))
->inlineLabel()
->columnSpanFull(),

Repeater::make('videos')
->schema([
TextInput::make('link')->label(__('bcr-project.labels.videos'))
->inlineLabel()
->columnSpanFull()
->required(),
])
->inlineLabel()
->columnSpanFull(),

]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->formatStateUsing(function (BcrProject $record) {
return sprintf('#%d', $record->id);
})
->label(__('volunteer.column.id'))
->sortable(),
TextColumn::make('title')
->label(__('bcr-project.labels.title'))
->searchable()
->sortable(),
TextColumn::make('start_date')
->label(__('bcr-project.labels.start_date'))
->searchable()
->sortable(),
TextColumn::make('end_date')
->label(__('bcr-project.labels.end_date'))
->searchable()
->sortable(),

])
->filters([
//
])
->actions([
ViewAction::make(),
EditAction::make(),
DeleteAction::make(),

])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
])->defaultSort('id', 'desc');
}

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

namespace App\Filament\Resources\BCRProjectResource\Pages;

use App\Filament\Resources\BCRProjectResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;

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

namespace App\Filament\Resources\BCRProjectResource\Pages;

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

class EditBCRProject extends EditRecord
{
protected static string $resource = BCRProjectResource::class;

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

namespace App\Filament\Resources\BCRProjectResource\Pages;

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

class ListBCRProjects extends ListRecords
{
protected static string $resource = BCRProjectResource::class;

protected function getActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
20 changes: 11 additions & 9 deletions app/Filament/Resources/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
Expand Down Expand Up @@ -78,7 +80,7 @@ function (callable $get) {
}
)
->disabled(),
Forms\Components\Toggle::make('is_national')
Toggle::make('is_national')
->label(__('project.labels.is_national'))
->inlineLabel()
->columnSpanFull()
Expand Down Expand Up @@ -108,21 +110,21 @@ function (callable $get) {
->maxLength(255),
TextInput::make('target_budget')
->required(),
Forms\Components\DatePicker::make('start')
DatePicker::make('start')
->required(),
Forms\Components\DatePicker::make('end')
DatePicker::make('end')
->required(),
Forms\Components\Textarea::make('description')
Textarea::make('description')
->maxLength(65535),
Forms\Components\Textarea::make('scope')
Textarea::make('scope')
->maxLength(65535),
Forms\Components\Textarea::make('beneficiaries')
Textarea::make('beneficiaries')
->maxLength(65535),
Forms\Components\Textarea::make('reason_to_donate')
Textarea::make('reason_to_donate')
->maxLength(65535),
Forms\Components\Toggle::make('accepting_volunteers')
Toggle::make('accepting_volunteers')
->required(),
Forms\Components\Toggle::make('accepting_comments')
Toggle::make('accepting_comments')
->required(),
SpatieMediaLibraryFileUpload::make('preview')
->collection('preview')
Expand Down
72 changes: 72 additions & 0 deletions app/Models/BCRProject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace App\Models;

use App\Concerns\HasLocation;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Vite;
use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class BCRProject extends Model implements HasMedia
{
use HasFactory;
use HasLocation;
use InteractsWithMedia;

protected $fillable = [
'title',
'description',
'start_date',
'end_date',
'external_articles',
'facebook_link',
'accepting_comments',
'videos',
'city_id',
'county_id',
'project_category_id',
'is_national',
];

protected $casts = [
'external_links' => 'array',
'videos' => 'array',
'start_date' => 'datetime',
'end_date' => 'datetime',
'accepting_comments' => 'boolean',
'is_national' => 'boolean',
];

public function registerMediaCollections(): void
{
$this->addMediaCollection('preview')
->useFallbackUrl(Vite::image('placeholder.png'))
->singleFile()
->registerMediaConversions(function (Media $media) {
$this
->addMediaConversion('preview')
->fit(Manipulations::FIT_CONTAIN, 300, 300)
->nonQueued();
});

$this->addMediaCollection('gallery')
->registerMediaConversions(function (Media $media) {
$this
->addMediaConversion('preview')
->fit(Manipulations::FIT_CONTAIN, 300, 300)
->nonQueued();
});
}

public function category(): BelongsTo
{
return $this->belongsTo(ProjectCategory::class, 'project_category_id');
}
}
Loading

0 comments on commit 7fdd703

Please sign in to comment.