diff --git a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php index e97e0ab9..3c431340 100644 --- a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php +++ b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php @@ -97,7 +97,7 @@ public function storeProblem(array $attributes): int { 'user_creator_id' => Auth::id(), 'slug' => Str::random(16), // temporary - will be changed after record creation 'status_id' => $attributes['problem-status'], - 'img_url' => $imgPath ?? null, + 'img_url' => $imgPath, 'default_language_id' => $attributes['problem-default-language'], // bookmark2 - default or generally another translation language? ]); @@ -112,6 +112,33 @@ public function storeProblem(array $attributes): int { return $crowdSourcingProjectProblem->id; } + public function updateProblem(int $id, array $attributes) { + if (isset($attributes['problem-image']) && $attributes['problem-image']->isValid()) { + $imgPath = FileUploader::uploadAndGetPath($attributes['problem-image'], 'problem_image'); + } else { + $imgPath = self::DEFAULT_IMAGE_PATH; + } + + $modelAttributes['project_id'] = $attributes['problem-owner-project']; + $modelAttributes['slug'] = $attributes['problem-slug']; + $modelAttributes['status_id'] = $attributes['problem-status']; + $modelAttributes['img_url'] = $imgPath; + $modelAttributes['default_language_id'] = $attributes['problem-default-language']; // bookmark2 - default or generally another translation language? + + $this->crowdSourcingProjectProblemTranslationManager + ->updateProblemTranslations($id, $attributes['problem-default-language'], $attributes['problem-title'], $attributes['problem-description']); + + $this->crowdSourcingProjectProblemRepository->update($modelAttributes, $id); + + // $this->crowdSourcingProjectTranslationManager->storeOrUpdateDefaultTranslationForProject( // bookmark3 - what's this? + // $attributes, $id); + + // if (isset($attributes['extra_translations'])) { // bookmark3 - what's this? + // $this->crowdSourcingProjectTranslationManager->storeOrUpdateTranslationsForProject( + // json_decode($attributes['extra_translations']), $project->id, intval($attributes['language_id'])); + // } + } + public function deleteProblem(int $id): bool { return $this->crowdSourcingProjectProblemRepository->delete($id); } diff --git a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslationManager.php b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslationManager.php index 5082d7ba..977558c5 100644 --- a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslationManager.php +++ b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslationManager.php @@ -38,4 +38,17 @@ public function getTranslationsForProblem(CrowdSourcingProjectProblem $problem): return $this->crowdSourcingProjectProblemTranslationRepository->allWhere(['problem_id' => $problem->id]); } + + public function updateProblemTranslations(int $problem_id, int $new_default_language_id, string $default_language_title, string $default_language_description) { + $this->crowdSourcingProjectProblemTranslationRepository->updateOrCreate( + [ + 'problem_id' => $problem_id, + 'language_id' => $new_default_language_id, + ], + [ + 'title' => $default_language_title, + 'description' => $default_language_description, + ] + ); + } } diff --git a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php index ac532b4b..b89dd55f 100644 --- a/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php +++ b/app/Http/Controllers/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemController.php @@ -66,8 +66,10 @@ public function store(Request $request): RedirectResponse { 'problem-owner-project' => ['required'], ]); + $attributes = $request->all(); + try { - $createdProblemId = $this->crowdSourcingProjectProblemManager->storeProblem($request->all()); + $createdProblemId = $this->crowdSourcingProjectProblemManager->storeProblem($attributes); } catch (\Exception $e) { session()->flash('flash_message_error', 'Error: ' . $e->getCode() . ' ' . $e->getMessage()); @@ -94,7 +96,29 @@ public function edit(int $id): View { * Update the specified resource in storage. */ public function update(Request $request, string $id) { - // + $this->validate($request, [ // bookmark2 + 'problem-title' => ['required', 'string', 'max:100'], + 'problem-description' => ['required', 'string', 'max:400'], + 'problem-status' => ['required'], // bookmark2 + 'problem-default-language' => ['required'], // bookmark2 + 'problem-slug' => 'required|string|alpha_dash|unique:crowd_sourcing_project_problems,slug,' . $id . '|max:111', + 'problem-image' => 'nullable|image|mimes:jpeg,png,jpg|max:2048', + 'problem-owner-project' => ['required'], + ]); + + $attributes = $request->all(); + + try { + $this->crowdSourcingProjectProblemManager->updateProblem($id, $attributes); + } catch (\Exception $e) { + session()->flash('flash_message_error', 'Error: ' . $e->getCode() . ' ' . $e->getMessage()); + + return back()->withInput(); + } + + session()->flash('flash_message_success', 'The problem has been successfully updated.'); + + return back(); } /** diff --git a/resources/assets/sass/project/problem/create-edit-problem.scss b/resources/assets/sass/project/problem/create-edit-problem.scss index 2985a6e7..66b66c2a 100644 --- a/resources/assets/sass/project/problem/create-edit-problem.scss +++ b/resources/assets/sass/project/problem/create-edit-problem.scss @@ -1,2 +1,16 @@ @import "../../variables"; @import "../../common/image-input-preview.scss"; + +.explanation-text { + font-weight: normal; + color: $gray-600; + display: block; + margin-left: 20px; + line-height: 1.25; + + ul { + list-style-type: none; + margin: 2px 2px 3px; + padding-left: 10px; + } +} diff --git a/resources/assets/sass/project/problem/landing-page.scss b/resources/assets/sass/project/problem/landing-page.scss index ef0198d9..7df747b1 100644 --- a/resources/assets/sass/project/problem/landing-page.scss +++ b/resources/assets/sass/project/problem/landing-page.scss @@ -11,8 +11,8 @@ padding-right: 0.5rem; font-family: "Noto Sans Variable", sans-serif; font-weight: 600; - font-size: 24px; // 24px // bookmark - calulate in rem - line-height: 32.69px; // 32.69px // bookmark - calculate in rem + font-size: 24px; // 24px // bookmark1 - calulate in rem + line-height: 32.69px; // 32.69px // bookmark1 - calculate in rem text-align: left; } @@ -24,8 +24,8 @@ .project-overview p { font-family: "Open Sans Variable", sans-serif; font-weight: 400; - font-size: 16px; // 16px // bookmark - calulate in rem - line-height: 21.82px; // 21.82px // bookmark - calulate in rem + font-size: 16px; // 16px // bookmark1 - calulate in rem + line-height: 21.82px; // 21.82px // bookmark1 - calulate in rem text-align: left; } @@ -93,7 +93,7 @@ &:focus-visible { border-radius: 1rem; - outline: 4px solid black; // bookmark - calculate in rem + outline: 4px solid black; // bookmark1 - calculate in rem } } @@ -131,8 +131,8 @@ .card-title { font-family: "Noto Sans Variable", sans-serif; font-weight: 500; - font-size: 24px; // 24px // bookmark - calulate in rem - line-height: 29.34px; // 29.34px // bookmark - calulate in rem + font-size: 24px; // 24px // bookmark1 - calulate in rem + line-height: 29.34px; // 29.34px // bookmark1 - calulate in rem // truncate at 2 lines display: -webkit-box; @@ -146,8 +146,8 @@ .card-text { font-family: "Open Sans Variable", sans-serif; font-weight: 400; - font-size: 16px; // 16px // bookmark - calulate in rem - line-height: 20.4px; // 20.4px // bookmark - calulate in rem + font-size: 16px; // 16px // bookmark1 - calulate in rem + line-height: 20.4px; // 20.4px // bookmark1 - calulate in rem // truncate at 4 lines display: -webkit-box; @@ -176,7 +176,7 @@ } &:focus-visible { - outline: 3px solid var(--btn-text-color); // bookmark - calculate in rem + outline: 3px solid var(--btn-text-color); // bookmark1 - calculate in rem } } @@ -190,15 +190,15 @@ box-shadow: 0 4px 4px 0 #00000040; font-family: "Noto Sans Variable", sans-serif; font-weight: 600; - font-size: 20px; // 20px // bookmark - calulate in rem - line-height: 27.24px; // 27.24px // bookmark - calulate in rem + font-size: 20px; // 20px // bookmark1 - calulate in rem + line-height: 27.24px; // 27.24px // bookmark1 - calulate in rem &:hover { box-shadow: 0 4px 4px 0 #00000040, 0 4px 4px 0 #00000040; } &:focus-visible { - outline: 4px solid black; // bookmark - calculate in rem + outline: 4px solid black; // bookmark1 - calculate in rem } } diff --git a/resources/views/crowdsourcing-project/problems/landing-page.blade.php b/resources/views/crowdsourcing-project/problems/landing-page.blade.php index a3496f8a..13d5194b 100644 --- a/resources/views/crowdsourcing-project/problems/landing-page.blade.php +++ b/resources/views/crowdsourcing-project/problems/landing-page.blade.php @@ -26,7 +26,7 @@ @if (App::environment('local')) -
+
xs (default)
sm
diff --git a/resources/views/crowdsourcing-project/problems/partials/problems-list.blade.php b/resources/views/crowdsourcing-project/problems/partials/problems-list.blade.php index 822474db..4b7132ba 100644 --- a/resources/views/crowdsourcing-project/problems/partials/problems-list.blade.php +++ b/resources/views/crowdsourcing-project/problems/partials/problems-list.blade.php @@ -48,7 +48,7 @@ {{--
- +
--}} diff --git a/resources/views/crowdsourcing-project/problems/partials/problems-overview.blade.php b/resources/views/crowdsourcing-project/problems/partials/problems-overview.blade.php index f19f21b9..e6b5e1b9 100644 --- a/resources/views/crowdsourcing-project/problems/partials/problems-overview.blade.php +++ b/resources/views/crowdsourcing-project/problems/partials/problems-overview.blade.php @@ -2,7 +2,7 @@
- {{ __("project-problems.back") }} + {{ __("project-problems.back") }}
diff --git a/resources/views/loggedin-environment/management/problem/create-edit/partials/basic-details.blade.php b/resources/views/loggedin-environment/management/problem/create-edit/partials/basic-details.blade.php index 7b8c63a1..327d466b 100644 --- a/resources/views/loggedin-environment/management/problem/create-edit/partials/basic-details.blade.php +++ b/resources/views/loggedin-environment/management/problem/create-edit/partials/basic-details.blade.php @@ -31,7 +31,31 @@ class="form-control {{ $errors->has('problem-owner-project') ? 'is-invalid' : ''
- + + +
{{ $errors->first('problem-default-language') }}
+
+
+ +
+
+
- +