Add ability to add language to project entities
This commit is contained in:
@@ -447,7 +447,7 @@ module.exports = function (options) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (translationArtifactVersion) {
|
if (translationArtifactVersion) {
|
||||||
const projectTranslationArtifactVersion = db.ProjectTranslationArtifactVersion.create({
|
const projectTranslationArtifactVersion = await db.ProjectTranslationArtifactVersion.create({
|
||||||
creatorId: request.user.id,
|
creatorId: request.user.id,
|
||||||
projectId: project.id,
|
projectId: project.id,
|
||||||
translationArtifactVersionId: translationArtifactVersion.id
|
translationArtifactVersionId: translationArtifactVersion.id
|
||||||
@@ -1536,5 +1536,229 @@ module.exports = function (options) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.route('/:id/languages/add')
|
||||||
|
.get(function(request, response, next) {
|
||||||
|
db.Project.findByPk(request.params.id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Project.Owner,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Owner.OwnerEntities,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.OwnerEntity.Entity,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Entity.EntityUsers,
|
||||||
|
required: false,
|
||||||
|
where: {
|
||||||
|
userId: request.user?.id ?? null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).then(async (project) => {
|
||||||
|
if (project) {
|
||||||
|
// TODO: Add language to
|
||||||
|
response.display("project-language-form", {
|
||||||
|
user: request.user,
|
||||||
|
pageTitle: "Project Langauges - Mantra",
|
||||||
|
project: project
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
next(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.post(async function(request, response, next) {
|
||||||
|
console.log("Request: ", request.body)
|
||||||
|
|
||||||
|
// TODO: Find dialectId
|
||||||
|
const dialectTokens = request.body.dialect?.split(":")
|
||||||
|
if (dialectTokens?.length == 2) {
|
||||||
|
const countryId = dialectTokens[0].split("-")[0]
|
||||||
|
const languageId = dialectTokens[0].split("-")[1]
|
||||||
|
|
||||||
|
const dialect = await db.Dialect.findOne({
|
||||||
|
where: {
|
||||||
|
countryId: countryId,
|
||||||
|
languageId: languageId
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (dialect) {
|
||||||
|
db.Project.findByPk(request.params.id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Project.ProjectArtifactVersions,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ProjectArtifactVersion.ArtifactVersion,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ArtifactVersion.Artifact
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.ArtifactVersion.TranslationArtifactVersions,
|
||||||
|
where: {
|
||||||
|
backTranslationFromId: null,
|
||||||
|
// forkedFromId: null
|
||||||
|
dialectId: dialect.id
|
||||||
|
},
|
||||||
|
required: false,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.ProjectTranslationArtifactVersions,
|
||||||
|
where: {
|
||||||
|
projectId: request.params.id
|
||||||
|
},
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.ArtifactVersion.Chapters,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Chapter.Chunks
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.Project.Owner,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Owner.OwnerEntities,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.OwnerEntity.Entity,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Entity.EntityUsers,
|
||||||
|
required: false, // TODO: Make required...
|
||||||
|
where: {
|
||||||
|
userId: request.user?.id ?? null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).then(async (project) => {
|
||||||
|
if (project) {
|
||||||
|
project.projectArtifactVersions
|
||||||
|
for (let i = 0; i < project.projectArtifactVersions.length; i++) {
|
||||||
|
const artifactVersion = project.projectArtifactVersions[i].artifactVersion;
|
||||||
|
|
||||||
|
if (artifactVersion.translationArtifactVersions.length == 0) {
|
||||||
|
console.log("Add this new language: ", dialect.toJSON())
|
||||||
|
const translationArtifactVersion = await db.TranslationArtifactVersion.create({
|
||||||
|
creatorId: request.user.id,
|
||||||
|
name: dialect.name,
|
||||||
|
artifactVersionId: artifactVersion.id,
|
||||||
|
visibility: artifactVersion.artifact.visibility,
|
||||||
|
dialectId: dialect.id,
|
||||||
|
owner: {
|
||||||
|
ownerEntities: [
|
||||||
|
{
|
||||||
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
translationChapters: artifactVersion.chapters.map(chapter => {
|
||||||
|
return {
|
||||||
|
creatorId: request.user.id,
|
||||||
|
chapterId: chapter.id,
|
||||||
|
index: chapter.index,
|
||||||
|
translationChunks: chapter.chunks.map(chunk => {
|
||||||
|
return {
|
||||||
|
creatorId: request.user.id,
|
||||||
|
chunkId: chunk.id,
|
||||||
|
text: chunk.text,
|
||||||
|
index: chunk.index
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
projectTranslationArtifactVersions: [
|
||||||
|
{
|
||||||
|
creatorId: request.user.id,
|
||||||
|
projectId: project.id
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.TranslationChapters,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationChapter.TranslationChunks
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.ProjectTranslationArtifactVersions,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.Owner,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Owner.OwnerEntities
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO: Associate in the project...
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log("Language already supported")
|
||||||
|
const translationArtifactVersion = artifactVersion.translationArtifactVersions[0]
|
||||||
|
|
||||||
|
// Associate in the project... if association doesn't exists
|
||||||
|
if (translationArtifactVersion.projectTranslationArtifactVersions == 0) {
|
||||||
|
const projectTranslationArtifactVersion = await db.ProjectTranslationArtifactVersion.create({
|
||||||
|
creatorId: request.user.id,
|
||||||
|
projectId: project.id,
|
||||||
|
translationArtifactVersionId: translationArtifactVersion.id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: Load all the entries associated with this project and translate them...
|
||||||
|
return response.redirect(`/projects/${project.id}`)
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
next(error)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// TODO: Show error
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: Show error...
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
})
|
||||||
return router;
|
return router;
|
||||||
};
|
};
|
||||||
22
server/views/project-language-form.pug
Normal file
22
server/views/project-language-form.pug
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
extend templates/layout.pug
|
||||||
|
|
||||||
|
block content
|
||||||
|
.container
|
||||||
|
.center
|
||||||
|
h1 Languages of #{project.name}
|
||||||
|
|
||||||
|
.row
|
||||||
|
.col.s12
|
||||||
|
form.row(action=`/projects/${project.id}/languages/add`, method="post")
|
||||||
|
|
||||||
|
.col.s12.input-field
|
||||||
|
i.material-icons.prefix record_voice_over
|
||||||
|
input#dialect-autocomplete.autocomplete(type="text", name="dialect", required, autocomplete="off")
|
||||||
|
label(for="dialect-autocomplete") Dialect which this projects translations will be made in.
|
||||||
|
.col.s12
|
||||||
|
button.btn.black(type="submit") add language
|
||||||
|
|
||||||
|
|
||||||
|
block additionalScripts
|
||||||
|
script
|
||||||
|
include js/init-dialect-autocomplete.js
|
||||||
@@ -38,6 +38,11 @@ block content
|
|||||||
i.material-icons.left file_upload
|
i.material-icons.left file_upload
|
||||||
span import spreadsheets
|
span import spreadsheets
|
||||||
|
|
||||||
|
.row
|
||||||
|
.col.s12
|
||||||
|
a.btn.black(href=`/projects/${project.id}/languages/add`)
|
||||||
|
i.material-icons.left record_voice_over
|
||||||
|
span add language
|
||||||
.divider
|
.divider
|
||||||
|
|
||||||
table.highlight
|
table.highlight
|
||||||
@@ -50,7 +55,7 @@ block content
|
|||||||
span
|
span
|
||||||
th Name
|
th Name
|
||||||
th
|
th
|
||||||
a.dropdown-trigger language ▼
|
a.dropdown-trigger language (#{project.get("languageCount")}) ▼
|
||||||
th Artifact
|
th Artifact
|
||||||
th Chapter
|
th Chapter
|
||||||
th
|
th
|
||||||
|
|||||||
Reference in New Issue
Block a user