diff --git a/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectManager.php b/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectManager.php index 8480f1ed..b58068d2 100644 --- a/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectManager.php +++ b/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectManager.php @@ -214,7 +214,7 @@ public function updateProject($id, array $attributes) { $this->crowdSourcingProjectTranslationManager->storeOrUpdateDefaultTranslationForProject( $attributes, $id); if (isset($attributes['extra_translations'])) { - $this->crowdSourcingProjectTranslationManager->storeOrUpdateTranslationsForProject( + $this->crowdSourcingProjectTranslationManager->storeOrUpdateExtraTranslationsForProject( json_decode($attributes['extra_translations']), $project->id, intval($attributes['language_id'])); } } diff --git a/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectTranslationManager.php b/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectTranslationManager.php index 7486746f..ccab1f4a 100644 --- a/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectTranslationManager.php +++ b/app/BusinessLogicLayer/CrowdSourcingProject/CrowdSourcingProjectTranslationManager.php @@ -40,7 +40,7 @@ public function getTranslationsForProject(CrowdSourcingProject $project): Collec return $this->crowdSourcingProjectTranslationRepository->allWhere(['project_id' => $project->id]); } - public function storeOrUpdateDefaultTranslationForProject(array $attributes, int $project_id) { + public function storeOrUpdateDefaultTranslationForProject(array $attributes, int $project_id): void { $allowedKeys = (new CrowdSourcingProjectTranslation)->getFillable(); $filtered = Helpers::getFilteredAttributes($attributes, $allowedKeys); $this->crowdSourcingProjectTranslationRepository->updateOrCreate( @@ -49,19 +49,19 @@ public function storeOrUpdateDefaultTranslationForProject(array $attributes, int ); } - public function storeOrUpdateTranslationsForProject(array $attributesArray, int $project_id, int $language_id) { + public function storeOrUpdateExtraTranslationsForProject(array $extraTranslations, int $project_id, int $language_id): void { $defaultLanguageContentForProject = $this->crowdSourcingProjectTranslationRepository->where([ 'project_id' => $project_id, 'language_id' => $language_id, ]) ->toArray(); $allowedKeys = (new CrowdSourcingProjectTranslation)->getFillable(); - foreach ($attributesArray as $attributes) { - $attributes = json_decode(json_encode($attributes), true); - foreach ($attributes as $key => $value) { + foreach ($extraTranslations as $extraTranslation) { + $extraTranslation = json_decode(json_encode($extraTranslation), true); + foreach ($extraTranslation as $key => $value) { if (!$value) { - $attributes[$key] = $defaultLanguageContentForProject[$key]; + $extraTranslation[$key] = $defaultLanguageContentForProject[$key]; } } - $filtered = Helpers::getFilteredAttributes($attributes, $allowedKeys); + $filtered = Helpers::getFilteredAttributes($extraTranslation, $allowedKeys); $filtered['project_id'] = $project_id; $this->crowdSourcingProjectTranslationRepository->updateOrCreate( ['project_id' => $project_id, 'language_id' => $filtered['language_id']], diff --git a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php index 3c431340..98db66dc 100644 --- a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php +++ b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemManager.php @@ -125,8 +125,16 @@ public function updateProblem(int $id, array $attributes) { $modelAttributes['img_url'] = $imgPath; $modelAttributes['default_language_id'] = $attributes['problem-default-language']; // bookmark2 - default or generally another translation language? + $extraTranslations = isset($attributes['extra_translations']) ? json_decode($attributes['extra_translations']) : []; + + $defaultTranslation = [ + 'language_id' => $attributes['problem-default-language'], + 'title' => $attributes['problem-title'], + 'description' => $attributes['problem-description'], + ]; + $this->crowdSourcingProjectProblemTranslationManager - ->updateProblemTranslations($id, $attributes['problem-default-language'], $attributes['problem-title'], $attributes['problem-description']); + ->updateProblemTranslations($id, $defaultTranslation, $extraTranslations); $this->crowdSourcingProjectProblemRepository->update($modelAttributes, $id); diff --git a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslationManager.php b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslationManager.php index 977558c5..4179a688 100644 --- a/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslationManager.php +++ b/app/BusinessLogicLayer/CrowdSourcingProject/Problem/CrowdSourcingProjectProblemTranslationManager.php @@ -39,16 +39,36 @@ 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) { + public function updateProblemTranslations(int $problemId, array $defaultTranslation, array $extraTranslations): void { + $this->updateProblemDefaultTranslation($problemId, $defaultTranslation); + + $this->updateProblemExtraTranslations($problemId, $extraTranslations); + } + + protected function updateProblemDefaultTranslation(int $problemId, array $defaultTranslation): void { $this->crowdSourcingProjectProblemTranslationRepository->updateOrCreate( [ - 'problem_id' => $problem_id, - 'language_id' => $new_default_language_id, + 'problem_id' => $problemId, + 'language_id' => $defaultTranslation['language_id'], ], [ - 'title' => $default_language_title, - 'description' => $default_language_description, + 'title' => $defaultTranslation['title'], + 'description' => $defaultTranslation['description'], ] ); } + + protected function updateProblemExtraTranslations(int $problemId, array $extraTranslations) { + // TODO + // get all available translations for problem + // for each translation in the existing ones, check if the translation exists in the $extraTranslations array + // if exists + // update the title and description + // remove the entry from the $extraTranslations array (or mark it as parsed) + // if not exists + // delete the record in the DB + + // foreach translation in the $extraTranslations + // if not parsed, create the record in the DB + } } diff --git a/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php index 66f8a1b6..0225781f 100644 --- a/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php +++ b/app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php @@ -13,6 +13,7 @@ class CreateEditProblem { public $languagesLkp; public $defaultLanguageCode = 'en'; public $projects; + public array $translationsMetaData; public function __construct( CrowdSourcingProjectProblem $crowdSourcingProjectProblem, @@ -26,6 +27,16 @@ public function __construct( $this->problemStatusesLkp = $problemStatusesLkp; $this->languagesLkp = $languagesLkp; $this->projects = $projects; + $this->translationsMetaData = [ + 'title' => [ + 'display_title' => 'Project Name (*)', + 'required' => true, + ], + 'description' => [ + 'display_title' => 'Project description (*)', + 'required' => true, + ], + ]; } public function isEditMode(): bool { diff --git a/database/seeders/LanguagesLkpTableSeeder.php b/database/seeders/LanguagesLkpTableSeeder.php index 44fbb3b7..f61a9f38 100644 --- a/database/seeders/LanguagesLkpTableSeeder.php +++ b/database/seeders/LanguagesLkpTableSeeder.php @@ -30,19 +30,19 @@ public function run() { 'code' => 'hr', 'name' => 'Croatian', 'default_color' => '#90caf9', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'cs', 'name' => 'Czech', 'default_color' => '#d32f2f', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'da', 'name' => 'Danish', 'default_color' => '#d50000', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'nl', @@ -65,13 +65,13 @@ public function run() { 'code' => 'fi', 'name' => 'Finnish', 'default_color' => '#29b6f6', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'ga', 'name' => 'Irish', 'default_color' => '#66bb6a', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'fr', @@ -101,7 +101,7 @@ public function run() { 'code' => 'it', 'name' => 'Italian', 'default_color' => '#3949ab', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'lv', @@ -113,13 +113,13 @@ public function run() { 'code' => 'lt', 'name' => 'Lithuanian', 'default_color' => '#43a047', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'pl', 'name' => 'Polish', 'default_color' => '#e57373', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'pt', @@ -131,43 +131,43 @@ public function run() { 'code' => 'ro', 'name' => 'Romanian', 'default_color' => '#ffb300', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'sk', 'name' => 'Slovak', 'default_color' => '#0d47a1', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'sl', 'name' => 'Slovenian', 'default_color' => '#d81b60', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'es', 'name' => 'Spanish', 'default_color' => '#fb8c00', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'sv', 'name' => 'Swedish', 'default_color' => '#fdd835', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'mt', 'name' => 'Maltese', 'default_color' => '#b71c1c', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'sq', 'name' => 'Albanian', 'default_color' => '#e53935', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], [ 'code' => 'sr', @@ -179,7 +179,7 @@ public function run() { 'code' => 'tr', 'name' => 'Turkish', 'default_color' => '#e53935', - 'available_for_platform_translation' => false, + 'available_for_platform_translation' => true, ], ]; $index = 1; diff --git a/resources/assets/js/project/problem/manage-problem.js b/resources/assets/js/project/problem/manage-problem.js index 6ae08fa5..766d8d1c 100644 --- a/resources/assets/js/project/problem/manage-problem.js +++ b/resources/assets/js/project/problem/manage-problem.js @@ -1,55 +1,20 @@ -// import "select2"; -// import "summernote/dist/summernote-bs4.min"; +import { createApp } from "vue"; +import store from "../../store/store"; -// import { createApp } from "vue"; -// import store from "../store/store"; +import TranslationsManager from "../../vue-components/common/TranslationsManager.vue"; -// 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, -// }, -// }); +const app = createApp({ + components: { + TranslationsManager, + }, +}); -// app.use(store); -// app.mount("#app"); +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 () { $(".js-image-input").each(function (i, obj) { @@ -68,34 +33,6 @@ import $ from "jquery"; }); }; - // 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)) { @@ -104,10 +41,7 @@ import $ from "jquery"; }; const init = function () { - // initializeSubmitFormListener(); initializeImgFileChangePreviewHandlers(); - // initializeSummernote(); - // initializeSocialMediaKeywordsTags(); checkURLAndActivateTranslationsTab(); }; diff --git a/resources/assets/js/vue-components/common/TranslationsManager.vue b/resources/assets/js/vue-components/common/TranslationsManager.vue index 9fdea6c1..ba0e64c7 100644 --- a/resources/assets/js/vue-components/common/TranslationsManager.vue +++ b/resources/assets/js/vue-components/common/TranslationsManager.vue @@ -85,7 +85,7 @@ {{ originalTranslation[key] }}