refactoring initial
link home page with items
This commit is contained in:
parent
37d25a0bc1
commit
f9a2ce72d6
@ -9,7 +9,6 @@ $.extend(ItemsCol.prototype,{
|
|||||||
bind: function() {
|
bind: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
$('#'+this.id) .click(function() {
|
$('#'+this.id) .click(function() {
|
||||||
window.location.hash=self.id;
|
|
||||||
home.pagination.page=0;
|
home.pagination.page=0;
|
||||||
home.pagination.perpage=10;
|
home.pagination.perpage=10;
|
||||||
self.load();
|
self.load();
|
||||||
@ -119,11 +118,16 @@ $.extend(HomePage.prototype,{
|
|||||||
update: function() {
|
update: function() {
|
||||||
this.table.empty();
|
this.table.empty();
|
||||||
if (this.current) {
|
if (this.current) {
|
||||||
|
$('#itemsanchor').attr('name',this.current.id+'s');
|
||||||
|
$('#blkitems').removeClass('hidden');
|
||||||
this.displayHeaders(this.current.headers);
|
this.displayHeaders(this.current.headers);
|
||||||
var self = this;
|
var self = this;
|
||||||
$.each(this.current.data, function(ind, elt) {
|
$.each(this.current.data, function(ind, elt) {
|
||||||
self.addRow(elt);
|
self.addRow(elt);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
$('#blkitems').addClass('hidden');
|
||||||
|
$('#itemsanchor').attr('name',null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updatePager: function(links) {
|
updatePager: function(links) {
|
||||||
@ -146,7 +150,10 @@ $.extend(HomePage.prototype,{
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
var home = new HomePage();
|
var home = new HomePage();
|
||||||
|
$.each([home.authors,home.books,home.series],function(i,itemsCol) {
|
||||||
|
if (window.location.hash == '#'+itemsCol.id+'s')
|
||||||
|
itemsCol.load();
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make link.
|
* Make link.
|
||||||
|
@ -5,29 +5,18 @@ var HashMap = require('hashmap').HashMap;
|
|||||||
|
|
||||||
/* All authors */
|
/* All authors */
|
||||||
router.get('/', function(req, res) {
|
router.get('/', function(req, res) {
|
||||||
|
var authors = new Array();
|
||||||
|
|
||||||
var qparams = new Array();
|
var qparams = new Array();
|
||||||
var query = 'SELECT authors.id as id,name,count(*) as count'+
|
var query = 'SELECT authors.id as id,name,count(*) as count'+
|
||||||
' FROM authors,books_authors_link'+
|
' FROM authors,books_authors_link'+
|
||||||
' WHERE authors.id = books_authors_link.author';
|
' WHERE authors.id = books_authors_link.author';
|
||||||
var initial = req.query.initial;
|
req.paginate = new paginate(req);
|
||||||
console.log(initial);
|
query = req.paginate.appendInitialQuery(query,'authors.sort',qparams,false);
|
||||||
if (initial) {
|
|
||||||
query+=' AND ';
|
|
||||||
if (initial == '0') {
|
|
||||||
query+=' (substr(authors.sort,1,1) < ? OR substr(authors.sort,1,1) > ?)';
|
|
||||||
qparams.push('A');
|
|
||||||
qparams.push('Z');
|
|
||||||
} else {
|
|
||||||
query+=' UPPER(authors.sort) LIKE ?';
|
|
||||||
qparams.push(req.query.initial.toUpperCase()+'%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
query+=' GROUP BY books_authors_link.author'+
|
query+=' GROUP BY books_authors_link.author'+
|
||||||
' ORDER BY sort LIMIT ? OFFSET ?';
|
' ORDER BY sort LIMIT ? OFFSET ?';
|
||||||
req.paginate = new paginate(req);
|
|
||||||
qparams.push(req.paginate.perpage + 1);
|
qparams.push(req.paginate.perpage + 1);
|
||||||
qparams.push(req.paginate.offset);
|
qparams.push(req.paginate.offset);
|
||||||
var authors = new Array();
|
|
||||||
req.db.each(query, qparams, function (err, row) {
|
req.db.each(query, qparams, function (err, row) {
|
||||||
if (authors.length < req.paginate.perpage)
|
if (authors.length < req.paginate.perpage)
|
||||||
authors.push(row);
|
authors.push(row);
|
||||||
|
@ -5,26 +5,16 @@ var HashMap = require('hashmap').HashMap;
|
|||||||
|
|
||||||
/* All books */
|
/* All books */
|
||||||
router.get('/', function(req, res) {
|
router.get('/', function(req, res) {
|
||||||
|
var books = new HashMap();
|
||||||
|
|
||||||
|
req.paginate = new paginate(req);
|
||||||
var qparams = new Array();
|
var qparams = new Array();
|
||||||
var query = 'SELECT books.id as id,title,series_index,name as series_name,series.id AS series_id'+
|
var query = 'SELECT books.id as id,title,series_index,name as series_name,series.id AS series_id'+
|
||||||
' FROM books' +
|
' FROM books' +
|
||||||
' LEFT OUTER JOIN books_series_link ON books.id = books_series_link.book' +
|
' 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 series ON series.id = books_series_link.series';
|
||||||
var initial = req.query.initial;
|
query = req.paginate.appendInitialQuery(query,'books.sort',qparams,true);
|
||||||
if (initial) {
|
|
||||||
query+=' WHERE';
|
|
||||||
if (initial == '0') {
|
|
||||||
query+=' substr(books.sort,1,1) < ? OR substr(books.sort,1,1) > ?';
|
|
||||||
qparams.push('A');
|
|
||||||
qparams.push('Z');
|
|
||||||
} else {
|
|
||||||
query+=' UPPER(books.sort) LIKE ?';
|
|
||||||
qparams.push(req.query.initial.toUpperCase()+'%');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
query+= ' ORDER BY books.sort LIMIT ? OFFSET ?';
|
query+= ' ORDER BY books.sort LIMIT ? OFFSET ?';
|
||||||
var books = new HashMap();
|
|
||||||
req.paginate = new paginate(req);
|
|
||||||
qparams.push(req.paginate.perpage + 1);
|
qparams.push(req.paginate.perpage + 1);
|
||||||
qparams.push(req.paginate.offset);
|
qparams.push(req.paginate.offset);
|
||||||
req.db.each(query, qparams,
|
req.db.each(query, qparams,
|
||||||
@ -49,16 +39,8 @@ router.get('/', function(req, res) {
|
|||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
res.format({
|
|
||||||
html: function(){
|
|
||||||
//TODO load items in home page
|
|
||||||
res.render('home', books.values());
|
|
||||||
},
|
|
||||||
json: function(){
|
|
||||||
res.json(books.values());
|
res.json(books.values());
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -5,10 +5,16 @@ var HashMap = require('hashmap').HashMap;
|
|||||||
|
|
||||||
/* All series */
|
/* All series */
|
||||||
router.get('/', function(req, res) {
|
router.get('/', function(req, res) {
|
||||||
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();
|
var series = new HashMap();
|
||||||
|
|
||||||
|
var qparams = 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';
|
||||||
req.paginate = new paginate(req);
|
req.paginate = new paginate(req);
|
||||||
req.db.each(query, req.paginate.perpage + 1, req.paginate.offset, function (err, row) {
|
query = req.paginate.appendInitialQuery(query,'sort',qparams,false);
|
||||||
|
query+=' GROUP BY books_series_link.series ORDER BY sort LIMIT ? OFFSET ?';
|
||||||
|
qparams.push(req.paginate.perpage + 1);
|
||||||
|
qparams.push(req.paginate.offset);
|
||||||
|
req.db.each(query, qparams, function (err, row) {
|
||||||
if (series.count() < req.paginate.perpage)
|
if (series.count() < req.paginate.perpage)
|
||||||
series.set(''+row.id,row);
|
series.set(''+row.id,row);
|
||||||
else
|
else
|
||||||
|
@ -6,6 +6,7 @@ var paginate = function(req) {
|
|||||||
this.offset = this.page * this.perpage;
|
this.offset = this.page * this.perpage;
|
||||||
this.oUrl = url.parse(req.originalUrl, true);
|
this.oUrl = url.parse(req.originalUrl, true);
|
||||||
this.hasNext = false;
|
this.hasNext = false;
|
||||||
|
this.initial = req.query.initial;
|
||||||
};
|
};
|
||||||
|
|
||||||
paginate.prototype = {
|
paginate.prototype = {
|
||||||
@ -23,6 +24,24 @@ paginate.prototype = {
|
|||||||
this.oUrl.query.page = this.page;
|
this.oUrl.query.page = this.page;
|
||||||
}
|
}
|
||||||
return links;
|
return links;
|
||||||
|
},
|
||||||
|
/** Append search clause for initial to query */
|
||||||
|
appendInitialQuery: function(query, column ,qparams, where) {
|
||||||
|
if (this.initial) {
|
||||||
|
if(where)
|
||||||
|
query+=' WHERE';
|
||||||
|
else
|
||||||
|
query+=' AND';
|
||||||
|
if (this.initial == '0') {
|
||||||
|
query+=' substr('+column+',1,1) < ? OR substr('+column+',1,1) > ?';
|
||||||
|
qparams.push('A');
|
||||||
|
qparams.push('Z');
|
||||||
|
} else {
|
||||||
|
query+=' UPPER('+column+') LIKE ?';
|
||||||
|
qparams.push(this.initial.toUpperCase()+'%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return query;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ block content
|
|||||||
li
|
li
|
||||||
a(href="/") Home
|
a(href="/") Home
|
||||||
li
|
li
|
||||||
a(href="/author") Auteurs
|
a(href="/#authors") Auteurs
|
||||||
li.active= title
|
li.active= title
|
||||||
div.container
|
div.container
|
||||||
div.page-header
|
div.page-header
|
||||||
|
@ -5,7 +5,7 @@ block content
|
|||||||
li
|
li
|
||||||
a(href="/") Home
|
a(href="/") Home
|
||||||
li
|
li
|
||||||
a(href="/book") Livres
|
a(href="/#books") Livres
|
||||||
li.active= title
|
li.active= title
|
||||||
div.container
|
div.container
|
||||||
div.page-header
|
div.page-header
|
||||||
|
@ -5,12 +5,13 @@ block content
|
|||||||
h1= title
|
h1= title
|
||||||
p Naviguez dans la bibliothèque.
|
p Naviguez dans la bibliothèque.
|
||||||
p
|
p
|
||||||
a#book.btn.btn-primary.btn-lg(role="button") Livres
|
a#book.btn.btn-primary.btn-lg(href="#books",role="button") Livres
|
||||||
|
|
||||||
a#author.btn.btn-primary.btn-lg(role="button") Auteurs
|
a#author.btn.btn-primary.btn-lg(href="#authors",role="button") Auteurs
|
||||||
|
|
||||||
a#serie.btn.btn-primary.btn-lg(role="button") Series
|
a#serie.btn.btn-primary.btn-lg(href="#series",role="button") Series
|
||||||
div.container-fluid
|
div#blkitems.container-fluid.hidden
|
||||||
|
a#itemsanchor
|
||||||
div.btn-group
|
div.btn-group
|
||||||
- var initials = '0ABCDEFGHIPQRSTUVWXYZ';
|
- var initials = '0ABCDEFGHIPQRSTUVWXYZ';
|
||||||
- for (var i=0;i<initials.length;i++) {
|
- for (var i=0;i<initials.length;i++) {
|
||||||
|
@ -5,7 +5,7 @@ block content
|
|||||||
li
|
li
|
||||||
a(href="/") Home
|
a(href="/") Home
|
||||||
li
|
li
|
||||||
a(href="/serie") Series
|
a(href="/#series") Series
|
||||||
li.active= title
|
li.active= title
|
||||||
div.container
|
div.container
|
||||||
div.page-header
|
div.page-header
|
||||||
|
Loading…
Reference in New Issue
Block a user