Translation chunks...
This commit is contained in:
@@ -10,21 +10,26 @@ module.exports = function (options) {
|
||||
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
required: true,
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.Chapters,
|
||||
required: true,
|
||||
limit: 1,
|
||||
// TODO: Order by chapter index
|
||||
}
|
||||
]
|
||||
association: db.TranslationArtifactVersion.TranslationChapters,
|
||||
limit: 1,
|
||||
required: true
|
||||
}
|
||||
// {
|
||||
// association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
// required: true,
|
||||
// include: [
|
||||
// {
|
||||
// association: db.ArtifactVersion.Chapters,
|
||||
// required: true,
|
||||
// limit: 1,
|
||||
// // TODO: Order by chapter index
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
]
|
||||
}).then(translationArtifactVersion => {
|
||||
if (translationArtifactVersion) {
|
||||
response.redirect(`/translate/${translationArtifactVersion.id}/chapter/${translationArtifactVersion.artifactVersion.chapters[0].id}`)
|
||||
response.redirect(`/translate/${translationArtifactVersion.id}/chapter/${translationArtifactVersion.translationChapters[0].id}`)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
@@ -33,44 +38,41 @@ module.exports = function (options) {
|
||||
|
||||
router.route('/:id/chapter/:chapterId')
|
||||
.get(function(request, response, next) {
|
||||
db.Chapter.findByPk(request.params.chapterId, {
|
||||
db.TranslationChapter.findByPk(request.params.chapterId, {
|
||||
include: [
|
||||
{
|
||||
association: db.Chapter.Chunks,
|
||||
association: db.TranslationChapter.TranslationChunks,
|
||||
include: [
|
||||
{
|
||||
association: db.Chunk.Translation
|
||||
association: db.TranslationChunk.Translation
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.Chapter.ArtifactVersion,
|
||||
required: true,
|
||||
association: db.TranslationChapter.TranslationArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.TranslationArtifactVersions,
|
||||
required: true,
|
||||
where: {
|
||||
id: request.params.id
|
||||
}
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(chapter => {
|
||||
if (chapter) {
|
||||
}).then(translationChapter => {
|
||||
if (translationChapter) {
|
||||
response.display("translate-chapter", {
|
||||
user: request.user,
|
||||
pageTitle: `Translate Chapter ${chapter.name}`,
|
||||
chapter: chapter
|
||||
pageTitle: `Translate Chapter ${translationChapter.name}`,
|
||||
translationChapter: translationChapter
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
@@ -82,44 +84,41 @@ module.exports = function (options) {
|
||||
|
||||
router.route('/:id/chapter/:chapterId/view')
|
||||
.get(function(request, response, next) {
|
||||
db.Chapter.findByPk(request.params.chapterId, {
|
||||
db.TranslationChapter.findByPk(request.params.chapterId, {
|
||||
include: [
|
||||
{
|
||||
association: db.Chapter.Chunks,
|
||||
association: db.TranslationChapter.TranslationChunks,
|
||||
include: [
|
||||
{
|
||||
association: db.Chunk.Translation
|
||||
association: db.TranslationChunk.Translation
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
association: db.Chapter.ArtifactVersion,
|
||||
required: true,
|
||||
association: db.TranslationChapter.TranslationArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.TranslationArtifactVersions,
|
||||
required: true,
|
||||
where: {
|
||||
id: request.params.id
|
||||
}
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(chapter => {
|
||||
if (chapter) {
|
||||
}).then(translationChapter => {
|
||||
if (translationChapter) {
|
||||
response.display("translate-chapter-view", {
|
||||
user: request.user,
|
||||
pageTitle: `Translate Chapter ${chapter.name}`,
|
||||
chapter: chapter
|
||||
pageTitle: `Translate Chapter ${translationChapter.name}`,
|
||||
translationChapter: translationChapter
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
@@ -133,9 +132,9 @@ module.exports = function (options) {
|
||||
.get(function(request, response, next) {
|
||||
const previousIndex = Number(request.params.chunkIndex)-1
|
||||
const nextIndex = Number(request.params.chunkIndex)+1
|
||||
db.Chunk.findAll({
|
||||
db.TranslationChunk.findAll({
|
||||
where: {
|
||||
chapterId: request.params.chapterId,
|
||||
translationChapterId: request.params.chapterId,
|
||||
index: {
|
||||
[Op.between]: [
|
||||
previousIndex,
|
||||
@@ -146,28 +145,26 @@ module.exports = function (options) {
|
||||
limit: 3,
|
||||
include: [
|
||||
{
|
||||
association: db.Chunk.Translation
|
||||
association: db.TranslationChunk.Translation
|
||||
},
|
||||
{
|
||||
association: db.Chunk.Chapter,
|
||||
association: db.TranslationChunk.TranslationChapter,
|
||||
required: true,
|
||||
include: [
|
||||
{
|
||||
association: db.Chapter.ArtifactVersion,
|
||||
association: db.TranslationChapter.TranslationArtifactVersion,
|
||||
required: true,
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.TranslationArtifactVersions,
|
||||
required: true,
|
||||
where: {
|
||||
id: request.params.id
|
||||
}
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -176,16 +173,16 @@ module.exports = function (options) {
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(chunks => {
|
||||
if (chunks.length > 0) {
|
||||
const chunk = chunks.find(chunk => chunk.index == Number(request.params.chunkIndex))
|
||||
if (chunk) {
|
||||
}).then(translationChunks => {
|
||||
if (translationChunks.length > 0) {
|
||||
const translationChunk = translationChunks.find(translationChunk => translationChunk.index == Number(request.params.chunkIndex))
|
||||
if (translationChunk) {
|
||||
response.display("translate-chunk", {
|
||||
user: request.user,
|
||||
pageTitle: `Translate ${chunk.chapter.artifactVersion.artifact.name}`,
|
||||
chunk: chunk,
|
||||
previousChunk: chunks.find(chunk => chunk.index == previousIndex),
|
||||
nextChunk: chunks.find(chunk => chunk.index == nextIndex)
|
||||
pageTitle: `Translate ${translationChunk.translationChapter.translationArtifactVersion.artifactVersion.artifact.name}`,
|
||||
translationChunk: translationChunk,
|
||||
previousTranslationChunk: translationChunks.find(translationChunk => translationChunk.index == previousIndex),
|
||||
nextTranslationChunk: translationChunks.find(translationChunk => translationChunk.index == nextIndex)
|
||||
})
|
||||
} else {
|
||||
response.redirect(`/translate/${request.params.id}/chapter/${request.params.chapterId}`)
|
||||
@@ -199,35 +196,33 @@ module.exports = function (options) {
|
||||
})
|
||||
})
|
||||
.post(function(request, response, next) {
|
||||
db.Chunk.findOne({
|
||||
db.TranslationChunk.findOne({
|
||||
where: {
|
||||
chapterId: request.params.chapterId,
|
||||
translationChapterId: request.params.chapterId,
|
||||
index: request.params.chunkIndex
|
||||
},
|
||||
include: [
|
||||
{
|
||||
association: db.Chunk.Translation
|
||||
association: db.TranslationChunk.Translation
|
||||
},
|
||||
{
|
||||
association: db.Chunk.Chapter,
|
||||
association: db.TranslationChunk.TranslationChapter,
|
||||
required: true,
|
||||
include: [
|
||||
{
|
||||
association: db.Chapter.ArtifactVersion,
|
||||
required: true,
|
||||
association: db.TranslationChapter.TranslationArtifactVersion,
|
||||
|
||||
include: [
|
||||
{
|
||||
association: db.ArtifactVersion.TranslationArtifactVersions,
|
||||
required: true,
|
||||
where: {
|
||||
id: request.params.id
|
||||
}
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
association: db.ArtifactVersion.Artifact,
|
||||
include: [
|
||||
{
|
||||
association: db.Artifact.Dialect
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -236,15 +231,15 @@ module.exports = function (options) {
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(async (chunk) => {
|
||||
if (chunk) {
|
||||
if (chunk.translation) {
|
||||
chunk.translation.text = request.body.translatedText
|
||||
await chunk.translation.save()
|
||||
}).then(async (translationChunk) => {
|
||||
if (translationChunk) {
|
||||
if (translationChunk.translation) {
|
||||
translationChunk.translation.text = request.body.translatedText
|
||||
await translationChunk.translation.save()
|
||||
} else {
|
||||
translation = await db.Translation.create({
|
||||
creatorId: request.user.id,
|
||||
chunkId: chunk.id,
|
||||
translationChunkId: translationChunk.id,
|
||||
text: request.body.translatedText,
|
||||
translationArtifactVersionId: request.params.id
|
||||
})
|
||||
|
||||
@@ -88,7 +88,13 @@ module.exports = function (options) {
|
||||
}).then(artifactVersion => {
|
||||
const isString = typeof request.body.text === "string" || request.body.text instanceof String
|
||||
if (artifactVersion && isString) {
|
||||
const chunks = request.body.text.trim().split(/\r?\n\r?\n/)
|
||||
const chunks = request.body.text.trim().split(/\r?\n/).filter(text => {
|
||||
if (text) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
db.Chapter.create({
|
||||
creatorId: request.user.id,
|
||||
name: chunks[0].trim(),
|
||||
@@ -176,6 +182,14 @@ module.exports = function (options) {
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.ForkedFrom
|
||||
},
|
||||
{
|
||||
association: db.TranslationArtifactVersion.TranslationChapters,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationChapter.Chapter
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(translationArtifactVersion => {
|
||||
@@ -237,6 +251,14 @@ module.exports = function (options) {
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.TranslationArtifactVersions
|
||||
},
|
||||
{
|
||||
association: db.ArtifactVersion.Chapters,
|
||||
include: [
|
||||
{
|
||||
association: db.Chapter.Chunks
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}).then(async (artifactVersion) => {
|
||||
@@ -259,7 +281,32 @@ module.exports = function (options) {
|
||||
name: dialect.name,
|
||||
artifactVersionId: artifactVersion.id,
|
||||
dialectId: dialect.id,
|
||||
entityId: request.user.individualEntityUser.entityUser.entityId
|
||||
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||
translationChapters: artifactVersion.chapters.map(chapter => {
|
||||
return {
|
||||
creatorId: request.user.id,
|
||||
chapterId: chapter.id,
|
||||
translationChunks: chapter.chunks.map(chunk => {
|
||||
return {
|
||||
creatorId: request.user.id,
|
||||
chunkId: chunk.id,
|
||||
text: chunk.text,
|
||||
index: chunk.index
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}, {
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationArtifactVersion.TranslationChapters,
|
||||
include: [
|
||||
{
|
||||
association: db.TranslationChapter.TranslationChunks
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
if (translationArtifactVersion) {
|
||||
|
||||
Reference in New Issue
Block a user