Show adjacent chunks when translating
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user