Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 17, 2023
1 parent ecf5bf5 commit 19abed9
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

namespace App\Filament\Resources\ProjectResource\Widgets;

use App\Enums\ProjectStatus;
use App\Filament\Resources\ProjectResource\Actions\Tables\Projects\ApproveProjectAction;
use App\Filament\Resources\ProjectResource\Actions\Tables\Projects\RejectProjectAction;
use App\Models\Project;
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Actions\ViewAction;
use Illuminate\Database\Eloquent\Builder;
Expand Down
8 changes: 0 additions & 8 deletions app/Http/Controllers/Dashboard/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ public function store(StoreRequest $request)
{
$data = $request->validated();
$project = (new ProjectService(Project::class))->create($data);
$project->addAllMediaFromRequest()->each(function ($fileAdder, $index) {
if ($index == 0) {
$fileAdder->toMediaCollection('preview');
} else {
$fileAdder->toMediaCollection('gallery');
}
});

return redirect()->route('dashboard.projects.edit', $project->id)->with('success', 'Project created.');
}

Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/Project/StoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function rules(): array
'is_national' => ['boolean', 'nullable'],
'file_group' => ['array', 'nullable'],
'file_group.*.file' => ['file', 'nullable'],
'preview' => ['file', 'nullable'],
];
}
}
11 changes: 10 additions & 1 deletion app/Services/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,23 @@ public function create(array $data): Project|RegionalProject
{
$data['organization_id'] = auth()->user()->organization_id;
$data['status'] = ProjectStatus::draft->value;

$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');
});
}

return $project;
}
Expand Down
4 changes: 3 additions & 1 deletion lang/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,9 @@
"projects.status.open" : "Deschis",
"projects.status.close" : "Închis",
"projects.status.starting_soon" : "Incepe in curand",
"projects.status.ending_soon" : "Se incheie in curand"
"projects.status.ending_soon" : "Se incheie in curand",

"project.labels.preview_image": "Imagine de prezentare"



Expand Down
51 changes: 25 additions & 26 deletions resources/js/Components/form/FileGroup.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<template>
<div class="col-span-full">
<label for="cover-photo" class="block text-sm font-medium leading-6 text-gray-900">{{
$t('photo_gallery')
}}</label>
<div class="flex justify-center p-6 px-6 mt-2 border border-dashed rounded-lg border-gray-900/25">
<div class="col-span-full grid">
<label v-show="label" for="cover-photo" class="block text-sm font-medium leading-6 text-gray-900" v-html="label"/>
<div class="w-1/3 flex justify-center p-6 px-6 mt-2 border border-dashed rounded-lg border-gray-900/25">
<div class="text-center">
<PhotographIcon class="w-12 h-12 mx-auto text-gray-300" aria-hidden="true" />

Expand All @@ -19,6 +17,7 @@
type="file"
@change="previewImage"
ref="photo"
multiple
class="sr-only"
/>
</label>
Expand All @@ -29,16 +28,10 @@
<p class="text-xs leading-5 text-gray-600">{{ $t('file_types') }}</p>
</div>
</div>
<div class="flex flex-wrap">
<div
:style="{ backgroundImage: 'url(' + files[index] + ')' }"
style="background-size: contain"
v-for="(url, index) in modelValue"
class="grid content-end grid-cols-2 gap-4 mx-2 my-2 w-60 h-60"
>
<DangerButton @click="removeImage(index)">{{ $t('remove_image') }} </DangerButton>

<SecondaryButton class="col-start-2" @click="setCoverImage(index)" :label="$t('set_cover_image')" />
<div class="grid">
<div v-for="(file, index) in modelValue" class="grid-cols-1">
<img v-if="file" :src="src(file)" alt="File Preview" class="object-contain max-w-xs mt-2 aspect-square" />
<DangerButton type="button" @click="removeImage(index)">{{ $t('remove_image') }} </DangerButton>
</div>
</div>
</div>
Expand All @@ -48,8 +41,7 @@
/** Import plugins. */
import { PhotographIcon, UserCircleIcon } from '@heroicons/vue/solid';
import DangerButton from '@/Components/buttons/DangerButton.vue';
import PrimaryButton from '@/Components/buttons/PrimaryButton.vue';
import SecondaryButton from '@/Components/buttons/SecondaryButton.vue';
import {ref} from "vue";
/** Component props. */
const props = defineProps({
Expand All @@ -60,21 +52,28 @@
error: {
type: String,
},
label:{
type: String,
default: null,
},
});
const files = [];
const files = ref(props.modelValue);
const previewImage = (e) => {
const file = e.target.files[0];
files.push(URL.createObjectURL(file));
props.modelValue.push(file);
console.log(e.target.files)
Object.keys(e.target.files).forEach((key) => {
files.value.push(e.target.files[key]);
});
};
const removeImage = (index) => {
files.splice(index, 1);
props.modelValue.splice(index, 1);
};
const setCoverImage = (index) => {
console.log(index)
files.value.splice(index, 1);
};
function src(file){
if (typeof file === 'string') {
return file;
}
return URL.createObjectURL(file);
}
/** Component emits. */
defineEmits(['update:modelValue']);
Expand Down
9 changes: 8 additions & 1 deletion resources/js/Components/form/Textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<label :for="id" :class="[`block text-sm font-medium leading-6 text-${color}`]">
<span v-if="label">{{ label }}</span>
<span v-else><slot /></span>
<slot />
<br/>
<span v-show="moreInfo" class="text-sm font-normal text-gray-500" v-html="moreInfo"/>
<slot/>
</label>

<div>
Expand Down Expand Up @@ -39,6 +41,10 @@
color: String,
isRequired: Boolean,
error: String,
moreInfo: {
type: String,
default: null,
},
numberOfCharacters: {
type: Number,
default: 1000,
Expand All @@ -51,6 +57,7 @@
return props.numberOfCharacters - props.modelValue.length;
})
/** Component emits. */
defineEmits(['update:modelValue']);
</script>
67 changes: 27 additions & 40 deletions resources/js/Pages/AdminOng/Projects/AddProject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
:error="form.errors.name"
/>

<!-- Project main image -->

<!-- Project amount target -->
<Input
Expand Down Expand Up @@ -61,13 +60,9 @@
/>
</div>
<label class="flex items-center">
<Checkbox name="remember" v-model:checked="form.is_national" />
<span class="ml-2 text-sm text-gray-700">{{ $t('is_national') }}</span>

<!-- Error -->
<p v-show="form.errors.is_national" class="mt-2 text-sm text-red-600">
{{ form.errors.is_national }}
</p>
<Checkbox name="remember" v-model:checked="form.is_national" />
<span class="ml-2 text-sm text-gray-700" v-html="$t('is_national') "/>
<p v-show="form.errors.is_national" class="mt-2 text-sm text-red-600" v-html="form.errors.is_national"/>
</label>

<!-- County -->
Expand All @@ -82,7 +77,6 @@
multiple
/>

<!-- Project description -->
<Textarea
class="w-full"
:label="$t('project_description_label')"
Expand All @@ -91,23 +85,18 @@
numberOfCharacters=800
v-model="form.description"
:error="form.errors.description"
>
<p class="text-sm font-normal text-gray-500">{{ $t('project_description_extra') }}</p>

</Textarea>
:more-info="$t('project_description_extra')"
/>

<!-- Project scope -->
<Textarea
class="w-full"
:label="$t('project_scope_label')"
id="project-scope"
color="gray-700"
v-model="form.scope"
:error="form.errors.scope"
>
<p class="text-sm font-normal text-gray-500">{{ $t('project_scope_extra') }}</p>

</Textarea>
:more-info="$t('project_scope_extra')"
/>

<!-- Project beneficiary -->
<Textarea
Expand All @@ -117,10 +106,8 @@
color="gray-700"
v-model="form.beneficiaries"
:error="form.errors.beneficiaries"
>
<p class="text-sm font-normal text-gray-500">{{ $t('project_beneficiary_extra') }}</p>

</Textarea>
:more-info="$t('project_beneficiary_extra')"
/>

<!-- Why to donate -->
<Textarea
Expand All @@ -130,33 +117,31 @@
color="gray-700"
v-model="form.reason_to_donate"
:error="form.errors.reason_to_donate"
>
<p class="text-sm font-normal text-gray-500">{{ $t('why_to_donate_extra') }}</p>

</Textarea>
:more-info="$t('why_to_donate_extra')"
/>

<label class="flex items-center">
<Checkbox name="remember" v-model:checked="form.accepting_volunteers" />
<span class="ml-2 text-sm text-gray-700">{{ $t('has_volunteers_label') }}</span>

<!-- Error -->
<p v-show="form.errors.accepting_volunteers" class="mt-2 text-sm text-red-600">
{{ form.errors.accepting_volunteers }}
</p>
<span class="ml-2 text-sm text-gray-700" v-html="$t('has_volunteers_label')"/>
<p v-show="form.errors.accepting_volunteers" class="mt-2 text-sm text-red-600" v-html="form.errors.accepting_volunteers"/>
</label>

<label class="flex items-center">
<Checkbox name="remember" v-model:checked="form.accepting_comments" />
<span class="ml-2 text-sm text-gray-700">{{ $t('has_comments_label') }}</span>
<span class="ml-2 text-sm text-gray-700" v-html="$t('has_comments_label')"/>
<p v-show="form.errors.accepting_comments" class="mt-2 text-sm text-red-600" v-html="form.errors.accepting_comments"/>
</label>

<label class="flex items-center">
<FileInput v-model="form.preview" :label="$t('project.labels.preview_image')" accept=""
@upload="(file)=>form.preview=file"
previewable
/>
<p v-show="form.errors.preview" class="mt-2 text-sm text-red-600" v-html="form.errors.preview"/>

<!-- Error -->
<p v-show="form.errors.accepting_comments" class="mt-2 text-sm text-red-600">
{{ form.errors.accepting_comments }}
</p>
</label>

<!-- File group -->
<FileGroup v-model="form.file_group" />
<FileGroup v-model="form.gallery" :label="$t('photo_gallery')" />

<div class="flex w-full border-t border-gray-300" v-for="(item, index) in projectLinks" :key="index">
<InputWithIcon
Expand Down Expand Up @@ -270,6 +255,7 @@
import DangerButton from '@/Components/buttons/DangerButton.vue';
import { ref } from 'vue';
import SelectMultiple from '@/Components/form/SelectMultiple.vue';
import FileInput from "@/Components/form/FileInput.vue";
/** Initialize inertia from Object. */
const form = useForm({
Expand All @@ -286,7 +272,8 @@
is_national: false,
accepting_comments: false,
accepting_volunteers: false,
file_group: [],
preview: null,
gallery: [],
project_links: [{ url: '' }],
project_articles: [{ url: '' }],
});
Expand Down

0 comments on commit 19abed9

Please sign in to comment.