Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] fix ordering when more than 10 fields #394

Merged
merged 2 commits into from
Apr 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/javascripts/ng-admin/es6/lib/Field/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ class Field {
}

order() {
if (arguments.length && arguments[1] !== true) {
console.warn('Setting order with Field.order is deprecated, order directly in fields array');
if (arguments.length) {
if(arguments[1] !== true) {
console.warn('Setting order with Field.order is deprecated, order directly in fields array');
}
this._order = arguments[0];
return this;
}

return this._order || 0;
return this._order;
}

isDetailLink(detailLink) {
Expand Down
14 changes: 14 additions & 0 deletions src/javascripts/ng-admin/es6/tests/lib/View/ViewTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ describe('View', function() {
assert.deepEqual(view.fields(), [field1, field2]);
});

it('should keep the default order of the given array to equal to the index even when more than 10 fields', function() {
var view = new View(new Entity('post'));
var fields = Array.from(new Array(11).keys()).map(function (i) {
return new Field(i);
});
view.fields(fields);

assert.deepEqual(view.fields(), fields);

fields.map(function (field, index) {
assert.equal(field.order(), index);
});
});

it('should add fields when called with a nested array argument', function() {
var view = new View(new Entity('post'));
var field1 = new Field('foo');
Expand Down