admin-config
Advanced tools
Comparing version 0.7.1 to 0.8.0
@@ -70,3 +70,3 @@ import {clone, cloneAndFlatten, cloneAndNest} from './Utils/objectProperties'; | ||
if (fieldName in restEntry) { | ||
restEntry[fieldName] = field.getTransformedValue(restEntry[fieldName]) | ||
restEntry[fieldName] = field.getTransformedValue(restEntry[fieldName], restEntry) | ||
} | ||
@@ -73,0 +73,0 @@ }); |
@@ -8,9 +8,20 @@ import ChoiceField from "./ChoiceField"; | ||
this._choices = [ | ||
{ value: null, label: 'undefined' }, | ||
{ value: true, label: 'true' }, | ||
{ value: null, label: 'undefined' }, | ||
{ value: true, label: 'true' }, | ||
{ value: false, label: 'false' } | ||
]; | ||
this._filterChoices = [ | ||
{ value: true, label: 'true' }, | ||
{ value: false, label: 'false' } | ||
]; | ||
} | ||
filterChoices(filterChoices) { | ||
if (!arguments.length) return this._filterChoices; | ||
this._filterChoices = filterChoices; | ||
return this; | ||
} | ||
} | ||
export default BooleanField; |
@@ -71,7 +71,9 @@ function isObject(value) { | ||
name.split('.').reduce((previous, current, index, list) => { | ||
if (typeof previous[current] === 'undefined') previous[current] = {}; | ||
if (index < (list.length - 1)) { | ||
return previous[current]; | ||
}; | ||
previous[current] = object[name]; | ||
if (previous != null) { | ||
if (typeof previous[current] === 'undefined') previous[current] = {}; | ||
if (index < (list.length - 1)) { | ||
return previous[current]; | ||
}; | ||
previous[current] = object[name]; | ||
} | ||
}, values) | ||
@@ -78,0 +80,0 @@ return values; |
@@ -16,2 +16,3 @@ import View from './View'; | ||
this._exportFields = null; | ||
this._entryCssClasses = null; | ||
@@ -168,4 +169,29 @@ this._sortField = 'id'; | ||
entryCssClasses(classes) { | ||
if (!arguments.length) { | ||
return this._entryCssClasses; | ||
} | ||
this._entryCssClasses = classes; | ||
return this; | ||
} | ||
getEntryCssClasses(entry) { | ||
if (!this._entryCssClasses) { | ||
return ''; | ||
} | ||
if (this._entryCssClasses.constructor === Array) { | ||
return this._entryCssClasses.join(' '); | ||
} | ||
if (typeof(this._entryCssClasses) === 'function') { | ||
return this._entryCssClasses(entry); | ||
} | ||
return this._entryCssClasses; | ||
} | ||
} | ||
export default ListView; |
{ | ||
"name": "admin-config", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -112,2 +112,18 @@ var assert = require('chai').assert; | ||
}); | ||
describe('transformToRest()', function() { | ||
it('should provide both the value and entry when invoking the callback', () => { | ||
var field = new Field('foo'); | ||
field.defaultValue(2); | ||
var entry = Entry.createForFields([field]); | ||
field.transform((value, entry) => { | ||
assert.equal(value, 2); | ||
assert.deepEqual(entry, {foo: 2}); | ||
}); | ||
entry.transformToRest([field]); | ||
}); | ||
}); | ||
}); |
@@ -155,3 +155,2 @@ var assert = require('chai').assert; | ||
}); | ||
}); |
@@ -63,2 +63,6 @@ const assert = require('chai').assert; | ||
); | ||
it('should not error on null nested objects', () => | ||
assert.deepEqual(cloneAndNest({ a: null, 'a.b': null }), | ||
{ a: null }) | ||
); | ||
}); |
@@ -6,2 +6,3 @@ /* global describe,it */ | ||
import Entity from '../../../lib/Entity/Entity'; | ||
import Entry from '../../../lib/Entry'; | ||
import Field from '../../../lib/Field/Field'; | ||
@@ -97,2 +98,35 @@ import ReferenceField from '../../../lib/Field/ReferenceField'; | ||
}); | ||
describe('getEntryCssClasses', function() { | ||
var view; | ||
beforeEach(function() { | ||
view = new ListView(new Entity('post')); | ||
}); | ||
it('should return result of callback called with entry if function', function() { | ||
view.entryCssClasses(entry => entry.values.id % 2 ? "odd-entry" : "even-entry"); | ||
var entry = new Entry('post', { id: 1 }); | ||
assert.equal("odd-entry", view.getEntryCssClasses(entry)); | ||
entry = new Entry('post', { id: 2 }); | ||
assert.equal("even-entry", view.getEntryCssClasses(entry)); | ||
}); | ||
it('should concatenate all elements if array', function() { | ||
view.entryCssClasses(["important", "approved"]); | ||
assert.equal("important approved", view.getEntryCssClasses()); | ||
}); | ||
it('should return passed classes if neither function nor array', function() { | ||
view.entryCssClasses("important approved"); | ||
assert.equal("important approved", view.getEntryCssClasses()); | ||
}); | ||
it('should return an empty string by default', function() { | ||
assert.equal(view.getEntryCssClasses(), ''); | ||
}); | ||
}); | ||
}); |
252208
74
4733