Initial changes to create a campaign

This commit is contained in:
2021-12-27 02:25:03 +02:00
parent 3141d8ed48
commit d8bf6dcafb
7 changed files with 137 additions and 2 deletions

View File

@@ -8,8 +8,15 @@ module.exports = function (options) {
.get(function(request, response, next) {
response.display("campaigns", {
user: request.user,
pageTitle: "Library - Mantra"
pageTitle: "Campaign - Mantra"
})
})
router.route('/create')
.post(function(request, response, next) {
console.log(request.body)
next()
})
return router;
};

View File

@@ -317,5 +317,76 @@ module.exports = function (options) {
next(error)
})
})
router.route('/:id/campaign')
.get(function(request, response, next) {
db.TranslationEntryVersion.findByPk(request.params.id, {
include: [
{
association: db.TranslationEntryVersion.TranslationEntryVersionCampaigns,
required: true,
include: [
{
association: db.TranslationEntryVersionCampaign.Campaign,
required: true
}
]
}
]
}).then(translationEntryVersion => {
if (translationEntryVersion) {
if (translationEntryVersion.translationEntryVersionCampaings.length == 1) {
response.redirect(`/campaigns/${translationEntryVersion.translationEntryVersionCampaings[0].campaignId}`)
} else {
// TODO: Display translation entry campaign...
next()
}
} else {
response.redirect(`/translate/${request.params.id}/campaign/create`)
}
})
})
router.route('/:id/campaign/create')
.get(function(request, response, next) {
db.TranslationEntryVersion.findByPk(request.params.id, {
include: [
{
association: db.TranslationEntryVersion.EntryVersion,
include: [
{
association: db.EntryVersion.Entry
}
]
},
{
association: db.TranslationEntryVersion.TranslationEntryVersionCampaigns,
required: false,
include: [
{
association: db.TranslationEntryVersionCampaign.Campaign,
required: false
}
]
}
]
}).then(translationEntryVersion => {
if (translationEntryVersion) {
response.display("campaign-form", {
user: request.user,
pageTitle: "Campaign - Mantra",
campaign: {
name: `Campaign for ${translationEntryVersion.name} translation of ${translationEntryVersion.entryVersion.entry.name}`
},
translationEntryVersions: [translationEntryVersion]
})
} else {
next()
}
}).catch(error => {
next(error)
})
})
return router;
};

View File

@@ -266,6 +266,35 @@ module.exports = function (options) {
next(error)
})
})
router.route('/:id/campaign/create')
.get(function(request, response, next) {
db.EntryVersion.findByPk(request.params.id, {
include: [
{
association: db.EntryVersion.Entry,
},
{
association: db.EntryVersion.TranslationEntryVersions
}
]
}).then(entryVersion => {
if (entryVersion) {
response.display("campaign-form", {
user: request.user,
pageTitle: "Campaign - Mantra",
campaign: {
name: `Campaign for ${entryVersion.translationEntryVersions.length} translations of ${entryVersion.entry.name}`
},
translationEntryVersions: entryVersion.translationEntryVersions
})
} else {
next()
}
}).catch(error => {
next(error)
})
})
return router;
};