-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bcr projects resources in front and admin
- Loading branch information
1 parent
7fdd703
commit 59ded3b
Showing
35 changed files
with
573 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
app/Filament/Resources/BCRProjectResource/Pages/CreateBCRProject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
app/Filament/Resources/BCRProjectResource/Pages/EditBCRProject.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
app/Filament/Resources/BCRProjectResource/Pages/ListBCRProjects.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
app/Filament/Resources/BadgeCategoryResource/Pages/CreateBadgeCategory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
app/Filament/Resources/BadgeCategoryResource/Pages/EditBadgeCategory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
app/Filament/Resources/BadgeCategoryResource/Pages/ListBadgeCategories.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
app/Http/Resources/Collections/BcrProjectCardCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [ | ||
|
||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.