Details auteur, serie

This commit is contained in:
Meutel 2014-06-22 00:35:59 +02:00
parent a7d3665362
commit cff3738dc9
7 changed files with 164 additions and 27 deletions

View File

@ -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');
}
];
});

View File

@ -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<booksIds.length-1; i++) autQuery+='?, ';
autQuery+='?)';
req.db.each(autQuery, booksIds,
function(err, autRow) {
if (autRow.id == req.params.id)
author = autRow;
else
authors.push(autRow);
},
function(err) {
if (err) console.log(err);
respond();
}
);
}
);
});
module.exports = router;

View File

@ -5,7 +5,7 @@ var HashMap = require('hashmap').HashMap;
/* All books */
router.get('/', function(req, res) {
var query = 'SELECT books.id as id,title,series_index,name as series_name FROM books LEFT OUTER JOIN books_series_link ON books.id = books_series_link.book LEFT OUTER JOIN series ON series.id = books_series_link.series ORDER BY books.sort LIMIT ? OFFSET ?';
var query = 'SELECT books.id as id,title,series_index,name as series_name,series.id AS series_id FROM books LEFT OUTER JOIN books_series_link ON books.id = books_series_link.book LEFT OUTER JOIN series ON series.id = books_series_link.series ORDER BY books.sort LIMIT ? OFFSET ?';
var books = new HashMap();
req.paginate = new paginate(req);
req.db.each(query, req.paginate.perpage + 1, req.paginate.offset, function (err, book) {
@ -59,8 +59,8 @@ router.get('/:id', function(req, res) {
};
// book
req.db.get('SELECT books.id AS id,title,timestamp,pubdate,series_index,isbn,lccn,path,uuid,has_cover,' +
'languages.lang_code,format,uncompressed_size,data.name AS data_name,series.name AS series_name' +
' FROM books ' +
'languages.lang_code,format,uncompressed_size,data.name AS data_name,series.name AS series_name,' +
'series.id AS series_id FROM books ' +
' LEFT OUTER JOIN books_languages_link ON books_languages_link.book = books.id ' +
' LEFT OUTER JOIN languages ON languages.id = books_languages_link.lang_code ' +
' LEFT OUTER JOIN data ON data.book = books.id ' +
@ -68,7 +68,7 @@ router.get('/:id', function(req, res) {
' LEFT OUTER JOIN series ON series.id = books_series_link.series ' +
' WHERE books.id = ?', req.params.id,
function(err, row) {
if (err) console.log(err);
if (err) console.log('ERR book: '+err);
book = row;
queries--;
callback();
@ -81,7 +81,7 @@ router.get('/:id', function(req, res) {
authors.push(author);
},
function(err) {
if (err) console.log(err);
if (err) console.log('ERR authors: '+err);
queries--;
callback();
}
@ -93,7 +93,7 @@ router.get('/:id', function(req, res) {
tags.push(tag);
},
function(err) {
if (err) console.log(err);
if (err) console.log('ERR tags: '+err);
queries--;
callback();
}

View File

@ -33,17 +33,62 @@ router.get('/', function(req, res) {
/* Single serie */
router.get('/:id', function(req, res) {
req.db.get('SELECT * FROM series WHERE id = ?', req.params.id, function(err, row) {
var nbq = 3;
var serie;
var books = new Array();
var authors = new Array();
var respond = function() {
if (nbq==0) {
serie.books = books;
serie.authors = authors;
res.format({
html: function(){
row.title = row.name;
res.render('serie', row);
serie.title = serie.name;
res.render('serie', serie);
},
json: function(){
res.json(row);
res.json(serie);
}
});
}
};
req.db.get('SELECT * FROM series WHERE id = ?', req.params.id, function(err, row) {
if (err) console.log(err);
serie = row;
nbq--;
respond();
});
var booksIds = new Array();
req.db.each('SELECT books.id AS id,title,series_index'+
' FROM books'+
' LEFT OUTER JOIN books_series_link ON books_series_link.book = books.id'+
' WHERE books_series_link.series = ?'+
' ORDER BY series_index', req.params.id,
function(err, book) {
books.push(book);
booksIds.push(book.id);
},
function(err) {
if (err) console.log(err);
nbq--;
var autq = 'SELECT DISTINCT authors.name AS name, authors.id AS id'+
' FROM authors'+
' LEFT OUTER JOIN books_authors_link ON books_authors_link.author = authors.id'+
' WHERE books_authors_link.book IN (';
for (var i=0;i<booksIds.length-1;i++) autq+='?,';
autq+='?)';
req.db.each(autq, booksIds,
function(err, author) {
authors.push(author);
},
function(err) {
if (err) console.log(err);
nbq--;
respond();
}
);
}
);
});
module.exports = router;

View File

@ -1,5 +1,33 @@
extends layout
block content
h1 Auteur
h2= name
ol.breadcrumb
li
a(href="/") Home
li
a(href="/author") Auteurs
li.active= title
div.container
div.page-header
h1
span.glyphicon.glyphicon-user
= ' '+name
h2
span.glyphicon.glyphicon-book
| Livres
ul
each book in books
li
a(href='/book/'+book.id)
= book.title+' '
if book.series_name
span.glyphicon.glyphicon-list
a(href='/serie/'+book.series_id)
= ' '+book.series_name+' ('+book.series_index+')'
if coauthors.length > 0
h2
span.glyphicon.glyphicon-user
| Co-Auteur(s)
ul
each author in coauthors
li: a(href='/author/'+author.id)= author.name

View File

@ -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

View File

@ -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