From a190aab20dae035e9891d4c88132318fc290478c Mon Sep 17 00:00:00 2001 From: Meutel Date: Sun, 22 Jun 2014 09:42:10 +0200 Subject: [PATCH] amelioration page auteur --- public/js/home.js | 1 + routes/author.js | 59 +++++++++++++++++++++++++++++------------------ views/author.jade | 15 ++++++++---- 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/public/js/home.js b/public/js/home.js index 19a5c65..c28a528 100644 --- a/public/js/home.js +++ b/public/js/home.js @@ -57,6 +57,7 @@ $('#serie').click(function() { }); $.each(['book','author','serie'], function (i, elt) { $('#'+elt).click(function() { + window.location.hash=elt='s'; url = '/'+elt; loadItems(); }); diff --git a/routes/author.js b/routes/author.js index d01fdab..698c122 100644 --- a/routes/author.js +++ b/routes/author.js @@ -1,6 +1,7 @@ var express = require('express'); var router = express.Router(); var paginate = require('../util/paginate'); +var HashMap = require('hashmap').HashMap; /* All authors */ router.get('/', function(req, res) { @@ -24,9 +25,11 @@ router.get('/:id', function(req, res) { var author; var books = new Array(); var authors = new Array(); + var series = new HashMap(); var respond = function() { - author.books = books; - author.coauthors = authors; + if (books.length>0) author.books = books; + if (series.count()>0) author.series = series.values(); + if (authors.length>0) author.coauthors = authors; res.format({ html: function(){ author.title = author.name; @@ -46,29 +49,41 @@ router.get('/:id', function(req, res) { ' 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, book) { + books.push(book); + if (book.series_id) { + book.serie = { id: book.series_id, name: book.series_name}; + series.set(''+book.serie.id, book.serie); + } + delete book.series_id; + delete book.series_name; + booksIds.push(book.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; i0) { + 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 + a(href='/serie/'+book.serie.id) + = ' '+book.serie.name+' ('+book.series_index+')' + if series + h2 + span.glyphicon.glyphicon-list + | Series + ul + each serie in series + li: a(href='/serie/'+serie.id)= ' '+serie.name + if coauthors h2 span.glyphicon.glyphicon-user | Co-Auteur(s)