From 809c01e647ee672ae1aa28407dba1b032283b5da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Sat, 30 May 2015 01:19:24 +0200 Subject: [PATCH 1/2] Fix sort for ReferenceListField and dashboard --- examples/blog/config.js | 7 +++++-- .../Crud/fieldView/ReferencedListFieldView.js | 4 ++-- .../Main/component/controller/DashboardController.js | 7 ++++++- .../ng-admin/Main/component/service/PanelBuilder.js | 12 ++++++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/examples/blog/config.js b/examples/blog/config.js index 757ce99b..e21cd6d4 100644 --- a/examples/blog/config.js +++ b/examples/blog/config.js @@ -64,6 +64,7 @@ // customize entities and views post.dashboardView() // customize the dashboard panel for this entity + .name('posts') .title('Recent posts') .order(1) // display the post panel first in the dashboard .perPage(5) // limit the panel to the 5 latest posts @@ -128,9 +129,11 @@ .targetEntity(comment) .targetReferenceField('post_id') .targetFields([ - nga.field('id'), + nga.field('created_at').label('Posted'), nga.field('body').label('Comment') - ]), + ]) + .sortField('created_at') + .sortDir('DESC'), nga.field('', 'template').label('') .template('') ]); diff --git a/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js b/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js index 3e2777b8..775f8dbb 100644 --- a/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js +++ b/src/javascripts/ng-admin/Crud/fieldView/ReferencedListFieldView.js @@ -7,7 +7,7 @@ define(function(require) { 'fields="::field.targetFields()" ' + 'list-actions="::field.listActions()" ' + 'entity="::field.targetEntity()" ' + - 'sort-field="::field.sortField()" ' + + 'sort-field="::field.getSortFieldName()" ' + 'sort-dir="::field.sortDir()">' + ''; } @@ -23,7 +23,7 @@ define(function(require) { 'fields="::field.targetFields()" ' + 'list-actions="::field.listActions()" ' + 'entity="::field.targetEntity()" ' + - 'sort-field="::field.sortField()" ' + + 'sort-field="::field.getSortFieldName()" ' + 'sort-dir="::field.sortDir()">' + ''; } diff --git a/src/javascripts/ng-admin/Main/component/controller/DashboardController.js b/src/javascripts/ng-admin/Main/component/controller/DashboardController.js index 281a2af4..7f98473b 100644 --- a/src/javascripts/ng-admin/Main/component/controller/DashboardController.js +++ b/src/javascripts/ng-admin/Main/component/controller/DashboardController.js @@ -16,6 +16,11 @@ define(function (require) { this.PanelBuilder = PanelBuilder; this.$scope.edit = this.edit.bind(this); + + var searchParams = this.$location.search(); + this.sortField = 'sortField' in searchParams ? searchParams.sortField : null; + this.sortDir = 'sortDir' in searchParams ? searchParams.sortDir : null; + this.retrievePanels(); $scope.$on('$destroy', this.destroy.bind(this)); @@ -28,7 +33,7 @@ define(function (require) { var self = this; this.panels = []; - this.PanelBuilder.getPanelsData().then(function (panels) { + this.PanelBuilder.getPanelsData(this.sortField, this.sortDir).then(function (panels) { self.panels = panels; }); }; diff --git a/src/javascripts/ng-admin/Main/component/service/PanelBuilder.js b/src/javascripts/ng-admin/Main/component/service/PanelBuilder.js index 06c451d8..f7bc5962 100644 --- a/src/javascripts/ng-admin/Main/component/service/PanelBuilder.js +++ b/src/javascripts/ng-admin/Main/component/service/PanelBuilder.js @@ -20,17 +20,25 @@ function PanelBuilder($q, $location, ReadQueries, Configuration, AdminDescriptio * * @returns {promise} */ -PanelBuilder.prototype.getPanelsData = function () { +PanelBuilder.prototype.getPanelsData = function (sortField, sortDir) { var dashboardViews = this.Configuration.getViewsOfType('DashboardView'), dataStore = this.dataStore, promises = [], dashboardView, + dashboardSortField, + dashboardSortDir, self = this, i; for (i in dashboardViews) { dashboardView = dashboardViews[i]; - promises.push(self.ReadQueries.getAll(dashboardView, 1, {}, dashboardView.getSortFieldName(), dashboardView.sortDir())); + dashboardSortField = dashboardView.getSortFieldName(); + dashboardSortDir = dashboardView.sortDir(); + if (sortField && sortField.split('.')[0] === dashboardView.name()) { + dashboardSortField = sortField; + dashboardSortDir = sortDir; + } + promises.push(self.ReadQueries.getAll(dashboardView, 1, {}, dashboardSortField, dashboardSortDir)); } return this.$q.all(promises).then(function (responses) { From 14ee18829254fabd2c56dbd58f70a444ebec09ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Macias?= Date: Mon, 1 Jun 2015 10:38:51 +0200 Subject: [PATCH 2/2] Fix e2e tests for ShowView --- src/javascripts/test/e2e/ShowViewSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/javascripts/test/e2e/ShowViewSpec.js b/src/javascripts/test/e2e/ShowViewSpec.js index 4890a6a6..a0c74258 100644 --- a/src/javascripts/test/e2e/ShowViewSpec.js +++ b/src/javascripts/test/e2e/ShowViewSpec.js @@ -28,7 +28,7 @@ describe('ShowView', function () { $$('.ng-admin-field-comments th').then(function (inputs) { expect(inputs.length).toBe(2); - expect(inputs[0].getAttribute('class')).toBe('ng-scope ng-admin-column-id'); + expect(inputs[0].getAttribute('class')).toBe('ng-scope ng-admin-column-created_at'); expect(inputs[1].getAttribute('class')).toBe('ng-scope ng-admin-column-body'); }); });