Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 25, 2023
1 parent 4a39fb4 commit 0d8f43f
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 123 deletions.
27 changes: 15 additions & 12 deletions app/Filament/Resources/BCRProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'))
Expand Down Expand Up @@ -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')
Expand All @@ -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()
Expand All @@ -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(),
Expand Down
119 changes: 47 additions & 72 deletions app/Http/Controllers/DonorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,

]);
}
}
21 changes: 21 additions & 0 deletions app/Http/Filters/DonationDatesFilter.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 DonationDatesFilter 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('created_at', '>=', $start)
->whereDate('created_at', '<=', $end);
}
}
2 changes: 2 additions & 0 deletions app/Models/BCRProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,7 @@ class BCRProject extends Model implements HasMedia
use HasFactory;
use HasLocation;
use InteractsWithMedia;
use HasSlug;

protected $fillable = [
'name',
Expand Down
1 change: 0 additions & 1 deletion resources/js/Helpers/useFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Loading

0 comments on commit 0d8f43f

Please sign in to comment.