Replace entry with artifact and add entity

This commit is contained in:
2022-01-05 03:04:43 +02:00
parent e22f85a1aa
commit 7be5200094
28 changed files with 560 additions and 523 deletions

View File

@@ -7,29 +7,29 @@ module.exports = function (options) {
router.route('/:id')
.get(function(request, response, next) {
db.EntryVersion.findByPk(request.params.id, {
db.ArtifactVersion.findByPk(request.params.id, {
include: [
{
association: db.EntryVersion.Entry,
association: db.ArtifactVersion.Artifact,
include: [
{
association: db.Entry.EntryApproval
association: db.Artifact.ArtifactApproval
}
]
},
{
association: db.EntryVersion.Chapters
association: db.ArtifactVersion.Chapters
},
{
association: db.EntryVersion.TranslationEntryVersions
association: db.ArtifactVersion.TranslationArtifactVersions
}
]
}).then(entryVersion => {
if (entryVersion) {
response.display("entry-version", {
}).then(artifactVersion => {
if (artifactVersion) {
response.display("artifact-version", {
user: request.user,
pageTitle: "Entry - Mantra",
entryVersion: entryVersion
pageTitle: "Artifact - Mantra",
artifactVersion: artifactVersion
})
} else {
next()
@@ -41,26 +41,26 @@ module.exports = function (options) {
router.route('/:id/chapters/add')
.get(function(request, response, next) {
db.EntryVersion.findByPk(request.params.id, {
db.ArtifactVersion.findByPk(request.params.id, {
include: [
{
association: db.EntryVersion.Entry,
association: db.ArtifactVersion.Artifact,
include: [
{
association: db.Entry.EntryApproval
association: db.Artifact.ArtifactApproval
}
]
},
{
association: db.EntryVersion.Chapters
association: db.ArtifactVersion.Chapters
}
]
}).then(entryVersion => {
if (entryVersion) {
}).then(artifactVersion => {
if (artifactVersion) {
response.display("chapter-form", {
user: request.user,
pageTitle: "Library - Mantra",
entryVersion: entryVersion
artifactVersion: artifactVersion
})
} else {
next()
@@ -71,27 +71,27 @@ module.exports = function (options) {
})
})
.post(function(request, response, next) {
db.EntryVersion.findByPk(request.params.id, {
db.ArtifactVersion.findByPk(request.params.id, {
include: [
{
association: db.EntryVersion.Entry,
association: db.ArtifactVersion.Artifact,
include: [
{
association: db.Entry.EntryApproval
association: db.Artifact.ArtifactApproval
}
]
},
{
association: db.EntryVersion.Chapters
association: db.ArtifactVersion.Chapters
}
]
}).then(entryVersion => {
}).then(artifactVersion => {
const isString = typeof request.body.text === "string" || request.body.text instanceof String
if (entryVersion && isString) {
if (artifactVersion && isString) {
const chunks = request.body.text.trim().split(/\r?\n\r?\n/)
db.Chapter.create({
name: chunks[0].trim(),
entryVersionId: entryVersion.id,
artifactVersionId: artifactVersion.id,
chunks: chunks.map((chunk,index) => {
return {
text: chunk,
@@ -106,12 +106,12 @@ module.exports = function (options) {
]
}).then(chapter => {
if (chapter) {
response.redirect(`/v/${chapter.entryVersionId}/chapters/${chapter.id}`)
response.redirect(`/v/${chapter.artifactVersionId}/chapters/${chapter.id}`)
} else {
response.display("chapter-form", {
user: request.user,
pageTitle: "Library - Mantra",
entryVersion: entryVersion
artifactVersion: artifactVersion
})
}
}).catch(error => {
@@ -134,10 +134,10 @@ module.exports = function (options) {
association: db.Chapter.Chunks
},
{
association: db.Chapter.EntryVersion,
association: db.Chapter.ArtifactVersion,
include: [
{
association: db.EntryVersion.Entry
association: db.ArtifactVersion.Artifact
}
]
}
@@ -157,28 +157,28 @@ module.exports = function (options) {
})
})
router.route('/:id/translations/:translationEntryVersionId')
router.route('/:id/translations/:translationArtifactVersionId')
.get(function(request, response, next) {
db.TranslationEntryVersion.findByPk(request.params.translationEntryVersionId, {
db.TranslationArtifactVersion.findByPk(request.params.translationArtifactVersionId, {
include: [
{
association: db.TranslationEntryVersion.EntryVersion,
association: db.TranslationArtifactVersion.ArtifactVersion,
include: [
{
association: db.EntryVersion.Entry
association: db.ArtifactVersion.Artifact
}
]
},
{
association: db.TranslationEntryVersion.ForkedFrom
association: db.TranslationArtifactVersion.ForkedFrom
}
]
}).then(translationEntryVersion => {
if (translationEntryVersion) {
response.display("translation-entry-version", {
}).then(translationArtifactVersion => {
if (translationArtifactVersion) {
response.display("translation-artifact-version", {
user: request.user,
pageTitle: "Translation Entry - Mantra",
translationEntryVersion: translationEntryVersion,
pageTitle: "Translation Artifact - Mantra",
translationArtifactVersion: translationArtifactVersion,
})
} else {
next()
@@ -190,26 +190,26 @@ module.exports = function (options) {
router.route('/:id/translations/add')
.get(function(request, response, next) {
db.EntryVersion.findByPk(request.params.id, {
db.ArtifactVersion.findByPk(request.params.id, {
include: [
{
association: db.EntryVersion.Entry,
association: db.ArtifactVersion.Artifact,
include: [
{
association: db.Entry.EntryApproval
association: db.Artifact.ArtifactApproval
}
]
},
{
association: db.EntryVersion.TranslationEntryVersions
association: db.ArtifactVersion.TranslationArtifactVersions
}
]
}).then(entryVersion => {
if (entryVersion) {
}).then(artifactVersion => {
if (artifactVersion) {
response.display("translation-form", {
user: request.user,
pageTitle: "Library - Mantra",
entryVersion: entryVersion
artifactVersion: artifactVersion
})
} else {
next()
@@ -220,22 +220,22 @@ module.exports = function (options) {
})
})
.post(function(request, response, next) {
db.EntryVersion.findByPk(request.params.id, {
db.ArtifactVersion.findByPk(request.params.id, {
include: [
{
association: db.EntryVersion.Entry,
association: db.ArtifactVersion.Artifact,
include: [
{
association: db.Entry.EntryApproval
association: db.Artifact.ArtifactApproval
}
]
},
{
association: db.EntryVersion.TranslationEntryVersions
association: db.ArtifactVersion.TranslationArtifactVersions
}
]
}).then(async (entryVersion) => {
if (entryVersion) {
}).then(async (artifactVersion) => {
if (artifactVersion) {
const dialectTokens = request.body.dialect?.split(":")
if (dialectTokens?.length == 2) {
const countryId = dialectTokens[0].split("-")[0]
@@ -249,14 +249,15 @@ module.exports = function (options) {
})
if (dialect) {
const translationEntryVersion = await db.TranslationEntryVersion.create({
const translationArtifactVersion = await db.TranslationArtifactVersion.create({
name: dialect.name,
entryVersionId: entryVersion.id,
dialectId: dialect.id
artifactVersionId: artifactVersion.id,
dialectId: dialect.id,
entityId: request.user.individualEntityUser.entityUser.entityId
})
if (translationEntryVersion) {
return response.redirect(`/v/${entryVersion.id}/translations/${translationEntryVersion.id}`)
if (translationArtifactVersion) {
return response.redirect(`/v/${artifactVersion.id}/translations/${translationArtifactVersion.id}`)
}
}
}
@@ -269,24 +270,24 @@ module.exports = function (options) {
router.route('/:id/campaign/create')
.get(function(request, response, next) {
db.EntryVersion.findByPk(request.params.id, {
db.ArtifactVersion.findByPk(request.params.id, {
include: [
{
association: db.EntryVersion.Entry,
association: db.ArtifactVersion.Artifact,
},
{
association: db.EntryVersion.TranslationEntryVersions
association: db.ArtifactVersion.TranslationArtifactVersions
}
]
}).then(entryVersion => {
if (entryVersion) {
}).then(artifactVersion => {
if (artifactVersion) {
response.display("campaign-form", {
user: request.user,
pageTitle: "Campaign - Mantra",
campaign: {
name: `Campaign for ${entryVersion.translationEntryVersions.length} translations of ${entryVersion.entry.name}`
name: `Campaign for ${artifactVersion.translationArtifactVersions.length} translations of ${artifactVersion.artifact.name}`
},
translationEntryVersions: entryVersion.translationEntryVersions
translationArtifactVersions: artifactVersion.translationArtifactVersions
})
} else {
next()