Display search result number

This commit is contained in:
Meutel 2017-01-14 17:52:52 +01:00
parent fce863d8f7
commit 4e8307a97f
3 changed files with 16 additions and 9 deletions

14
main.c
View File

@ -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));

View File

@ -30,12 +30,13 @@
<h1>Recherche</h1>
</div>
<div v-if="books.length > 0">
<h2>Livres</h2>
<h2>{{ booksCount }} <template v-if="booksCount>1">livres</template><template v-else>livre</template></h2>
<ul>
<li v-for="book in books">
<span class="glyphicon glyphicon-book"></span>
<a :href="'book.html?id='+book.id">{{ book.title }}</a>
</li>
<li v-if="books.length < booksCount">...</li>
</ul>
</div>
</div>

View File

@ -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() {