admin-config
Advanced tools
Comparing version 0.2.19 to 0.3.0
@@ -1,2 +0,3 @@ | ||
import Queries from './Queries' | ||
import Queries from './Queries'; | ||
import ReferenceExtractor from '../Utils/ReferenceExtractor'; | ||
@@ -119,2 +120,19 @@ class ReadQueries extends Queries { | ||
getReferenceData(references, rawValues) { | ||
var nonOptimizedReferencedData = this.getFilteredReferenceData(ReferenceExtractor.getNonOptimizedReferences(references), rawValues); | ||
var optimizedReferencedData = this.getOptimizedReferenceData(ReferenceExtractor.getOptimizedReferences(references), rawValues); | ||
return Promise.all([nonOptimizedReferencedData, optimizedReferencedData]) | ||
.then((results) => { | ||
let data = {}; | ||
let name; | ||
for (name in results[0]) { | ||
data[name] = results[0][name]; | ||
} | ||
for (name in results[1]) { | ||
data[name] = results[1][name]; | ||
} | ||
return data; | ||
}) | ||
} | ||
/** | ||
@@ -159,3 +177,3 @@ * Returns all References for an entity with associated values [{targetEntity.identifier: targetLabel}, ...] | ||
*/ | ||
getOptimizedReferencedData(references, rawValues) { | ||
getOptimizedReferenceData(references, rawValues) { | ||
if (!references || !Object.keys(references).length) { | ||
@@ -162,0 +180,0 @@ return this._promisesResolver.empty({}); |
@@ -234,3 +234,3 @@ import Entry from "../Entry"; | ||
if (typeof validation.validator === 'function') { | ||
validation.validator(entry.values[field.name()]); | ||
validation.validator(entry.values[field.name()], entry.values); | ||
} | ||
@@ -237,0 +237,0 @@ }); |
{ | ||
"name": "admin-config", | ||
"version": "0.2.19", | ||
"version": "0.3.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -222,3 +222,3 @@ let assert = require('chai').assert, | ||
readQueries.getOptimizedReferencedData(post.views["ListView"].getReferences(), rawPosts) | ||
readQueries.getOptimizedReferenceData(post.views["ListView"].getReferences(), rawPosts) | ||
.then((referencedData) => { | ||
@@ -225,0 +225,0 @@ assert.equal(referencedData['author'].length, 2); |
@@ -215,2 +215,45 @@ var assert = require('chai').assert; | ||
}); | ||
it('should call validator with the targeted field as first parameter', function (done) { | ||
var entry = new Entry(), | ||
view = new View('myView'), | ||
field1 = new Field('field1').label('field1'); | ||
entry.values = { | ||
field1: "field1_value", | ||
}; | ||
view.addField(field1); | ||
field1.validation().validator = function (value) { | ||
assert.equal("field1_value", value); | ||
done(); | ||
}; | ||
view.validate(entry); | ||
}); | ||
it('should call validator with the all other fields as second parameter', function (done) { | ||
var entry = new Entry(), | ||
view = new View('myView'), | ||
field1 = new Field('field1').label('field1'), | ||
field2 = new Field('field2').label('field2'); | ||
entry.values = { | ||
field1: "field1_value", | ||
field2: "field2_value", | ||
}; | ||
view.addField(field1).addField(field2); | ||
field1.validation().validator = function (value, all) { | ||
assert.deepEqual({ | ||
field1: "field1_value", | ||
field2: "field2_value", | ||
}, all); | ||
done(); | ||
}; | ||
view.validate(entry); | ||
}); | ||
}); | ||
@@ -217,0 +260,0 @@ |
166343
4241