Skip to content

Commit

Permalink
wip projects
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 10, 2023
1 parent da0d3c0 commit 85a6648
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Dashboard/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function toArray(Request $request): array
$project->setRelation('organization', $this);

return $project;
// dump(\func_get_args());
})
),
];
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Resources/ProjectCardResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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();
Expand All @@ -169,6 +175,7 @@ public function getIsEndingSoonAttribute(): bool
if (empty($this->end)) {
return false;
}

return $this->end->diffInDays(today()) <= 5;
}
}
9 changes: 7 additions & 2 deletions app/Traits/HasProjectStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
16 changes: 5 additions & 11 deletions resources/js/Components/cards/ProjectCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@
</div>

<SecondaryButton
v-if="'admin' == cardType && 'pending' == project.status"
v-if="'admin' == cardType && project.is_active"
class="w-full mt-4 py-2.5"
@click="changeProjectStatus(project.id, 'draft', project.type)"
:label="$t('draft')"
/>

<SecondaryButton
v-if="'admin' == cardType && 'draft' == project.status"

v-if="'admin' == cardType && (!project.is_active)"
class="w-full mt-4 py-2.5 text-primary-500 ring-1 ring-inset ring-primary-500 hover:bg-primary-400"
@click="changeProjectStatus(project.id, 'pending', project.type)"
:label="$t('publish')"
Expand Down Expand Up @@ -175,14 +176,7 @@
project: Object,
cardType: String,
});
const percentage = computed(() => {
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(() => {
Expand All @@ -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?')) {
Expand Down

0 comments on commit 85a6648

Please sign in to comment.