Skip to content

Commit

Permalink
Fix display gala project in organization dashboard page
Browse files Browse the repository at this point in the history
Fix display logic
Fix update gala project
  • Loading branch information
gheorghelupu17 committed Jul 4, 2024
1 parent 91f5969 commit 5f421c8
Show file tree
Hide file tree
Showing 17 changed files with 526 additions and 187 deletions.
1 change: 1 addition & 0 deletions app/Concerns/Enums/Comparable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ trait Comparable
*/
public function is(mixed $enum): bool
{

if ($enum instanceof static) {
return $this->value === $enum->value;
}
Expand Down
24 changes: 24 additions & 0 deletions app/Enums/GalaProjectStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace App\Enums;

use App\Concerns\Enums\Arrayable;
use App\Concerns\Enums\Comparable;
use App\Concerns\Enums\HasLabel;

enum GalaProjectStatus: string
{
use Arrayable;
use Comparable;
use HasLabel;

case draft = 'draft';
case publish = 'published';

protected function labelKeyPrefix(): ?string
{
return 'project.gala_project_status_ar';
}
}
6 changes: 6 additions & 0 deletions app/Filament/Resources/GalaProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Filament\Resources;

use App\Enums\GalaProjectStatus;
use App\Enums\OrganizationType;
use App\Enums\ProjectArea;
use App\Filament\Forms\Components\Value;
Expand Down Expand Up @@ -315,6 +316,11 @@ public static function getRelations(): array
];
}

public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->where('status', GalaProjectStatus::publish);
}

public static function getPages(): array
{
return [
Expand Down
27 changes: 12 additions & 15 deletions app/Http/Controllers/Dashboard/GalaProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use App\Http\Requests\RegionalProject\StoreRequest;
use App\Http\Resources\Edition\EditionShowResource;
use App\Http\Resources\GalaProjectCardResource;
use App\Models\County;
use App\Models\Edition;
use App\Models\Gala;
use App\Models\GalaProject;
Expand Down Expand Up @@ -78,21 +77,27 @@ public function store(StoreRequest $request)
/**
* Display the specified resource.
*/
public function show(string $id)
public function show(GalaProject $project)
{
//
$this->authorize('view', $project);
$project->load('media');

return Inertia::render('AdminOng/GalaProjects/View', [
'project' => $project,
]);
}

/**
* Show the form for editing the specified resource.
*/
public function edit(GalaProject $project)
{
$this->authorize('update', $project);
$project->load('media');

return Inertia::render('AdminOng/GalaProjects/Edit', [
'project' => $project,
'counties' => County::get(['name', 'id']),
'counties' => $project->gala->counties()->get(['name', 'counties.id']),
'projectCategories' => ProjectCategory::get(['name', 'id']),
]);
}
Expand All @@ -102,7 +107,7 @@ public function edit(GalaProject $project)
*/
public function update(Request $request, GalaProject $project)
{
$this->authorize('editAsNgo', $project);
$this->authorize('update', $project);
if ($request->has('counties')) {
$project->counties()->sync(collect($request->get('counties'))->pluck('id'));
}
Expand All @@ -112,18 +117,10 @@ public function update(Request $request, GalaProject $project)
->with('success', __('project.project_updated'));
}

/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}

public function changeStatus(Request $request, string $id)
public function changeStatus(Request $request, GalaProject $project)
{
try {
(new ProjectService(RegionalProject::class))->changeStatus($id, $request->get('status'));
(new ProjectService(GalaProject::class))->changeStatus($project, $request->get('status'));
} catch (\Exception $exception) {
return redirect()->back()
->with('error', $exception->getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
use App\Http\Resources\Articles\ArticleCardResource;
use App\Http\Resources\Edition\EditionShowResource;
use App\Http\Resources\Edition\GalaShowResource;
use App\Http\Resources\GalaProject\ShowResource;
use App\Models\Edition;
use App\Models\EditionCategories;
use App\Models\Gala;
use App\Models\GalaProject;
use App\Models\Project;
use Illuminate\Support\Facades\Request;
use Inertia\Inertia;

class RegionalController extends Controller
class GalaController extends Controller
{
public function index()
{
Expand Down Expand Up @@ -133,117 +135,12 @@ public function gala(Gala $gala, Request $request)
'gala' => GalaShowResource::make($gala),
'categories' => $categories,
]);

}

public function project(Project $project)
public function project(GalaProject $project)
{
$gallery = [
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => 'https://youtu.be/f-t2nWVauSE',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'video',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
[
'src' => '/images/project_img.png',
'type' => 'image',
],
];

return Inertia::render('Public/Regional/Project', [
'project' => $project,
'gallery' => $gallery,
'project' => new ShowResource($project),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Http\Controllers;

class RegionalProjectController extends Controller
class GalaProjectController extends Controller
{
/**
* Display a listing of the resource.
Expand Down
57 changes: 57 additions & 0 deletions app/Http/Resources/GalaProject/ShowResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace App\Http\Resources\GalaProject;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class ShowResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public static $wrap = null;

public function toArray(Request $request): array
{
return [

'organization' => [
'name' => $this->organization->name,
'id' => $this->organization->id,
],
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
'start_date' => $this->start_date,
'end_date' => $this->end_date,
'areas' => $this->area,
'youth' => $this->youth ? __('field.boolean.true') : __('field.boolean.false'),
'organization_type' => $this->organization_type->label(),
'reason' => $this->reason,
'solution' => $this->solution,
'project_details' => $this->project_details,
'special' => $this->special,
'is_draft' => $this->isDraft(),
'results' => $this->results,
'proud' => $this->proud,
'partnership' => $this->partnership ? __('field.boolean.true') : __('field.boolean.false'),
'partnership_details' => $this->partnership_details,
'budget_details' => $this->budget_details,
'participants' => $this->participants,
'team_details' => $this->team_details,
'contact' => $this->contact,
'status' => $this->status->label(),
'eligible' => $this->eligible ? __('field.boolean.true') : __('field.boolean.false'),
'short_list' => $this->short_list ? __('field.boolean.true') : __('field.boolean.false'),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,

];
}

}
10 changes: 7 additions & 3 deletions app/Http/Resources/GalaProjectCardResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ public function toArray(Request $request): array
{
return [
'id' => $this->id,
'type' => 'project',
'type' => 'gala_project',
'name' => $this->name,
'slug' => $this->slug,
'county' => $this->counties->pluck('name')->join(', '), // $this->county?->name,
'image' => $this->getFirstMediaUrl('preview'),
'counties' => $this->counties->pluck('name')->join(', '), // $this->county?->name,
'counties_count' => $this->counties->count(),
'image' => $this->getFirstMediaUrl('regionalProjectFiles'),
'organization' => [
'name' => $this->organization->name,
'slug' => $this->organization->slug,
'id' => $this->organization->id,
],
'categories' => $this->categories->pluck('name')->join(', '),
'is_draft' => $this->isDraft(),

];
}
}
11 changes: 9 additions & 2 deletions app/Models/GalaProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
use App\Concerns\BelongsToOrganization;
use App\Concerns\HasCounties;
use App\Concerns\HasSlug;
use App\Traits\HasProjectStatus;
use App\Enums\GalaProjectStatus;
use App\Enums\OrganizationType;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -27,7 +28,6 @@ class GalaProject extends Model implements HasMedia
use BelongsToOrganization;
use HasCounties;
use InteractsWithMedia;
use HasProjectStatus;
use LogsActivity;
use BelongsToThroughTrait;

Expand Down Expand Up @@ -72,6 +72,8 @@ class GalaProject extends Model implements HasMedia
'eligible' => 'boolean',
'short_list' => 'boolean',
'contact' => 'array',
'status' => GalaProjectStatus::class,
'organization_type' => OrganizationType::class,
];

public string $slugFieldSource = 'name';
Expand Down Expand Up @@ -123,4 +125,9 @@ public function removeFromShortList(): bool
{
return $this->update(['short_list' => 0]);
}

public function isDraft(): bool
{
return $this->status->value === GalaProjectStatus::draft->value;
}
}
Loading

0 comments on commit 5f421c8

Please sign in to comment.