Paginate authors
This commit is contained in:
parent
0d4efcddc8
commit
74ab124903
@ -15,8 +15,8 @@
|
||||
<div class="jumbotron">
|
||||
<h1>Bouquins</h1>
|
||||
<p>Cette bibliothèque contient actuellement <strong>{{ booksCount }}</strong> livres et BD en format papier ou électronique.</p>
|
||||
<button class="btn btn-primary" type="button" @click="loadBooks">Livres</button>
|
||||
<button class="btn btn-primary" type="button" @click="loadAuthors">Authors</button>
|
||||
<button class="btn btn-primary" type="button" @click="showBooks">Livres</button>
|
||||
<button class="btn btn-primary" type="button" @click="showAuthors">Authors</button>
|
||||
</div>
|
||||
<div class="table-responsive" v-if="books.length > 0 || authors.length > 0">
|
||||
<nav aria-label="Pages">
|
||||
|
24
index.js
24
index.js
@ -43,22 +43,26 @@ var app = new Vue({
|
||||
this.sendQuery('cgi-bin/bouquins/index', this.stdError, this.indexSuccess);
|
||||
},
|
||||
authorsSuccess: function(resp) {
|
||||
this.books = [];
|
||||
this.authors = resp;
|
||||
},
|
||||
booksSuccess: function(resp) {
|
||||
this.authors = []
|
||||
this.books = resp;
|
||||
},
|
||||
prevPage: function() {
|
||||
if (this.page > 1) {
|
||||
this.page--;
|
||||
this.loadBooks();
|
||||
if (this.books.length > 0)
|
||||
this.loadBooks();
|
||||
if (this.authors.length > 0)
|
||||
this.loadAuthors();
|
||||
}
|
||||
},
|
||||
nextPage: function() {
|
||||
this.page++;
|
||||
this.loadBooks();
|
||||
if (this.books.length > 0)
|
||||
this.loadBooks();
|
||||
if (this.authors.length > 0)
|
||||
this.loadAuthors();
|
||||
},
|
||||
loadAuthors: function() {
|
||||
this.sendQuery('cgi-bin/bouquins/authors?page=' + this.page + '&perpage=' + this.perpage,
|
||||
@ -67,6 +71,18 @@ var app = new Vue({
|
||||
loadBooks: function() {
|
||||
this.sendQuery('cgi-bin/bouquins/books?page=' + this.page + '&perpage=' + this.perpage,
|
||||
this.stdError, this.booksSuccess);
|
||||
},
|
||||
showAuthors: function() {
|
||||
this.books = [];
|
||||
this.page = 1;
|
||||
this.perpage = 20;
|
||||
this.loadAuthors();
|
||||
},
|
||||
showBooks: function() {
|
||||
this.authors = [];
|
||||
this.page = 1;
|
||||
this.perpage = 20;
|
||||
this.loadBooks();
|
||||
}
|
||||
},
|
||||
mounted: function() {
|
||||
|
30
main.c
30
main.c
@ -187,6 +187,22 @@ putbookfull(struct kjsonreq *req, BookFull *b)
|
||||
kjson_putstringp(req, "publisher", b->publisher);
|
||||
}
|
||||
|
||||
static int
|
||||
initpage(struct kreq *r)
|
||||
{
|
||||
if (NULL != r->fieldmap[KEY_PAGE])
|
||||
return r->fieldmap[KEY_PAGE]->parsed.i;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
initperpage(struct kreq *r)
|
||||
{
|
||||
if (NULL != r->fieldmap[KEY_PERPAGE])
|
||||
return r->fieldmap[KEY_PERPAGE]->parsed.i;
|
||||
return 20;
|
||||
}
|
||||
|
||||
static void
|
||||
sendbooks(struct kreq *r)
|
||||
{
|
||||
@ -194,12 +210,11 @@ sendbooks(struct kreq *r)
|
||||
const char *errid;
|
||||
int64_t id = -1;
|
||||
BookFull *b = NULL;
|
||||
int res, i = 0, page = 1, per = 20;
|
||||
int res, i = 0;
|
||||
|
||||
int page = initpage(r);
|
||||
int per = initperpage(r);
|
||||
|
||||
if (NULL != r->fieldmap[KEY_PAGE])
|
||||
page = r->fieldmap[KEY_PAGE]->parsed.i;
|
||||
if (NULL != r->fieldmap[KEY_PERPAGE])
|
||||
per = r->fieldmap[KEY_PERPAGE]->parsed.i;
|
||||
if (NULL != r->fieldmap[KEY_ID])
|
||||
id = r->fieldmap[KEY_ID]->parsed.i;
|
||||
if (r->path[0] != '\0')
|
||||
@ -241,7 +256,10 @@ static void
|
||||
sendauthors(struct kreq *r)
|
||||
{
|
||||
struct kjsonreq req;
|
||||
int res, i = 0, page = 1, per = 20;
|
||||
int res, i = 0;
|
||||
|
||||
int page = initpage(r);
|
||||
int per = initperpage(r);
|
||||
|
||||
http_open(r, KHTTP_200);
|
||||
kjson_open(&req, r);
|
||||
|
Loading…
Reference in New Issue
Block a user