From 85a6648cf2802e58dd1d56553786deaa1dfd648e Mon Sep 17 00:00:00 2001 From: Lupu Gheorghe Date: Tue, 10 Oct 2023 12:36:45 +0300 Subject: [PATCH] wip projects --- .../Controllers/Dashboard/ProjectController.php | 2 +- .../Organizations/ShowOrganizationResource.php | 1 - app/Http/Resources/ProjectCardResource.php | 3 ++- app/Models/Project.php | 7 +++++++ app/Traits/HasProjectStatus.php | 9 +++++++-- resources/js/Components/cards/ProjectCard.vue | 16 +++++----------- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Dashboard/ProjectController.php b/app/Http/Controllers/Dashboard/ProjectController.php index b77803f8..5f4df4cb 100644 --- a/app/Http/Controllers/Dashboard/ProjectController.php +++ b/app/Http/Controllers/Dashboard/ProjectController.php @@ -22,7 +22,7 @@ public function index(Request $request) { // TODO: fix issue with approved projects not being displayed $projectStatus = $request->get('project_status'); -// dd($projectStatus); + return Inertia::render('AdminOng/Projects/Projects', [ 'query' => ProjectCardResource::collection( diff --git a/app/Http/Resources/Organizations/ShowOrganizationResource.php b/app/Http/Resources/Organizations/ShowOrganizationResource.php index f3571bc3..238b6179 100644 --- a/app/Http/Resources/Organizations/ShowOrganizationResource.php +++ b/app/Http/Resources/Organizations/ShowOrganizationResource.php @@ -37,7 +37,6 @@ public function toArray(Request $request): array $project->setRelation('organization', $this); return $project; - // dump(\func_get_args()); }) ), ]; diff --git a/app/Http/Resources/ProjectCardResource.php b/app/Http/Resources/ProjectCardResource.php index bb376ef9..a5ecdb41 100644 --- a/app/Http/Resources/ProjectCardResource.php +++ b/app/Http/Resources/ProjectCardResource.php @@ -29,8 +29,9 @@ public function toArray(Request $request): array 'total' => money_format($this->total_donations), 'percentage' => $this->percentage, ], - 'is_active' => $this->is_active, + 'is_active' => $this->is_active || $this->is_pending, 'is_ending_soon' => $this->is_ending_soon, + 'championship' => [ 'troffees_count' => 2, 'score' => 100, diff --git a/app/Models/Project.php b/app/Models/Project.php index ce39122d..359b9ee2 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -144,6 +144,7 @@ public function getPercentageAttribute(): float if ($this->target_budget == 0) { return 0; } + return min(100, $this->total_donations / $this->target_budget * 100); } @@ -152,6 +153,11 @@ public function getActiveAttribute(): bool return $this->status == ProjectStatus::approved; } + public function getIsPendingAttribute(): bool + { + return $this->status == ProjectStatus::pending; + } + public function getIsPeriodActiveAttribute(): bool { return $this->start->isPast() && $this->end->isFuture(); @@ -169,6 +175,7 @@ public function getIsEndingSoonAttribute(): bool if (empty($this->end)) { return false; } + return $this->end->diffInDays(today()) <= 5; } } diff --git a/app/Traits/HasProjectStatus.php b/app/Traits/HasProjectStatus.php index bc4e72ce..420242ce 100644 --- a/app/Traits/HasProjectStatus.php +++ b/app/Traits/HasProjectStatus.php @@ -64,10 +64,15 @@ public function scopeWhereStartsSoon(): Builder ->orderBy('start'); } - public function scopeStatusIs($status): Builder + public function scopeWhereIsDraft(Builder $query): Builder + { + return $query->where('status', ProjectStatus::draft); + } + + public function scopeStatusIs(Builder $query, $status): Builder { -// dd($status); return match ($status) { + 'draft' => $this->whereIsDraft(), 'pending' => $this->whereIsPending(), 'approved' => $this->whereIsApproved(), 'rejected' => $this->whereIsRejected(), diff --git a/resources/js/Components/cards/ProjectCard.vue b/resources/js/Components/cards/ProjectCard.vue index 7fde0f18..fc0b0f0f 100644 --- a/resources/js/Components/cards/ProjectCard.vue +++ b/resources/js/Components/cards/ProjectCard.vue @@ -108,14 +108,15 @@ { - if (props.project.total_donations > props.project.target_budget) { - return 100; - } - - return (props.project.total_donations / props.project.target_budget) * 100; - }); + console.log(props.project,props.cardType); /** Get days till project ends. */ const project_end_date = computed(() => { @@ -198,7 +192,7 @@ status: status, id: id, }); - console.log(type); + console.log(form); let tmpRoute = type === 'regional' ? route('dashboard.projects.regional.status', id) : route('dashboard.projects.status', id); if (confirm('Are you sure you want to change the status of this project?')) {