Show adjacent chunks when translating

This commit is contained in:
2021-12-23 00:47:06 +02:00
parent b21637f015
commit 5bfa6285f2
4 changed files with 98 additions and 10 deletions

View File

@@ -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()

View File

@@ -0,0 +1,6 @@
document.addEventListener('DOMContentLoaded', function() {
const adjecentTabs = document.querySelector("#adjacent-tabs")
var instance = M.Tabs.init(adjecentTabs, {
});
});

View File

@@ -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
a.btn.black(href=`/translate/${chapter.entry.translationEntries[0].id}/chapter/${chapter.id}/t/${chunk.index}`) translate

View File

@@ -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
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