-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from fac-14/challenges-dynamic-content
Challenges dynamic content
- Loading branch information
Showing
16 changed files
with
323 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,9 @@ | ||
// go tests | ||
const fs = require('fs'); | ||
const dbConnection = require('./db_connection'); | ||
const fs = require("fs"); | ||
const dbConnection = require("./db_connection"); | ||
|
||
const sql = fs.readFileSync(`${__dirname}/test_build.sql`).toString(); | ||
|
||
const initialiseTestDatabase = () => dbConnection.query(sql); | ||
|
||
// const runDbTestBuild = () => | ||
// new Promise((resolve, reject) => { | ||
// dbConnection.query(sql, (err, result) => { | ||
// if (err) { | ||
// reject(err); | ||
// } else { | ||
// resolve(result); | ||
// } | ||
// }); | ||
// }); | ||
|
||
module.exports = initialiseTestDatabase; | ||
module.exports = initialiseTestDatabase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
const queries = require("../model/index"); | ||
|
||
exports.get = (req, res) => { | ||
res.render("challSelect", { layout: "content-selected" }); | ||
queries.getSingleChallenge().then(challengeDetails => { | ||
console.log("challenge details: ", challengeDetails); | ||
res.render("challSelect", { | ||
layout: "content-selected", | ||
challenge: challengeDetails[0] | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
const queries = require("../model/index"); | ||
|
||
exports.get = (req, res) => { | ||
res.render("dashboard"); | ||
}; | ||
|
||
const newChallenges = queries.getChallenges(); | ||
const acceptedChallenges = queries.getAcceptedChallenges(); | ||
const completedChallenges = queries.getCompletedChallenges(); | ||
|
||
Promise.all([newChallenges, acceptedChallenges, completedChallenges]) | ||
.then(challenges => { | ||
res.render("dashboard", { | ||
newChallenges: challenges[0], | ||
acceptedChallenges: challenges[1], | ||
completedChallenges: challenges[2] | ||
}); | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const queries = require("../model/index"); | ||
|
||
exports.get = (req, res) => { | ||
queries.getAcceptedChallenges().then(acceptedChallenges => { | ||
res.render("dashboard", { acceptedChallenges: acceptedChallenges }); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const queries = require("../model/index"); | ||
|
||
exports.get = (req, res) => { | ||
queries.getCompletedChallenges().then(completedChallenges => { | ||
res.render("dashboard", { completedChallenges: completedChallenges }); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,50 @@ | ||
// getAccepetedChallenges | ||
// DUMMY CODE!!!!!! | ||
|
||
const getAcceptedChallenges = () => { | ||
return new Promise((resolve, reject) => { | ||
const result = [ | ||
{ | ||
id: 1, | ||
inventory_id: 2, | ||
title: "Go to a farmers market", | ||
what: "Go to a farmers market", | ||
why: "you can find organic produces and save packaging waste", | ||
ext_link: "https://www.lfm.org.uk/", | ||
img_link: | ||
"https://s3.eu-central-1.amazonaws.com/lfm-web-prod/images/2016_May_Balham_Herbal_Haven_herbs.0f37de8c.fill-360x360.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&X-Amz-Credential=AKIAJXL7S33WNUYF726A%2F20180912%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Date=20180912T140221Z&X-Amz-Signature=3683277a9cc390d6d2d38d8bbad863a38bf16da79f3049a897ac8dad46078746", | ||
reward_points: 10, | ||
repeatable: false | ||
}, | ||
{ | ||
id: 2, | ||
inventory_id: null, | ||
title: "Dont buy plastic water bottles for a week", | ||
what: "maybe buy refillable bottle", | ||
why: "saving lots of plastic", | ||
ext_link: | ||
"https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html", | ||
img_link: | ||
"https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg", | ||
reward_points: 10, | ||
repeatable: true | ||
}, | ||
{ | ||
id: 3, | ||
inventory_id: null, | ||
title: "Stop trashing you dick", | ||
what: "maybe buy refillable bottle", | ||
why: "saving lots of plastic", | ||
ext_link: | ||
"https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html", | ||
img_link: | ||
"https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg", | ||
reward_points: 10, | ||
repeatable: true | ||
} | ||
]; | ||
|
||
resolve(result); | ||
}); | ||
}; | ||
|
||
module.exports = getAcceptedChallenges; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,76 @@ | ||
const dbConnection = require('../../db/db_connection'); | ||
// DUMMY CODE!!!!!! | ||
|
||
module.exports = () => | ||
new Promise((resolve,reject) => { | ||
dbConnection.query( | ||
`SELECT * FROM challenges`, | ||
(err,res) =>{ | ||
if (err) return reject(err); | ||
resolve(res); | ||
} | ||
) | ||
}); | ||
const getChallenges = () => { | ||
return new Promise((resolve, reject) => { | ||
const result = [ | ||
{ | ||
id: 1, | ||
inventory_id: 2, | ||
title: "Go to a farmers market", | ||
what: "Go to a farmers market", | ||
why: "you can find organic produces and save packaging waste", | ||
ext_link: "https://www.lfm.org.uk/", | ||
img_link: | ||
"https://s3.eu-central-1.amazonaws.com/lfm-web-prod/images/2016_May_Balham_Herbal_Haven_herbs.0f37de8c.fill-360x360.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Expires=3600&X-Amz-Credential=AKIAJXL7S33WNUYF726A%2F20180912%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-SignedHeaders=host&X-Amz-Date=20180912T140221Z&X-Amz-Signature=3683277a9cc390d6d2d38d8bbad863a38bf16da79f3049a897ac8dad46078746", | ||
reward_points: 10, | ||
repeatable: false | ||
}, | ||
{ | ||
id: 2, | ||
inventory_id: null, | ||
title: "Dont buy plastic water bottles for a week", | ||
what: "maybe buy refillable bottle", | ||
why: "saving lots of plastic", | ||
ext_link: | ||
"https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html", | ||
img_link: | ||
"https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg", | ||
reward_points: 10, | ||
repeatable: true | ||
}, | ||
{ | ||
id: 3, | ||
inventory_id: null, | ||
title: "Stop trashing you dick", | ||
what: "maybe buy refillable bottle", | ||
why: "saving lots of plastic", | ||
ext_link: | ||
"https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html", | ||
img_link: | ||
"https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg", | ||
reward_points: 10, | ||
repeatable: true | ||
}, | ||
{ | ||
id: 4, | ||
inventory_id: null, | ||
title: "Get a reusable coffee cup", | ||
what: "maybe buy refillable bottle", | ||
why: "saving lots of plastic", | ||
ext_link: | ||
"https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html", | ||
img_link: | ||
"https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg", | ||
reward_points: 10, | ||
repeatable: true | ||
}, | ||
{ | ||
id: 5, | ||
inventory_id: null, | ||
title: "Something else importat", | ||
what: "maybe buy refillable bottle", | ||
why: "saving lots of plastic", | ||
ext_link: | ||
"https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html", | ||
img_link: | ||
"https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg", | ||
reward_points: 10, | ||
repeatable: true | ||
} | ||
]; | ||
|
||
resolve(result); | ||
}); | ||
}; | ||
|
||
module.exports = getChallenges; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
// getCompletedChalllenges | ||
const getCompletedChallenges = () => { | ||
return new Promise((resolve, reject) => { | ||
const result = [ | ||
{ | ||
id: 2, | ||
inventory_id: null, | ||
title: "Dont buy plastic water bottles for a week", | ||
what: "maybe buy refillable bottle", | ||
why: "saving lots of plastic", | ||
ext_link: | ||
"https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html", | ||
img_link: | ||
"https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg", | ||
reward_points: 10, | ||
repeatable: true | ||
}, | ||
{ | ||
id: 3, | ||
inventory_id: null, | ||
title: "Stop trashing you dick", | ||
what: "maybe buy refillable bottle", | ||
why: "saving lots of plastic", | ||
ext_link: | ||
"https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html", | ||
img_link: | ||
"https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg", | ||
reward_points: 10, | ||
repeatable: true | ||
} | ||
]; | ||
resolve(result); | ||
}); | ||
}; | ||
|
||
module.exports = getCompletedChallenges; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// DUMMY CODE!!!!!! | ||
|
||
const getSingleChallenge = () => { | ||
return new Promise((resolve, reject) => { | ||
const result = [ | ||
{ | ||
id: 5, | ||
inventory_id: null, | ||
title: "Something else importat", | ||
what: "maybe buy refillable bottle", | ||
why: "saving lots of plastic", | ||
ext_link: | ||
"https://www.independent.co.uk/environment/plastic-bottles-waste-recycling-pollution-single-use-keep-britain-tidy-water-a8307591.html", | ||
img_link: | ||
"https://www.banthebottle.net/wp-content/uploads/2009/06/ban-all-bottles-300x225.jpg", | ||
reward_points: 10, | ||
repeatable: true | ||
} | ||
]; | ||
|
||
resolve(result); | ||
}); | ||
}; | ||
|
||
module.exports = getSingleChallenge; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
// booo index.js | ||
const acceptChallenge = require('./acceptChallenge') | ||
const completeChallenge = require('./completeChallenge') | ||
const getAcceptedChallenges = require('./getAcceptedChallenges') | ||
const getChallenges = require('./getChallenges') | ||
const getCompletedChallenges = require ('./getCompletedChallenges') | ||
const acceptChallenge = require("./acceptChallenge"); | ||
const completeChallenge = require("./completeChallenge"); | ||
const getAcceptedChallenges = require("./getAcceptedChallenges"); | ||
const getChallenges = require("./getChallenges"); | ||
const getCompletedChallenges = require("./getCompletedChallenges"); | ||
const getSingleChallenge = require("./getSingleChallenge"); | ||
|
||
module.exports = { | ||
acceptChallenge, | ||
completeChallenge, | ||
getAcceptedChallenges, | ||
getChallenges, | ||
getCompletedChallenges | ||
} | ||
acceptChallenge, | ||
completeChallenge, | ||
getAcceptedChallenges, | ||
getChallenges, | ||
getCompletedChallenges, | ||
getSingleChallenge | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,32 @@ | ||
{{!-- hello again --}} | ||
|
||
<h1>this is the selected challenge</h1> | ||
|
||
<form action="/challenge/accepted" method="POST"> | ||
<h1>Accept challenge?</h1> | ||
<button type="submit">Yes!</button> | ||
</form> | ||
<section class="challenge-page"> | ||
|
||
<img class="challenge-img" src="{{challenge.img_link}}"> | ||
|
||
<h2>{{{challenge.title}}}</h2> | ||
|
||
<article class="challenge-what"> | ||
<h3>What</h3> | ||
<p> | ||
{{{challenge.what}}} | ||
</p> | ||
</article> | ||
|
||
<article class="challenge-why"> | ||
<h3>Why</h3> | ||
<p> | ||
{{{challenge.why}}} | ||
</p> | ||
</article> | ||
|
||
<a href="{{{challenge.ext_link}}}" target="_blank" class="ext-link"><button>Find out more</button></a> | ||
|
||
<form action="/challenge/accepted" method="POST"> | ||
<h1>Accept challenge?</h1> | ||
<button type="submit">Yes!</button> | ||
</form> | ||
|
||
|
||
|
||
</section> |
Oops, something went wrong.