diff --git a/app/Http/Controllers/Dashboard/SettingController.php b/app/Http/Controllers/Dashboard/SettingController.php index b838e54..1fb1db0 100644 --- a/app/Http/Controllers/Dashboard/SettingController.php +++ b/app/Http/Controllers/Dashboard/SettingController.php @@ -8,6 +8,7 @@ use App\Http\Requests\SettingRequest; use App\Models\Setting; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\Storage; use Inertia\Response; class SettingController extends Controller @@ -21,11 +22,42 @@ public function edit(): Response public function update(SettingRequest $request): RedirectResponse { - Setting::query()->first() - ->update($request->validated()); + $settings = Setting::query()->firstOrFail(); + $settings->fill($request->getData()); + + if ($request->file("logo")) { + if ($settings->logo) { + Storage::disk("public")->delete($settings->logo); + } + $file = $request->file("logo"); + $fileName = $file->getClientOriginalName(); + $path = "/logo"; + + $fullPath = Storage::disk("public")->putFileAs($path, $file, $fileName); + $settings->logo = $fullPath; + } + + $settings->save(); return redirect() ->back() ->with("success", "Zaktualizowano ustawienia"); } + + public function removeLogo(): RedirectResponse + { + $settings = Setting::query()->firstOrFail(); + + if ($settings->logo) { + $res = Storage::disk("public")->delete($settings->logo); + $settings->logo = null; + $settings->save(); + + return redirect() + ->back() + ->with("success", "Usunięto logo"); + } + + abort(404); + } } diff --git a/app/Http/Requests/SettingRequest.php b/app/Http/Requests/SettingRequest.php index 3a4f223..ae103e1 100644 --- a/app/Http/Requests/SettingRequest.php +++ b/app/Http/Requests/SettingRequest.php @@ -16,6 +16,22 @@ public function rules(): array "teacher_titles" => ["required", "max:255"], "university_name" => ["required", "max:255"], "department_name" => ["required", "max:255"], + "primary_color" => ["required", "regex:/^#([A-Fa-f0-9]{6})$/"], + "secondary_color" => ["required", "regex:/^#([A-Fa-f0-9]{6})$/"], + "logo" => ["nullable", "image", "max:1024"], + ]; + } + + public function getData(): array + { + return [ + "teacher_name" => $this->input("teacher_name"), + "teacher_email" => $this->input("teacher_email"), + "teacher_titles" => $this->input("teacher_titles"), + "university_name" => $this->input("university_name"), + "department_name" => $this->input("department_name"), + "primary_color" => $this->input("primary_color"), + "secondary_color" => $this->input("secondary_color"), ]; } } diff --git a/app/Models/Setting.php b/app/Models/Setting.php index ecb6a98..bb4dc61 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -30,5 +30,8 @@ class Setting extends Model "teacher_titles", "university_name", "department_name", + "primary_color", + "secondary_color", + "logo", ]; } diff --git a/database/factories/SettingFactory.php b/database/factories/SettingFactory.php index 876e117..89664ef 100644 --- a/database/factories/SettingFactory.php +++ b/database/factories/SettingFactory.php @@ -16,6 +16,8 @@ public function definition(): array "teacher_email" => fake()->email, "department_name" => "Zakład Informatyki, Wydział Nauk Technicznych i Ekonomicznych", "university_name" => "Collegium Witelona Uczelnia Państwowa", + "primary_color" => "#000000", + "secondary_color" => "#ffffff", ]; } } diff --git a/database/migrations/2024_08_07_075139_add_fields_to_settings_table.php b/database/migrations/2024_08_07_075139_add_fields_to_settings_table.php new file mode 100644 index 0000000..edc1f8d --- /dev/null +++ b/database/migrations/2024_08_07_075139_add_fields_to_settings_table.php @@ -0,0 +1,27 @@ +string("primary_color")->nullable(); + $table->string("secondary_color")->nullable(); + $table->string("logo")->nullable(); + }); + } + + public function down(): void + { + Schema::table("settings", function (Blueprint $table): void { + $table->dropColumn("primary_color"); + $table->dropColumn("secondary_color"); + $table->dropColumn("logo"); + }); + } +}; diff --git a/environment/dev/app/Dockerfile b/environment/dev/app/Dockerfile index 1024bc8..a45f0a0 100644 --- a/environment/dev/app/Dockerfile +++ b/environment/dev/app/Dockerfile @@ -41,7 +41,9 @@ RUN apt-get update \ && echo "deb https://nginx.org/packages/mainline/debian bullseye nginx" | tee /etc/apt/sources.list.d/nginx.list \ && apt-get update && apt-get install --assume-yes \ nginx=${NGINX_VERSION} \ + gnupg \ libzip-dev \ + libpng-dev \ libpq-dev \ supervisor \ cron \ @@ -49,6 +51,7 @@ RUN apt-get update \ && docker-php-ext-install \ zip \ pdo_pgsql \ + gd \ && docker-php-ext-enable \ redis diff --git a/environment/dev/app/nginx.conf b/environment/dev/app/nginx.conf index 0350a9f..ddeabbe 100644 --- a/environment/dev/app/nginx.conf +++ b/environment/dev/app/nginx.conf @@ -26,6 +26,8 @@ http { listen 80 default; server_name keating-nginx; + client_max_body_size 20M; + access_log /dev/stdout; error_log /dev/stderr; diff --git a/environment/dev/app/php.ini b/environment/dev/app/php.ini index 8ffeea5..1d16a3e 100644 --- a/environment/dev/app/php.ini +++ b/environment/dev/app/php.ini @@ -1,5 +1,7 @@ [PHP] memory_limit = 256M +upload_max_filesize = 20m +post_max_size = 20m [xdebug] xdebug.client_host=xdebug://gateway diff --git a/resources/js/Pages/Dashboard/Setting/Edit.vue b/resources/js/Pages/Dashboard/Setting/Edit.vue index bebafa1..0666a81 100644 --- a/resources/js/Pages/Dashboard/Setting/Edit.vue +++ b/resources/js/Pages/Dashboard/Setting/Edit.vue @@ -9,6 +9,9 @@ import { useForm } from '@inertiajs/inertia-vue3' import FormError from '@/Shared/Forms/FormError.vue' import ManagementHeader from '@/Shared/Components/ManagementHeader.vue' import ManagementHeaderItem from '@/Shared/Components/ManagementHeaderItem.vue' +import ColorInput from '../../../Shared/Forms/ColorInput.vue' +import { ref } from 'vue' +import { Method } from '@inertiajs/inertia' const props = defineProps({ settings: Object, @@ -20,10 +23,29 @@ const form = useForm({ teacher_titles: props.settings.teacher_titles, university_name: props.settings.university_name, department_name: props.settings.department_name, + primary_color: props.settings.primary_color, + secondary_color: props.settings.secondary_color, + logo: null, }) +const imageUrl = ref('') + function updateSettings() { - form.patch('/dashboard/settings') + form.post('/dashboard/settings') +} + +function onFileSelected(event) { + const file = event.target?.files[0] + + if (file.size > 1024 * 1024) { + form.errors.logo = 'Plik nie może być większy niż 1MB' + + return + } + + form.logo = file + imageUrl.value = URL.createObjectURL(event.target?.files[0]) + form.errors.logo = '' } @@ -40,7 +62,7 @@ function updateSettings() { -