Show adjacent chunks when translating
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
const { Op } = require("sequelize")
|
||||||
|
|
||||||
module.exports = function (options) {
|
module.exports = function (options) {
|
||||||
const db = options.db;
|
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) {
|
.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: [
|
include: [
|
||||||
{
|
{
|
||||||
association: db.Chunk.Translation
|
association: db.Chunk.Translation
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
association: db.Chunk.Chapter,
|
association: db.Chunk.Chapter,
|
||||||
where: {
|
required: true,
|
||||||
id: request.params.chapterId
|
|
||||||
},
|
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
association: db.Chapter.Entry,
|
association: db.Chapter.Entry,
|
||||||
@@ -106,12 +117,15 @@ module.exports = function (options) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}).then(chunk => {
|
}).then(chunks => {
|
||||||
if (chunk) {
|
if (chunks.length > 0) {
|
||||||
|
const chunk = chunks.find(chunk => chunk.index == Number(request.params.chunkIndex))
|
||||||
response.display("translate-chunk", {
|
response.display("translate-chunk", {
|
||||||
user: request.user,
|
user: request.user,
|
||||||
pageTitle: `Translate ${chunk.chapter.entry.name}`,
|
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 {
|
} else {
|
||||||
next()
|
next()
|
||||||
|
|||||||
6
server/views/js/init-adjacent-tabs.js
Normal file
6
server/views/js/init-adjacent-tabs.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const adjecentTabs = document.querySelector("#adjacent-tabs")
|
||||||
|
var instance = M.Tabs.init(adjecentTabs, {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -33,4 +33,4 @@ block content
|
|||||||
else if chunk.translation
|
else if chunk.translation
|
||||||
a.btn.blue review
|
a.btn.blue review
|
||||||
else
|
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
|
||||||
@@ -5,10 +5,78 @@ block content
|
|||||||
.center
|
.center
|
||||||
h1 Translate into #{chunk.chapter.entry.translationEntries[0].name}
|
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}`)
|
form.row(action=`/translate/${chunk.chapter.entry.translationEntries[0].id}/chapter/${chunk.chapter.id}/t/${chunk.id}`)
|
||||||
.col.s12.m6.input-field
|
.col.s12.m6.input-field
|
||||||
textarea#original-text.materialize-textarea(name="originalText")= chunk.text
|
textarea#original-text.materialize-textarea(name="originalText")= chunk.text
|
||||||
label(for="original-text") Original Text
|
label(for="original-text") Original Text
|
||||||
.col.s12.m6.input-field
|
.col.s12.m6.input-field
|
||||||
textarea#translated-text.materialize-textarea(name="translatedText", placeholder=chunk.text)
|
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
|
||||||
Reference in New Issue
Block a user