Skip to content

Commit

Permalink
Merge branch 'master' of github.com:scify/Crowdsourcing-Platform
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlosIsaris committed Nov 12, 2024
2 parents 3e423a3 + a76cb0b commit 87dc214
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@ public function getCrowdSourcingProjectProblemsLandingPageViewModel(string $crow
return new CrowdSourcingProjectProblemsLandingPage($crowdSourcingProject, $crowdSourcingProjectProblems);
}

public function getCrowdSourcingProjectProblem(int $id): CrowdSourcingProjectProblem {
$problem = $this->crowdSourcingProjectProblemRepository->find($id);

return $problem;
}

public function getCreateEditProblemViewModel(?int $id = null): CreateEditProblem {
// if ($id) {
// $project = $this->getCrowdSourcingProject($id);
// } else {
// $project = $this->crowdSourcingProjectRepository->getModelInstance();
// }

// $project = $this->populateInitialValuesForProjectIfNotSet($project);
$problem = new CrowdSourcingProjectProblem;
$problem->default_language_id = 6; // @todo change with lookuptable value - bookmark2
$problem->setRelation('defaultTranslation', new CrowdSourcingProjectProblemTranslation); // bookmark2 - is this an "empty" relationship?
if ($id) {
$problem = $this->getCrowdSourcingProjectProblem($id);
} else {
$problem = new CrowdSourcingProjectProblem;
$problem->default_language_id = 6; // @todo change with lookuptable value - bookmark2
$problem->setRelation('defaultTranslation', new CrowdSourcingProjectProblemTranslation); // bookmark2 - is this an "empty" relationship?
}

$translations = $this->crowdSourcingProjectProblemTranslationManager->getTranslationsForProblem($problem);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public function store(Request $request): RedirectResponse {

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

return redirect()->route('problems.edit', ['problem' => $createdProblemId]);
$route = route('problems.edit', ['problem' => $createdProblemId]) . '?translations=1';

return redirect($route);
}

/**
Expand Down
118 changes: 118 additions & 0 deletions resources/assets/js/project/problem/manage-problem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// import "select2";
// import "summernote/dist/summernote-bs4.min";

// import { createApp } from "vue";
// import store from "../store/store";

// import TranslationsManager from "../vue-components/common/TranslationsManager.vue";
// import CrowdSourcingProjectColors from "../vue-components/crowd-sourcing-project/CrowdSourcingProjectColors.vue";

// import select2 from "select2";
import $ from "jquery";

// select2($);

// const app = createApp({
// components: {
// TranslationsManager,
// CrowdSourcingProjectColors,
// },
// });

// app.use(store);
// app.mount("#app");

(function () {
// const initializeSummernote = function () {
// window.setTimeout(function () {
// $(".summernote").summernote({
// height: 150, // set editable area's height
// prettifyHtml: true,
// });
// initializeCommunicationResourcesHandlers();
// }, 2000);
// };

// const initializeSubmitFormListener = function () {
// $("#project-form").one("submit", function (event) {
// event.preventDefault();
// fixAllSummerNoteCodes();
// $(this).submit();
// });
// };

// const fixAllSummerNoteCodes = function () {
// $(".summernote").each((index, element) => {
// updateSummerNoteCodeContent($(element));
// });
// };

// const updateSummerNoteCodeContent = function (el) {
// el.val(el.summernote("code"));
// };

// const initializeImgFileChangePreviewHandlers = function () {
// $(".image-input").each(function (i, obj) {
// $(obj).change(function () {
// const event = this;
// if (event.files && event.files[0]) {
// const parent = $(obj).closest(".image-input-container");
// const imgPreview = parent.find(".selected-image-preview");
// const reader = new FileReader();
// reader.onload = function (e) {
// imgPreview.attr("src", e.target.result);
// };
// reader.readAsDataURL(event.files[0]);
// }
// });
// });
// };

// const initializeCommunicationResourcesHandlers = function () {
// initializeSummernoteAndUpdateElementOnKeyup($("#questionnaire_response_email_intro_text"), $("#intro_text"));
// initializeSummernoteAndUpdateElementOnKeyup($("#questionnaire_response_email_outro_text"), $("#outro_text"));
// };

// const initializeSummernoteAndUpdateElementOnKeyup = function (summernoteEl, targetEl) {
// summernoteEl.summernote({
// height: 150,
// callbacks: {
// onChange: function (contents) {
// setTimeout(function () {
// targetEl.html(contents);
// }, 50);
// },
// },
// });
// };

// const initializeSocialMediaKeywordsTags = function () {
// $("#social-media-tab").one("click", function () {
// window.setTimeout(function () {
// $("#sm_keywords").select2({
// tags: true,
// });
// }, 200);
// });
// };

const checkURLAndActivateTranslationsTab = function () {
// should check the URL for a `translations=1` variable and if set and if true, it should activate the tab. SEE DESCR
if ( (window.location.search.indexOf("?translations=1") > -1) || (window.location.search.indexOf("&translations=1") > -1)) {
$("#translations-tab").click();
}
};

const init = function () {
// initializeSubmitFormListener();
// initializeImgFileChangePreviewHandlers();
// initializeSummernote();
// initializeSocialMediaKeywordsTags();
checkURLAndActivateTranslationsTab();
};

$(document).ready(function () {
init();
});

})();
3 changes: 1 addition & 2 deletions resources/assets/sass/common/alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

.alert-dismissable.alert-floating {
position: absolute;
max-width: 50%;
z-index: 100000;
right: 25px;
top: 25px;
min-width: 400px;
width: min(calc(100% - 50px), 26.25rem);

* {
color: $white;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@section('content')

<form id="problem-form" enctype="multipart/form-data"{{-- bookmark2 - enctype? --}} method="POST"
<form id="problem-form" enctype="multipart/form-data" method="POST"
action="{{ $viewModel->isEditMode() ? route('problems.update', $viewModel->problem) : route('problems.store') }}">

@if($viewModel->isEditMode())
Expand All @@ -27,13 +27,20 @@
<a class="nav-link active" id="basic-details-tab" data-toggle="tab" href="#basic-details" role="tab"
aria-controls="basic-details" aria-selected="true">Basic Details</a>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="translations-tab" data-toggle="tab" href="#translations" role="tab"
aria-controls="translations" aria-selected="false">Translations</a>
</li>
</ul>
<div class="tab-content " id="myTabContent">
<div class="tab-pane fade show active " id="basic-details" role="tabpanel"
aria-labelledby="basic-details-tab">
@include('loggedin-environment.management.problem.create-edit.partials.basic-details')

</div>
<div class="tab-pane fade " id="translations" role="tabpanel" aria-labelledby="translations-tab">
@include('loggedin-environment.management.problem.create-edit.partials.translations')
</div>
</div>
<div>
<div class="container-fluid p-0">
Expand All @@ -50,3 +57,7 @@
</form>

@endsection

@push('scripts')
@vite('resources/assets/js/project/problem/manage-problem.js')
@endpush
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class="form-control {{ $errors->has('problem-title') ? 'is-invalid' : '' }}"
placeholder="Problem Title"
maxlength="100"
{{ $errors->has('problem-title') ? 'aria-describedby="problem-title-feedback"' : '' }}
{{-- value="{{ old('problem-title') ? old('problem-title') : $viewModel->problem->defaultTranslation->title }}" bookmark2 --}}
value="{{ old('problem-title') ? old('problem-title') : '' }}"
value="{{ old('problem-title') ? old('problem-title') : $viewModel->problem->defaultTranslation->title }}"
>
<div id="problem-title-feedback" class="invalid-feedback"><strong>{{ $errors->first('problem-title') }}</strong></div>
</div>
Expand All @@ -59,7 +58,7 @@ class="form-control {{ $errors->has('problem-description') ? 'is-invalid' : '' }
placeholder="Problem Description"
maxlength="400"
{{ $errors->has('problem-description') ? 'aria-describedby="problem-description-feedback"' : '' }}
>{{-- {{ old('problem-description') ? old('problem-description') : $viewModel->problem->defaultTranslation->description }} bookmark2 --}}{{ old('problem-description') ? old('problem-description') : '' }}</textarea>
>{{ old('problem-description') ? old('problem-description') : $viewModel->problem->defaultTranslation->description }}</textarea>
<div id="problem-description-feedback" class="invalid-feedback"><strong>{{ $errors->first('problem-description') }}</strong></div>
</div>
</div>
Expand Down Expand Up @@ -147,17 +146,27 @@ class="form-control {{ $errors->has('problem-slug') ? 'is-invalid' : '' }}"
</div>
@endif

<div class="form-row">
<div class="form-group col-sm-12">
<label for="problem-image">Problem Image (max-size: 2MB)</label></label>
<input type="file"
id="problem-image"
name="problem-image"
class="form-control p-2 h-auto {{ $errors->has('problem-image') ? 'is-invalid' : '' }}"
accept="image/png,image/jpeg,image/jpg"
placeholder="Problem Image"
>
<div id="problem-image-feedback" class="invalid-feedback"><strong>{{ $errors->first('problem-image') }}</strong></div>
<div class="form-row js-bookmark3-image-input-container">
<div class="col-sm-12">
<div class="form-group css-bookmark3-input-file-wrapper">
<label for="problem-image">Problem Image (max-size: 2MB)</label></label>
<small>In order to update the currently selected image, please choose a new image by clicking the button below.</small><br>
<input type="file"
id="problem-image"
name="problem-image"
class="form-control p-2 h-auto {{ $errors->has('problem-image') ? 'is-invalid' : '' }} js-bookmark3-image-input"
accept="image/png,image/jpeg,image/jpg"
placeholder="Problem Image"
>
<div id="problem-image-feedback" class="invalid-feedback"><strong>{{ $errors->first('problem-image') }}</strong></div>
</div>
<div class="css-bookmark3-image-preview-container">
<img
loading="lazy"
class="css-js-bookmark3-selected-image-preview"
src="{{ asset($viewModel->problem->img_url) }}"
alt="">
</div>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-body">

@if (!$viewModel->isEditMode())
Please <b>save the problem first </b> to start translating.
@else
{{--
<translations-manager
:model-meta-data='@json( $viewModel->translationsMetaData)'
:existing-translations=' @json( $viewModel->translations)'
:default-lang-id="{{ $viewModel->project->language_id }}">
</translations-manager>
--}}

translations component

@endif

</div>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default defineConfig({
"resources/assets/js/questionnaire/questionnaire-statistics-colors.js",
"resources/assets/js/questionnaire/questionnaire-statistics.js",
"resources/assets/js/questionnaire/questionnaire-thanks.js",
"resources/assets/js/project/problem/manage-problem.js",
],
refresh: true,
}),
Expand Down

0 comments on commit 87dc214

Please sign in to comment.