amélioration contenu des pages des recherche
This commit is contained in:
parent
07f30c6767
commit
abb47b4690
@ -1,15 +1,58 @@
|
||||
var url;
|
||||
var links;
|
||||
var cols;
|
||||
var headers;
|
||||
var urlp={};
|
||||
function link(content, href, glyph) {
|
||||
var link="";
|
||||
if (content) {
|
||||
if (glyph) link+="<span class=\"glyphicon "+glyph+"\"></span> ";
|
||||
link += "<a href=\""+href+"\">";
|
||||
link+=content+"</a>";
|
||||
}
|
||||
return link;
|
||||
}
|
||||
$('#book').click(function() {
|
||||
cols = [ 'title', 'author_sort' ];
|
||||
headers = ['Titre', 'Auteur(s)', 'Serie'];
|
||||
cols = [
|
||||
function(elt) {
|
||||
return link(elt.title, '/book/'+elt.id, 'glyphicon-book');
|
||||
}, function(elt) {
|
||||
var links="";
|
||||
if (Array.isArray(elt.authors)) {
|
||||
$.each(elt.authors, function(ida, author) {
|
||||
links+=link(author.name, '/author/'+author.id,'glyphicon-user');
|
||||
});
|
||||
}
|
||||
return links;
|
||||
}, function(elt) {
|
||||
return link(elt.series_name, '/serie/'+elt.id, 'glyphicon-list');
|
||||
}
|
||||
];
|
||||
});
|
||||
$('#author').click(function() {
|
||||
cols = [ 'name' ];
|
||||
headers = ['Nom', 'Livres'];
|
||||
cols = [ function(elt){
|
||||
return link(elt.name, '/author/'+elt.id,'glyphicon-user');
|
||||
}, function(elt) { return elt.count; } ];
|
||||
});
|
||||
$('#serie').click(function() {
|
||||
cols = [ 'name' ];
|
||||
headers = ['Nom', 'Auteur(s)', 'Livres'];
|
||||
cols = [
|
||||
function(elt) {
|
||||
return link(elt.name, '/serie/'+elt.id, 'glyphicon-list');
|
||||
}, function(elt) {
|
||||
var links="";
|
||||
if (Array.isArray(elt.authors)) {
|
||||
$.each(elt.authors, function(ida, author) {
|
||||
links+=link(author.name, '/author/'+author.id,'glyphicon-user');
|
||||
});
|
||||
}
|
||||
return links;
|
||||
}, function(elt) {
|
||||
return elt.count;
|
||||
}
|
||||
];
|
||||
});
|
||||
$.each(['book','author','serie'], function (i, elt) {
|
||||
$('#'+elt).click(function() {
|
||||
@ -33,17 +76,22 @@ $(".perpage").click(function() {
|
||||
|
||||
function loadItems() {
|
||||
$.getJSON( url, urlp, function( data, textStatus, xhr ) {
|
||||
$('#items').empty();
|
||||
var items = [];
|
||||
var items = $('#items');
|
||||
items.empty();
|
||||
var item = "<tr>";
|
||||
$.each(headers, function(ih, h) {
|
||||
item+="<th>"+h+"</th>";
|
||||
});
|
||||
item += "</tr>";
|
||||
items.append(item);
|
||||
$.each( data, function(i, elt ) {
|
||||
var item = "<tr id='" + elt.id + "'>";
|
||||
$.each(cols, function(icol, col) {
|
||||
item+="<td><a href=\""+url+"/"+elt.id+"\">"+elt[col]+"</a></td>";
|
||||
item+="<td>"+col(elt)+"</td>";
|
||||
});
|
||||
item += "</tr>";
|
||||
items.push(item);
|
||||
items.append(item);
|
||||
});
|
||||
$('#items').append(items.join(""));
|
||||
|
||||
var linkHeader = xhr.getResponseHeader('link');
|
||||
links = parse_link_header(linkHeader);
|
||||
|
@ -4,7 +4,7 @@ var paginate = require('../util/paginate');
|
||||
|
||||
/* All authors */
|
||||
router.get('/', function(req, res) {
|
||||
var query = 'SELECT * FROM authors LIMIT ? OFFSET ?';
|
||||
var query = 'SELECT authors.id as id,name,count(*) as count FROM authors,books_authors_link WHERE authors.id = books_authors_link.author GROUP BY books_authors_link.author ORDER BY sort LIMIT ? OFFSET ?';
|
||||
var authors = new Array();
|
||||
req.paginate = new paginate(req);
|
||||
req.db.each(query, req.paginate.perpage + 1, req.paginate.offset, function (err, row) {
|
||||
@ -13,6 +13,7 @@ router.get('/', function(req, res) {
|
||||
else
|
||||
req.paginate.hasNext = true;
|
||||
}, function(err) {
|
||||
if (err) console.log(err);
|
||||
res.links(req.paginate.links());
|
||||
res.json(authors);
|
||||
});
|
||||
|
@ -1,20 +1,33 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var paginate = require('../util/paginate');
|
||||
var HashMap = require('hashmap').HashMap;
|
||||
|
||||
/* All books */
|
||||
router.get('/', function(req, res) {
|
||||
var query = 'SELECT * FROM books LIMIT ? OFFSET ?';
|
||||
var books = new Array();
|
||||
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 books = new HashMap();
|
||||
req.paginate = new paginate(req);
|
||||
req.db.each(query, req.paginate.perpage + 1, req.paginate.offset, function (err, row) {
|
||||
if (books.length < req.paginate.perpage)
|
||||
books.push(row);
|
||||
else
|
||||
req.paginate.hasNext = true;
|
||||
req.db.each(query, req.paginate.perpage + 1, req.paginate.offset, function (err, book) {
|
||||
if (books.count() < req.paginate.perpage) {
|
||||
books.set(''+book.id, book);
|
||||
} else
|
||||
req.paginate.hasNext = true; /* more than perpage */
|
||||
}, function(err) {
|
||||
if (err) console.log(err);
|
||||
res.links(req.paginate.links());
|
||||
res.json(books);
|
||||
/* query books authors */
|
||||
var qAuthors = 'SELECT books_authors_link.book as book,authors.id as id,name FROM authors, books_authors_link WHERE books_authors_link.author = authors.id AND books_authors_link.book IN (';
|
||||
for (var i=0;i<books.count()-1;i++) qAuthors+='?,';
|
||||
qAuthors+='?)';
|
||||
req.db.each(qAuthors, books.keys(), function(err, author) {
|
||||
var book = books.get(''+author.book);
|
||||
if (!book.authors) book.authors = new Array();
|
||||
book.authors.push(author);
|
||||
}, function(err) {
|
||||
if (err) console.log(err);
|
||||
res.json(books.values());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -1,20 +1,33 @@
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
var paginate = require('../util/paginate');
|
||||
var HashMap = require('hashmap').HashMap;
|
||||
|
||||
/* All series */
|
||||
router.get('/', function(req, res) {
|
||||
var query = 'SELECT * FROM series LIMIT ? OFFSET ?';
|
||||
var series = new Array();
|
||||
var query = 'SELECT series.id as id,name,count(*) as count FROM series,books_series_link WHERE books_series_link.series = series.id GROUP BY books_series_link.series ORDER BY sort LIMIT ? OFFSET ?';
|
||||
var series = new HashMap();
|
||||
req.paginate = new paginate(req);
|
||||
req.db.each(query, req.paginate.perpage + 1, req.paginate.offset, function (err, row) {
|
||||
if (series.length < req.paginate.perpage)
|
||||
series.push(row);
|
||||
if (series.count() < req.paginate.perpage)
|
||||
series.set(''+row.id,row);
|
||||
else
|
||||
req.paginate.hasNext = true;
|
||||
}, function(err) {
|
||||
if (err) console.log(err);
|
||||
res.links(req.paginate.links());
|
||||
res.json(series);
|
||||
/* query series authors */
|
||||
var qAuthors = 'SELECT DISTINCT books_series_link.series as serie, authors.id as id,name FROM authors,books_authors_link,books_series_link WHERE books_series_link.book = books_authors_link.book AND books_authors_link.author = authors.id AND books_series_link.series IN (';
|
||||
for (var i=0;i<series.count()-1;i++) qAuthors+='?,';
|
||||
qAuthors+='?)';
|
||||
req.db.each(qAuthors, series.keys(), function(err, author) {
|
||||
var serie = series.get(''+author.serie);
|
||||
if (!serie.authors) serie.authors = new Array();
|
||||
serie.authors.push(author);
|
||||
}, function(err) {
|
||||
if (err) console.log(err);
|
||||
res.json(series.values());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user