Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IP-263: Problem Editing actions are updated in the DB #144

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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?
]);

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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();
}

/**
Expand Down
14 changes: 14 additions & 0 deletions resources/assets/sass/project/problem/create-edit-problem.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}
26 changes: 13 additions & 13 deletions resources/assets/sass/project/problem/landing-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>

@if (App::environment('local'))
<div class="fixed-bottom"> <!-- bookmark - for use only during development -->
<div class="fixed-bottom"> <!-- bookmark1 - for use only during development -->
<div class="alert alert-danger text-center font-weight-bold" style="top: -40px; width: 160px; margin: 0 auto; opacity: 0.25">
<div class="d-block d-sm-none">xs (default)</div>
<div class="d-none d-sm-block d-md-none">sm</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{{--
<div class="row pb-5">
<div class="col-12 d-flex justify-content-center">
<button class="cta-btn">{{ __("project-problems.list_of_problems") }}</button> <!-- bookmark - add click handler / or hide for now -->
<button class="cta-btn">{{ __("project-problems.list_of_problems") }}</button> <!-- bookmark1 - add click handler / or hide for now -->
</div>
</div>
--}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="row">
<div class="col-12 my-4 my-lg-5 pt-4">
<x-go-back-link href="/{{ app()->getLocale() .'/'. $viewModel->project->slug }}" class="d-none d-lg-block">{{ __("project-problems.back") }}</x-go-back-link> <!-- bookmark - app()->getLocale() // is this OK? -->
<x-go-back-link href="/{{ app()->getLocale() .'/'. $viewModel->project->slug }}" class="d-none d-lg-block">{{ __("project-problems.back") }}</x-go-back-link> <!-- bookmark1 - app()->getLocale() // is this OK? -->
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,31 @@ class="form-control {{ $errors->has('problem-owner-project') ? 'is-invalid' : ''

<div class="form-row">
<div class="form-group col-sm-12">
<label for="problem-title">Problem Title (<span class="red">*</span>)</label>
<label for="problem-default-language">Problem Default Language (<span class="red">*</span>)</label>
<select
id="problem-default-language"
name="problem-default-language"
class="form-control {{ $errors->has('problem-default-language') ? 'is-invalid' : '' }}"
required
>
@foreach ($viewModel->languagesLkp as $language)
<option
@if ($viewModel->shouldLanguageBeSelected($language))
selected
@endif
value="{{ $language->id }}"
>
{{ $language->language_name }}
</option>
@endforeach
</select>
<div id="problem-default-language-feedback" class="invalid-feedback"><strong>{{ $errors->first('problem-default-language') }}</strong></div>
</div>
</div>

<div class="form-row">
<div class="form-group col-sm-12">
<label for="problem-title">Problem Default Title (<span class="red">*</span>)</label>
<input type="text"
id="problem-title"
name="problem-title"
Expand All @@ -48,7 +72,7 @@ class="form-control {{ $errors->has('problem-title') ? 'is-invalid' : '' }}"

<div class="form-row">
<div class="form-group col-sm-12">
<label for="problem-description">Problem Description (<span class="red">*</span>)</label>
<label for="problem-description">Problem Default Description (<span class="red">*</span>)</label>
<textarea
id="problem-description"
name="problem-description"
Expand All @@ -66,8 +90,8 @@ class="form-control {{ $errors->has('problem-description') ? 'is-invalid' : '' }
<div class="form-row">
<div class="form-group col-sm-12">
<label for="problem-status">Problem Status (<span class="red">*</span>)</label>
@if(!Gate::check('manage-platform-content'))
<small class="text-blue">(The problem status can only be changed by a platform administrator.)</small>{{-- bookmark2 - is this what we want? --}}
@if(!Gate::check('manage-platform-content')){{-- bookmark2 - do we need this? --}}
<small class="text-blue">(The problem status can only be changed by a platform administrator.)</small>{{-- bookmark2 - and content-manager? do we need this? --}}
@endif
<select
id="problem-status"
Expand All @@ -79,7 +103,7 @@ class="form-control {{ $errors->has('problem-status') ? 'is-invalid' : '' }}"
@foreach ($viewModel->problemStatusesLkp as $status)
<option
@if(!Gate::check('manage-platform-content'))
disabled{{-- bookmark2 - is this what we want? --}}
disabled{{-- bookmark2 - do we need this? --}}
@endif
@if ($viewModel->problem->status_id == $status->id || old('problem-status') == $status->id)
selected
Expand All @@ -94,42 +118,18 @@ class="form-control {{ $errors->has('problem-status') ? 'is-invalid' : '' }}"
</div>
</div>

<div class="form-row">
<div class="form-group col-sm-12">
<label for="problem-default-language">Problem Default Language (<span class="red">*</span>)</label>
<select
id="problem-default-language"
name="problem-default-language"
class="form-control {{ $errors->has('problem-default-language') ? 'is-invalid' : '' }}"
required
>
@foreach ($viewModel->languagesLkp as $language)
<option
@if ($viewModel->shouldLanguageBeSelected($language))
selected
@endif
value="{{ $language->id }}"
>
{{ $language->language_name }}
</option>
@endforeach
</select>
<div id="problem-default-language-feedback" class="invalid-feedback"><strong>{{ $errors->first('problem-default-language') }}</strong></div>
</div>
</div>

@if($viewModel->isEditMode())
<div class="form-row">
<div class="form-group col-sm-12">
<label for="problem-slug">Problem Slug (<span class="red">*</span>)
<span class="text-sm">
<br>(it defines the problems's url, for example:
<br><i>For english | https://crowdsourcing.ecas.org/en/your-problem-slug</i>)
<br><i>For greek | https://crowdsourcing.ecas.org/gr/your-problem-slug</i>)
<br><i>For dutch | https://crowdsourcing.ecas.org/nl/your-problem-slug</i>)
<br>The url can contain only letters, numbers, and dashes.
<br>If left empty, we will take care of creating the URL, based on the problem name. {{-- bookmark2 - implement auto-creation - best done with js (client-side) --}}
<br>Please note that once you publish the problem you <i>cannot</i> change the slug. {{-- bookmark2 - once published or once created? --}}
<span class="text-sm explanation-text">
(It defines the problems's url, for example:
<ul>
<li><i>For english | https://crowdsourcing.ecas.org/en/project-slug/problem-slug</i></li>
<li><i>For greek | https://crowdsourcing.ecas.org/gr/project-slug/problem-slug</i></li>
<li><i>For dutch | https://crowdsourcing.ecas.org/nl/project-slug/problem-slug</i></li>
</ul>
The slug must be unique and can contain only letters, numbers, and dashes.)
</span>
</label>
<input type="text"
Expand All @@ -138,6 +138,7 @@ class="form-control {{ $errors->has('problem-default-language') ? 'is-invalid' :
class="form-control {{ $errors->has('problem-slug') ? 'is-invalid' : '' }}"
required
placeholder="Problem Slug"
maxlength="111"
value="{{ old('problem-slug') ? old('problem-slug') : $viewModel->problem->slug }}"
>
<div id="problem-slug-feedback" class="invalid-feedback"><strong>{{ $errors->first('problem-slug') }}</strong></div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/questionnaire/questionnaire-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</div>

@if (App::environment('local'))
<div class="fixed-bottom"> <!-- bookmark - for use only during development -->
<div class="fixed-bottom"> <!-- bookmark1 - for use only during development -->
<div class="alert alert-danger text-center font-weight-bold" style="top: -40px; width: 160px; margin: 0 auto; opacity: 0.25">
<div class="d-block d-sm-none">xs (default)</div>
<div class="d-none d-sm-block d-md-none">sm</div>
Expand Down
Loading