Skip to content

Commit

Permalink
IP-79: Create a new page with the new solution form
Browse files Browse the repository at this point in the history
  • Loading branch information
papandrk committed Dec 11, 2024
1 parent 2e27426 commit bebe83d
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 7 deletions.
23 changes: 22 additions & 1 deletion app/BusinessLogicLayer/Solution/SolutionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\BusinessLogicLayer\Solution;

use App\BusinessLogicLayer\CrowdSourcingProject\CrowdSourcingProjectTranslationManager;
use App\BusinessLogicLayer\lkp\SolutionStatusLkp;
use App\BusinessLogicLayer\Problem\ProblemTranslationManager;
use App\Models\Solution\Solution;
use App\Models\Solution\SolutionTranslation;
use App\Repository\LanguageRepository;
Expand All @@ -11,6 +13,7 @@
use App\Repository\Solution\SolutionRepository;
use App\Utils\FileHandler;
use App\ViewModels\Solution\CreateEditSolution;
use App\ViewModels\Solution\ProposeSolutionPage;
use Exception;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
Expand All @@ -24,19 +27,25 @@ class SolutionManager {
protected SolutionTranslationManager $solutionTranslationManager;
protected SolutionStatusManager $solutionStatusManager;
protected LanguageRepository $languageRepository;
protected CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager;
protected ProblemTranslationManager $problemTranslationManager;

public function __construct(
SolutionRepository $solutionRepository,
ProblemRepository $problemRepository,
SolutionTranslationManager $solutionTranslationManager,
SolutionStatusManager $solutionStatusManager,
LanguageRepository $languageRepository
LanguageRepository $languageRepository,
CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager,
ProblemTranslationManager $problemTranslationManager,
) {
$this->solutionRepository = $solutionRepository;
$this->problemRepository = $problemRepository;
$this->solutionTranslationManager = $solutionTranslationManager;
$this->solutionStatusManager = $solutionStatusManager;
$this->languageRepository = $languageRepository;
$this->crowdSourcingProjectTranslationManager = $crowdSourcingProjectTranslationManager;
$this->problemTranslationManager = $problemTranslationManager;
}

/**
Expand Down Expand Up @@ -211,4 +220,16 @@ public function deleteSolution(int $id): bool {

return $this->solutionRepository->delete($id);
}

public function getProposeSolutionPageViewModel(string $locale, string $project_slug, string $problem_slug): ProposeSolutionPage {
$project = $this->problemRepository->getProjectWithProblemsByProjectSlug($project_slug);
$project->currentTranslation = $this->crowdSourcingProjectTranslationManager->getFieldsTranslationForProject($project);

$problem = $this->problemRepository->findBy('slug', $problem_slug);
$problem->currentTranslation = $this->problemTranslationManager->getProblemCurrentTranslation($problem->id, $locale);

$localeLanguage = $this->languageRepository->getLanguageByCode($locale);

return new ProposeSolutionPage($project, $problem, $localeLanguage);
}
}
53 changes: 53 additions & 0 deletions app/Http/Controllers/Solution/SolutionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,57 @@ public function getSolutions(Request $request): JsonResponse {

return response()->json($this->solutionManager->getSolutions($request->problem_id));
}

public function userProposalCreate(string $locale, string $project_slug, string $problem_slug): View|RedirectResponse {
$validator = Validator::make([
'project_slug' => $project_slug,
'problem_slug' => $problem_slug,
], [
'project_slug' => 'required|different:execute_solution|exists:crowd_sourcing_projects,slug',
'problem_slug' => 'required|different:execute_solution|exists:problems,slug',
]);
if ($validator->fails()) {
abort(ResponseAlias::HTTP_NOT_FOUND);
}
try {
$viewModel = $this->solutionManager->getProposeSolutionPageViewModel($locale, $project_slug, $problem_slug);

return view('solution.propose', ['viewModel' => $viewModel]);
} catch (\Exception $e) {
session()->flash('flash_message_error', 'Error: ' . $e->getCode() . ' ' . $e->getMessage());

return back()->withInput();
}
}

// public function userProposalStore(Request $request): RedirectResponse {
// return 'user ProposalStore';
// $this->validate($request, [
// 'solution-title' => ['required', 'string', 'max:100'],
// 'solution-description' => ['required', 'string', 'max:400'],
// 'solution-status' => ['required'],
// 'solution-image' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
// 'solution-owner-problem' => ['required'],
// ]);

// $attributes = $request->all();

// try {
// $createdSolutionId = $this->solutionManager->storeSolution($attributes);
// } catch (\Exception $e) {
// session()->flash('flash_message_error', 'Error: ' . $e->getCode() . ' ' . $e->getMessage());

// return back()->withInput();
// }

// session()->flash('flash_message_success', 'Solution Created Successfully.');

// $route = route('solutions.edit', ['solution' => $createdSolutionId]) . '?translations=1';

// return redirect($route);
// }

public function userProposalSubmitted(Request $request) {
return 'userProposalSubmitted';
}
}
25 changes: 25 additions & 0 deletions app/ViewModels/Solution/ProposeSolutionPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\ViewModels\Solution;

use App\Models\CrowdSourcingProject\CrowdSourcingProject;
use App\Models\Language;
use App\Models\Problem\Problem;

class ProposeSolutionPage {
public CrowdSourcingProject $project;
public Problem $problem;
public Language $language;
public string $page_title;

public function __construct(
CrowdSourcingProject $project,
Problem $problem,
Language $language,
) {
$this->project = $project;
$this->problem = $problem;
$this->language = $language;
$this->page_title = $project->currentTranslation->name . ' | ' . $problem->currentTranslation->title . '' . __('solution.propose_solution');
}
}
6 changes: 3 additions & 3 deletions resources/assets/sass/problem/landing-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
padding-right: 0.5rem;
font-family: "Noto Sans Variable", sans-serif;
font-weight: 600;
font-size: 24px; // 24px // bookmark1 - calulate in rem
font-size: 24px; // 24px // bookmark1 - calculate in rem
line-height: 32.69px; // 32.69px // bookmark1 - calculate in rem
text-align: left;
}
Expand All @@ -23,8 +23,8 @@
.project-overview p {
font-family: "Open Sans Variable", sans-serif;
font-weight: 400;
font-size: 16px; // 16px // bookmark1 - calulate in rem
line-height: 21.82px; // 21.82px // bookmark1 - calulate in rem
font-size: 16px; // 16px // bookmark1 - calculate in rem
line-height: 21.82px; // 21.82px // bookmark1 - calculate in rem
text-align: left;
}

Expand Down
6 changes: 3 additions & 3 deletions resources/assets/sass/problem/show-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
padding-right: 0.5rem;
font-family: "Noto Sans Variable", sans-serif;
font-weight: 600;
font-size: 24px; // 24px // bookmark1 - calulate in rem
font-size: 24px; // 24px // bookmark1 - calculate in rem
line-height: 32.69px; // 32.69px // bookmark1 - calculate in rem
text-align: left;
}
Expand All @@ -24,8 +24,8 @@
.section-body p {
font-family: "Open Sans Variable", sans-serif;
font-weight: 400;
font-size: 16px; // 16px // bookmark1 - calulate in rem
line-height: 21.82px; // 21.82px // bookmark1 - calulate in rem
font-size: 16px; // 16px // bookmark1 - calculate in rem
line-height: 21.82px; // 21.82px // bookmark1 - calculate in rem
text-align: left;
}

Expand Down
29 changes: 29 additions & 0 deletions resources/assets/sass/solution/propose-page.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#propose-solution-page {
#propose-solution-overview,
.row.propose-solution-description {
padding-bottom: 3.25rem;
}

.section-title {
padding-left: 0.5rem;
padding-right: 0.5rem;
font-family: "Noto Sans Variable", sans-serif;
font-weight: 600;
font-size: 24px; // 24px // bookmark1 - calculate in rem
line-height: 32.69px; // 32.69px // bookmark1 - calculate in rem
text-align: left;
}

.section-body {
padding-left: 0.5rem;
padding-right: 0.5rem;
}

.section-body p {
font-family: "Open Sans Variable", sans-serif;
font-weight: 400;
font-size: 16px; // 16px // bookmark1 - calculate in rem
line-height: 21.82px; // 21.82px // bookmark1 - calculate in rem
text-align: left;
}
}
5 changes: 5 additions & 0 deletions resources/lang/el/solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'propose_solution' => 'Πρότεινε Λύση',
];
5 changes: 5 additions & 0 deletions resources/lang/en/solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'propose_solution' => 'Propose Solution',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>solution-form-works!</p>
20 changes: 20 additions & 0 deletions resources/views/solution/propose.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@extends('crowdsourcing-project.layout')
@push('css')
@vite('resources/assets/sass/solution/propose-page.scss')
<style>
:root {
--project-primary-color: {{ $viewModel->project->lp_primary_color}};
--btn-text-color: {{ $viewModel->project->lp_btn_text_color_theme == "light" ? "#ffffff" : "#212529"}};
}
</style>
@endpush

@section('content')

<h2>propose-solution-works!</h2>

<section id="propose-solution-overview" class="bg-clr-primary-white">
@include('solution.partials.new-solution-form')
</section>

@endsection
4 changes: 4 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

Route::group(['middleware' => ['auth', 'setlocale']], function () use ($localeInfo, $backOfficePrefix) {
Route::group($localeInfo, function () use ($backOfficePrefix) {
Route::get('/{project_slug}/problems/{problem_slug}/solutions/propose', [SolutionController::class, 'userProposalCreate'])->name('solutions.user-proposal-create');
Route::post('/{project_slug}/problems/{problem_slug}/solutions', [SolutionController::class, 'userProposalStore'])->name('solutions.user-proposal-store');
Route::get('/{project_slug}/problems/{problem_slug}/solutions/solution-submitted', [SolutionController::class, 'userProposalSubmitted'])->name('solutions.user-proposal-submitted');
Route::group(['prefix' => $backOfficePrefix], function () {
Route::get('/my-dashboard', [UserController::class, 'myDashboard'])->name('my-dashboard');
Route::get('/my-account', [UserController::class, 'myAccount'])->name('my-account');
Expand Down Expand Up @@ -122,6 +125,7 @@
Route::get('/{project_slug}/{questionnaire_id}/thanks', [QuestionnaireResponseController::class, 'showQuestionnaireThanksForRespondingPage'])->name('questionnaire.thanks');
Route::get('/{project_slug}/problems', [ProblemController::class, 'showProblemsPage'])->name('project.problems-page');
Route::get('/{project_slug}/problems/{problem_slug}', [ProblemController::class, 'show'])->name('problem.show');
Route::get('/{project_slug}/problems/{problem_slug}/solutions/', [ProblemController::class, 'show'])->name('problem.show.solutions');
});

Route::group(['middleware' => 'auth'], function () {
Expand Down
1 change: 1 addition & 0 deletions vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default defineConfig({
"resources/assets/sass/problem/landing-page.scss",
"resources/assets/sass/problem/show-page.scss",
"resources/assets/sass/solution/create-edit-solution.scss",
"resources/assets/sass/solution/propose-page.scss",
"resources/assets/sass/gamification/progress.scss",
"resources/assets/sass/pages/my-contributions.scss",
"resources/assets/js/common-backoffice.js",
Expand Down

0 comments on commit bebe83d

Please sign in to comment.