Skip to content

Commit

Permalink
Relates #26 - get /sendinfo redirecting to /results and display info
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinlondon committed Sep 19, 2018
1 parent 54630bb commit ac9c18f
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 9 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"dependencies": {
"body-parser": "^1.18.3",
"cookie-parser": "^1.4.3",
"env2": "^2.2.2",
"express": "^4.16.3",
"express-handlebars": "^3.0.0",
Expand Down
3 changes: 3 additions & 0 deletions public/stylesheets/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/stylesheets/main.css.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions public/stylesheets/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ progress[value]::-moz-progress-bar {
justify-content: center;
}

.flex-column {
flex-direction: column;
}

.eight-padding {
padding: 8px;
}
Expand Down
3 changes: 3 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const controllers = require('./controllers/index.js');
// const helpers = require('./views/helpers/index.js');
// const favicon = require('serve-favicon');
const cookieParser = require('cookie-parser');

const app = express();

Expand Down Expand Up @@ -32,6 +33,8 @@ app.use(sassMiddleware({
prefix: '/stylesheets'
}));
app.use(express.static(path.join(__dirname, '..', 'public')));
// add cookie parser, needs to come before controllers so cookies are parsed before routes are rendered
app.use(cookieParser());
app.use(controllers);

module.exports = app;
3 changes: 2 additions & 1 deletion src/controllers/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ exports.get = (req, res) => {
layout: 'scrollable',
progressamt: '100',
title: 'Results',
pageInfo: 'Based on the checkboxes you have selected, here are your results.'
pageInfo: 'Based on the checkboxes you have selected, here are your results.',
results: req.cookies.tastyResultsCookie
});
}
12 changes: 8 additions & 4 deletions src/controllers/sendinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ exports.post = (req, response) => {
console.log('resultArray', resultArray);
const outArray = filterByType(resultArray);
console.log('OUTPUT ARRAY', outArray);
//res.render('results', {outArray});
response.send(outArray);
//store the response in a cookie as a stringified object
response.cookie('tastyResultsCookie', outArray)
// then redirect to the results page
response.redirect('/results');
})
.catch(err => console.log(err));

function filterByType(inArray) {
const types = ['meetup', 'online course', 'article', 'classroom course'];
const outArr = []
const types = ['meetup', 'online course', 'article', 'classroom course', 'mentor'];
//change from Arr to Obj because having trouble accessing arr
// const outArr = []
const outArr = {}
types.forEach(mytype => {
//outArr[meetup]= filtered result
// setting keys to values from filter function
Expand Down
2 changes: 1 addition & 1 deletion src/database/db_build.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DROP TYPE IF EXISTS e_resource_type CASCADE;
DROP TYPE IF EXISTS e_demographic_tag_name CASCADE;
DROP TYPE IF EXISTS e_relevance CASCADE;

CREATE TYPE e_resource_type AS ENUM ('meetup', 'online course', 'article', 'classroom course' );
CREATE TYPE e_resource_type AS ENUM ('meetup', 'online course', 'article', 'classroom course', 'mentor');

CREATE TABLE resource (
resource_id SERIAL PRIMARY KEY,
Expand Down
41 changes: 39 additions & 2 deletions src/views/results.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
<section class='grid-row'>
<div class='centered-column centered-content secondary-background thirtytwo-padding full-height'>
<p>WE GOT NUTHIN</p>
<div class='centered-column centered-content secondary-background thirtytwo-padding full-height flex-column'>
{{#with results}}
<div>
<h2>meetups</h2>

<ul>
{{#if meetup}}
{{#each meetup}}
<li>
{{#with resource_name}}
{{this}}
{{/with}}
{{#with url}}
{{this}}
{{/with}}
</li>
{{/each}}
{{/if}}
</ul>
</div>
<div>
<h2>articles</h2>

<ul>
{{#if article}}
{{#each article}}
<li>
{{#with resource_name}}
{{this}}
{{/with}}
{{#with url}}
{{this}}
{{/with}}
</li>
{{/each}}
{{/if}}
</ul>
</div>
{{/with}}
</div>
</section>
<section class='grid-row'>
Expand Down

0 comments on commit ac9c18f

Please sign in to comment.