added random ordering

This commit is contained in:
zadam 2021-04-22 19:53:11 +02:00
parent c5b0c60797
commit 02988ed2b3
2 changed files with 5 additions and 1 deletions

View file

@ -21,6 +21,7 @@ const TPL = `
<option value="ownedLabelCount">Number of labels</option>
<option value="ownedRelationCount">Number of relations</option>
<option value="targetRelationCount">Number of relations targeting the note</option>
<option value="random">Random order</option>
</select>
<select name="orderDirection" class="form-control w-auto d-inline">

View file

@ -69,7 +69,7 @@ class ValueExtractor {
i++;
}
else if (pathEl in PROP_MAPPING) {
else if (pathEl in PROP_MAPPING || pathEl === 'random') {
if (i !== this.propertyPath.length - 1) {
return `${pathEl} is a terminal property specifier and must be at the end`;
}
@ -113,6 +113,9 @@ class ValueExtractor {
else if (cur() === 'children') {
cursor = cursor.children[0];
}
else if (cur() === 'random') {
return Math.random();
}
else if (cur() in PROP_MAPPING) {
return cursor[PROP_MAPPING[cur()]];
}