From 5cdf4000bc328dc515b9f80df4a2b7c2ae827605 Mon Sep 17 00:00:00 2001 From: Jiatao Cheng Date: Fri, 3 Mar 2017 10:34:38 -0600 Subject: [PATCH 1/4] added sort to get quotes --- src/services/quote/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/quote/index.js b/src/services/quote/index.js index 9c94dca..2c30870 100644 --- a/src/services/quote/index.js +++ b/src/services/quote/index.js @@ -12,7 +12,8 @@ module.exports = function() { paginate: { default: 1000, max: 1000 - } + }, + sort: { name: 1, createdAt: 1} }; // Initialize our service with any options it requires From da73e6ba93e9a12c8194f289ca61ed39e10a8eb2 Mon Sep 17 00:00:00 2001 From: Jiatao Cheng Date: Fri, 3 Mar 2017 10:35:16 -0600 Subject: [PATCH 2/4] removed date sort --- src/services/quote/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/quote/index.js b/src/services/quote/index.js index 2c30870..c4c3ea5 100644 --- a/src/services/quote/index.js +++ b/src/services/quote/index.js @@ -13,7 +13,7 @@ module.exports = function() { default: 1000, max: 1000 }, - sort: { name: 1, createdAt: 1} + sort: { name: 1} }; // Initialize our service with any options it requires From 1c5b520828ca6e277ba25e53f45113dc8ee878cd Mon Sep 17 00:00:00 2001 From: Jiatao Cheng Date: Fri, 3 Mar 2017 10:49:14 -0600 Subject: [PATCH 3/4] added sort to find --- client/pages/admin.js | 2 +- src/services/quote/index.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client/pages/admin.js b/client/pages/admin.js index ebb03c2..178ad64 100644 --- a/client/pages/admin.js +++ b/client/pages/admin.js @@ -80,7 +80,7 @@ var AdminPage = { const app = window.app; vm.quotes = m.prop([]); this.reloadQuotes = () => { - app.service('quotes').find().then(quotes => { + app.service('quotes').find({$sort: { name: 1}}).then(quotes => { vm.quotes(quotes.data); m.redraw(); }); diff --git a/src/services/quote/index.js b/src/services/quote/index.js index c4c3ea5..9c94dca 100644 --- a/src/services/quote/index.js +++ b/src/services/quote/index.js @@ -12,8 +12,7 @@ module.exports = function() { paginate: { default: 1000, max: 1000 - }, - sort: { name: 1} + } }; // Initialize our service with any options it requires From f42124d90b8b1d1f9220952a0ed569bac5f866ed Mon Sep 17 00:00:00 2001 From: Jiatao Cheng Date: Fri, 3 Mar 2017 11:13:12 -0600 Subject: [PATCH 4/4] added sorting functionality --- client/pages/admin.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/client/pages/admin.js b/client/pages/admin.js index 178ad64..a29bd16 100644 --- a/client/pages/admin.js +++ b/client/pages/admin.js @@ -14,18 +14,33 @@ function printDate(d) { else return "" } +function sorts(list) { + return { + onclick: function(e) { + var prop = e.target.getAttribute("data-sort-by") + if (prop) { + var first = list[0] + list.sort(function(a, b) { + return a[prop] > b[prop] ? 1 : a[prop] < b[prop] ? -1 : 0 + }) + if (first === list[0]) list.reverse() + } + } + } +} + /********** QUOTE TABLE **********/ function tableWithQuotes(quotes, editCallback, deleteCallback, reviewCallback) { var header = [ - m('tr', [ + m('tr', sorts(quotes), [ m('th', 'ID'), - m('th.client', 'Client'), + m('th[data-sort-by=name].client', 'Client'), m('th.description', 'Description'), - m('th.email', 'Email'), - m('th.date', 'Date'), + m('th[data-sort-by=email].email', 'Email'), + m('th[data-sort-by=date].date', 'Date'), m('th.edit', 'Edit'), m('th.delete', 'Delete'), m('th.preview', 'Review')