diff --git a/src/public/app/widgets/note_attributes.js b/src/public/app/widgets/note_attributes.js index 5af12943f..c71e4daf4 100644 --- a/src/public/app/widgets/note_attributes.js +++ b/src/public/app/widgets/note_attributes.js @@ -93,12 +93,18 @@ const TPL = ` max-height: 500px; overflow: auto; } + +.attr-extras-list { + padding-left: 20px; + margin-top: 10px; + margin-bottom: 10px; +}
@@ -117,6 +123,8 @@ export default class NoteAttributesWidget extends TabAwareWidget { const content = this.textEditor.getData(); this.parse(content); + + this.$attrExtras.hide(); }); } @@ -129,16 +137,19 @@ export default class NoteAttributesWidget extends TabAwareWidget { this.$attrExtrasMoreNotes = this.$widget.find('.attr-extras-more-notes'); this.initialized = this.initEditor(); - this.$editor.keypress(async e => { + this.$editor.on('keydown', async e => { const keycode = (e.keyCode ? e.keyCode : e.which); + if (keycode === 13) { const attributes = attributesParser.lexAndParse(this.textEditor.getData()); await server.put(`notes/${this.noteId}/attributes2`, attributes, this.componentId); - - console.log("Saved!"); } - }) + + this.$attrExtras.hide(); + }); + + this.$editor.on('blur', () => this.$attrExtras.hide()); return this.$widget; } @@ -178,20 +189,26 @@ export default class NoteAttributesWidget extends TabAwareWidget { } if (!matchedAttr) { - console.log(`Not found attribute for index ${clickIndex}, attr: ${JSON.stringify(parsedAttrs)}, text: ${attrText}`); + this.$attrExtras.hide(); return; } - let noteIds = await server.post('attributes/notes-with-attribute', { + const searchString = this.formatAttrForSearch(matchedAttr); + + let {count, results} = await server.get('search/' + encodeURIComponent(searchString), { type: matchedAttr.type, name: matchedAttr.name, value: matchedPart === 'value' ? matchedAttr.value : undefined }); - noteIds = noteIds.filter(noteId => noteId !== this.noteId); + for (const res of results) { + res.noteId = res.notePathArray[res.notePathArray.length - 1]; + } - if (noteIds.length === 0) { + results = results.filter(({noteId}) => noteId !== this.noteId); + + if (results.length === 0) { this.$attrExtrasTitle.text( `There are no other notes with ${matchedAttr.type} name "${matchedAttr.name}"` // not displaying value since it can be long @@ -208,9 +225,9 @@ export default class NoteAttributesWidget extends TabAwareWidget { this.$attrExtrasList.empty(); - const displayedNoteIds = noteIds.length <= DISPLAYED_NOTES ? noteIds : noteIds.slice(0, DISPLAYED_NOTES); - const displayedNotes = await treeCache.getNotes(displayedNoteIds); -console.log(displayedNoteIds, displayedNotes); + const displayedResults = results.length <= DISPLAYED_NOTES ? results : results.slice(0, DISPLAYED_NOTES); + const displayedNotes = await treeCache.getNotes(displayedResults.map(res => res.noteId)); + for (const note of displayedNotes) { const notePath = treeService.getSomeNotePath(note); const $noteLink = await linkService.createNoteLink(notePath, {showNotePath: true}); @@ -220,15 +237,15 @@ console.log(displayedNoteIds, displayedNotes); ); } - if (noteIds.length > DISPLAYED_NOTES) { - this.$attrExtrasMoreNotes.show().text(`... and ${noteIds.length - DISPLAYED_NOTES} more.`); + if (results.length > DISPLAYED_NOTES) { + this.$attrExtrasMoreNotes.show().text(`... and ${count - DISPLAYED_NOTES} more.`); } else { this.$attrExtrasMoreNotes.hide(); } this.$attrExtras.css("left", e.pageX - this.$attrExtras.width() / 2); - this.$attrExtras.css("top", e.pageY + 20); + this.$attrExtras.css("top", e.pageY + 30); this.$attrExtras.show(); } }); @@ -315,7 +332,7 @@ console.log(displayedNoteIds, displayedNotes); const $attributesContainer = $("')) { content = content.substr(3); diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.js index edcf8874d..010e074c6 100644 --- a/src/public/app/widgets/note_title.js +++ b/src/public/app/widgets/note_title.js @@ -46,7 +46,7 @@ export default class NoteTitleWidget extends TabAwareWidget { this.$noteTitle.on('input', () => this.spacedUpdate.scheduleUpdate()); utils.bindElShortcut(this.$noteTitle, 'return', () => { - this.triggerCommand('focusOnDetail', {tabId: this.tabContext.tabId}); + this.triggerCommand('focusOnAttributes', {tabId: this.tabContext.tabId}); }); return this.$widget; diff --git a/src/routes/api/attributes.js b/src/routes/api/attributes.js index c5988d210..4f6baa4b6 100644 --- a/src/routes/api/attributes.js +++ b/src/routes/api/attributes.js @@ -258,14 +258,6 @@ async function deleteRelation(req) { } } -async function getNotesWithAttribute(req) { - const {type, name, value} = req.body; - - const notes = await attributeService.getNotesWithAttribute(type, name, value); - - return notes.map(note => note.noteId); -} - module.exports = { updateNoteAttributes, updateNoteAttributes2, @@ -275,6 +267,5 @@ module.exports = { getValuesForAttribute, getEffectiveNoteAttributes, createRelation, - deleteRelation, - getNotesWithAttribute + deleteRelation }; diff --git a/src/routes/api/search.js b/src/routes/api/search.js index 1bbbfbc40..89068c5f2 100644 --- a/src/routes/api/search.js +++ b/src/routes/api/search.js @@ -7,12 +7,13 @@ const scriptService = require('../../services/script'); const searchService = require('../../services/search/search'); async function searchNotes(req) { - const notePaths = await searchService.searchNotes(req.params.searchString); + const {count, results} = await searchService.searchNotes(req.params.searchString); try { return { success: true, - results: notePaths + count, + results } } catch { diff --git a/src/routes/routes.js b/src/routes/routes.js index 3748b01e2..7f202f1dc 100644 --- a/src/routes/routes.js +++ b/src/routes/routes.js @@ -177,7 +177,6 @@ function register(app) { apiRoute(DELETE, '/api/notes/:noteId/attributes/:attributeId', attributesRoute.deleteNoteAttribute); apiRoute(GET, '/api/attributes/names', attributesRoute.getAttributeNames); apiRoute(GET, '/api/attributes/values/:attributeName', attributesRoute.getValuesForAttribute); - apiRoute(POST, '/api/attributes/notes-with-attribute', attributesRoute.getNotesWithAttribute); apiRoute(POST, '/api/notes/:noteId/link-map', linkMapRoute.getLinkMap); diff --git a/src/services/attributes.js b/src/services/attributes.js index 0f8fcd783..571f9e332 100644 --- a/src/services/attributes.js +++ b/src/services/attributes.js @@ -41,27 +41,6 @@ const BUILTIN_ATTRIBUTES = [ { type: 'relation', name: 'renderNote', isDangerous: true } ]; -async function getNotesWithAttribute(type, name, value) { - let valueCondition = ""; - let params = [type, name]; - - if (value !== undefined) { - valueCondition = " AND attributes.value = ?"; - params.push(value); - } - - return await repository.getEntities(` - SELECT notes.* - FROM notes - JOIN attributes USING (noteId) - WHERE notes.isDeleted = 0 - AND attributes.isDeleted = 0 - AND attributes.type = ? - AND attributes.name = ? - ${valueCondition} - ORDER BY position`, params); -} - async function getNotesWithLabel(name, value) { let valueCondition = ""; let params = [name]; @@ -155,7 +134,6 @@ function getBuiltinAttributeNames() { } module.exports = { - getNotesWithAttribute, getNotesWithLabel, getNotesWithLabels, getNoteWithLabel, diff --git a/src/services/search/search.js b/src/services/search/search.js index 1e7437b58..c2302f619 100644 --- a/src/services/search/search.js +++ b/src/services/search/search.js @@ -87,11 +87,13 @@ async function searchNotes(query) { fuzzyAttributeSearch: false }); - let searchResults = await findNotesWithQuery(query, parsingContext); + const allSearchResults = await findNotesWithQuery(query, parsingContext); + const trimmedSearchResults = allSearchResults.slice(0, 200); - searchResults = searchResults.slice(0, 200); - - return searchResults; + return { + count: allSearchResults.length, + results: trimmedSearchResults + }; } async function searchNotesForAutocomplete(query) {