Add ability to add language to project entities
This commit is contained in:
@@ -447,7 +447,7 @@ module.exports = function (options) {
|
||||
})
|
||||
|
||||
if (translationArtifactVersion) {
|
||||
const projectTranslationArtifactVersion = db.ProjectTranslationArtifactVersion.create({
|
||||
const projectTranslationArtifactVersion = await db.ProjectTranslationArtifactVersion.create({
|
||||
creatorId: request.user.id,
|
||||
projectId: project.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;
|
||||
};
|
||||
Reference in New Issue
Block a user