Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Oct 18, 2023
1 parent 49e90a6 commit e5e84c4
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 187 deletions.
5 changes: 3 additions & 2 deletions app/Http/Resources/Project/EditProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Http\Resources\Resource;
use Illuminate\Http\Request;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class EditProjectResource extends Resource
{
Expand All @@ -20,10 +21,10 @@ public function toArray(Request $request): array

'image' => $this->getFirstMediaUrl('preview'),
'target_budget' => $this->target_budget,
'gallery' => $this->getMedia('gallery')->map(function ($media) {
'gallery' => $this->getMedia('gallery')->map(function (Media $media) {
return [
'id' => $media->id,
'url' => $media->getFullUrl(),
'url' => $media->getFullUrl('preview'),
];
})->toArray(),
'organization' => [
Expand Down
8 changes: 7 additions & 1 deletion app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ public function registerMediaCollections(): void
->nonQueued();
});

$this->addMediaCollection('gallery');
$this->addMediaCollection('gallery')
->registerMediaConversions(function (Media $media) {
$this
->addMediaConversion('preview')
->fit(Manipulations::FIT_CONTAIN, 300, 300)
->nonQueued();
});
}

public function getActivitylogOptions(): LogOptions
Expand Down
8 changes: 7 additions & 1 deletion app/Services/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ private static function updateGallery(Project $project, ?array $value): void
$mediaIds = collect($value)
->filter(fn ($item) => \is_array($item))
->pluck('id');

$project->getMedia('gallery')
->map(function (Media $media) use ($mediaIds) {
if (! $mediaIds->contains($media->id)) {
$media->delete();
}
});

collect($value)->filter(fn ($image) => ! \is_array($image))
->map(fn ($image) => $project->addMedia($image)->toMediaCollection('gallery'));
}
Expand All @@ -45,17 +47,21 @@ public function create(array $data): Project|RegionalProject
{
$data['organization_id'] = auth()->user()->organization_id;
$data['status'] = ProjectStatus::draft->value;
// dd($data);

$project = $this->createDraftProject($data);

if (! empty($data['categories'])) {
$project->categories()->attach($data['categories']);
}

if (! empty($data['counties'])) {
$project->counties()->attach($data['counties']);
}

if (! empty($data['preview'])) {
$project->addMedia($data['preview'])->toMediaCollection('preview');
}

if (! empty($data['gallery'])) {
collect($data['gallery'])->map(function ($image) use ($project) {
$project->addMedia($image)->toMediaCollection('gallery');
Expand Down
8 changes: 4 additions & 4 deletions resources/js/Components/Field.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<div class="flex md:justify-end">
<slot name="action" />
</div>

</div>
</template>

<script setup>
import {computed} from "vue";
import { computed } from 'vue';
const props = defineProps({
label: String,
hasPendingChanges: {
Expand All @@ -37,10 +37,10 @@ import {computed} from "vue";
type: Boolean,
default: false,
},
errors:{
errors: {
type: String,
default: null,
}
},
});
const hasErrors = computed(() => {
Expand Down
53 changes: 17 additions & 36 deletions resources/js/Components/cards/ProjectCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,32 @@
/>

<div class="flex flex-col items-start justify-end gap-2 p-3">
<ProjectTag
v-if="project.is_pending"
:label="$t('project_waiting_for_approval')"
/>
<ProjectTag v-if="project.is_pending" :label="$t('project_waiting_for_approval')" />
<ProjectTag v-else-if="project.is_draft" :label="$t('project_draft')" />

<ProjectTag
v-else-if="project.is_starting_soon"
:label="$t('project_starting_soon')"
icon="clock"
/>
<ProjectTag v-else-if="project.is_starting_soon" :label="$t('project_starting_soon')" icon="clock" />
<ProjectTag
v-else-if="project.is_active && project.is_ending_soon"
:label="$t('project_ending_soon')"
icon="clock"
/>

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




<!-- <div v-if="project.is_active && project.championship" class="flex flex-wrap items-center gap-1">-->
<!-- <ProjectTag-->
<!-- v-if="project.championship.troffees_count"-->
<!-- :label="project.championship.troffees_count"-->
<!-- icon="troffee"-->
<!-- accent-->
<!-- />-->

<!-- <ProjectTag v-if="project.championship.score" accent>-->
<!-- <span class="font-bold" v-text="$t('scor')" />-->
<!-- <span class="font-extrabold" v-text="project.championship.score" />-->
<!-- </ProjectTag>-->
<!-- </div>-->




<!-- <div v-if="project.is_active && project.championship" class="flex flex-wrap items-center gap-1">-->
<!-- <ProjectTag-->
<!-- v-if="project.championship.troffees_count"-->
<!-- :label="project.championship.troffees_count"-->
<!-- icon="troffee"-->
<!-- accent-->
<!-- />-->

<!-- <ProjectTag v-if="project.championship.score" accent>-->
<!-- <span class="font-bold" v-text="$t('scor')" />-->
<!-- <span class="font-extrabold" v-text="project.championship.score" />-->
<!-- </ProjectTag>-->
<!-- </div>-->
</div>
</Link>

Expand Down Expand Up @@ -105,7 +87,7 @@

<div
v-if="'admin' == cardType"
class="flex mt-4 border border-gray-300 divide-x divide-gray-300 rounded-md shadow-sm"
class="flex mt-4 overflow-hidden border border-gray-300 divide-x divide-gray-300 rounded-md shadow-sm"
>
<Link
:href="route('project', project.slug)"
Expand Down Expand Up @@ -190,7 +172,6 @@
project: Object,
cardType: String,
});
console.log(props.project,props.cardType);
/** Get days till project ends. */
const project_end_date = computed(() => {
Expand Down
Loading

0 comments on commit e5e84c4

Please sign in to comment.