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 exportfields config #381

Merged
merged 3 commits into from
Apr 7, 2015
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion build/ng-admin.min.css

Large diffs are not rendered by default.

38 changes: 18 additions & 20 deletions build/ng-admin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/ng-admin.min.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/javascripts/ng-admin/Crud/misc/EntryFormater.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ define(function () {
}

EntryFormatter.prototype.formatField = function formatField(field) {
var label = field.label() || filed.name();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

switch (field.type()) {
case 'number':
case 'text':
Expand All @@ -20,13 +21,13 @@ define(function () {
case 'choices':
case 'file':
case 'template':
return { label: field.label(), name: field.name(), type: 'field' };
return { label: label, name: field.name(), type: 'field' };
case 'reference':
return { label: field.label(), name: field.name(), type: 'reference' };
return { label: label, name: field.name(), type: 'reference' };
case 'referenced_list':
return; //ignored
}
}
};

EntryFormatter.prototype.getFormatter = function getFormatter(fields) {
var formattedFields = fields.map(this.formatField);
Expand Down
15 changes: 15 additions & 0 deletions src/javascripts/ng-admin/es6/lib/Utils/fieldsUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
/**
* Convert fieldsLiteral as returned by fields methods to an array of field sorted by their order
*/
fieldsLiteralToArray: function (fieldsLiteral) {
var array = Object.keys(fieldsLiteral).map(function (key) {
return fieldsLiteral[key];
})
.sort(function (a, b) {
return a.order() - b.order();
});

return array;
}
};
6 changes: 4 additions & 2 deletions src/javascripts/ng-admin/es6/lib/View/ListView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import View from './View';
import fieldsUtils from '../Utils/fieldsUtils';

class ListView extends View {
constructor(name) {
Expand Down Expand Up @@ -101,10 +102,11 @@ class ListView extends View {

exportFields() {
if (!arguments.length) {
return this._exportFields.length == 0 ? this._fields : this._exportFields;
return this._exportFields.length === 0 ? this._fields : this._exportFields;
}
var fields = fieldsUtils.fieldsLiteralToArray(arguments[0]);

this._exportFields = arguments[0];
this._exportFields = fields;

return this;
}
Expand Down
44 changes: 44 additions & 0 deletions src/javascripts/ng-admin/es6/tests/lib/Utils/fieldsUtilsTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var assert = require('chai').assert;

import fieldsUtils from "../../../lib/Utils/fieldsUtils";
import Field from "../../../lib/Field/Field";

describe('fieldsUtils', function() {
describe('fieldsLiteralToArray', function() {

it('should convert fields in literal form to array', function() {
var a = new Field('a');
var b = new Field('b');
var c = new Field('c');
var fields = {
a: a,
b: b,
c: c
}

assert.deepEqual(fieldsUtils.fieldsLiteralToArray(fields), [a, b, c]);
});

it('should sort array using order if specified', function() {
var a = new Field('a').order(3);
var b = new Field('b').order(2);
var c = new Field('c').order(1);
var fields = {
a: a,
b: b,
c: c,
}

assert.deepEqual(fieldsUtils.fieldsLiteralToArray(fields), [c, b, a]);
});

it('should return an array if given an array', function() {
var a = new Field('a').order(3);
var b = new Field('b').order(2);
var c = new Field('c').order(1);
var fields = [a,b,c];

assert.deepEqual(fieldsUtils.fieldsLiteralToArray(fields), [c, b, a]);
});
});
});