diff --git a/main.c b/main.c index 4cbdceb..0f6335f 100644 --- a/main.c +++ b/main.c @@ -295,18 +295,22 @@ sendbooks(struct kreq *r) kjson_obj_close(&req); db_book_full_free(b); } if (termz > 0) { - kjson_array_open(&req); const char **terms = kcalloc(termz, sizeof(char *)); initterms(r, terms); - Book **books = kcalloc(10, sizeof(Book)); - int c = db_books_search(r, 10, books, terms, termz, 0); - while (i < 10 && i < c) { + Book **books = kcalloc(per, sizeof(Book)); + int c = db_books_search(r, per, books, terms, termz, 0); + kjson_obj_open(&req); + kjson_putintp(&req, "count", c); + kjson_arrayp_open(&req, "books"); + while (i < per && i < c) { putbook(&req, books[i]); kjson_obj_close(&req); i++; } - // TODO free kjson_array_close(&req); + kjson_obj_close(&req); + free(books); + free(terms); } else { kjson_array_open(&req); BookAdv **books = kcalloc(per, sizeof(BookAdv)); diff --git a/search.html b/search.html index ac3dbf8..0e0d6d8 100644 --- a/search.html +++ b/search.html @@ -30,12 +30,13 @@

Recherche

-

Livres

+

{{ booksCount }}

diff --git a/search.js b/search.js index 90c4a30..2547ebb 100644 --- a/search.js +++ b/search.js @@ -3,8 +3,9 @@ var app = new Vue({ data: { urlParams: {}, authors: [], + books: [], series: [], - books: [] + booksCount: 0 }, methods: { urlParse: function() { @@ -58,11 +59,11 @@ var app = new Vue({ res += 'term=' + encodeURIComponent(t.trim()); } } - console.log(res); return res; }, searchBooksSuccess: function(res) { - this.books = res; + this.booksCount = res.count; + this.books = res.books; }, searchBooks: function() { this.sendQuery(this.searchParams('cgi-bin/bouquins/books'), this.stdError, this.searchBooksSuccess); @@ -71,6 +72,7 @@ var app = new Vue({ this.authors = []; this.books = []; this.series = []; + this.booksCount = 0; this.searchBooks(); }, searchUrl: function() {