diff --git a/db_build.sql b/db_build.sql index f530899..8876fd5 100644 --- a/db_build.sql +++ b/db_build.sql @@ -13,7 +13,9 @@ CREATE TABLE users ( ); INSERT INTO users(firstname, lastname, github, email, username, password) VALUES - ('Jen', 'Spencer', 'jsms90', 'jen@foundersandcoders.com', 'jsms90', '$2a$10$UpA4.c39Yp09g5zZZnmeTuE7gabMK2wWeEWlM4d.uSs8iO86FZvyS'); + ('Jen', 'Spencer', 'jsms90', 'jen@foundersandcoders.com', 'jsms90', '$2a$10$UpA4.c39Yp09g5zZZnmeTuE7gabMK2wWeEWlM4d.uSs8iO86FZvyS'), + ('William', 'Savage', 'SavageWilliam', 'willsavage@hotmail.com', 'SavageWilliam', '$2a$10$UpA4.c39Yp09g5zZZnmeTuE7gabMK2wWeEWlM4d.uSs8iO86FZvyS'); + CREATE TABLE topics ( id SMALLINT PRIMARY KEY, @@ -74,4 +76,11 @@ CREATE TABLE reviews ( user_id INTEGER NOT NULL REFERENCES users(id) ); +INSERT INTO reviews(rating, resource_id, content, user_id) VALUES + (5, 1, 'Great resource! I hope someone writes one for learning JS in 2017!', 2), + (3, 1, 'I love JS!', 1), + (3, 2, 'I learnt the importance of testing via this resource!', 2), + (4, 3, 'HTML & CSS is my bread and butter!', 2); + + COMMIT; diff --git a/public/main.css b/public/main.css index 29d3b11..973b0e2 100644 --- a/public/main.css +++ b/public/main.css @@ -1,20 +1,57 @@ +@import url("reviews.css"); + body { background-color: #ddd; + margin: 0; } .navbar { margin-bottom: 10px; + background: #2C333A; + padding: 1rem; +} + +.navbar__list { + margin: 0; + padding: 0; +} + +.navbar__listitem { + list-style-type: none; + display: inline-block; + transition: color 1s ease; + margin-left: 1rem; +} + +.navbar__listitem:hover { + color: #ff4422; +} + +.navbar__listitem a { + color: white; + font-family: 'Lato', 'Futura', 'Didact Gothic', sans-serif; + font-size: 1.2rem; + text-decoration: none; } .topics, .resources, .reviews { + width: 95%; + margin: 0 auto; + display: flex; + flex-direction: row; + justify-content: center; + flex-wrap: wrap; +} + +.topic, .resource, .review { font-family: 'Lato', 'Futura', 'Didact Gothic', sans-serif; - display: inline-block; + display: block; height: 200px; width: 200px; margin: 20px; padding: 0px 20px; border-radius: 10px; - background-color: #eee; + background-color: #fff; background-size: cover; background-position: center; background-repeat: no-repeat; @@ -23,7 +60,7 @@ body { .topic_title, .resources_title { text-align: center; margin-top: -25px; - margin-bottom: 15px; + margin-bottom: 10px; } .reviews_title { diff --git a/public/reviews.css b/public/reviews.css new file mode 100644 index 0000000..ea513b3 --- /dev/null +++ b/public/reviews.css @@ -0,0 +1,13 @@ +.rating-static { + width: 60px; + height: 16px; + display: block; + background: url('http://www.itsalif.info/blogfiles/rating/star-rating.png') 0 0 no-repeat; +} + +.rating-5 { background-position: 0 0; } +.rating-4 { background-position: -12px 0; } +.rating-3 { background-position: -24px 0; } +.rating-2 { background-position: -36px 0; } +.rating-1 { background-position: -48px 0; } +.rating-0 { background-position: -60px 0; } diff --git a/src/queries.js b/src/queries.js index a432936..af9217e 100644 --- a/src/queries.js +++ b/src/queries.js @@ -58,6 +58,7 @@ queries.getTopics = (cb) => { queries.getResources = (topicsEndpoint, cb) => { const sql = `SELECT resources.title, resources.endpoint, url, topics.endpoint AS topics_endpoint, + (SELECT label FROM type WHERE type.id = resources.type_id) AS type, (SELECT COUNT(*) FROM reviews WHERE reviews.resource_id = resources.id) AS reviews_count, (SELECT AVG(rating) FROM reviews WHERE reviews.resource_id = resources.id)::int AS reviews_avg, (EXISTS (SELECT * FROM reviews WHERE reviews.resource_id = resources.id)) AS has_reviews diff --git a/src/routes.js b/src/routes.js index 3158066..b6850cf 100644 --- a/src/routes.js +++ b/src/routes.js @@ -5,7 +5,6 @@ const home = { path: '/', handler (req, reply) { queries.getTopics((err, topics) => { - console.log(req.auth.credentials); if (err) console.log('No topics were loaded!', err); reply.view('topics', { topics }); }); diff --git a/views/resources.hbs b/views/resources.hbs index ac7d33a..f391334 100644 --- a/views/resources.hbs +++ b/views/resources.hbs @@ -1,12 +1,24 @@ -{{#each resources}} -
-

{{this.title}}


-

{{this.reviews_count}} reviews{{# if this.has_reviews}}, average rating {{this.reviews_avg}}{{/if}}

- {{# if ../credentials}} - Write review
- Edit
- {{else}} -

Login/register to add a review

- {{/if}} -
-{{/each}} +
+ {{#each resources}} +
+

{{this.title}}

+

+ {{this.type}} +

+

+ {{this.reviews_count}} reviews + + {{# if this.has_reviews}} + + {{/if}} +

+ + {{# if ../credentials}} + Write review
+ Edit
+ {{else}} +

Login/register to add a review

+ {{/if}} +
+ {{/each}} +
diff --git a/views/reviews.hbs b/views/reviews.hbs index 6193573..7101bdd 100644 --- a/views/reviews.hbs +++ b/views/reviews.hbs @@ -1,8 +1,10 @@

Reviews of: {{title}}

-{{#each reviews}} -
-

Rating: {{this.rating}} stars


-

{{this.content}}

-
-{{/each}} +
+ {{#each reviews}} +
+

Rating: {{this.rating}} stars


+

{{this.content}}

+
+ {{/each}} +
diff --git a/views/reviews_by_user.hbs b/views/reviews_by_user.hbs index c88e949..ecdfd5a 100644 --- a/views/reviews_by_user.hbs +++ b/views/reviews_by_user.hbs @@ -2,7 +2,7 @@ {{#each reviews}} -
+

Review of {{this.title}}

Rating: {{this.rating}}

{{this.content}}

diff --git a/views/topics.hbs b/views/topics.hbs index 14fe76d..76224ee 100644 --- a/views/topics.hbs +++ b/views/topics.hbs @@ -1,11 +1,11 @@ -{{#each topics}} - -
-

{{this.title}}

-
- -
-
- -{{/each}} +
+ {{#each topics}} +
+

{{this.title}}

+
+ +
+
+ {{/each}} +