fix label => attributes omissions

This commit is contained in:
azivner 2018-08-09 20:55:16 +02:00
parent ac25770c0e
commit 7ac109e7f7
3 changed files with 17 additions and 16 deletions

View File

@ -14,13 +14,13 @@ const $fileOpen = $("#file-open");
async function show() {
const currentNote = noteDetailService.getCurrentNote();
const labels = await server.get('notes/' + currentNote.noteId + '/labels');
const labelMap = utils.toObject(labels, l => [l.name, l.value]);
const attributes = await server.get('notes/' + currentNote.noteId + '/attributes');
const attributeMap = utils.toObject(attributes, l => [l.name, l.value]);
$noteDetailFile.show();
$fileFileName.text(labelMap.original_file_name);
$fileFileSize.text(labelMap.file_size + " bytes");
$fileFileName.text(attributeMap.original_file_name);
$fileFileSize.text(attributeMap.file_size + " bytes");
$fileFileType.text(currentNote.mime);
}

View File

@ -1,4 +1,4 @@
module.exports = function(labelFilters) {
module.exports = function(attributeFilters) {
const joins = [];
const joinParams = [];
let where = '1';
@ -6,31 +6,31 @@ module.exports = function(labelFilters) {
let i = 1;
for (const filter of labelFilters) {
joins.push(`LEFT JOIN labels AS label${i} ON label${i}.noteId = notes.noteId AND label${i}.name = ?`);
for (const filter of attributeFilters) {
joins.push(`LEFT JOIN attributes AS attribute${i} ON attribute${i}.noteId = notes.noteId AND attribute${i}.name = ?`);
joinParams.push(filter.name);
where += " " + filter.relation + " ";
if (filter.operator === 'exists') {
where += `label${i}.labelId IS NOT NULL`;
where += `attribute${i}.attributeId IS NOT NULL`;
}
else if (filter.operator === 'not-exists') {
where += `label${i}.labelId IS NULL`;
where += `attribute${i}.attributeId IS NULL`;
}
else if (filter.operator === '=' || filter.operator === '!=') {
where += `label${i}.value ${filter.operator} ?`;
where += `attribute${i}.value ${filter.operator} ?`;
whereParams.push(filter.value);
}
else if ([">", ">=", "<", "<="].includes(filter.operator)) {
const floatParam = parseFloat(filter.value);
if (isNaN(floatParam)) {
where += `label${i}.value ${filter.operator} ?`;
where += `attribute${i}.value ${filter.operator} ?`;
whereParams.push(filter.value);
}
else {
where += `CAST(label${i}.value AS DECIMAL) ${filter.operator} ?`;
where += `CAST(attribute${i}.value AS DECIMAL) ${filter.operator} ?`;
whereParams.push(floatParam);
}
}

View File

@ -7,10 +7,11 @@ async function runNotesWithLabel(runAttrValue) {
const notes = await repository.getEntities(`
SELECT notes.*
FROM notes
JOIN labels ON labels.noteId = notes.noteId
AND labels.isDeleted = 0
AND labels.name = 'run'
AND labels.value = ?
JOIN attributes ON attributes.noteId = notes.noteId
AND attributes.isDeleted = 0
AND attributes.type = 'label'
AND attributes.name = 'run'
AND attributes.value = ?
WHERE
notes.type = 'code'
AND notes.isDeleted = 0`, [runAttrValue]);