Skip to content

Commit

Permalink
Fix sort for ReferenceListField and dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromemacias committed May 29, 2015
1 parent a87124a commit 2937ca7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
7 changes: 5 additions & 2 deletions examples/blog/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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('<span class="pull-right"><ma-filtered-list-button entity-name="comments" filter="{ post_id: entry.values.id }" size="sm"></ma-filtered-list-button></span>')
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()">' +
'</ma-datagrid>';
}
Expand All @@ -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()">' +
'</ma-datagrid>';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
});
};
Expand Down
12 changes: 10 additions & 2 deletions src/javascripts/ng-admin/Main/component/service/PanelBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2937ca7

Please sign in to comment.