From c69bf98f3174df223ce31743f4a84ed73339ef29 Mon Sep 17 00:00:00 2001 From: Meutel Date: Sun, 8 Jan 2017 17:15:01 +0100 Subject: [PATCH] Display series, links --- Makefile | 4 ++-- author.html | 2 +- book.html | 2 +- db_series.c | 2 +- index.html | 26 +++++++++++++++++++++-- index.js | 21 +++++++++++++++++++ series.html | 50 ++++++++++++++++++++++++++++++++++++++++++++ series.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 160 insertions(+), 7 deletions(-) create mode 100644 series.html create mode 100644 series.js diff --git a/Makefile b/Makefile index d03bf49..ce7ae34 100644 --- a/Makefile +++ b/Makefile @@ -60,8 +60,8 @@ sinclude GNUmakefile.local DATABASE = metadata.db OBJS = db.o db_author.o db_book.o db_series.o json.o main.o -HTMLS = index.html book.html author.html -JSMINS = index.min.js book.min.js author.min.js +HTMLS = index.html book.html author.html series.html +JSMINS = index.min.js book.min.js author.min.js series.min.js EXTJS = externals/vue.min.js CSS = externals/bootstrap.min.css FONTS = externals/fonts/* diff --git a/author.html b/author.html index bbf84e1..b3f7865 100644 --- a/author.html +++ b/author.html @@ -41,7 +41,7 @@
diff --git a/book.html b/book.html index 811fcc4..14467d4 100644 --- a/book.html +++ b/book.html @@ -49,7 +49,7 @@ Serie
- {{ book.series.name }} + {{ book.series.name }} {{ book.series.idx }}
diff --git a/db_series.c b/db_series.c index bf173f4..8391336 100644 --- a/db_series.c +++ b/db_series.c @@ -52,7 +52,7 @@ static const char *const stmts[STMT__MAX] = { /* STMT_SERIE_BOOKS */ "SELECT books.id, title, series_index FROM books \ LEFT OUTER JOIN books_series_link ON books.id = books_series_link.book \ - WHERE books_series_link.series = ?", + WHERE books_series_link.series = ? ORDER BY series_index DESC", /* STMT_SERIE_AUTHORS */ "SELECT DISTINCT authors.id, authors.name \ FROM authors, books_authors_link, books_series_link \ diff --git a/index.html b/index.html index f372831..f92920d 100644 --- a/index.html +++ b/index.html @@ -17,14 +17,35 @@

Cette bibliothèque contient actuellement {{ booksCount }} livres et BD en format papier ou électronique.

+ -
+
+ + + + + + + + + + + +
NomLivre(s)Auteur(s)
+ + {{ serie.name }} + {{ serie.count }} + +
@@ -55,7 +76,8 @@ diff --git a/index.js b/index.js index 14ef86b..b52f63c 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ var app = new Vue({ data: { books: [], authors: [], + series: [], booksCount: 0, page: 1, perpage: 20 @@ -48,6 +49,9 @@ var app = new Vue({ booksSuccess: function(resp) { this.books = resp; }, + seriesSuccess: function(resp) { + this.series = resp; + }, prevPage: function() { if (this.page > 1) { this.page--; @@ -55,6 +59,8 @@ var app = new Vue({ this.loadBooks(); if (this.authors.length > 0) this.loadAuthors(); + if (this.series.length > 0) + this.loadSeries(); } }, nextPage: function() { @@ -63,6 +69,8 @@ var app = new Vue({ this.loadBooks(); if (this.authors.length > 0) this.loadAuthors(); + if (this.series.length > 0) + this.loadSeries(); }, loadAuthors: function() { this.sendQuery('cgi-bin/bouquins/authors?page=' + this.page + '&perpage=' + this.perpage, @@ -72,14 +80,27 @@ var app = new Vue({ this.sendQuery('cgi-bin/bouquins/books?page=' + this.page + '&perpage=' + this.perpage, this.stdError, this.booksSuccess); }, + loadSeries: function() { + this.sendQuery('cgi-bin/bouquins/series?page=' + this.page + '&perpage=' + this.perpage, + this.stdError, this.seriesSuccess); + }, + showSeries: function() { + this.books = []; + this.authors = []; + this.page = 1; + this.perpage = 20; + this.loadSeries(); + }, showAuthors: function() { this.books = []; + this.series = []; this.page = 1; this.perpage = 20; this.loadAuthors(); }, showBooks: function() { this.authors = []; + this.series = []; this.page = 1; this.perpage = 20; this.loadBooks(); diff --git a/series.html b/series.html new file mode 100644 index 0000000..904741b --- /dev/null +++ b/series.html @@ -0,0 +1,50 @@ + + + + Serie | Bouquins + + + + + + + + + +
+ + + + +
+ + + + + diff --git a/series.js b/series.js new file mode 100644 index 0000000..9a79b75 --- /dev/null +++ b/series.js @@ -0,0 +1,60 @@ +var app = new Vue({ + el: '#app', + data: { + urlParams: {}, + series: {} + }, + methods: { + urlParse: function() { + var match, + pl = /\+/g, // Regex for replacing addition symbol with a space + search = /([^&=]+)=?([^&]*)/g, + decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }, + query = window.location.search.substring(1); + while (match = search.exec(query)) + this.urlParams[decode(match[1])] = decode(match[2]); + }, + sendQuery: function(url, error, success) { + var xmh = new XMLHttpRequest(); + var v; + + xmh.onreadystatechange = function() { + v = xmh.responseText; + if (xmh.readyState === 4 && xmh.status === 200) { + var res; + try { + res = JSON.parse(v); + } catch (err) { + if (null !== error) + error(err.name, err.message); + } + if (null !== success) + success(res); + } else if (xmh.readyState === 4) { + if (null !== error) + error(xmh.status, v); + } + }; + + xmh.open('GET', url, true); + xmh.send(null); + }, + stdError: function(code, resp) { + console.log('ERROR ' + code + ': ' + resp); + }, + seriesSucces: function(resp) { + this.series = resp; + document.title = this.series.name +' | Bouquins'; + }, + loadSeries: function() { + if (this.urlParams.id) + this.sendQuery('cgi-bin/bouquins/series/' + this.urlParams.id, this.stdError, this.seriesSucces); + } + }, + created: function() { + this.urlParse(); + }, + mounted: function() { + this.loadSeries(); + } +})
Nom