From 0d8f43fda1a1fa67c6e27c9683959207c159ae0c Mon Sep 17 00:00:00 2001 From: Lupu Gheorghe Date: Wed, 25 Oct 2023 11:43:40 +0300 Subject: [PATCH] fix --- app/Filament/Resources/BCRProjectResource.php | 27 +-- app/Http/Controllers/DonorController.php | 119 +++++-------- app/Http/Filters/DonationDatesFilter.php | 21 +++ app/Models/BCRProject.php | 2 + resources/js/Helpers/useFilters.js | 1 - resources/js/Pages/Donor/Donations.vue | 162 ++++++++++++++---- 6 files changed, 209 insertions(+), 123 deletions(-) create mode 100644 app/Http/Filters/DonationDatesFilter.php diff --git a/app/Filament/Resources/BCRProjectResource.php b/app/Filament/Resources/BCRProjectResource.php index d7edb3cc..187733d3 100644 --- a/app/Filament/Resources/BCRProjectResource.php +++ b/app/Filament/Resources/BCRProjectResource.php @@ -5,8 +5,11 @@ namespace App\Filament\Resources; use App\Filament\Resources\BCRProjectResource\Pages; +use App\Models\Article; use App\Models\BCRProject; +use Camya\Filament\Forms\Components\TitleWithSlugInput; use Filament\Forms\Components\DatePicker; +use Filament\Forms\Components\Grid; use Filament\Forms\Components\Repeater; use Filament\Forms\Components\Select; use Filament\Forms\Components\SpatieMediaLibraryFileUpload; @@ -53,11 +56,14 @@ public static function form(Form $form): Form { return $form ->schema([ - TextInput::make('name') - ->label(__('bcr-project.labels.name')) - ->inlineLabel() - ->columnSpanFull() - ->required(), + TitleWithSlugInput::make( + fieldTitle: 'name', + fieldSlug: 'slug', + urlPath: '/bcr-projects/', + urlVisitLinkRoute: fn (?BCRProject $record) => $record?->slug + ? route('bcr.show', $record) + : null, + )->inlineLabel()->columnSpanFull()->label(__('bcr-project.labels.title')), Select::make('category_id') ->label(__('bcr-project.labels.category')) @@ -94,8 +100,7 @@ public static function form(Form $form): Form TextInput::make('facebook_link') ->label(__('bcr-project.labels.facebook_link')) ->inlineLabel() - ->columnSpanFull() - ->required(), + ->columnSpanFull()->url(), SpatieMediaLibraryFileUpload::make('preview') ->collection('preview') @@ -120,12 +125,10 @@ public static function form(Form $form): Form TextInput::make('title') ->label(__('bcr-project.labels.external_links.title')) ->inlineLabel() - ->columnSpanFull() - ->required(), + ->columnSpanFull(), TextInput::make('link')->label(__('bcr-project.labels.external_links.link')) ->inlineLabel() - ->columnSpanFull() - ->required(), + ->columnSpanFull()->url(), ]) ->label(__('bcr-project.labels.external_links.label')) ->inlineLabel() @@ -136,7 +139,7 @@ public static function form(Form $form): Form TextInput::make('link')->label(__('bcr-project.labels.videos')) ->inlineLabel() ->columnSpanFull() - ->required(), + ->url(), ]) ->inlineLabel() ->columnSpanFull(), diff --git a/app/Http/Controllers/DonorController.php b/app/Http/Controllers/DonorController.php index b16a65c8..2d71e5a8 100644 --- a/app/Http/Controllers/DonorController.php +++ b/app/Http/Controllers/DonorController.php @@ -4,7 +4,16 @@ namespace App\Http\Controllers; +use App\Enums\EuPlatescStatus; +use App\Http\Filters\DonationDatesFilter; +use App\Http\Filters\ProjectDatesFilter; +use App\Http\Resources\Collections\DonationCollection; +use App\Models\Donation; +use Illuminate\Http\Request; use Inertia\Inertia; +use Spatie\QueryBuilder\AllowedFilter; +use Spatie\QueryBuilder\AllowedSort; +use Spatie\QueryBuilder\QueryBuilder; class DonorController extends Controller { @@ -30,82 +39,48 @@ public function index() ]); } - public function donations() + public function donations(Request $request) { - $donations = [ - 'current_page' => 2, - 'data' => [ - [ - 'id' => 1, - 'organization' => 'Asociația Un Zâmbet pentru copilul tău', - 'project' => 'Zambet pentru copiii noștri', - 'created_at' => '12.08.2022', - 'amount' => '300', - ], - [ - 'id' => 2, - 'organization' => 'Asociația Un Zâmbet pentru copilul tău', - 'project' => 'Zambet pentru copiii noștri', - 'created_at' => '12.08.2022', - 'amount' => '300', - ], + $donations = auth()->user()->donations()->with(['project:id,name,organization_id', 'organization:id,name'])->get(); + + $organizations = collect([]); + $projects = collect([]); + + $donations->map(function ($donation) use (&$organizations, &$projects) { + $organizations->push($donation->project->organization); + $projects->push($donation->project); + }); + $dates = $donations->pluck('created_at')->map(fn ($date) => $date->format('Y-m'))->unique(); - [ - 'id' => 3, - 'organization' => 'Asociația Un Zâmbet pentru copilul tău', - 'project' => 'Zambet pentru copiii noștri', - 'created_at' => '12.08.2022', - 'amount' => '300', - ], - [ - 'id' => 4, - 'organization' => 'Asociația Un Zâmbet pentru copilul tău', - 'project' => 'Zambet pentru copiii noștri', - 'created_at' => '12.08.2022', - 'amount' => '300', - ], - ], - 'first_page_url' => 'http=>//bursabinelui.test/proiecte?page=1', - 'from' => 1, - 'last_page' => 2, - 'last_page_url' => 'http://bursabinelui.test/proiecte?page=2', - 'links' => [ - [ - 'url' => 'http://bursabinelui.test/proiecte?page=1', - 'label' => '1', - 'active' => true, - ], - [ - 'url' => 'http://bursabinelui.test/proiecte?page=1', - 'label' => '1', - 'active' => true, - ], - [ - 'url' => 'http://bursabinelui.test/proiecte?page=2', - 'label' => '2', - 'active' => false, - ], - [ - 'url' => 'http://bursabinelui.test/proiecte?page=3', - 'label' => '3', - 'active' => false, - ], - [ - 'url' => 'http://bursabinelui.test/proiecte?page=1', - 'label' => '1', - 'active' => true, - ], - ], - 'next_page_url' => 'http://bursabinelui.test/proiecte?page=3', - 'path' => 'http://bursabinelui.test/proiecte', - 'per_page' => 15, - 'prev_page_url' => 'http://bursabinelui.test/proiecte?page=1', - 'to' => 15, - 'total' => 20, - ]; return Inertia::render('Donor/Donations', [ - 'donations' => $donations, + 'filter' => $request->query('filter'), + 'collection' => new DonationCollection( + QueryBuilder::for(Donation::class) + ->where('user_id', auth()->user()->id) + ->with('project:id,name,organization_id') + ->allowedFilters([ + + AllowedFilter::custom('date', new DonationDatesFilter), + AllowedFilter::exact('organization', 'project.organization_id'), + AllowedFilter::exact('project', 'project_id'), + AllowedFilter::exact('status', 'status'), + + + ]) + ->allowedSorts([ + AllowedSort::field('publish_date', 'start'), + AllowedSort::field('end_date', 'end'), + ]) + ->defaultSorts('-created_at') + ->paginate() + ->withQueryString() + ), + 'organizations' => $organizations->pluck('name', 'id'), + 'projects' => $projects->pluck('name', 'id'), + 'statuses' => EuPlatescStatus::options(), + 'dates' => $dates, + ]); } } diff --git a/app/Http/Filters/DonationDatesFilter.php b/app/Http/Filters/DonationDatesFilter.php new file mode 100644 index 00000000..cc089ed4 --- /dev/null +++ b/app/Http/Filters/DonationDatesFilter.php @@ -0,0 +1,21 @@ +whereDate('created_at', '>=', $start) + ->whereDate('created_at', '<=', $end); + } +} diff --git a/app/Models/BCRProject.php b/app/Models/BCRProject.php index b8034e1f..b0a6080b 100644 --- a/app/Models/BCRProject.php +++ b/app/Models/BCRProject.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Concerns\HasLocation; +use App\Concerns\HasSlug; use Embed\Embed; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -21,6 +22,7 @@ class BCRProject extends Model implements HasMedia use HasFactory; use HasLocation; use InteractsWithMedia; + use HasSlug; protected $fillable = [ 'name', diff --git a/resources/js/Helpers/useFilters.js b/resources/js/Helpers/useFilters.js index f0de6464..332fb5ba 100644 --- a/resources/js/Helpers/useFilters.js +++ b/resources/js/Helpers/useFilters.js @@ -4,7 +4,6 @@ import useSort from '@/Helpers/useSort.js'; export default function (props, sort, url) { const { sortValue } = useSort(sort); - const applyFilters = () => { return router.get(url, pickBy({ filter: pickBy(props.value), diff --git a/resources/js/Pages/Donor/Donations.vue b/resources/js/Pages/Donor/Donations.vue index 0404dac5..85f88b20 100644 --- a/resources/js/Pages/Donor/Donations.vue +++ b/resources/js/Pages/Donor/Donations.vue @@ -1,44 +1,130 @@