From 7ac109e7f7866e6f0164560c72220a3bbcc9baac Mon Sep 17 00:00:00 2001 From: azivner Date: Thu, 9 Aug 2018 20:55:16 +0200 Subject: [PATCH] fix label => attributes omissions --- .../javascripts/services/note_detail_file.js | 8 ++++---- src/services/build_search_query.js | 16 ++++++++-------- src/services/scheduler.js | 9 +++++---- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/public/javascripts/services/note_detail_file.js b/src/public/javascripts/services/note_detail_file.js index 6176538f2..9dab36d47 100644 --- a/src/public/javascripts/services/note_detail_file.js +++ b/src/public/javascripts/services/note_detail_file.js @@ -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); } diff --git a/src/services/build_search_query.js b/src/services/build_search_query.js index 84aa89f8c..cf340ac77 100644 --- a/src/services/build_search_query.js +++ b/src/services/build_search_query.js @@ -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); } } diff --git a/src/services/scheduler.js b/src/services/scheduler.js index e2f729cd9..c671278af 100644 --- a/src/services/scheduler.js +++ b/src/services/scheduler.js @@ -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]);