diff --git a/server/router/translate/index.js b/server/router/translate/index.js index 5beaa96..18d4c58 100644 --- a/server/router/translate/index.js +++ b/server/router/translate/index.js @@ -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 }) diff --git a/server/router/versions/index.js b/server/router/versions/index.js index 3f0b692..7de87a3 100644 --- a/server/router/versions/index.js +++ b/server/router/versions/index.js @@ -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) { diff --git a/server/views/artifact-version.pug b/server/views/artifact-version.pug index 3fc7027..debbfba 100644 --- a/server/views/artifact-version.pug +++ b/server/views/artifact-version.pug @@ -31,7 +31,7 @@ block content a.btn.black(href=`/v/${artifactVersion.id}/translations/add`) add translation if artifactVersion.translationArtifactVersions.length == 0 - p.flow-text No chapters added + p.flow-text No translations added else .row each translationArtifact in artifactVersion.translationArtifactVersions diff --git a/server/views/translate-chapter-view.pug b/server/views/translate-chapter-view.pug index ee38ce5..f07dcc4 100644 --- a/server/views/translate-chapter-view.pug +++ b/server/views/translate-chapter-view.pug @@ -3,20 +3,20 @@ extend templates/layout.pug block content .container .center - h1= chapter.artifactVersion.translationArtifactVersions[0].name - h2= chapter.artifactVersion.artifact.name + h1= translationChapter.translationArtifactVersion.name + h2= translationChapter.translationArtifactVersion.artifactVersion.artifact.name //- TODO: export to markdown... .row .col.s12 - a.btn.black(href=`/translate/${chapter.artifactVersion.translationArtifactVersions[0].id}/chapter/${chapter.id}/markdown`) export markdown + a.btn.black(href=`/translate/${translationChapter.translationArtifactVersion.id}/chapter/${translationChapter.id}/markdown`) export markdown .row .col.s12 - each chunk in chapter.chunks + each translationChunk in translationChapter.translationChunks.sort((a,b) => a.index - b.index) p.flow-text - if chunk.translation - span= chunk.translation.text + if translationChunk.translation + span= translationChunk.translation.text else - span.grey-text= chunk.text + span.grey-text= translationChunk.text diff --git a/server/views/translate-chapter.pug b/server/views/translate-chapter.pug index a6e2a16..3a61dfe 100644 --- a/server/views/translate-chapter.pug +++ b/server/views/translate-chapter.pug @@ -3,34 +3,34 @@ extend templates/layout.pug block content .container .center - h1= chapter.artifactVersion.translationArtifactVersions[0].name - h2= chapter.artifactVersion.artifact.name + h1= translationChapter.translationArtifactVersion.name + h2= translationChapter.translationArtifactVersion.artifactVersion.artifact.name - //- TODO: List chunks in the chapter + //- TODO: List translationChunks in the chapter .row .col.s12 table thead tr - th #{chapter.artifactVersion.artifact.dialect.name} - th #{chapter.artifactVersion.translationArtifactVersions[0].name} + th #{translationChapter.translationArtifactVersion.artifactVersion.artifact.dialect.name} + th #{translationChapter.translationArtifactVersion.name} th tbody - each chunk in chapter.chunks + each translationChunk in translationChapter.translationChunks.sort((a,b) => a.index - b.index) tr - td= chunk.text + td= translationChunk.text td - if chunk.translated - span= chunk.text - else if chunk.translation - span= chunk.translation.text + if translationChunk.translated + span= translationChunk.text + else if translationChunk.translation + span= translationChunk.translation.text else - span.grey-text.lighten-4= chunk.text + span.grey-text.lighten-4= translationChunk.text td - if chunk.translated + if translationChunk.translated span nothing - else if chunk.translation - a.btn.blue(href=`/translate/${chapter.artifactVersion.translationArtifactVersions[0].id}/chapter/${chapter.id}/t/${chunk.index}`) edit + else if translationChunk.translation + a.btn.blue(href=`/translate/${translationChapter.translationArtifactVersion.id}/chapter/${translationChapter.id}/t/${translationChunk.index}`) edit else - a.btn.black(href=`/translate/${chapter.artifactVersion.translationArtifactVersions[0].id}/chapter/${chapter.id}/t/${chunk.index}`) translate \ No newline at end of file + a.btn.black(href=`/translate/${translationChapter.translationArtifactVersion.id}/chapter/${translationChapter.id}/t/${translationChunk.index}`) translate \ No newline at end of file diff --git a/server/views/translate-chunk.pug b/server/views/translate-chunk.pug index 6b59b9c..2e6ac23 100644 --- a/server/views/translate-chunk.pug +++ b/server/views/translate-chunk.pug @@ -4,15 +4,15 @@ block content .container .center h1 Translate into - a(href=`/translate/${chunk.chapter.artifactVersion.translationArtifactVersions[0].id}/chapter/${chunk.chapter.id}`) #{chunk.chapter.artifactVersion.translationArtifactVersions[0].name} + a(href=`/translate/${translationChunk.translationChapter.translationArtifactVersion.id}/chapter/${translationChunk.translationChapter.id}`) #{translationChunk.translationChapter.translationArtifactVersion.name} //- TODO: Show previous... - form.row(action=`/translate/${chunk.chapter.artifactVersion.translationArtifactVersions[0].id}/chapter/${chunk.chapter.id}/t/${chunk.index}`, method="post") + form.row(action=`/translate/${translationChunk.translationChapter.translationArtifactVersion.id}/chapter/${translationChunk.translationChapter.id}/t/${translationChunk.index}`, method="post") .col.s12.m6.input-field - textarea#original-text.materialize-textarea(name="originalText", readonly)= chunk.text + textarea#original-text.materialize-textarea(name="originalText", readonly)= translationChunk.text label(for="original-text") Original Text .col.s12.m6.input-field - textarea#translated-text.materialize-textarea(name="translatedText", placeholder=chunk.text)= chunk.translation ? chunk.translation.text : null + textarea#translated-text.materialize-textarea(name="translatedText", placeholder=translationChunk.text)= translationChunk.translation ? translationChunk.translation.text : null label(for="original-text") Translated Text .col.s12 .center @@ -22,63 +22,59 @@ block content .row .col.s12 ul.tabs#adjacent-tabs - if previousChunk + if previousTranslationChunk li.tab.col.s6 a(href="#previous-translation") Previous Translation - if nextChunk + if nextTranslationChunk li.tab.col.s6 a(href="#next-translation") Next Translation - if previousChunk + if previousTranslationChunk .col.s12#previous-translation table - //- thead - tr - th #{chunk.chapter.artifact.dialect.name} - th #{chunk.chapter.artifact.translationArtifactVersions[0].name} - th + tbody tr - td= previousChunk.text + td= previousTranslationChunk.text td - if previousChunk.translated - span= previousChunk.text - else if previousChunk.translation - span= previousChunk.translation.text + if previousTranslationChunk.translated + span= previousTranslationChunk.text + else if previousTranslationChunk.translation + span= previousTranslationChunk.translation.text else - span.grey-text= previousChunk.text + span.grey-text= previousTranslationChunk.text td - if previousChunk.translated + if previousTranslationChunk.translated span nothing - else if previousChunk.translation - a.btn.blue(href=`/translate/${previousChunk.chapter.artifactVersion.translationArtifactVersions[0].id}/chapter/${previousChunk.chapter.id}/t/${previousChunk.index}`) edit + else if previousTranslationChunk.translation + a.btn.blue(href=`/translate/${previousTranslationChunk.translationChapter.translationArtifactVersion.id}/chapter/${previousTranslationChunk.translationChapter.id}/t/${previousTranslationChunk.index}`) edit else - a.btn.black(href=`/translate/${previousChunk.chapter.artifactVersion.translationArtifactVersions[0].id}/chapter/${previousChunk.chapter.id}/t/${previousChunk.index}`) previous translation + a.btn.black(href=`/translate/${previousTranslationChunk.translationChapter.translationArtifactVersion.id}/chapter/${previousTranslationChunk.translationChapter.id}/t/${previousTranslationChunk.index}`) previous translation - if nextChunk + if nextTranslationChunk .col.s12#next-translation table //- thead tr - th #{chunk.chapter.artifact.dialect.name} - th #{chunk.chapter.artifact.translationArtifactVersions[0].name} + th #{translationChunk.translationChapter.artifact.dialect.name} + th #{translationChunk.translationChapter.artifact.translationArtifactVersions[0].name} th tbody tr - td= nextChunk.text + td= nextTranslationChunk.text td - if nextChunk.translated - span= nextChunk.text - else if nextChunk.translation - span= nextChunk.translation.text + if nextTranslationChunk.translated + span= nextTranslationChunk.text + else if nextTranslationChunk.translation + span= nextTranslationChunk.translation.text else - span.grey-text= nextChunk.text + span.grey-text= nextTranslationChunk.text td - if nextChunk.translated + if nextTranslationChunk.translated span nothing - else if nextChunk.translation - a.btn.blue(href=`/translate/${nextChunk.chapter.artifactVersion.translationArtifactVersions[0].id}/chapter/${nextChunk.chapter.id}/t/${nextChunk.index}`) edit + else if nextTranslationChunk.translation + a.btn.blue(href=`/translate/${nextTranslationChunk.translationChapter.translationArtifactVersion.id}/chapter/${nextTranslationChunk.translationChapter.id}/t/${nextTranslationChunk.index}`) edit else - a.btn.black(href=`/translate/${nextChunk.chapter.artifactVersion.translationArtifactVersions[0].id}/chapter/${nextChunk.chapter.id}/t/${nextChunk.index}`) next translation + a.btn.black(href=`/translate/${nextTranslationChunk.translationChapter.translationArtifactVersion.id}/chapter/${nextTranslationChunk.translationChapter.id}/t/${nextTranslationChunk.index}`) next translation block additionalScripts diff --git a/server/views/translation-artifact-version.pug b/server/views/translation-artifact-version.pug index 331d057..b821d70 100644 --- a/server/views/translation-artifact-version.pug +++ b/server/views/translation-artifact-version.pug @@ -35,6 +35,6 @@ block content //- TODO: Give summary of chapters... h2 Chapters - each chapter in translationArtifactVersion.artifactVersion.chapters + each translationChapter in translationArtifactVersion.translationChapters p.flow-text - a(href=`/translate/${translationArtifactVersion.id}/chapter/${chapter.id}`)= chapter.name \ No newline at end of file + a(href=`/translate/${translationArtifactVersion.id}/chapter/${translationChapter.id}`)= translationChapter.chapter.name \ No newline at end of file