From 992918a65b16bc28e6e78663eefd142219d9e167 Mon Sep 17 00:00:00 2001 From: Meutel Date: Sat, 5 Aug 2017 20:06:11 +0200 Subject: [PATCH] Sort cols, improved events --- README.md | 1 - assets/js/index.js | 24 ++++++++++++++++++++++-- templates/index.html | 6 +++--- 3 files changed, 25 insertions(+), 6 deletions(-) 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 @@
- + - +