From d224bafd2283a24bf52ab712a4a59aa3dcc24cc4 Mon Sep 17 00:00:00 2001 From: Leo Wong Date: Fri, 14 Oct 2016 00:52:43 +0800 Subject: [PATCH 1/4] Use `descending` instead of `sortDesc` --- app/adapters/application.js | 4 ++-- app/appointments/search/template.hbs | 10 +++++----- app/components/sortable-column.js | 8 ++++---- app/controllers/abstract-paged-controller.js | 8 ++++---- app/inventory/listing/template.hbs | 10 +++++----- app/patients/index/template.hbs | 12 ++++++------ app/routes/abstract-index-route.js | 6 +++--- app/templates/components/sortable-column.hbs | 2 +- app/utils/pouch-views.js | 2 +- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/adapters/application.js b/app/adapters/application.js index 1ab7fd8aea..52bef695e0 100644 --- a/app/adapters/application.js +++ b/app/adapters/application.js @@ -152,8 +152,8 @@ export default Adapter.extend(PouchAdapterUtils, { if (query.options) { queryParams = Ember.copy(query.options); if (query.sortKey || query.filterBy) { - if (query.sortDesc) { - queryParams.sortDesc = query.sortDesc; + if (query.descending) { + queryParams.descending = query.descending; } if (query.sortKey) { queryParams.sortKey = query.sortKey; diff --git a/app/appointments/search/template.hbs b/app/appointments/search/template.hbs index 92dd510597..297a802387 100644 --- a/app/appointments/search/template.hbs +++ b/app/appointments/search/template.hbs @@ -24,12 +24,12 @@ - {{#sortable-column sortBy='date' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.date'}}{{/sortable-column}} + {{#sortable-column sortBy='date' descending=descending sortKey=sortKey }}{{t 'labels.date'}}{{/sortable-column}} - {{#sortable-column sortBy='appointmentType' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.type'}}{{/sortable-column}} - {{#sortable-column sortBy='location' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.location'}}{{/sortable-column}} - {{#sortable-column sortBy='provider' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.with'}}{{/sortable-column}} - {{#sortable-column sortBy='status' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.status'}}{{/sortable-column}} + {{#sortable-column sortBy='appointmentType' descending=descending sortKey=sortKey }}{{t 'labels.type'}}{{/sortable-column}} + {{#sortable-column sortBy='location' descending=descending sortKey=sortKey }}{{t 'labels.location'}}{{/sortable-column}} + {{#sortable-column sortBy='provider' descending=descending sortKey=sortKey }}{{t 'labels.with'}}{{/sortable-column}} + {{#sortable-column sortBy='status' descending=descending sortKey=sortKey }}{{t 'labels.status'}}{{/sortable-column}} {{#each model as |appointment|}} diff --git a/app/components/sortable-column.js b/app/components/sortable-column.js index 2fe151ed83..a1f12d63fe 100644 --- a/app/components/sortable-column.js +++ b/app/components/sortable-column.js @@ -3,7 +3,7 @@ export default Ember.Component.extend({ classNames: ['sortable-column'], tagName: 'th', action: 'sortByKey', - sortDesc: false, + descending: false, sortBy: null, sortKey: null, sorted: function() { @@ -15,10 +15,10 @@ export default Ember.Component.extend({ click() { let sortBy = this.get('sortBy'); let sorted = this.get('sorted'); - let sortDesc = false; + let descending = false; if (sorted) { - sortDesc = this.toggleProperty('sortDesc'); + descending = this.toggleProperty('descending'); } - this.sendAction('action', sortBy, sortDesc); + this.sendAction('action', sortBy, descending); } }); diff --git a/app/controllers/abstract-paged-controller.js b/app/controllers/abstract-paged-controller.js index 792a07d7ab..d4a6e9a15d 100644 --- a/app/controllers/abstract-paged-controller.js +++ b/app/controllers/abstract-paged-controller.js @@ -10,8 +10,8 @@ export default Ember.Controller.extend(PaginationProps, ProgressDialog, UserSess previousStartKeys: [], progressMessage: 'Loading Records. Please wait...', progressTitle: 'Loading', - queryParams: ['startKey', 'sortKey', 'sortDesc'], - sortDesc: false, + queryParams: ['startKey', 'sortKey', 'descending'], + descending: false, sortKey: null, canAdd: function() { @@ -73,11 +73,11 @@ export default Ember.Controller.extend(PaginationProps, ProgressDialog, UserSess this.set('previousStartKeys', previousStartKeys); this.showProgressModal(); }, - sortByKey: function(sortKey, sortDesc) { + sortByKey: function(sortKey, descending) { this.setProperties({ previousStartKey: null, previousStartKeys: [], - sortDesc: sortDesc, + descending: descending, sortKey: sortKey, startKey: null }); diff --git a/app/inventory/listing/template.hbs b/app/inventory/listing/template.hbs index 14dbb9fda6..ab0e723c3f 100644 --- a/app/inventory/listing/template.hbs +++ b/app/inventory/listing/template.hbs @@ -2,12 +2,12 @@ {{#if hasRecords}}
{{t 'labels.name'}}{{t 'labels.actions'}}
- {{#sortable-column sortBy='friendlyId' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.id'}}{{/sortable-column}} - {{#sortable-column sortBy='name' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.name'}}{{/sortable-column}} - {{#sortable-column sortBy='inventoryType' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.type'}}{{/sortable-column}} - {{#sortable-column sortBy='quantity' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.quantity'}}{{/sortable-column}} + {{#sortable-column sortBy='friendlyId' descending=descending sortKey=sortKey }}{{t 'labels.id'}}{{/sortable-column}} + {{#sortable-column sortBy='name' descending=descending sortKey=sortKey }}{{t 'labels.name'}}{{/sortable-column}} + {{#sortable-column sortBy='inventoryType' descending=descending sortKey=sortKey }}{{t 'labels.type'}}{{/sortable-column}} + {{#sortable-column sortBy='quantity' descending=descending sortKey=sortKey }}{{t 'labels.quantity'}}{{/sortable-column}} - {{#sortable-column sortBy='crossReference' sortDesc=sortDesc sortKey=sortKey }}{{t 'inventory.labels.xref'}}{{/sortable-column}} + {{#sortable-column sortBy='crossReference' descending=descending sortKey=sortKey }}{{t 'inventory.labels.xref'}}{{/sortable-column}} {{#each model as |inventory|}} diff --git a/app/patients/index/template.hbs b/app/patients/index/template.hbs index 124f881c73..cb036011e8 100644 --- a/app/patients/index/template.hbs +++ b/app/patients/index/template.hbs @@ -3,12 +3,12 @@
{{t 'inventory.labels.location'}}{{t 'labels.actions'}}
- {{#sortable-column sortBy='id' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.id'}}{{/sortable-column}} - {{#sortable-column sortBy='firstName' sortDesc=sortDesc sortKey=sortKey }}{{t 'patients.labels.firstName'}}{{/sortable-column}} - {{#sortable-column sortBy='lastName' sortDesc=sortDesc sortKey=sortKey }}{{t 'patients.labels.lastName'}}{{/sortable-column}} - {{#sortable-column sortBy='sex' sortDesc=sortDesc sortKey=sortKey }}{{t 'patients.labels.sex'}}{{/sortable-column}} - {{#sortable-column sortBy='dateOfBirth' sortDesc=sortDesc sortKey=sortKey }}{{t 'patients.labels.dob'}}{{/sortable-column}} - {{#sortable-column sortBy='status' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.status'}}{{/sortable-column}} + {{#sortable-column sortBy='id' descending=descending sortKey=sortKey }}{{t 'labels.id'}}{{/sortable-column}} + {{#sortable-column sortBy='firstName' descending=descending sortKey=sortKey }}{{t 'patients.labels.firstName'}}{{/sortable-column}} + {{#sortable-column sortBy='lastName' descending=descending sortKey=sortKey }}{{t 'patients.labels.lastName'}}{{/sortable-column}} + {{#sortable-column sortBy='sex' descending=descending sortKey=sortKey }}{{t 'patients.labels.sex'}}{{/sortable-column}} + {{#sortable-column sortBy='dateOfBirth' descending=descending sortKey=sortKey }}{{t 'patients.labels.dob'}}{{/sortable-column}} + {{#sortable-column sortBy='status' descending=descending sortKey=sortKey }}{{t 'labels.status'}}{{/sortable-column}} {{#if showActions}} {{/if}} diff --git a/app/routes/abstract-index-route.js b/app/routes/abstract-index-route.js index 971437c963..7d7f2527df 100644 --- a/app/routes/abstract-index-route.js +++ b/app/routes/abstract-index-route.js @@ -58,8 +58,8 @@ export default Ember.Route.extend(PouchDbMixin, ProgressDialog, AuthenticatedRou let queryParams = this._modelQueryParams(params); if (!Ember.isEmpty(params.sortKey)) { queryParams.sortKey = params.sortKey; - if (!Ember.isEmpty(params.sortDesc)) { - queryParams.sortDesc = params.sortDesc; + if (!Ember.isEmpty(params.descending)) { + queryParams.descending = params.descending; } } if (!Ember.isEmpty(filterParams)) { @@ -88,7 +88,7 @@ export default Ember.Route.extend(PouchDbMixin, ProgressDialog, AuthenticatedRou }, queryParams: { - sortDesc: { refreshModel: true }, + descending: { refreshModel: true }, sortKey: { refreshModel: true }, startKey: { refreshModel: true } }, diff --git a/app/templates/components/sortable-column.hbs b/app/templates/components/sortable-column.hbs index df77cd44f2..258f9b0e72 100644 --- a/app/templates/components/sortable-column.hbs +++ b/app/templates/components/sortable-column.hbs @@ -1,5 +1,5 @@ {{#if sorted}} - + {{else}} {{/if}} diff --git a/app/utils/pouch-views.js b/app/utils/pouch-views.js index 086803ad45..0be82cd34b 100644 --- a/app/utils/pouch-views.js +++ b/app/utils/pouch-views.js @@ -99,7 +99,7 @@ function generateSortFunction(sortFunction, includeCompareDate, filterFunction) '}' + '}' + '}' + - 'if (req.query.sortDesc) {' + + 'if (req.query.descending) {' + 'rows = rows.reverse();' + '}' + 'if (req.query.sortLimit) {' + From 8c69f9d0001af22e830b37f9dbc2558d3a17bb49 Mon Sep 17 00:00:00 2001 From: Leo Wong Date: Fri, 14 Oct 2016 11:39:25 +0800 Subject: [PATCH 2/4] Revert "Use `descending` instead of `sortDesc`" This reverts commit d224bafd2283a24bf52ab712a4a59aa3dcc24cc4. --- app/adapters/application.js | 4 ++-- app/appointments/search/template.hbs | 10 +++++----- app/components/sortable-column.js | 8 ++++---- app/controllers/abstract-paged-controller.js | 8 ++++---- app/inventory/listing/template.hbs | 10 +++++----- app/patients/index/template.hbs | 12 ++++++------ app/routes/abstract-index-route.js | 6 +++--- app/templates/components/sortable-column.hbs | 2 +- app/utils/pouch-views.js | 2 +- 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/adapters/application.js b/app/adapters/application.js index 52bef695e0..1ab7fd8aea 100644 --- a/app/adapters/application.js +++ b/app/adapters/application.js @@ -152,8 +152,8 @@ export default Adapter.extend(PouchAdapterUtils, { if (query.options) { queryParams = Ember.copy(query.options); if (query.sortKey || query.filterBy) { - if (query.descending) { - queryParams.descending = query.descending; + if (query.sortDesc) { + queryParams.sortDesc = query.sortDesc; } if (query.sortKey) { queryParams.sortKey = query.sortKey; diff --git a/app/appointments/search/template.hbs b/app/appointments/search/template.hbs index 297a802387..92dd510597 100644 --- a/app/appointments/search/template.hbs +++ b/app/appointments/search/template.hbs @@ -24,12 +24,12 @@
{{t 'labels.actions'}}
- {{#sortable-column sortBy='date' descending=descending sortKey=sortKey }}{{t 'labels.date'}}{{/sortable-column}} + {{#sortable-column sortBy='date' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.date'}}{{/sortable-column}} - {{#sortable-column sortBy='appointmentType' descending=descending sortKey=sortKey }}{{t 'labels.type'}}{{/sortable-column}} - {{#sortable-column sortBy='location' descending=descending sortKey=sortKey }}{{t 'labels.location'}}{{/sortable-column}} - {{#sortable-column sortBy='provider' descending=descending sortKey=sortKey }}{{t 'labels.with'}}{{/sortable-column}} - {{#sortable-column sortBy='status' descending=descending sortKey=sortKey }}{{t 'labels.status'}}{{/sortable-column}} + {{#sortable-column sortBy='appointmentType' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.type'}}{{/sortable-column}} + {{#sortable-column sortBy='location' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.location'}}{{/sortable-column}} + {{#sortable-column sortBy='provider' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.with'}}{{/sortable-column}} + {{#sortable-column sortBy='status' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.status'}}{{/sortable-column}} {{#each model as |appointment|}} diff --git a/app/components/sortable-column.js b/app/components/sortable-column.js index a1f12d63fe..2fe151ed83 100644 --- a/app/components/sortable-column.js +++ b/app/components/sortable-column.js @@ -3,7 +3,7 @@ export default Ember.Component.extend({ classNames: ['sortable-column'], tagName: 'th', action: 'sortByKey', - descending: false, + sortDesc: false, sortBy: null, sortKey: null, sorted: function() { @@ -15,10 +15,10 @@ export default Ember.Component.extend({ click() { let sortBy = this.get('sortBy'); let sorted = this.get('sorted'); - let descending = false; + let sortDesc = false; if (sorted) { - descending = this.toggleProperty('descending'); + sortDesc = this.toggleProperty('sortDesc'); } - this.sendAction('action', sortBy, descending); + this.sendAction('action', sortBy, sortDesc); } }); diff --git a/app/controllers/abstract-paged-controller.js b/app/controllers/abstract-paged-controller.js index d4a6e9a15d..792a07d7ab 100644 --- a/app/controllers/abstract-paged-controller.js +++ b/app/controllers/abstract-paged-controller.js @@ -10,8 +10,8 @@ export default Ember.Controller.extend(PaginationProps, ProgressDialog, UserSess previousStartKeys: [], progressMessage: 'Loading Records. Please wait...', progressTitle: 'Loading', - queryParams: ['startKey', 'sortKey', 'descending'], - descending: false, + queryParams: ['startKey', 'sortKey', 'sortDesc'], + sortDesc: false, sortKey: null, canAdd: function() { @@ -73,11 +73,11 @@ export default Ember.Controller.extend(PaginationProps, ProgressDialog, UserSess this.set('previousStartKeys', previousStartKeys); this.showProgressModal(); }, - sortByKey: function(sortKey, descending) { + sortByKey: function(sortKey, sortDesc) { this.setProperties({ previousStartKey: null, previousStartKeys: [], - descending: descending, + sortDesc: sortDesc, sortKey: sortKey, startKey: null }); diff --git a/app/inventory/listing/template.hbs b/app/inventory/listing/template.hbs index ab0e723c3f..14dbb9fda6 100644 --- a/app/inventory/listing/template.hbs +++ b/app/inventory/listing/template.hbs @@ -2,12 +2,12 @@ {{#if hasRecords}}
{{t 'labels.name'}}{{t 'labels.actions'}}
- {{#sortable-column sortBy='friendlyId' descending=descending sortKey=sortKey }}{{t 'labels.id'}}{{/sortable-column}} - {{#sortable-column sortBy='name' descending=descending sortKey=sortKey }}{{t 'labels.name'}}{{/sortable-column}} - {{#sortable-column sortBy='inventoryType' descending=descending sortKey=sortKey }}{{t 'labels.type'}}{{/sortable-column}} - {{#sortable-column sortBy='quantity' descending=descending sortKey=sortKey }}{{t 'labels.quantity'}}{{/sortable-column}} + {{#sortable-column sortBy='friendlyId' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.id'}}{{/sortable-column}} + {{#sortable-column sortBy='name' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.name'}}{{/sortable-column}} + {{#sortable-column sortBy='inventoryType' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.type'}}{{/sortable-column}} + {{#sortable-column sortBy='quantity' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.quantity'}}{{/sortable-column}} - {{#sortable-column sortBy='crossReference' descending=descending sortKey=sortKey }}{{t 'inventory.labels.xref'}}{{/sortable-column}} + {{#sortable-column sortBy='crossReference' sortDesc=sortDesc sortKey=sortKey }}{{t 'inventory.labels.xref'}}{{/sortable-column}} {{#each model as |inventory|}} diff --git a/app/patients/index/template.hbs b/app/patients/index/template.hbs index cb036011e8..124f881c73 100644 --- a/app/patients/index/template.hbs +++ b/app/patients/index/template.hbs @@ -3,12 +3,12 @@
{{t 'inventory.labels.location'}}{{t 'labels.actions'}}
- {{#sortable-column sortBy='id' descending=descending sortKey=sortKey }}{{t 'labels.id'}}{{/sortable-column}} - {{#sortable-column sortBy='firstName' descending=descending sortKey=sortKey }}{{t 'patients.labels.firstName'}}{{/sortable-column}} - {{#sortable-column sortBy='lastName' descending=descending sortKey=sortKey }}{{t 'patients.labels.lastName'}}{{/sortable-column}} - {{#sortable-column sortBy='sex' descending=descending sortKey=sortKey }}{{t 'patients.labels.sex'}}{{/sortable-column}} - {{#sortable-column sortBy='dateOfBirth' descending=descending sortKey=sortKey }}{{t 'patients.labels.dob'}}{{/sortable-column}} - {{#sortable-column sortBy='status' descending=descending sortKey=sortKey }}{{t 'labels.status'}}{{/sortable-column}} + {{#sortable-column sortBy='id' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.id'}}{{/sortable-column}} + {{#sortable-column sortBy='firstName' sortDesc=sortDesc sortKey=sortKey }}{{t 'patients.labels.firstName'}}{{/sortable-column}} + {{#sortable-column sortBy='lastName' sortDesc=sortDesc sortKey=sortKey }}{{t 'patients.labels.lastName'}}{{/sortable-column}} + {{#sortable-column sortBy='sex' sortDesc=sortDesc sortKey=sortKey }}{{t 'patients.labels.sex'}}{{/sortable-column}} + {{#sortable-column sortBy='dateOfBirth' sortDesc=sortDesc sortKey=sortKey }}{{t 'patients.labels.dob'}}{{/sortable-column}} + {{#sortable-column sortBy='status' sortDesc=sortDesc sortKey=sortKey }}{{t 'labels.status'}}{{/sortable-column}} {{#if showActions}} {{/if}} diff --git a/app/routes/abstract-index-route.js b/app/routes/abstract-index-route.js index 7d7f2527df..971437c963 100644 --- a/app/routes/abstract-index-route.js +++ b/app/routes/abstract-index-route.js @@ -58,8 +58,8 @@ export default Ember.Route.extend(PouchDbMixin, ProgressDialog, AuthenticatedRou let queryParams = this._modelQueryParams(params); if (!Ember.isEmpty(params.sortKey)) { queryParams.sortKey = params.sortKey; - if (!Ember.isEmpty(params.descending)) { - queryParams.descending = params.descending; + if (!Ember.isEmpty(params.sortDesc)) { + queryParams.sortDesc = params.sortDesc; } } if (!Ember.isEmpty(filterParams)) { @@ -88,7 +88,7 @@ export default Ember.Route.extend(PouchDbMixin, ProgressDialog, AuthenticatedRou }, queryParams: { - descending: { refreshModel: true }, + sortDesc: { refreshModel: true }, sortKey: { refreshModel: true }, startKey: { refreshModel: true } }, diff --git a/app/templates/components/sortable-column.hbs b/app/templates/components/sortable-column.hbs index 258f9b0e72..df77cd44f2 100644 --- a/app/templates/components/sortable-column.hbs +++ b/app/templates/components/sortable-column.hbs @@ -1,5 +1,5 @@ {{#if sorted}} - + {{else}} {{/if}} diff --git a/app/utils/pouch-views.js b/app/utils/pouch-views.js index 0be82cd34b..086803ad45 100644 --- a/app/utils/pouch-views.js +++ b/app/utils/pouch-views.js @@ -99,7 +99,7 @@ function generateSortFunction(sortFunction, includeCompareDate, filterFunction) '}' + '}' + '}' + - 'if (req.query.descending) {' + + 'if (req.query.sortDesc) {' + 'rows = rows.reverse();' + '}' + 'if (req.query.sortLimit) {' + From d5e8ef82c8e5883cc2045cd9caf10e58857c2b9b Mon Sep 17 00:00:00 2001 From: Leo Wong Date: Fri, 14 Oct 2016 17:49:02 +0800 Subject: [PATCH 3/4] Fix the `sort` list function in couchdb design docs --- app/utils/pouch-views.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/utils/pouch-views.js b/app/utils/pouch-views.js index 086803ad45..9be7141827 100644 --- a/app/utils/pouch-views.js +++ b/app/utils/pouch-views.js @@ -90,6 +90,9 @@ function generateSortFunction(sortFunction, includeCompareDate, filterFunction) generatedFunction += 'rows = rows.filter(' + filterFunction + ');'; } generatedFunction += 'rows.sort(' + sortFunction + ');' + + 'if (req.query.sortDesc) {' + + 'rows = rows.reverse();' + + '}' + 'if (req.query.sortStartKey) {' + 'var startKey = JSON.parse(req.query.sortStartKey);' + 'for (var i=0; i 0) {' + @@ -351,7 +351,7 @@ let designDocs = [{ name: 'patient_by_display_id', function: generateView('patient', patientListingKey), sort: patientListingSearch, - version: 6 + version: 7 }, { name: 'patient_by_status', function: generateView('patient', @@ -366,7 +366,7 @@ let designDocs = [{ '}' ), sort: patientListingSearch, - version: 3 + version: 4 }, { name: 'photo_by_patient', function: generateView('photo', From df97f76f18001026d26726744dcde26c32308a9c Mon Sep 17 00:00:00 2001 From: Leo Wong Date: Fri, 14 Oct 2016 23:00:02 +0800 Subject: [PATCH 4/4] Update version of affected couchdb views https://github.com/HospitalRun/hospitalrun-frontend/pull/738#pullrequest review-4281915 --- app/utils/pouch-views.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/utils/pouch-views.js b/app/utils/pouch-views.js index 9be7141827..7756360c79 100644 --- a/app/utils/pouch-views.js +++ b/app/utils/pouch-views.js @@ -241,7 +241,7 @@ let designDocs = [{ } return includeRow; }.toString()), - version: 5 + version: 6 }, { name: 'appointments_by_patient', function: generateView('appointment', @@ -283,7 +283,7 @@ let designDocs = [{ } } }.toString()), - version: 4 + version: 5 }, { name: 'inventory_by_type', function: generateView('inventory',
{{t 'labels.actions'}}