Skip to content

Commit

Permalink
Added Bootstrap styling in translation Vue, updated languages, added …
Browse files Browse the repository at this point in the history
…the translations component in the problem form
  • Loading branch information
PavlosIsaris committed Nov 14, 2024
1 parent 15bc67a commit bc3e307
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
11 changes: 11 additions & 0 deletions app/ViewModels/CrowdSourcingProject/Problem/CreateEditProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CreateEditProblem {
public $languagesLkp;
public $defaultLanguageCode = 'en';
public $projects;
public array $translationsMetaData;

public function __construct(
CrowdSourcingProjectProblem $crowdSourcingProjectProblem,
Expand All @@ -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 {
Expand Down
32 changes: 16 additions & 16 deletions database/seeders/LanguagesLkpTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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;
Expand Down
86 changes: 10 additions & 76 deletions resources/assets/js/project/problem/manage-problem.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)) {
Expand All @@ -104,10 +41,7 @@ import $ from "jquery";
};

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
{{ originalTranslation[key] }}
</td>
<td>
<textarea v-model="translation[key]"></textarea>
<textarea class="form-control" v-model="translation[key]"></textarea>
</td>
</tr>
</tbody>
Expand Down
Loading

0 comments on commit bc3e307

Please sign in to comment.