From 2c572463b5738035583bceb572ab02a683e7fe41 Mon Sep 17 00:00:00 2001 From: Lupu Gheorghe Date: Mon, 16 Oct 2023 16:12:55 +0300 Subject: [PATCH] wip on show pages --- app/Http/Controllers/ProjectController.php | 4 +- .../Resources/Project/ShowProjectResource.php | 7 ++- lang/ro.json | 8 +++- resources/js/Pages/Public/Projects/Show.vue | 44 ++++++------------- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index b0af988b..2e03d470 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -12,6 +12,7 @@ use App\Http\Filters\ProjectStatusFilter; use App\Http\Filters\SearchFilter; use App\Http\Resources\Collections\ProjectCardCollection; +use App\Http\Resources\Project\ShowProjectResource; use App\Http\Sorts\ProjectDonationsCountSort; use App\Http\Sorts\ProjectDonationsSumSort; use App\Models\Project; @@ -70,9 +71,8 @@ protected function projectList(Request $request, string $view): Response public function show(Project $project) { // TODO: prevent display of unpublished projects - return Inertia::render('Public/Projects/Show', [ - 'project' => $project, + 'project' => new ShowProjectResource($project), ]); } diff --git a/app/Http/Resources/Project/ShowProjectResource.php b/app/Http/Resources/Project/ShowProjectResource.php index f6ba4ccd..31bdc6b4 100644 --- a/app/Http/Resources/Project/ShowProjectResource.php +++ b/app/Http/Resources/Project/ShowProjectResource.php @@ -15,10 +15,10 @@ public function toArray(Request $request): array { return [ 'id' => $this->id, - // 'type' => $this->type, 'name' => $this->name, 'slug' => $this->slug, 'counties' => $this->counties->pluck('name')->join(', '), + 'status' =>$this->visible_status, 'image' => $this->getFirstMediaUrl('preview'), 'target_budget' => $this->target_budget, 'gallery' => $this->getMedia('gallery')->map(function ($media) { @@ -43,6 +43,11 @@ public function toArray(Request $request): array 'videos' => '', 'external_links' => $this->external_links, 'categories' => $this->categories->pluck('name')->join(', '), + 'donations' => [ + 'target' => money_format($this->target_budget), + 'total' => money_format($this->total_donations), + 'percentage' => $this->percentage, + ], 'championship' => [ 'troffees_count' => 2, 'score' => 100, diff --git a/lang/ro.json b/lang/ro.json index 0e261b07..5c90f960 100644 --- a/lang/ro.json +++ b/lang/ro.json @@ -444,6 +444,12 @@ "navigation.volunteers": "Voluntari", "locales.ro": "Română", - "locales.en": "English" + "locales.en": "English", + "projects.status.open" : "Deschis", + "projects.status.close" : "Închis", + "projects.status.starting_soon" : "Incepe in curand", + "projects.status.ending_soon" : "Se incheie in curand" + + } diff --git a/resources/js/Pages/Public/Projects/Show.vue b/resources/js/Pages/Public/Projects/Show.vue index e309f1ad..138817a7 100644 --- a/resources/js/Pages/Public/Projects/Show.vue +++ b/resources/js/Pages/Public/Projects/Show.vue @@ -23,16 +23,16 @@ />

- {{ project.is_period_active ? $t('active') : $t('inactive') }} + {{ $t('projects.status.'+project.status)}}

-
+

- {{ project.category }} + {{ project.categories }}

@@ -42,7 +42,7 @@
- +
@@ -103,29 +103,29 @@
-

{{ project.total_donations }} {{ $t('currency') }}

-

{{ project.target_budget }} {{ $t('currency') }}

+

{{ project.donations.total }} {{ $t('currency') }}

+

{{ project.donations.target }} {{ $t('currency') }}

- {{ project.donations.length }} {{ $t('donations') }} + {{ project.donations.total }} {{ $t('donations') }}

- +
@@ -153,7 +153,7 @@

{{ $t('range') }}

- {{ project.counties.map((county) => county.name).join(', ') }} + {{ project.counties}}

@@ -349,24 +349,6 @@ }); const project = ref(props.project); - /** Percentage */ - const percentage = computed(() => { - if (props.project.total_donations > props.project.target_budget) { - return 100; - } - - return (props.project.total_donations / props.project.target_budget) * 100; - }); - - /** Get days till project ends. */ - // const project_end_date = computed(() => { - // const targetDate = new Date(project.period_end); - // const today = new Date(); - // const timeDiff = targetDate.getTime() - today.getTime(); - // const daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24)); - - // return daysDiff; - // }) /** * Copy embed code.