Create pledge from translation
This commit is contained in:
@@ -6,10 +6,21 @@ module.exports = function (options) {
|
|||||||
|
|
||||||
router.route('/')
|
router.route('/')
|
||||||
.get(function(request, response, next) {
|
.get(function(request, response, next) {
|
||||||
response.display("pledges", {
|
db.Pledge.findAll({
|
||||||
user: request.user,
|
}).then(pledges => {
|
||||||
pageTitle: "Library - Mantra"
|
if (pledges) {
|
||||||
|
response.display("pledges", {
|
||||||
|
user: request.user,
|
||||||
|
pageTitle: "Pledges - Mantra",
|
||||||
|
pledges: pledges
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
next(error)
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
return router;
|
return router;
|
||||||
};
|
};
|
||||||
@@ -318,7 +318,7 @@ module.exports = function (options) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
router.route('/:id/campaign')
|
router.route('/:id/campaigns')
|
||||||
.get(function(request, response, next) {
|
.get(function(request, response, next) {
|
||||||
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||||
include: [
|
include: [
|
||||||
@@ -335,19 +335,19 @@ module.exports = function (options) {
|
|||||||
]
|
]
|
||||||
}).then(translationArtifactVersion => {
|
}).then(translationArtifactVersion => {
|
||||||
if (translationArtifactVersion) {
|
if (translationArtifactVersion) {
|
||||||
if (translationArtifactVersion.translationArtifactVersionCampaings.length == 1) {
|
if (translationArtifactVersion.translationArtifactVersionCampaigns.length == 1) {
|
||||||
response.redirect(`/campaigns/${translationArtifactVersion.translationArtifactVersionCampaings[0].campaignId}`)
|
response.redirect(`/campaigns/${translationArtifactVersion.translationArtifactVersionCampaigns[0].campaignId}`)
|
||||||
} else {
|
} else {
|
||||||
// TODO: Display translation artifact campaign...
|
// TODO: Display translation artifact campaign...
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
response.redirect(`/translate/${request.params.id}/campaign/create`)
|
response.redirect(`/translate/${request.params.id}/campaigns/create`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
router.route('/:id/campaign/create')
|
router.route('/:id/campaigns/create')
|
||||||
.get(function(request, response, next) {
|
.get(function(request, response, next) {
|
||||||
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||||
include: [
|
include: [
|
||||||
@@ -442,5 +442,125 @@ module.exports = function (options) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.route('/:id/pledges')
|
||||||
|
.get(function(request, response, next) {
|
||||||
|
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.TranslationArtifactVersionPledges,
|
||||||
|
required: true,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersionPledge.Pledge,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).then(translationArtifactVersion => {
|
||||||
|
if (translationArtifactVersion) {
|
||||||
|
if (translationArtifactVersion.translationArtifactVersionPledges.length == 1) {
|
||||||
|
response.redirect(`/pledges/${translationArtifactVersion.translationArtifactVersionPledges[0].campaignId}`)
|
||||||
|
} else {
|
||||||
|
// TODO: Display translation artifact campaign...
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
response.redirect(`/translate/${request.params.id}/pledges/create`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.route('/:id/pledges/create')
|
||||||
|
.get(function(request, response, next) {
|
||||||
|
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ArtifactVersion.Artifact
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.TranslationArtifactVersionPledges,
|
||||||
|
required: false,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersionPledge.Pledge,
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).then(translationArtifactVersion => {
|
||||||
|
if (translationArtifactVersion) {
|
||||||
|
response.display("pledge-form", {
|
||||||
|
user: request.user,
|
||||||
|
pageTitle: "Pledge - Mantra",
|
||||||
|
campaign: {
|
||||||
|
name: `Pledge for ${translationArtifactVersion.name} translation of ${translationArtifactVersion.artifactVersion.artifact.name}`,
|
||||||
|
},
|
||||||
|
translationArtifactVersions: [translationArtifactVersion]
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
next(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.post(function(request, response, next) {
|
||||||
|
db.TranslationArtifactVersion.findByPk(request.params.id, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.ArtifactVersion,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.ArtifactVersion.Artifact
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersion.TranslationArtifactVersionPledges,
|
||||||
|
required: false,
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.TranslationArtifactVersionPledge.Pledge,
|
||||||
|
required: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}).then(async (translationArtifactVersion) => {
|
||||||
|
if (translationArtifactVersion) {
|
||||||
|
// TODO: Create campaign...
|
||||||
|
const pledge = await db.Pledge.create({
|
||||||
|
message: request.body.message,
|
||||||
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
|
translationArtifactVersionPledges: [
|
||||||
|
{
|
||||||
|
translationArtifactVersionId: translationArtifactVersion.id,
|
||||||
|
entityId: request.user.individualEntityUser.entityUser.entityId,
|
||||||
|
satoshis: request.body.satoshis
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
association: db.Pledge.TranslationArtifactVersionPledges
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
response.redirect(`/pledges/${pledge.id}`)
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
next(error)
|
||||||
|
})
|
||||||
|
})
|
||||||
return router;
|
return router;
|
||||||
};
|
};
|
||||||
@@ -9,7 +9,7 @@ block content
|
|||||||
.row
|
.row
|
||||||
.col.s12
|
.col.s12
|
||||||
a.btn.black(href=`/fork/e/${artifactVersion.id}`) fork
|
a.btn.black(href=`/fork/e/${artifactVersion.id}`) fork
|
||||||
.row
|
//- .row
|
||||||
.col.s12
|
.col.s12
|
||||||
a.btn.black(href=`/v/${artifactVersion.id}/campaign/create`) funding campaign
|
a.btn.black(href=`/v/${artifactVersion.id}/campaign/create`) funding campaign
|
||||||
.divider
|
.divider
|
||||||
|
|||||||
22
server/views/pledge-form.pug
Normal file
22
server/views/pledge-form.pug
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
extend templates/layout.pug
|
||||||
|
|
||||||
|
block content
|
||||||
|
.container
|
||||||
|
.center
|
||||||
|
h1 Create Pledge
|
||||||
|
each translationArtifactVersion in translationArtifactVersions
|
||||||
|
p.flow-text #{translationArtifactVersion.name} - #{translationArtifactVersion.artifactVersion.artifact.name} - #{translationArtifactVersion.artifactVersion.tag}
|
||||||
|
|
||||||
|
.row
|
||||||
|
.col.s12
|
||||||
|
form.row(action=urlEndpoint, method="post")
|
||||||
|
.col.s12.input-field
|
||||||
|
input#message(type="text", name="message", value=campaign.description)
|
||||||
|
label(for="message") Message
|
||||||
|
each translationArtifactVersion in translationArtifactVersions
|
||||||
|
input(type="hidden", name="translationArtifactVersions", value=translationArtifactVersion.id)
|
||||||
|
.col.s12.input-field
|
||||||
|
input(id=translationArtifactVersion.id+"-satoshis",type="number", name="satoshis", placeholder="100000 satoshis", step=1, min=1, max=2100000000000000, required)
|
||||||
|
label(for=translationArtifactVersion.id+"-satoshis") Satoshi's required for the #{translationArtifactVersion.name} translation
|
||||||
|
.col.s12
|
||||||
|
button.btn.black(type="submit") create pledge
|
||||||
@@ -28,5 +28,8 @@ block content
|
|||||||
|
|
||||||
.row
|
.row
|
||||||
.col.s12
|
.col.s12
|
||||||
a.btn.black(href=`/translate/${translationArtifactVersion.id}/campaign`) funding campaign
|
a.btn.black(href=`/translate/${translationArtifactVersion.id}/campaigns`) funding campaign
|
||||||
|
.row
|
||||||
|
.col.s12
|
||||||
|
a.btn.black(href=`/translate/${translationArtifactVersion.id}/pledges`) pledge
|
||||||
//- TODO: Give summary of chapters...
|
//- TODO: Give summary of chapters...
|
||||||
|
|||||||
Reference in New Issue
Block a user