From 316212b627ff64e67e77bfb4c9da0f065a80d110 Mon Sep 17 00:00:00 2001 From: mitroio Date: Fri, 12 Oct 2018 10:45:27 +0100 Subject: [PATCH] Finished up until Linking pages --- .../02_dynamic_website/bookshop/index.js | 18 +++++++----- .../02_dynamic_website/bookshop/package.json | 7 ----- .../bookshop/public/css/style.css | 9 +++--- .../bookshop/views/details.handlebars | 11 +++++-- .../bookshop/views/home.handlebars | 13 --------- .../bookshop/views/layouts/main.handlebars | 12 ++++---- .../bookshop/views/newindex.handlebars | 29 ++++++++++++++----- 7 files changed, 49 insertions(+), 50 deletions(-) diff --git a/exercises/01_nodejs/02_dynamic_website/bookshop/index.js b/exercises/01_nodejs/02_dynamic_website/bookshop/index.js index c13173e..c55bbaf 100644 --- a/exercises/01_nodejs/02_dynamic_website/bookshop/index.js +++ b/exercises/01_nodejs/02_dynamic_website/bookshop/index.js @@ -22,7 +22,7 @@ const db = new sqlite3.Database('./bookshop.db', (err) => { console.log('Connected to the "bookshop.db" SQlite database.') }) -app.get('/', async(req, res) => { +/*app.get('/', async(req, res) => { const sql = 'SELECT id, title, description, publisher FROM books;' console.log(sql) db.all(sql, (err, data) => { @@ -31,17 +31,19 @@ app.get('/', async(req, res) => { console.log(JSON.stringify(data, null, 2)) res.render('home', {books: data}) }) -}) +})*/ -/* app.get('/', async(req, res) => { +app.get('/', async(req, res) => { let sql = 'SELECT id, title FROM books;' // -------- let querystring = '' console.log(req.query.q) if(req.query !== undefined && req.query.q !== undefined) { - sql = `SELECT id, title FROM books + sql = `SELECT id, title, description, year, publisher FROM books WHERE upper(title) LIKE "%${req.query.q}%" - OR upper(description) LIKE upper("%${req.query.q}%");` + OR upper(description) LIKE upper("%${req.query.q}%") + OR upper(publisher) LIKE upper("%${req.query.q}%") + OR upper(year) LIKE upper("%${req.query.q}%");` querystring = req.query.q } // -------- @@ -50,15 +52,15 @@ app.get('/', async(req, res) => { console.log(data) res.render('newindex', {books: data, query: querystring}) }) -}) */ +}) app.get('/details/:id', (req, res) => { - console.log(req.params.id) + console.log(req.headers.referer) const sql = `SELECT * FROM books WHERE id = ${req.params.id};` console.log(sql) db.get(sql, (err, data) => { if(err) console.error(err.message) - console.log(data) + data.referer = req.headers.referer; res.render('details', data) }) }) diff --git a/exercises/01_nodejs/02_dynamic_website/bookshop/package.json b/exercises/01_nodejs/02_dynamic_website/bookshop/package.json index 82d88c8..6a345b1 100644 --- a/exercises/01_nodejs/02_dynamic_website/bookshop/package.json +++ b/exercises/01_nodejs/02_dynamic_website/bookshop/package.json @@ -10,15 +10,8 @@ "license": "ISC", "dependencies": { "express": "^4.16.3", -<<<<<<< HEAD "express-es6-template-engine": "^2.0.3", "express-handlebars": "latest", -||||||| merged common ancestors - "express-es6-template-engine": "^2.0.3", - "express-handlebars": "^3.0.0", -======= - "express-handlebars": "^3.0.0", ->>>>>>> c67bf3ae57c2be05ac191dcdb105faa490aba5cc "sqlite3": "^4.0.2" }, "devDependencies": { diff --git a/exercises/01_nodejs/02_dynamic_website/bookshop/public/css/style.css b/exercises/01_nodejs/02_dynamic_website/bookshop/public/css/style.css index 958c4d3..38456db 100644 --- a/exercises/01_nodejs/02_dynamic_website/bookshop/public/css/style.css +++ b/exercises/01_nodejs/02_dynamic_website/bookshop/public/css/style.css @@ -1,7 +1,6 @@ -<<<<<<< HEAD body{ - overflow: hidden; + } table{ border-collapse: collapse; @@ -46,10 +45,10 @@ td.haspopup{ td.haspopup:hover > .popup { display: inline; } -||||||| merged common ancestors -======= body { font-family: Arial, Helvetica, sans-serif; } ->>>>>>> c67bf3ae57c2be05ac191dcdb105faa490aba5cc +.details h1 { + color: red; +} diff --git a/exercises/01_nodejs/02_dynamic_website/bookshop/views/details.handlebars b/exercises/01_nodejs/02_dynamic_website/bookshop/views/details.handlebars index fd1391a..6fdebfc 100644 --- a/exercises/01_nodejs/02_dynamic_website/bookshop/views/details.handlebars +++ b/exercises/01_nodejs/02_dynamic_website/bookshop/views/details.handlebars @@ -1,5 +1,10 @@ +{{#if referer}} +
+ Go back to search results +
+{{/if}}
-

{{title}}

-

ISBN: {{isbn}}

-

{{description}}

+

{{title}}

+

ISBN: {{isbn}}

+

{{description}}

\ No newline at end of file diff --git a/exercises/01_nodejs/02_dynamic_website/bookshop/views/home.handlebars b/exercises/01_nodejs/02_dynamic_website/bookshop/views/home.handlebars index 913b8fd..0142200 100644 --- a/exercises/01_nodejs/02_dynamic_website/bookshop/views/home.handlebars +++ b/exercises/01_nodejs/02_dynamic_website/bookshop/views/home.handlebars @@ -1,17 +1,11 @@

The following books will help you in this module:

-<<<<<<< HEAD -||||||| merged common ancestors -
    -======= -
{{/each}} -<<<<<<< HEAD
Title Publisher Amazon
@@ -23,11 +17,4 @@ Buy
- -||||||| merged common ancestors - -======= - ->>>>>>> c67bf3ae57c2be05ac191dcdb105faa490aba5cc diff --git a/exercises/01_nodejs/02_dynamic_website/bookshop/views/layouts/main.handlebars b/exercises/01_nodejs/02_dynamic_website/bookshop/views/layouts/main.handlebars index 26bc86b..25c648b 100644 --- a/exercises/01_nodejs/02_dynamic_website/bookshop/views/layouts/main.handlebars +++ b/exercises/01_nodejs/02_dynamic_website/bookshop/views/layouts/main.handlebars @@ -1,14 +1,12 @@ - - My Favourite Books -<<<<<<< HEAD + {{#if title}} + {{title}} + {{else}} + Bookshop + {{/if}} -||||||| merged common ancestors -======= - ->>>>>>> c67bf3ae57c2be05ac191dcdb105faa490aba5cc
diff --git a/exercises/01_nodejs/02_dynamic_website/bookshop/views/newindex.handlebars b/exercises/01_nodejs/02_dynamic_website/bookshop/views/newindex.handlebars index e103db5..ec30efe 100644 --- a/exercises/01_nodejs/02_dynamic_website/bookshop/views/newindex.handlebars +++ b/exercises/01_nodejs/02_dynamic_website/bookshop/views/newindex.handlebars @@ -4,9 +4,10 @@ - Bookshop + +

Bookshop

@@ -14,13 +15,27 @@ -
    {{#if query}}

    {{query}}

    - {{/if}} - {{#each books}} -
  1. {{this.title}}
  2. - {{/each}} -
+ + + + + + + {{#each books}} + + + + + + + {{/each}} +
TitlePublisherAmazon
+ {{this.title}} + + {{this.publisher}}Buy
+ {{/if}} +