Skip to content

Commit

Permalink
fix projects
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 19, 2023
1 parent a6011ac commit 323c0a1
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ protected function getTableQuery(): Builder
'archived_at',
'start',
'end',
'slug',
'status',
])->whereIsApproved();
}
Expand Down
12 changes: 11 additions & 1 deletion app/Filament/Resources/ProjectResource/Widgets/NewProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ protected function getTableHeading(): string

protected function getTableQuery(): Builder
{
return Project::query()->select(['id', 'organization_id', 'name', 'target_budget', 'is_national', 'created_at', 'status_updated_at', 'status'])->whereIsPending();
return Project::query()->select([
'id',
'organization_id',
'slug',
'name',
'target_budget',
'is_national',
'created_at',
'status_updated_at',
'status',
])->whereIsPending();
}

protected function getTableQueryStringIdentifier(): ?string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ protected function getTableHeading(): string

protected function getTableQuery(): Builder
{
return Project::query()->select(['id', 'organization_id', 'name', 'target_budget', 'is_national', 'created_at', 'status_updated_at', 'status'])->whereIsRejected();
return Project::query()->select([
'id',
'organization_id',
'slug',
'name',
'target_budget',
'is_national',
'created_at',
'status_updated_at',
'status',
])->whereIsRejected();
}

protected function getTableQueryStringIdentifier(): ?string
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Dashboard/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function update(EditRequest $request, Project $project)
{

$this->authorize('editAsNgo', $project);
// dd($request->validated());
ProjectService::update($project, $request->validated());

return redirect()->back()
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Project/EditRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function rules(): array
'is_national' => ['boolean', 'nullable'],
'gallery' => ['array', 'nullable'],
'gallery.*.file' => ['file', 'nullable'],
'preview' => ['file', 'nullable'],
'image' => ['file', 'nullable'],
];
}
}
1 change: 1 addition & 0 deletions app/Http/Resources/ProjectCardResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function toArray(Request $request): array
'is_draft' => $this->is_draft,
'is_starting_soon' => $this->isStartingSoon(),
'can_be_archived' => $this->can_be_archived,
'is_rejected' => $this->is_rejected,
'championship' => [
'troffees_count' => 2,
'score' => 100,
Expand Down
21 changes: 9 additions & 12 deletions app/Models/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,18 @@ public function approve(): void
$this->subject->setAttribute($key, $value['new']);
});

if ($this->subject instanceof Organization)
{
if ($this->subject instanceof Organization) {
$value = data_get($this->properties, $this->changed_field . '.new');
if ($this->description === 'statute') {
$this->subject->getMedia('statute')->map(function(Media $media) use ($value){
if ($media->id != $value)
{
$media->delete();
}
});
$media = Media::find($value);
$this->subject->media->add($media);
$this->subject->getMedia('statute')->map(function (Media $media) use ($value) {
if ($media->id != $value) {
$media->delete();
}
});
$media = Media::find($value);
$this->subject->media->add($media);
}
}
else{
} else {
$this->subject->save();
}

Expand Down
1 change: 1 addition & 0 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public function markAsRejected(?string $reason = null): void
'content' => $reason,
'user_id' => auth()->user()->id,
]);
$this->projects->each->markAsRejected();
}

public function markAsPending(): bool
Expand Down
26 changes: 21 additions & 5 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ public function getIsEndingSoonAttribute(): bool
return $this->end->diffInDays(today()) <= 5;
}

public function getIsRejectedAttribute(): bool
{
return $this->status == ProjectStatus::rejected;
}

public function getVisibleStatusAttribute(): string
{
if ($this->isStartingSoon()) {
Expand All @@ -223,9 +228,16 @@ public function getVisibleStatusAttribute(): string

public function markAsApproved(): bool
{
$slug = \Str::slug($this->name);
// dd($this);
$count = Project::whereRaw("slug RLIKE '^{$this->slug}(-[0-9]+)?$'")->count();
if ($count > 0) {
$slug .= '-' . ($count + 1);
}
return $this->update([
'status' => ProjectStatus::approved,
'status_updated_at' => $this->freshTimestamp(),
'slug' => $slug,
]);
}

Expand All @@ -236,11 +248,15 @@ public function markAsRejected(?string $reason = null): void
'status_updated_at' => $this->freshTimestamp(),
]);

$this->organization->tickets()->create([
'subject' => __('project.ticket_rejected.subject', ['project' => $this->name]),
'content' => $reason,
'user_id' => auth()->user()->id,
]);
if ($reason)
{
$this->organization->tickets()->create([
'subject' => __('project.ticket_rejected.subject', ['project' => $this->name]),
'content' => $reason,
'user_id' => auth()->user()->id,
]);
}

}

public function getEmbeddedVideosAttribute(): array
Expand Down
3 changes: 2 additions & 1 deletion app/Services/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ private function createDraftProject(array $data): Project|RegionalProject
}
$slug = \Str::slug($data['name']);
$count = Project::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count();
$data['organization_id'] = auth()->user()->organization_id;
$data['slug'] = $slug;
if ($count > 0) {
$data['slug'] .= '-' . ($count + 1);
}
$data['organization_id'] = auth()->user()->organization_id;


return $this->project::create($data);
}
Expand Down
3 changes: 3 additions & 0 deletions lang/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
"edit": "Editează",
"draft": "Mută în draft",
"projects_title": "Proiecte",
"projects_all": "Toate proiectele",
"of_projects": "proiecte",
"project_slug_label": "Url proiect",
"projects_list": "Lista proiecte",
"projects_map": "Hartă proiecte",
"status": "Status",
Expand Down Expand Up @@ -132,6 +134,7 @@
"donate_btn": "Donează",
"publish": "Publică",
"project_closed": "Proiect închis",
"project_rejected": "Proiect respins",
"project_draft": "Proiect draft",
"project_waiting_for_approval": "Proiect în aprobare",
"code4_solution": "O solutie Code for Romania.",
Expand Down
2 changes: 1 addition & 1 deletion lang/ro/project.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
'pending' => 'Proiecte in curs de aprobare (:number)',
'pending_changes' => 'Proiecte cu modificări (:number)',
'approved' => 'Proiecte aprobate (:number)',
'rejected' => 'Proiecte refuzate (:number)',
'rejected' => 'Proiecte respinse (:number)',
],
'label' => [
'singular' => 'Proiect',
Expand Down
3 changes: 2 additions & 1 deletion resources/js/Components/cards/ProjectCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
/>

<ProjectTag v-else-if="project.is_active" :label="$t('project_active')" icon="clock" />
<ProjectTag v-else-if="!project.is_active" :label="$t('project_closed')" />
<ProjectTag v-else-if="!project.is_active && !project.is_rejected" :label="$t('project_closed')" />
<ProjectTag v-if="project.is_rejected" :label="$t('project_rejected')" />

<!-- <div v-if="project.is_active && project.championship" class="flex flex-wrap items-center gap-1">-->
<!-- <ProjectTag-->
Expand Down
3 changes: 2 additions & 1 deletion resources/js/Layouts/DashboardLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
UserRemoveIcon,
} from '@heroicons/vue/outline';
import OrganizationStatus from "@/Components/OrganizationStatus.vue";
import {trans} from "laravel-vue-i18n";
const props = defineProps({
gridClass: {
Expand All @@ -104,7 +105,7 @@
icon: OfficeBuildingIcon,
},
{
name: 'Proiecte',
name: trans('projects_all'),
route: route('dashboard.projects.index'),
icon: FolderIcon,
subMenu: [
Expand Down
14 changes: 12 additions & 2 deletions resources/js/Pages/AdminOng/Projects/EditProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
</EditModal>
</template>
</Field>
<Field
:label="$t('project_slug_label')"
:errors="formChangeStatus.errors.slug"
>
<template #value>
<a :href="route('project',project.slug)" target="_blank" v-text="project.slug" />
</template>

<template #action>
</template>
</Field>

<Field
:label="$t('amount_target_label')"
Expand Down Expand Up @@ -331,7 +342,7 @@
<label for="accepting_comments" class="font-medium text-gray-900">
{{ $t('accepting_volunteers') }}
</label>
<p class="text-gray-500">{{ $t('accepting_volunteers_extra') }}</p>

</div>
</div>
</div>
Expand Down Expand Up @@ -376,7 +387,6 @@
<label for="accepting_comments" class="font-medium text-gray-900">{{
$t('accepting_comments')
}}</label>
<p class="text-gray-500">{{ $t('accepting_comments_extra') }}</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Public/Projects/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
<div class="mt-10 overflow-hidden rounded-lg group aspect-w-2 aspect-h-1"
v-for="(video,index) in project.embedded_videos"
:key="index"
v-html="video.html"
v-html="video?.html"
/>
</div>
Expand Down

0 comments on commit 323c0a1

Please sign in to comment.