fixed some incorrect order by behavior, #1881

This commit is contained in:
zadam 2021-04-22 20:28:26 +02:00
parent 02988ed2b3
commit b5674223e5
6 changed files with 45 additions and 7 deletions

View File

@ -317,7 +317,9 @@ class NoteListRenderer {
const $expander = $('<span class="note-expander bx bx-chevron-right"></span>');
const {$renderedAttributes} = await attributeRenderer.renderNormalAttributes(note);
const notePath = this.parentNote.noteId + '/' + note.noteId;
const notePath = this.parentNote.type === 'search'
? note.noteId // for search note parent we want to display non-search path
: this.parentNote.noteId + '/' + note.noteId;
const $card = $('<div class="note-book-card">')
.attr('data-note-id', note.noteId)

View File

@ -1,6 +1,7 @@
"use strict";
const Expression = require('./expression');
const TrueExp = require("./true.js");
class AndExp extends Expression {
static of(subExpressions) {
@ -10,6 +11,8 @@ class AndExp extends Expression {
return subExpressions[0];
} else if (subExpressions.length > 0) {
return new AndExp(subExpressions);
} else {
return new TrueExp();
}
}

View File

@ -2,6 +2,7 @@
const Expression = require('./expression');
const NoteSet = require('../note_set');
const TrueExp = require("./true");
class OrExp extends Expression {
static of(subExpressions) {
@ -13,6 +14,9 @@ class OrExp extends Expression {
else if (subExpressions.length > 0) {
return new OrExp(subExpressions);
}
else {
return new TrueExp();
}
}
constructor(subExpressions) {

View File

@ -28,17 +28,33 @@ class OrderByAndLimitExp extends Expression {
let valA = valueExtractor.extract(a);
let valB = valueExtractor.extract(b);
if (!isNaN(valA) && !isNaN(valB)) {
if (valA === null && valB === null) {
// neither has attribute at all
continue;
}
else if (valB === null) {
return smaller;
}
else if (valA === null) {
return larger;
}
// if both are numbers then parse them for numerical comparison
// beware that isNaN will return false for empty string and null
if (valA.trim() !== "" && valB.trim() !== "" && !isNaN(valA) && !isNaN(valB)) {
valA = parseFloat(valA);
valB = parseFloat(valB);
}
if (valA < valB) {
if (!valA && !valB) {
// the attribute is not defined in either note so continue to next order definition
continue;
} else if (!valB || valA < valB) {
return smaller;
} else if (valA > valB) {
} else if (!valA || valA > valB) {
return larger;
}
// else go to next order definition
// else the values are equal and continue to next order definition
}
return 0;

View File

@ -0,0 +1,11 @@
"use strict";
const Expression = require('./expression');
class TrueExp extends Expression {
execute(inputNoteSet, executionContext) {
return inputNoteSet;
}
}
module.exports = TrueExp;

View File

@ -329,6 +329,9 @@ function getExpression(tokens, searchContext, level = 0) {
else if (op === 'or') {
return OrExp.of(expressions);
}
else {
throw new Error(`Unrecognized op=${op}`);
}
}
for (i = 0; i < tokens.length; i++) {
@ -358,8 +361,7 @@ function getExpression(tokens, searchContext, level = 0) {
continue;
}
exp.subExpression = getAggregateExpression();
exp.subExpression = getAggregateExpression();console.log(exp);
return exp;
}
else if (token === 'not') {