diff --git a/app/Concerns/Enums/Comparable.php b/app/Concerns/Enums/Comparable.php index efefc281..1c871899 100644 --- a/app/Concerns/Enums/Comparable.php +++ b/app/Concerns/Enums/Comparable.php @@ -11,6 +11,7 @@ trait Comparable */ public function is(mixed $enum): bool { + if ($enum instanceof static) { return $this->value === $enum->value; } diff --git a/app/Enums/GalaProjectStatus.php b/app/Enums/GalaProjectStatus.php new file mode 100644 index 00000000..b860b388 --- /dev/null +++ b/app/Enums/GalaProjectStatus.php @@ -0,0 +1,24 @@ +where('status', GalaProjectStatus::publish); + } + public static function getPages(): array { return [ diff --git a/app/Http/Controllers/Dashboard/GalaProjectController.php b/app/Http/Controllers/Dashboard/GalaProjectController.php index 92464139..b5d2c5ca 100644 --- a/app/Http/Controllers/Dashboard/GalaProjectController.php +++ b/app/Http/Controllers/Dashboard/GalaProjectController.php @@ -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; @@ -78,9 +77,14 @@ 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, + ]); } /** @@ -88,11 +92,12 @@ public function show(string $id) */ 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']), ]); } @@ -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')); } @@ -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()); diff --git a/app/Http/Controllers/RegionalController.php b/app/Http/Controllers/GalaController.php similarity index 61% rename from app/Http/Controllers/RegionalController.php rename to app/Http/Controllers/GalaController.php index ec5c9bdb..f6afb025 100644 --- a/app/Http/Controllers/RegionalController.php +++ b/app/Http/Controllers/GalaController.php @@ -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() { @@ -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), ]); } diff --git a/app/Http/Controllers/RegionalProjectController.php b/app/Http/Controllers/GalaProjectController.php similarity index 85% rename from app/Http/Controllers/RegionalProjectController.php rename to app/Http/Controllers/GalaProjectController.php index cfadcb0e..3448fcdf 100644 --- a/app/Http/Controllers/RegionalProjectController.php +++ b/app/Http/Controllers/GalaProjectController.php @@ -4,7 +4,7 @@ namespace App\Http\Controllers; -class RegionalProjectController extends Controller +class GalaProjectController extends Controller { /** * Display a listing of the resource. diff --git a/app/Http/Resources/GalaProject/ShowResource.php b/app/Http/Resources/GalaProject/ShowResource.php new file mode 100644 index 00000000..9076199c --- /dev/null +++ b/app/Http/Resources/GalaProject/ShowResource.php @@ -0,0 +1,57 @@ + + */ + 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, + + ]; + } + +} diff --git a/app/Http/Resources/GalaProjectCardResource.php b/app/Http/Resources/GalaProjectCardResource.php index 99fa1b69..83791ff7 100644 --- a/app/Http/Resources/GalaProjectCardResource.php +++ b/app/Http/Resources/GalaProjectCardResource.php @@ -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(), + ]; } } diff --git a/app/Models/GalaProject.php b/app/Models/GalaProject.php index 83ada486..d6a18843 100644 --- a/app/Models/GalaProject.php +++ b/app/Models/GalaProject.php @@ -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; @@ -27,7 +28,6 @@ class GalaProject extends Model implements HasMedia use BelongsToOrganization; use HasCounties; use InteractsWithMedia; - use HasProjectStatus; use LogsActivity; use BelongsToThroughTrait; @@ -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'; @@ -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; + } } diff --git a/app/Policies/GalaProjectPolicy.php b/app/Policies/GalaProjectPolicy.php new file mode 100644 index 00000000..da013f3b --- /dev/null +++ b/app/Policies/GalaProjectPolicy.php @@ -0,0 +1,38 @@ +isSuperAdmin()) { + return true; + } + + return $user->belongsToOrganization($project->organization); + } + + public function update(User $user, GalaProject $project): bool + { + if ($user->isSuperAdmin()) { + return true; + } + + if (! $project->isDraft()) { + return false; + } + + return $user->belongsToOrganization($project->organization); + } +} diff --git a/app/Services/ProjectService.php b/app/Services/ProjectService.php index 64c5477d..f6d2f72f 100644 --- a/app/Services/ProjectService.php +++ b/app/Services/ProjectService.php @@ -4,6 +4,7 @@ namespace App\Services; +use App\Enums\GalaProjectStatus; use App\Enums\ProjectStatus; use App\Enums\UserRole; use App\Models\GalaProject; @@ -128,6 +129,7 @@ public function changeStatus(Project|GalaProject $project, string $status): void match ($status) { ProjectStatus::pending->value => $this->pending($project), ProjectStatus::archived->value => $this->archive($project), + GalaProjectStatus::publish->value => $this->publish($project), default => Log::error('Invalid status on change project status [# %s ]: %s', $project->id, $status), }; } @@ -166,4 +168,12 @@ private function archive(Project|GalaProject $project): void $this->project->archived_at = now(); $this->project->save(); } + + private function publish(GalaProject|Project $project): void + { + $this->project = $project; + $this->project->status_updated_at = now(); + $this->project->status = GalaProjectStatus::publish; + $this->project->save(); + } } diff --git a/database/migrations/2024_07_03_135808_add_default_for_status_add_status_updated_at_to_gala_projects.php b/database/migrations/2024_07_03_135808_add_default_for_status_add_status_updated_at_to_gala_projects.php new file mode 100644 index 00000000..c8f96676 --- /dev/null +++ b/database/migrations/2024_07_03_135808_add_default_for_status_add_status_updated_at_to_gala_projects.php @@ -0,0 +1,32 @@ +string('status')->default(GalaProjectStatus::draft->value)->change(); + $table->date('status_updated_at')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('gala_projects', function (Blueprint $table) { + // + }); + } +}; diff --git a/resources/js/Components/cards/RegionalProject.vue b/resources/js/Components/cards/RegionalProject.vue index 2c7e6316..687aa4bd 100644 --- a/resources/js/Components/cards/RegionalProject.vue +++ b/resources/js/Components/cards/RegionalProject.vue @@ -1,12 +1,9 @@ diff --git a/resources/js/Pages/AdminOng/GalaProjects/Edit.vue b/resources/js/Pages/AdminOng/GalaProjects/Edit.vue index bc3421e7..7a61ca57 100644 --- a/resources/js/Pages/AdminOng/GalaProjects/Edit.vue +++ b/resources/js/Pages/AdminOng/GalaProjects/Edit.vue @@ -493,21 +493,6 @@ const props = defineProps({ error_message: String, }); -const impact_areas = [ - { - label: 'Local', - value: 'local', - }, - { - label: 'Judetean', - value: 'judetean', - }, - { - label: 'Regional', - value: 'regional', - }, -]; - let project = ref(props.project); let form = useForm(project.value); @@ -519,6 +504,6 @@ const editField = (field) => { let newForm = useForm({ [field]: form[field], }); - newForm.post(route('dashboard.projects.gala.update', project.value.id)); + newForm.put(route('dashboard.projects.gala.update', project.value.id)); }; diff --git a/resources/js/Pages/AdminOng/GalaProjects/View.vue b/resources/js/Pages/AdminOng/GalaProjects/View.vue new file mode 100644 index 00000000..7960874c --- /dev/null +++ b/resources/js/Pages/AdminOng/GalaProjects/View.vue @@ -0,0 +1,257 @@ +