Display search result number
This commit is contained in:
parent
fce863d8f7
commit
4e8307a97f
14
main.c
14
main.c
@ -295,18 +295,22 @@ sendbooks(struct kreq *r)
|
|||||||
kjson_obj_close(&req);
|
kjson_obj_close(&req);
|
||||||
db_book_full_free(b);
|
db_book_full_free(b);
|
||||||
} if (termz > 0) {
|
} if (termz > 0) {
|
||||||
kjson_array_open(&req);
|
|
||||||
const char **terms = kcalloc(termz, sizeof(char *));
|
const char **terms = kcalloc(termz, sizeof(char *));
|
||||||
initterms(r, terms);
|
initterms(r, terms);
|
||||||
Book **books = kcalloc(10, sizeof(Book));
|
Book **books = kcalloc(per, sizeof(Book));
|
||||||
int c = db_books_search(r, 10, books, terms, termz, 0);
|
int c = db_books_search(r, per, books, terms, termz, 0);
|
||||||
while (i < 10 && i < c) {
|
kjson_obj_open(&req);
|
||||||
|
kjson_putintp(&req, "count", c);
|
||||||
|
kjson_arrayp_open(&req, "books");
|
||||||
|
while (i < per && i < c) {
|
||||||
putbook(&req, books[i]);
|
putbook(&req, books[i]);
|
||||||
kjson_obj_close(&req);
|
kjson_obj_close(&req);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
// TODO free
|
|
||||||
kjson_array_close(&req);
|
kjson_array_close(&req);
|
||||||
|
kjson_obj_close(&req);
|
||||||
|
free(books);
|
||||||
|
free(terms);
|
||||||
} else {
|
} else {
|
||||||
kjson_array_open(&req);
|
kjson_array_open(&req);
|
||||||
BookAdv **books = kcalloc(per, sizeof(BookAdv));
|
BookAdv **books = kcalloc(per, sizeof(BookAdv));
|
||||||
|
@ -30,12 +30,13 @@
|
|||||||
<h1>Recherche</h1>
|
<h1>Recherche</h1>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="books.length > 0">
|
<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>
|
<ul>
|
||||||
<li v-for="book in books">
|
<li v-for="book in books">
|
||||||
<span class="glyphicon glyphicon-book"></span>
|
<span class="glyphicon glyphicon-book"></span>
|
||||||
<a :href="'book.html?id='+book.id">{{ book.title }}</a>
|
<a :href="'book.html?id='+book.id">{{ book.title }}</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li v-if="books.length < booksCount">...</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,8 +3,9 @@ var app = new Vue({
|
|||||||
data: {
|
data: {
|
||||||
urlParams: {},
|
urlParams: {},
|
||||||
authors: [],
|
authors: [],
|
||||||
|
books: [],
|
||||||
series: [],
|
series: [],
|
||||||
books: []
|
booksCount: 0
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
urlParse: function() {
|
urlParse: function() {
|
||||||
@ -58,11 +59,11 @@ var app = new Vue({
|
|||||||
res += 'term=' + encodeURIComponent(t.trim());
|
res += 'term=' + encodeURIComponent(t.trim());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(res);
|
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
searchBooksSuccess: function(res) {
|
searchBooksSuccess: function(res) {
|
||||||
this.books = res;
|
this.booksCount = res.count;
|
||||||
|
this.books = res.books;
|
||||||
},
|
},
|
||||||
searchBooks: function() {
|
searchBooks: function() {
|
||||||
this.sendQuery(this.searchParams('cgi-bin/bouquins/books'), this.stdError, this.searchBooksSuccess);
|
this.sendQuery(this.searchParams('cgi-bin/bouquins/books'), this.stdError, this.searchBooksSuccess);
|
||||||
@ -71,6 +72,7 @@ var app = new Vue({
|
|||||||
this.authors = [];
|
this.authors = [];
|
||||||
this.books = [];
|
this.books = [];
|
||||||
this.series = [];
|
this.series = [];
|
||||||
|
this.booksCount = 0;
|
||||||
this.searchBooks();
|
this.searchBooks();
|
||||||
},
|
},
|
||||||
searchUrl: function() {
|
searchUrl: function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user