Page détail livre

This commit is contained in:
Meutel 2014-06-20 20:58:12 +02:00
parent abb47b4690
commit a7d3665362
3 changed files with 113 additions and 17 deletions

View File

@ -26,7 +26,8 @@ $('#book').click(function() {
}
return links;
}, function(elt) {
return link(elt.series_name, '/serie/'+elt.id, 'glyphicon-list');
var content = elt.series_name == null ? '' : elt.series_name + '(' + elt.series_index + ')';
return link(content, '/serie/'+elt.id, 'glyphicon-list');
}
];
});

View File

@ -26,23 +26,79 @@ router.get('/', function(req, res) {
book.authors.push(author);
}, function(err) {
if (err) console.log(err);
res.json(books.values());
res.format({
html: function(){
//TODO load items in home page
res.render('home', books.values());
},
json: function(){
res.json(books.values());
}
});
});
});
});
/* Single book */
router.get('/:id', function(req, res) {
req.db.get('SELECT * FROM books WHERE id = ?', req.params.id, function(err, row) {
res.format({
html: function(){
res.render('book', row);
},
json: function(){
res.json(row);
}
});
});
var book, authors, tags;
var queries = 3;
var callback = function() {
if (queries == 0) {
book.authors = authors;
book.tags = tags;
res.format({
html: function(){
res.render('book', book);
},
json: function(){
res.json(book);
}
});
}
};
// 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 ' +
' 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 ' +
' LEFT OUTER JOIN books_series_link ON books.id = books_series_link.book ' +
' 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);
book = row;
queries--;
callback();
}
);
// authors
authors = new Array();
req.db.each('SELECT authors.id as id,name FROM authors, books_authors_link WHERE books_authors_link.author = authors.id AND books_authors_link.book = ?', req.params.id,
function(err, author) {
authors.push(author);
},
function(err) {
if (err) console.log(err);
queries--;
callback();
}
);
// tags
tags = new Array();
req.db.each('SELECT tags.id as id,name FROM tags, books_tags_link WHERE books_tags_link.tag = tags.id AND books_tags_link.book = ?', req.params.id,
function(err, tag) {
tags.push(tag);
},
function(err) {
if (err) console.log(err);
queries--;
callback();
}
);
});
module.exports = router;

View File

@ -1,7 +1,46 @@
extends layout
block content
h1 Titre
h2= title
h1 Auteur
h2= author_sort
ol.breadcrumb
li
a(href="/") Home
li
a(href="/book") Livres
li.active= title
div.container
div.page-header
h1
span.glyphicon.glyphicon-book
= ' '+title+' '
a.btn.btn-success(href='/calibre/'+path+'/'+data_name+'.'+format.toLowerCase())
span.glyphicon.glyphicon-download-alt
= ' Telecharger ' + format
div.row
div.col-md-5
h2
span.glyphicon.glyphicon-user
| Auteur(s)
ul.list-unstyled
each author in authors
li: a(href='/author/'+author.id)= author.name
if series_name
h2
span.glyphicon.glyphicon-list
| Serie
div
a(href="#")= series_name + ' '
span.badge= series_index
h2
span.glyphicon.glyphicon-globe
| Langue
div= lang_code
h2
span.glyphicon.glyphicon-tags
| Etiquette(s)
div
each tag in tags
span.label.label-info= tag.name
|
div.col-md-7
if has_cover == 1
img.img-rounded.img-responsive(src='/calibre/'+path+'/cover.jpg',alt="Pas de couverture")