From 40dc219c4525d06b0001ef2501c3ae1d1c5e55d4 Mon Sep 17 00:00:00 2001 From: Meutel Date: Tue, 2 Sep 2014 20:07:44 +0200 Subject: [PATCH 1/3] Display book details (publisher) --- locales/dev/translation.json | 7 ++++++- locales/fr/translation.json | 7 ++++++- routes/book.js | 17 +++++++++++++++-- views/book.jade | 18 +++++++++++++++--- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/locales/dev/translation.json b/locales/dev/translation.json index de92a6f..e06b547 100644 --- a/locales/dev/translation.json +++ b/locales/dev/translation.json @@ -33,7 +33,12 @@ "serie": "Serie", "language": "Language", "tags": "Tag(s)", - "nocover": "No cover" + "nocover": "No cover", + "details": "Details", + "detail": { + "pubdate": "Publication date", + "pubname": "Publisher" + } }, "author": { "books": "Books", diff --git a/locales/fr/translation.json b/locales/fr/translation.json index e004d3a..c605e88 100644 --- a/locales/fr/translation.json +++ b/locales/fr/translation.json @@ -33,7 +33,12 @@ "serie": "Série", "language": "Langue", "tags": "Tag(s)", - "nocover": "Pas de couverture" + "nocover": "Pas de couverture", + "details": "Détails", + "detail": { + "pubdate": "Date de publication", + "pubname": "Editeur" + } }, "author": { "books": "Livres", diff --git a/routes/book.js b/routes/book.js index bc8cf3c..81f8ec1 100644 --- a/routes/book.js +++ b/routes/book.js @@ -150,12 +150,13 @@ router.post('/', function(req,res) { /* Single book */ router.get('/:id', function(req, res) { - var book, authors, tags; - var queries = 3; + var book, authors, tags, details; + var queries = 4; var callback = function() { if (queries == 0) { book.authors = authors; book.tags = tags; + book.custom = custom; res.format({ html: function(){ res.render('book', book); @@ -207,6 +208,18 @@ router.get('/:id', function(req, res) { callback(); } ); + // details + custom = new Array(); + req.db.each('SELECT publishers.name as pubname FROM publishers, books_publishers_link WHERE books_publishers_link.publisher = publishers.id AND books_publishers_link.book = ?', req.params.id, + function(err, publisher) { + custom.push({name:'pubname',value:publisher.pubname}); + }, + function(err) { + if (err) console.log('ERR tags: '+err); + queries--; + callback(); + } + ); }); diff --git a/views/book.jade b/views/book.jade index 89fbbe5..8259e44 100644 --- a/views/book.jade +++ b/views/book.jade @@ -12,9 +12,10 @@ block content h1 span.glyphicon.glyphicon-book | #{title} - a.btn.btn-success(href='/calibre/'+path+'/'+data_name+'.'+format.toLowerCase()) - span.glyphicon.glyphicon-download-alt - | #{t('bouquins.book.download')} #{format} + if format + a.btn.btn-success(href='/calibre/'+path+'/'+data_name+'.'+format.toLowerCase()) + span.glyphicon.glyphicon-download-alt + | #{t('bouquins.book.download')} #{format} div.row div.col-md-5 h2 @@ -41,6 +42,17 @@ block content each tag in tags span.label.label-info= tag.name | + h2 #{t('bouquins.book.details')} + ul + if pubdate + li + strong #{t('bouquins.book.detail.pubdate')} + | #{new Date(pubdate).getMonth()}-#{new Date(pubdate).getFullYear()} + if custom + each item in custom + li + strong #{t('bouquins.book.detail.'+item.name)} + | #{item.value} div.col-md-7 if has_cover == 1 img.img-rounded.img-responsive(src='/calibre/'+path+'/cover.jpg',alt=t('bouquins.book.nocover')) From c5fe707e3445c9ce483987314a8fca3f75768642 Mon Sep 17 00:00:00 2001 From: Meutel Date: Wed, 3 Sep 2014 19:39:55 +0200 Subject: [PATCH 2/3] sample configuration file --- sample.config.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sample.config.json diff --git a/sample.config.json b/sample.config.json new file mode 100644 index 0000000..f906e6c --- /dev/null +++ b/sample.config.json @@ -0,0 +1,16 @@ +{ + "calibre_path": "./public/calibre", + "calibre_db_path": "./public/calibre/metadata.db", + "trust proxy": true, + "book_details_custom": [ + { + "name": "a_lire", + "query": "SELECT custom_columns.name AS label, custom_column_2.value AS value FROM custom_column_2 LEFT OUTER JOIN custom_columns ON custom_columns.id = 2 WHERE custom_column_2.book = ?", + "type": "bool" + }, { + "name": "phy", + "query": "SELECT custom_columns.name AS label, custom_column_3.value AS value FROM custom_column_3 LEFT OUTER JOIN custom_columns ON custom_columns.id = 3 WHERE custom_column_3.book = ?", + "type": "bool" + } + ] +} From e811b461afdb35dd7d5fb8bdd5b98f0bf93dc13b Mon Sep 17 00:00:00 2001 From: Meutel Date: Wed, 3 Sep 2014 19:40:12 +0200 Subject: [PATCH 3/3] better handling of book details, use custom columns --- bouquins.js | 1 + config/development.json | 13 ++++++++++++- routes/book.js | 33 +++++++++++++++++++++------------ views/book.jade | 18 ++++++++++++++++-- 4 files changed, 50 insertions(+), 15 deletions(-) diff --git a/bouquins.js b/bouquins.js index 833bfc2..409f974 100644 --- a/bouquins.js +++ b/bouquins.js @@ -42,6 +42,7 @@ var db = new sqlite3.Database(dbPath); app.use(function(req, res, next) { req.db = db; + req.locals = app.locals; next(); }); diff --git a/config/development.json b/config/development.json index 6123a77..f906e6c 100644 --- a/config/development.json +++ b/config/development.json @@ -1,5 +1,16 @@ { "calibre_path": "./public/calibre", "calibre_db_path": "./public/calibre/metadata.db", - "trust proxy": true + "trust proxy": true, + "book_details_custom": [ + { + "name": "a_lire", + "query": "SELECT custom_columns.name AS label, custom_column_2.value AS value FROM custom_column_2 LEFT OUTER JOIN custom_columns ON custom_columns.id = 2 WHERE custom_column_2.book = ?", + "type": "bool" + }, { + "name": "phy", + "query": "SELECT custom_columns.name AS label, custom_column_3.value AS value FROM custom_column_3 LEFT OUTER JOIN custom_columns ON custom_columns.id = 3 WHERE custom_column_3.book = ?", + "type": "bool" + } + ] } diff --git a/routes/book.js b/routes/book.js index 81f8ec1..7ef89ce 100644 --- a/routes/book.js +++ b/routes/book.js @@ -151,7 +151,8 @@ router.post('/', function(req,res) { /* Single book */ router.get('/:id', function(req, res) { var book, authors, tags, details; - var queries = 4; + var queries = 3; + if (req.locals.book_details_custom) queries+=req.locals.book_details_custom.length; var callback = function() { if (queries == 0) { book.authors = authors; @@ -170,12 +171,14 @@ 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,' + - 'series.id AS series_id FROM books ' + + 'series.id AS series_id, publishers.name AS pubname 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 ' + + ' LEFT OUTER JOIN books_publishers_link ON books.id = books_publishers_link.book ' + + ' LEFT OUTER JOIN publishers ON publishers.id = books_publishers_link.publisher ' + ' WHERE books.id = ?', req.params.id, function(err, row) { if (err) console.log('ERR book: '+err); @@ -210,16 +213,22 @@ router.get('/:id', function(req, res) { ); // details custom = new Array(); - req.db.each('SELECT publishers.name as pubname FROM publishers, books_publishers_link WHERE books_publishers_link.publisher = publishers.id AND books_publishers_link.book = ?', req.params.id, - function(err, publisher) { - custom.push({name:'pubname',value:publisher.pubname}); - }, - function(err) { - if (err) console.log('ERR tags: '+err); - queries--; - callback(); - } - ); + if (req.locals.book_details_custom) { + _.each(req.locals.book_details_custom, function(detail) { + req.db.each(detail.query, req.params.id, + function(err, row) { + row.name = detail.name; + row.type = detail.type; + custom.push(row); + }, + function(err) { + if (err) console.log('ERR tags: '+err); + queries--; + callback(); + } + ); + }); + } }); diff --git a/views/book.jade b/views/book.jade index 8259e44..60b49e6 100644 --- a/views/book.jade +++ b/views/book.jade @@ -48,11 +48,25 @@ block content li strong #{t('bouquins.book.detail.pubdate')} | #{new Date(pubdate).getMonth()}-#{new Date(pubdate).getFullYear()} + if pubname + li + strong #{t('bouquins.book.detail.pubname')} + | #{pubname} if custom each item in custom li - strong #{t('bouquins.book.detail.'+item.name)} - | #{item.value} + if item.label + strong #{item.label} + else + strong #{t('bouquins.book.detail.'+item.name)} + case item.type + when "bool" + if item.value == 1 + span.glyphicon.glyphicon-ok + else + span.glyphicon.glyphicon-remove + default + | #{item.value} div.col-md-7 if has_cover == 1 img.img-rounded.img-responsive(src='/calibre/'+path+'/cover.jpg',alt=t('bouquins.book.nocover'))