Commit 663898c1 authored by Bertrand  NÉRON's avatar Bertrand NÉRON
Browse files

BUGFIX

fix bug #917
the view was harcoded in pagination links
the "key" parameter was omitted in pagination links
parent 934bc01b
......@@ -5,6 +5,8 @@ function(head, req) {
var limit = (req.query.limit)? req.query.limit -1: 0;
var curr_page = (req.query.curr_page)? parseInt(req.query.curr_page) : 0 ;
var query_type = (req.query.query_type)? req.query.query_type: "is";
var query_key = req.query.key;
var view_name = req.path.pop();
provides("html", function() {
var first_key, last_key ;
......@@ -43,42 +45,47 @@ function(head, req) {
if (!first_key){
send( 'No results found');
}
var pagination = {};
if( limit ){
if( query_type =="is"){
if( !req.query.descending ){
if (more_results){
pagination.next = path.list( "index" ,"by_replicon_name" ,{ startkey:next_key,
startkey_docid: next_docid,
limit: limit +1,
curr_page: curr_page+1
});
pagination.next = path.list( "index" , view_name ,{ key: query_key,
startkey:next_key,
startkey_docid: next_docid,
limit: limit +1,
curr_page: curr_page+1
});
}
if(curr_page > 0 ){
pagination.prev = path.list( "index" ,"by_replicon_name" ,{ startkey:first_key,
startkey_docid: first_docid,
limit: limit +1,
skip:1,
descending:true,
curr_page: curr_page-1
});
pagination.prev = path.list( "index" , view_name ,{ key:query_key,
startkey:first_key,
startkey_docid: first_docid,
limit: limit +1,
skip:1,
descending:true,
curr_page: curr_page-1
});
}
}else{
// si je descend il ya forecement un next
pagination.next = path.list( "index" ,"by_replicon_name" ,{ startkey:first_key,
startkey_docid: first_docid,
limit: limit +1,
skip:1,
curr_page: curr_page+1
});
pagination.next = path.list( "index" , view_name ,{ key: query_key,
startkey:first_key,
startkey_docid: first_docid,
limit: limit +1,
skip:1,
curr_page: curr_page+1
});
if (more_results){
pagination.prev = path.list( "index" ,"by_replicon_name" ,{ startkey: next_key,
startkey_docid: next_docid,
limit: limit +1,
descending:true,
curr_page: curr_page-1
});
pagination.prev = path.list( "index" , view_name ,{ key: query_key,
startkey: next_key,
startkey_docid: next_docid,
limit: limit +1,
descending:true,
curr_page: curr_page-1
});
}
}
} else if ( query_type == "start_with"){
......@@ -86,55 +93,59 @@ function(head, req) {
var storestartkey= (req.query.storestartkey)? req.query.storestartkey: '"'+first_key+'"' ;
if( !req.query.descending ){
if(more_results){
pagination.next = path.list( "index" ,"by_replicon_name" ,{ startkey:next_key,
startkey_docid: next_docid,
endkey: storeendkey ,
limit: limit +1,
curr_page: curr_page+1,
query_type:"start_with",
storeendkey: storeendkey,
storestartkey: storestartkey
});
pagination.next = path.list( "index" ,view_name ,{ key:query_key,
startkey:next_key,
startkey_docid: next_docid,
endkey: storeendkey ,
limit: limit +1,
curr_page: curr_page+1,
query_type:"start_with",
storeendkey: storeendkey,
storestartkey: storestartkey
});
}
if(curr_page > 0){
pagination.prev =path.list( "index" ,"by_replicon_name" ,{startkey:first_key,
startkey_docid: first_docid,
endkey: storestartkey,
limit: limit +1,
skip:1,
descending:true,
curr_page: curr_page-1,
query_type:"start_with",
storeendkey: storeendkey ,
storestartkey: storestartkey
});
pagination.prev =path.list( "index" ,view_name ,{key:query_key,
startkey:first_key,
startkey_docid: first_docid,
endkey: storestartkey,
limit: limit +1,
skip:1,
descending:true,
curr_page: curr_page-1,
query_type:"start_with",
storeendkey: storeendkey ,
storestartkey: storestartkey
});
}
}else{
// je descend
if (more_results){
pagination.prev = path.list( "index" ,"by_replicon_name" ,{ startkey: next_key,
startkey_docid: next_docid,
end_key: storestartkey,
limit: limit +1,
descending:true,
curr_page: curr_page-1,
query_type:"start_with",
storestartkey: storestartkey,
storeendkey: storeendkey,
});
pagination.prev = path.list( "index" ,view_name ,{ key:query_key,
startkey: next_key,
startkey_docid: next_docid,
end_key: storestartkey,
limit: limit +1,
descending:true,
curr_page: curr_page-1,
query_type:"start_with",
storestartkey: storestartkey,
storeendkey: storeendkey,
});
}
// si je descend il ya forecement un next
pagination.next = path.list( "index" ,"by_replicon_name" ,{ startkey:first_key,
startkey_docid: first_docid,
endkey: storeendkey,
limit: limit +1,
skip:1,
curr_page: curr_page+1,
query_type:"start_with",
storestartkey: storestartkey,
storeendkey: storeendkey,
});
pagination.next = path.list( "index" ,view_name ,{ key:query_key,
startkey:first_key,
startkey_docid: first_docid,
endkey: storeendkey,
limit: limit +1,
skip:1,
curr_page: curr_page+1,
query_type:"start_with",
storestartkey: storestartkey,
storeendkey: storeendkey,
});
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment