amelioration page auteur
This commit is contained in:
parent
cff3738dc9
commit
a190aab20d
@ -57,6 +57,7 @@ $('#serie').click(function() {
|
|||||||
});
|
});
|
||||||
$.each(['book','author','serie'], function (i, elt) {
|
$.each(['book','author','serie'], function (i, elt) {
|
||||||
$('#'+elt).click(function() {
|
$('#'+elt).click(function() {
|
||||||
|
window.location.hash=elt='s';
|
||||||
url = '/'+elt;
|
url = '/'+elt;
|
||||||
loadItems();
|
loadItems();
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
var express = require('express');
|
var express = require('express');
|
||||||
var router = express.Router();
|
var router = express.Router();
|
||||||
var paginate = require('../util/paginate');
|
var paginate = require('../util/paginate');
|
||||||
|
var HashMap = require('hashmap').HashMap;
|
||||||
|
|
||||||
/* All authors */
|
/* All authors */
|
||||||
router.get('/', function(req, res) {
|
router.get('/', function(req, res) {
|
||||||
@ -24,9 +25,11 @@ router.get('/:id', function(req, res) {
|
|||||||
var author;
|
var author;
|
||||||
var books = new Array();
|
var books = new Array();
|
||||||
var authors = new Array();
|
var authors = new Array();
|
||||||
|
var series = new HashMap();
|
||||||
var respond = function() {
|
var respond = function() {
|
||||||
author.books = books;
|
if (books.length>0) author.books = books;
|
||||||
author.coauthors = authors;
|
if (series.count()>0) author.series = series.values();
|
||||||
|
if (authors.length>0) author.coauthors = authors;
|
||||||
res.format({
|
res.format({
|
||||||
html: function(){
|
html: function(){
|
||||||
author.title = author.name;
|
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'+
|
' LEFT OUTER JOIN series ON books_series_link.series = series.id'+
|
||||||
' WHERE books_authors_link.author = ?'+
|
' WHERE books_authors_link.author = ?'+
|
||||||
' ORDER BY author_id', req.params.id,
|
' ORDER BY author_id', req.params.id,
|
||||||
function(err, row) {
|
function(err, book) {
|
||||||
books.push(row);
|
books.push(book);
|
||||||
booksIds.push(row.id);
|
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) {
|
function(err) {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
|
if (!err && books.length>0) {
|
||||||
var autQuery = 'SELECT authors.id AS id,authors.name AS name'+
|
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'+
|
' FROM authors LEFT OUTER JOIN books_authors_link ON authors.id = books_authors_link.author'+
|
||||||
' WHERE books_authors_link.book IN (';
|
' WHERE books_authors_link.book IN (';
|
||||||
for (var i=0; i<booksIds.length-1; i++) autQuery+='?, ';
|
for (var i=0; i<booksIds.length-1; i++) autQuery+='?, ';
|
||||||
autQuery+='?)';
|
autQuery+='?) ORDER BY id';
|
||||||
req.db.each(autQuery, booksIds,
|
req.db.each(autQuery, booksIds,
|
||||||
function(err, autRow) {
|
function(err, autRow) {
|
||||||
if (autRow.id == req.params.id)
|
if (autRow.id == req.params.id)
|
||||||
author = autRow;
|
author = autRow;
|
||||||
else
|
else {
|
||||||
|
if (authors.length == 0 || authors[authors.length-1].id != autRow.id)
|
||||||
authors.push(autRow);
|
authors.push(autRow);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
respond();
|
respond();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
respond();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -20,11 +20,18 @@ block content
|
|||||||
li
|
li
|
||||||
a(href='/book/'+book.id)
|
a(href='/book/'+book.id)
|
||||||
= book.title+' '
|
= book.title+' '
|
||||||
if book.series_name
|
if book.serie
|
||||||
span.glyphicon.glyphicon-list
|
span.glyphicon.glyphicon-list
|
||||||
a(href='/serie/'+book.series_id)
|
a(href='/serie/'+book.serie.id)
|
||||||
= ' '+book.series_name+' ('+book.series_index+')'
|
= ' '+book.serie.name+' ('+book.series_index+')'
|
||||||
if coauthors.length > 0
|
if series
|
||||||
|
h2
|
||||||
|
span.glyphicon.glyphicon-list
|
||||||
|
| Series
|
||||||
|
ul
|
||||||
|
each serie in series
|
||||||
|
li: a(href='/serie/'+serie.id)= ' '+serie.name
|
||||||
|
if coauthors
|
||||||
h2
|
h2
|
||||||
span.glyphicon.glyphicon-user
|
span.glyphicon.glyphicon-user
|
||||||
| Co-Auteur(s)
|
| Co-Auteur(s)
|
||||||
|
Loading…
Reference in New Issue
Block a user