Skip to content

Commit

Permalink
fix bcr projects resources in front and admin
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 24, 2023
1 parent 7fdd703 commit 59ded3b
Show file tree
Hide file tree
Showing 35 changed files with 573 additions and 342 deletions.
1 change: 0 additions & 1 deletion app/Enums/EuPlatescStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Enums;

use App\Concerns\Enums\Arrayable;
use App\Concerns\Enums\Comparable;
use App\Concerns\Enums\HasLabel;

enum EuPlatescStatus: string
Expand Down
10 changes: 5 additions & 5 deletions app/Filament/Resources/BCRProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->label(__('bcr-project.labels.title'))
TextInput::make('name')
->label(__('bcr-project.labels.name'))
->inlineLabel()
->columnSpanFull()
->required(),
Expand Down Expand Up @@ -152,10 +152,10 @@ public static function table(Table $table): Table
->formatStateUsing(function (BcrProject $record) {
return sprintf('#%d', $record->id);
})
->label(__('volunteer.column.id'))
->label(__('bcr-project.labels.id'))
->sortable(),
TextColumn::make('title')
->label(__('bcr-project.labels.title'))
TextColumn::make('name')
->label(__('bcr-project.labels.name'))
->searchable()
->sortable(),
TextColumn::make('start_date')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\BCRProjectResource\Pages;

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

class CreateBCRProject extends CreateRecord
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\BCRProjectResource\Pages;

use App\Filament\Resources\BCRProjectResource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\BCRProjectResource\Pages;

use App\Filament\Resources\BCRProjectResource;
Expand Down
10 changes: 3 additions & 7 deletions app/Filament/Resources/BadgeCategoryResource.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Enums\VolunteerStatus;
use App\Filament\Resources\BadgeCategoryResource\Pages;
use App\Filament\Resources\BadgeCategoryResource\RelationManagers;
use App\Models\BadgeCategory;
use App\Models\VolunteerRequest;
use Filament\Forms;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use Filament\Resources\Resource;
Expand All @@ -16,7 +14,6 @@
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\TernaryFilter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class BadgeCategoryResource extends Resource
{
Expand Down Expand Up @@ -46,14 +43,13 @@ protected static function getNavigationBadge(): ?string
return (string) BadgeCategory::query()->whereHas('badges')->count();
}


public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('title')
->label(__('badge.category.title'))
->required()
->required(),
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\BadgeCategoryResource\Pages;

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

class CreateBadgeCategory extends CreateRecord
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\BadgeCategoryResource\Pages;

use App\Filament\Resources\BadgeCategoryResource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\BadgeCategoryResource\Pages;

use App\Filament\Resources\BadgeCategoryResource;
Expand Down
59 changes: 59 additions & 0 deletions app/Http/Controllers/BcrProjectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Filters\AcceptsVolunteersFilter;
use App\Http\Filters\BcrProjectDatesFilter;
use App\Http\Filters\CountiesFilter;
use App\Http\Filters\ProjectCategoriesFilter;
use App\Http\Filters\ProjectDatesFilter;
use App\Http\Filters\ProjectStatusFilter;
use App\Http\Filters\SearchFilter;
use App\Http\Resources\BCRProjectCardResource;
use App\Http\Resources\BcrProjectResource;
use App\Http\Resources\Collections\BcrProjectCardCollection;
use App\Http\Sorts\ProjectDonationsCountSort;
use App\Http\Sorts\ProjectDonationsSumSort;
use App\Models\BCRProject;
use App\Models\Project;
use Inertia\Inertia;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\AllowedSort;
use Spatie\QueryBuilder\QueryBuilder;

class BcrProjectController extends Controller
{
public function index()
{
return Inertia::render('Public/Bcr/Index', [
'view' => 'list',
'categories' => $this->getProjectCategories(),
'counties' => $this->getCounties(),
'collection' => new BcrProjectCardCollection(
QueryBuilder::for(BCRProject::class)
->allowedFilters([
AllowedFilter::exact('county', 'county_id'),
AllowedFilter::exact('category', 'project_category_id'),
AllowedFilter::custom('date', new BcrProjectDatesFilter),
AllowedFilter::custom('search', new SearchFilter),
])
->allowedSorts([
AllowedSort::field('publish_date', 'start_date'),
AllowedSort::field('end_date', 'end_date'),
])
->orderBy('id', 'desc')
->paginate()
->withQueryString()
),
]);
}

public function show(BCRProject $project)
{
return Inertia::render('Public/Bcr/Show', [
'project' => new BcrProjectResource($project),
]);
}
}
5 changes: 3 additions & 2 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Resources\BCRProjectCardResource;
use App\Http\Resources\ProjectCardResource;
use App\Models\Article;
use App\Models\BCRProject;
use App\Models\Organization;
use App\Models\Project;
use Inertia\Inertia;
Expand Down Expand Up @@ -35,8 +36,8 @@ public function index()
),

'bcr_projects' => BCRProjectCardResource::collection(
Project::whereIsOpen()
// TODO: ->whereOrganizationIsBCR()
BCRProject::query()
->with('county')
->limit(12)
->get()
),
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Filters/BcrProjectDatesFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Http\Filters;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Spatie\QueryBuilder\Filters\Filter;

class BcrProjectDatesFilter implements Filter
{
public function __invoke(Builder $query, $dates, string $property): void
{
$start = Carbon::createFromFormat('Y-m-d', $dates[0]);
$end = Carbon::createFromFormat('Y-m-d', $dates[1]);

$query->whereDate('start_date', '>=', $start)
->whereDate('end_date', '<=', $end);
}
}
20 changes: 11 additions & 9 deletions app/Http/Resources/BCRProjectCardResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ public function toArray(Request $request): array
{
return [
'id' => $this->id,
// 'type' => $this->type,
'type' => 'bcr_project',
'name' => $this->name,
'slug' => $this->slug,
'county' => 'Replace me', // $this->county?->name,
'image' => Vite::asset('resources/images/placeholder.png'),
'organization' => [
'name' => $this->organization->name,
'id' => $this->organization->id,
],
'county' => $this->county?->name,
'image' => $this->getFirstMediaUrl('preview') ?? Vite::image('placeholder.png'),
'description' => $this->description,
'start_date' => $this->start_date,
'end_date' => $this->end_date,
'facebook_link' => $this->facebook_link,
'is_national' => $this->is_national,
'accepting_comments' => $this->accepting_comments,
'videos' => $this->videos,
'external_links' => $this->external_links,

'is_active' => $this->is_active,
'is_ending_soon' => $this->is_ending_soon,
];
}
}
51 changes: 51 additions & 0 deletions app/Http/Resources/BcrProjectResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class BcrProjectResource extends JsonResource
{
public static $wrap = null;

public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'county' => $this->county->name,
'image' => $this->getFirstMediaUrl('preview'),
'gallery' => $this->getMedia('gallery')->map(function ($media) {
return [
'id' => $media->id,
'url' => $media->getFullUrl(),
];
})->toArray(),
'is_national' => \boolval($this->is_national),
'area' => $this->is_national ? __('bcr-project.labels.national') : $this->county->name,
'start' => $this->start_date?->format('d.m.Y'),
'end' => $this->end_date?->format('d.m.Y'),
'description' => $this->description,
'accepting_comments' => \boolval($this->accepting_comments),
'embedded_videos' => $this->embedded_videos,
'swipe_gallery' => $this->getMedia('gallery')->map(function ($media) {
return [
'src' => $media->getFullUrl(),
'thumbnail' => $media->getFullUrl('preview'),
'w' => 1200,
'h' => 800,
];
})->toArray(),
'external_links' => collect($this->external_links)->map(function (array $link) {
$link['source'] = parse_url($link['link'], \PHP_URL_HOST);

return $link;
}),
'category' => $this->category->name,
];
}
}
20 changes: 20 additions & 0 deletions app/Http/Resources/Collections/BcrProjectCardCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources\Collections;

use App\Http\Resources\BCRProjectCardResource;
use App\Http\Resources\ProjectCardResource;

class BcrProjectCardCollection extends ResourceCollection
{
public $collects = BCRProjectCardResource::class;

protected function getColumns(): array
{
return [

];
}
}
4 changes: 2 additions & 2 deletions app/Http/Resources/Project/ShowProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function toArray(Request $request): array
],
'is_national' => \boolval($this->is_national),
'beneficiaries' => $this->beneficiaries,
'start' => $this->start?->format('Y-m-d'),
'end' => $this->end?->format('Y-m-d'),
'start' => $this->start?->format('d.m.Y'),
'end' => $this->end?->format('d.m.Y'),
'description' => $this->description,
'scope' => $this->scope,
'reason_to_donate' => $this->reason_to_donate,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/ProjectCardResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function toArray(Request $request): array
{
return [
'id' => $this->id,
// 'type' => $this->type,
'type' => 'project',
'name' => $this->name,
'slug' => $this->slug,
'county' => $this->counties->pluck('name')->join(', '), // $this->county?->name,
Expand Down
Loading

0 comments on commit 59ded3b

Please sign in to comment.