diff --git a/server/router/translate/index.js b/server/router/translate/index.js index 5f314ad..d569b6b 100644 --- a/server/router/translate/index.js +++ b/server/router/translate/index.js @@ -1,4 +1,5 @@ const express = require('express') +const { Op } = require("sequelize") module.exports = function (options) { const db = options.db; @@ -74,18 +75,28 @@ module.exports = function (options) { }) }) - router.route('/:id/chapter/:chapterId/t/:chunkId') + router.route('/:id/chapter/:chapterId/t/:chunkIndex') .get(function(request, response, next) { - db.Chunk.findByPk(request.params.chunkId, { + const previousIndex = Number(request.params.chunkIndex)-1 + const nextIndex = Number(request.params.chunkIndex)+1 + db.Chunk.findAll({ + where: { + chapterId: request.params.chapterId, + index: { + [Op.between]: [ + previousIndex, + nextIndex + ], + } + }, + limit: 3, include: [ { association: db.Chunk.Translation }, { association: db.Chunk.Chapter, - where: { - id: request.params.chapterId - }, + required: true, include: [ { association: db.Chapter.Entry, @@ -106,12 +117,15 @@ module.exports = function (options) { ] } ] - }).then(chunk => { - if (chunk) { + }).then(chunks => { + if (chunks.length > 0) { + const chunk = chunks.find(chunk => chunk.index == Number(request.params.chunkIndex)) response.display("translate-chunk", { user: request.user, pageTitle: `Translate ${chunk.chapter.entry.name}`, - chunk: chunk + chunk: chunk, + previousChunk: chunks.find(chunk => chunk.index == previousIndex), + nextChunk: chunks.find(chunk => chunk.index == nextIndex) }) } else { next() diff --git a/server/views/js/init-adjacent-tabs.js b/server/views/js/init-adjacent-tabs.js new file mode 100644 index 0000000..288bafb --- /dev/null +++ b/server/views/js/init-adjacent-tabs.js @@ -0,0 +1,6 @@ +document.addEventListener('DOMContentLoaded', function() { + const adjecentTabs = document.querySelector("#adjacent-tabs") + var instance = M.Tabs.init(adjecentTabs, { + + }); +}); \ No newline at end of file diff --git a/server/views/translate-chapter.pug b/server/views/translate-chapter.pug index 813c1b0..71b0def 100644 --- a/server/views/translate-chapter.pug +++ b/server/views/translate-chapter.pug @@ -33,4 +33,4 @@ block content else if chunk.translation a.btn.blue review else - a.btn.black(href=`/translate/${chapter.entry.translationEntries[0].id}/chapter/${chapter.id}/t/${chunk.id}`) translate \ No newline at end of file + a.btn.black(href=`/translate/${chapter.entry.translationEntries[0].id}/chapter/${chapter.id}/t/${chunk.index}`) translate \ No newline at end of file diff --git a/server/views/translate-chunk.pug b/server/views/translate-chunk.pug index 4fca0c7..e2c12ee 100644 --- a/server/views/translate-chunk.pug +++ b/server/views/translate-chunk.pug @@ -5,10 +5,78 @@ block content .center h1 Translate into #{chunk.chapter.entry.translationEntries[0].name} + //- TODO: Show previous... form.row(action=`/translate/${chunk.chapter.entry.translationEntries[0].id}/chapter/${chunk.chapter.id}/t/${chunk.id}`) .col.s12.m6.input-field textarea#original-text.materialize-textarea(name="originalText")= 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 \ No newline at end of file + label(for="original-text") Translated Text + + //- TODO: Show next... + .row + .col.s12 + ul.tabs#adjacent-tabs + if previousChunk + li.tab.col.s6 + a(href="#previous-translation") Previous Translation + if nextChunk + li.tab.col.s6 + a(href="#next-translation") Next Translation + if previousChunk + .col.s12#previous-translation + table + //- thead + tr + th #{chunk.chapter.entry.dialect.name} + th #{chunk.chapter.entry.translationEntries[0].name} + th + tbody + tr + td= previousChunk.text + td + if previousChunk.translated + span= previousChunk.text + else if previousChunk.translation + span= previousChunk.translation.text + else + span.grey-text= previousChunk.text + td + if previousChunk.translated + span nothing + else if previousChunk.translation + a.btn.blue review + else + a.btn.black(href=`/translate/${previousChunk.chapter.entry.translationEntries[0].id}/chapter/${previousChunk.chapter.id}/t/${previousChunk.index}`) previous translation + + if nextChunk + .col.s12#next-translation + table + //- thead + tr + th #{chunk.chapter.entry.dialect.name} + th #{chunk.chapter.entry.translationEntries[0].name} + th + tbody + tr + td= nextChunk.text + td + if nextChunk.translated + span= nextChunk.text + else if nextChunk.translation + span= nextChunk.translation.text + else + span.grey-text= nextChunk.text + td + if nextChunk.translated + span nothing + else if nextChunk.translation + a.btn.blue review + else + a.btn.black(href=`/translate/${nextChunk.chapter.entry.translationEntries[0].id}/chapter/${nextChunk.chapter.id}/t/${nextChunk.index}`) next translation + + +block additionalScripts + script + include js/init-adjacent-tabs.js \ No newline at end of file