From cff3738dc9879fff912aa20742ccb0e03e89c7d1 Mon Sep 17 00:00:00 2001 From: Meutel Date: Sun, 22 Jun 2014 00:35:59 +0200 Subject: [PATCH] Details auteur, serie --- public/js/home.js | 2 +- routes/author.js | 49 ++++++++++++++++++++++++++++++++---- routes/book.js | 12 ++++----- routes/serie.js | 63 ++++++++++++++++++++++++++++++++++++++++------- views/author.jade | 32 ++++++++++++++++++++++-- views/book.jade | 2 +- views/serie.jade | 31 ++++++++++++++++++++--- 7 files changed, 164 insertions(+), 27 deletions(-) diff --git a/public/js/home.js b/public/js/home.js index a7fab05..19a5c65 100644 --- a/public/js/home.js +++ b/public/js/home.js @@ -27,7 +27,7 @@ $('#book').click(function() { return links; }, function(elt) { var content = elt.series_name == null ? '' : elt.series_name + '(' + elt.series_index + ')'; - return link(content, '/serie/'+elt.id, 'glyphicon-list'); + return link(content, '/serie/'+elt.series_id, 'glyphicon-list'); } ]; }); diff --git a/routes/author.js b/routes/author.js index 43cfbb4..d01fdab 100644 --- a/routes/author.js +++ b/routes/author.js @@ -21,17 +21,56 @@ router.get('/', function(req, res) { /* Single author */ router.get('/:id', function(req, res) { - req.db.get('SELECT * FROM authors WHERE id = ?', req.params.id, function(err, row) { + var author; + var books = new Array(); + var authors = new Array(); + var respond = function() { + author.books = books; + author.coauthors = authors; res.format({ html: function(){ - row.title = row.name; - res.render('author', row); + author.title = author.name; + res.render('author', author); }, json: function(){ - res.json(row); + res.json(author); } }); - }); + }; + + var booksIds = new Array(); + req.db.each('SELECT books.id AS id,title,series_index,series.id AS series_id,series.name AS series_name,books_authors_link.author AS author_id' + + ' FROM books' + + ' LEFT OUTER JOIN books_authors_link ON books_authors_link.book = books.id'+ + ' LEFT OUTER JOIN books_series_link ON books_series_link.book = books.id'+ + ' LEFT OUTER JOIN series ON books_series_link.series = series.id'+ + ' WHERE books_authors_link.author = ?'+ + ' ORDER BY author_id', req.params.id, + function(err, row) { + books.push(row); + booksIds.push(row.id); + }, + function(err) { + if (err) console.log(err); + var autQuery = 'SELECT authors.id AS id,authors.name AS name'+ + ' FROM authors LEFT OUTER JOIN books_authors_link ON authors.id = books_authors_link.author'+ + ' WHERE books_authors_link.book IN ('; + for (var i=0; i 0 + h2 + span.glyphicon.glyphicon-user + | Co-Auteur(s) + ul + each author in coauthors + li: a(href='/author/'+author.id)= author.name diff --git a/views/book.jade b/views/book.jade index 85a5dfa..274b0ac 100644 --- a/views/book.jade +++ b/views/book.jade @@ -28,7 +28,7 @@ block content span.glyphicon.glyphicon-list | Serie div - a(href="#")= series_name + ' ' + a(href='/serie/'+series_id)= series_name + ' ' span.badge= series_index h2 span.glyphicon.glyphicon-globe diff --git a/views/serie.jade b/views/serie.jade index 0aff7a6..dbde4fa 100644 --- a/views/serie.jade +++ b/views/serie.jade @@ -1,5 +1,30 @@ -extend layout +extends layout block content - h1 Serie - h2= name + ol.breadcrumb + li + a(href="/") Home + li + a(href="/serie") Series + li.active= title + div.container + div.page-header + h1 + span.glyphicon.glyphicon-list + = ' '+name + h2 + span.glyphicon.glyphicon-book + | Livres + ul + each book in books + li + = book.series_index+'. ' + a(href='/book/'+book.id) + = book.title + if authors.length > 0 + h2 + span.glyphicon.glyphicon-user + | Auteur(s) + ul + each author in authors + li: a(href='/author/'+author.id)= author.name