From 83aa1f5cba65129b69aba42a46a1eceda07b4710 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sat, 25 Dec 2021 02:03:56 +0200 Subject: [PATCH] Capture trnaslation --- server/router/translate/index.js | 58 ++++++++++++++++++++++++++++++++ server/views/translate-chunk.pug | 7 ++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/server/router/translate/index.js b/server/router/translate/index.js index 98e42e1..689218a 100644 --- a/server/router/translate/index.js +++ b/server/router/translate/index.js @@ -144,5 +144,63 @@ module.exports = function (options) { next(error) }) }) + .post(function(request, response, next) { + db.Chunk.findOne({ + where: { + chapterId: request.params.chapterId, + index: request.params.chunkIndex + }, + include: [ + { + association: db.Chunk.Translation + }, + { + association: db.Chunk.Chapter, + required: true, + include: [ + { + association: db.Chapter.EntryVersion, + required: true, + include: [ + { + association: db.EntryVersion.TranslationEntryVersions, + required: true, + where: { + id: request.params.id + } + }, + { + association: db.EntryVersion.Entry, + include: [ + { + association: db.Entry.Dialect + } + ] + } + ] + } + ] + } + ] + }).then(async (chunk) => { + if (chunk) { + if (chunk.translation) { + chunk.translation.text = request.body.translatedText + await chunk.translation.save() + } else { + translation = await db.Translation.create({ + chunkId: chunk.id, + text: request.body.translatedText, + translationEntryVersionId: request.params.id + }) + } + response.redirect(`/translate/${request.params.id}/chapter/${request.params.chapterId}/t/${request.params.chunkIndex}`) + } else { + next() + } + }).catch(error => { + next(error) + }) + }) return router; }; \ No newline at end of file diff --git a/server/views/translate-chunk.pug b/server/views/translate-chunk.pug index 9f02c19..d59fcc1 100644 --- a/server/views/translate-chunk.pug +++ b/server/views/translate-chunk.pug @@ -6,13 +6,16 @@ block content h1 Translate into #{chunk.chapter.entryVersion.translationEntryVersions[0].name} //- TODO: Show previous... - form.row(action=`/translate/${chunk.chapter.entryVersion.translationEntryVersions[0].id}/chapter/${chunk.chapter.id}/t/${chunk.id}`) + form.row(action=`/translate/${chunk.chapter.entryVersion.translationEntryVersions[0].id}/chapter/${chunk.chapter.id}/t/${chunk.index}`, method="post") .col.s12.m6.input-field - textarea#original-text.materialize-textarea(name="originalText")= chunk.text + textarea#original-text.materialize-textarea(name="originalText", readonly)= chunk.text label(for="original-text") Original Text .col.s12.m6.input-field textarea#translated-text.materialize-textarea(name="translatedText", placeholder=chunk.text) label(for="original-text") Translated Text + .col.s12 + .center + button.btn.black(type="submit") save //- TODO: Show next... .row