From 7c74c77a2c529044c10a1ae607c17bc233a1f7ac Mon Sep 17 00:00:00 2001 From: azivner Date: Tue, 6 Feb 2018 21:18:09 -0500 Subject: [PATCH] allow duplicated attribute per note (in effect attributes can be multi-valued). Closes #33 --- db/migrations/0072__allow_multiple_attributes_per_note.sql | 1 + db/schema.sql | 1 - src/public/javascripts/dialogs/attributes.js | 2 +- src/routes/api/notes.js | 4 +++- src/services/app_info.js | 2 +- src/views/index.ejs | 3 +-- 6 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 db/migrations/0072__allow_multiple_attributes_per_note.sql diff --git a/db/migrations/0072__allow_multiple_attributes_per_note.sql b/db/migrations/0072__allow_multiple_attributes_per_note.sql new file mode 100644 index 000000000..9023a6ab1 --- /dev/null +++ b/db/migrations/0072__allow_multiple_attributes_per_note.sql @@ -0,0 +1 @@ +DROP INDEX IDX_attributes_noteId_name; \ No newline at end of file diff --git a/db/schema.sql b/db/schema.sql index 13df0a262..1d9f7a3fc 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -118,4 +118,3 @@ CREATE INDEX IDX_note_images_noteId ON note_images (noteId); CREATE INDEX IDX_note_images_imageId ON note_images (imageId); CREATE INDEX IDX_note_images_noteId_imageId ON note_images (noteId, imageId); CREATE INDEX IDX_attributes_noteId ON attributes (noteId); -CREATE UNIQUE INDEX IDX_attributes_noteId_name ON attributes (noteId, name); diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js index 8b6318c10..9043bb60c 100644 --- a/src/public/javascripts/dialogs/attributes.js +++ b/src/public/javascripts/dialogs/attributes.js @@ -28,7 +28,7 @@ const attributesDialog = (function() { function isValid() { for (let attrs = self.attributes(), i = 0; i < attrs.length; i++) { - if (self.isEmptyName(i) || self.isNotUnique(i)) { + if (self.isEmptyName(i)) { return false; } } diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js index 9789bc431..bb69c817b 100644 --- a/src/routes/api/notes.js +++ b/src/routes/api/notes.js @@ -62,6 +62,8 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => { const {query, params} = getSearchQuery(attrFilters, searchText); + console.log(query, params); + const noteIds = await sql.getColumn(query, params); res.send(noteIds); @@ -152,7 +154,7 @@ function getSearchQuery(attrFilters, searchText) { searchParams.push(searchText); // two occurences in searchCondition } - const query = `SELECT notes.noteId FROM notes + const query = `SELECT DISTINCT notes.noteId FROM notes ${joins.join('\r\n')} WHERE notes.isDeleted = 0 diff --git a/src/services/app_info.js b/src/services/app_info.js index ad29652a2..509dcace9 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -3,7 +3,7 @@ const build = require('./build'); const packageJson = require('../../package'); -const APP_DB_VERSION = 71; +const APP_DB_VERSION = 72; module.exports = { app_version: packageJson.version, diff --git a/src/views/index.ejs b/src/views/index.ejs index d6446ab73..88f2fde8b 100644 --- a/src/views/index.ejs +++ b/src/views/index.ejs @@ -394,8 +394,7 @@ - -
Attribute name must be unique per note.
+
Duplicate attribute.
Attribute name can't be empty.