diff --git a/README.md b/README.md index 799d48e..a3ce393 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ Bouquins in Go ## TODO -* paginate index * search * About * translations diff --git a/assets/js/index.js b/assets/js/index.js index bfeba0f..b80deb2 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -1,8 +1,10 @@ +var bus = new Vue(); Vue.component('results', { template: '#results-template', props: ['results', 'cols','sort_by','order_desc'], methods: { sortBy: function(col) { + bus.$emit('sort-on', col); } } }); @@ -71,10 +73,10 @@ Vue.component('paginate', { props: ['page','more'], methods: { prevPage: function() { - if (this.page > 1) this.$emit('prev'); + if (this.page > 1) bus.$emit('update-page', -1); }, nextPage: function() { - if (this.more) this.$emit('next'); + if (this.more) bus.$emit('update-page', 1); } } }); @@ -91,6 +93,20 @@ var index = new Vue({ results: [] }, methods: { + sortBy: function(col) { + if (this.sort_by == col) { + if (this.order_desc) { + this.order_desc = false; + this.sort_by = null; + } else { + this.order_desc = true; + } + } else { + this.order_desc = false; + this.sort_by = col; + } + this.updateResults(); + }, updatePage: function(p) { this.page += p; this.updateResults(); @@ -188,5 +204,9 @@ var index = new Vue({ stdError: function(code, resp) { console.log('ERROR ' + code + ': ' + resp); } + }, + mounted: function() { + bus.$on('sort-on', this.sortBy); + bus.$on('update-page', this.updatePage); } }); diff --git a/templates/index.html b/templates/index.html index 0fa2cd8..fc045ef 100644 --- a/templates/index.html +++ b/templates/index.html @@ -8,9 +8,9 @@