diff --git a/client/src/components/NoteInputPanel.vue b/client/src/components/NoteInputPanel.vue index 606a44e..7a1b21b 100644 --- a/client/src/components/NoteInputPanel.vue +++ b/client/src/components/NoteInputPanel.vue @@ -85,7 +85,7 @@ -
+
Archived Notes

Shared Notes

- +

Tags

@@ -61,72 +61,33 @@
-

No notes found. Check your spelling, try completing the word or using a different phrase.

No Notes Yet. Create one when you feel ready.

- - -
- -
- -

Pinned

+ +
+

{{ sectionData[index][1] }}

+
- -
- -

Notes

-
- -
-
- - -
-

Found in Text ({{containsTextResults}})

-
- -
-
-
@@ -206,14 +167,22 @@ foundAttachments: [], + sectionData: { + 'pinned': ['thumbtack', 'Pinned'], + 'archived': ['archive', 'Archived'], + 'shared': ['envelope outline', 'Received Notes'], + 'sent': ['paper plane outline', 'Shared Notes'], + 'notes': ['file','Notes'], + 'highlights': ['paragraph', 'Found In Text'] + }, noteSections: { - 'pinned': {}, - 'archived': {}, - 'recieved': {}, - 'sent':{}, - 'notes':{}, - 'textMatch':{} - } + pinned: [], + archived: [], + shared:[], + sent:[], + notes: [], + highlights: [], + }, } }, @@ -232,18 +201,18 @@ } }) + this.$bus.$on('note_deleted', (noteId) => { //Remove deleted note from set, its deleted - this.notes.forEach( (note, index) => { - if(note.id == noteId){ - if(note.pinned == 1){ - this.containsPinnednotes-- - } else { - this.containsNormalNotes-- + Object.keys(this.noteSections).forEach( key => { + this.noteSections[key].forEach( (note, index) => { + if(note.id == noteId){ + this.noteSections[key].splice(index,1) + return } - this.notes.splice(index, 1) - } + }) }) + }) this.$bus.$on('update_fast_filters', newFilter => { this.fastFilters = newFilter @@ -403,8 +372,6 @@ //Determine percentage down the page const percentageDown = Math.round( (bottomOfWindow/offsetHeight)*100 ) - - // console.log( percentageDown + '%' ) //If greater than 80 of the way down the page, load the next batch if(percentageDown >= 80){ @@ -444,7 +411,6 @@ //@TODO - set a timeout on this like 2 minutes or just dont do shit and update it via socket.io //If user leaves page then returns to page, reload the first batch if(this.lastVisibilityState == 'hidden' && document.visibilityState == 'visible'){ - // console.log('Welcome back. Reloading a batch') //Load initial batch, then tags, then other batch this.search(false, this.firstLoadBatchSize) .then( () => { @@ -475,53 +441,52 @@ let foundNote = false if(newNote === undefined){ - console.log('Note not visible on this page') return } - //Go through each note and find the one just updated - this.notes.forEach( (note,index) => { + //Find Just updated note and modify all its attributes + Object.keys(this.noteSections).forEach(key => { - if(note.id == noteId){ - foundNote = true + this.noteSections[key].forEach( (note,index) => { + + if(note.id == noteId){ + foundNote = true + + //Don't move notes that were not changed + if(note.updated == newNote.updated){ + return + } + + //Compare note tags, if they changed, reload tags + if(newNote.tag_count != note.tag_count){ + this.fetchUserTags() + } + + //go through each prop and update it with new values + Object.keys(newNote).forEach(prop => { + note[prop] = newNote[prop] + }) + + //Remove note from location and push to front + this.noteSections[key].splice(index, 1) + this.noteSections[key].unshift(note) - //Don't move notes that were not changed - if(note.updated == newNote.updated){ return } - - //Compare note tags, if they changed, reload tags - if(newNote.tag_count != note.tag_count){ - console.log('Tags changed, update those bitches') - this.fetchUserTags() - } - - //go through each prop and update it with new values - Object.keys(newNote).forEach(prop => { - note[prop] = newNote[prop] - }) - - this.notes.splice(index, 1) - this.notes.unshift(note) - } + }) }) - //This note was not found, update it in list - if(foundNote == false){ - if(newNote.pinned == 1){ - this.containsPinnednotes++ - } else { - this.containsNormalNotes++ - } - this.notes.unshift(newNote) + //New notes don't exist in list, push them to the front + if(!foundNote){ + this.noteSections.notes.unshift(newNote) } + //Trigger section rebuild + this.rebuildNoteCategorise() }) }, searchAttachments(){ axios.post('/api/attachment/textsearch', {'searchTerm':this.searchTerm}) .then(results => { - console.log('Attachment Results') - console.log(results.data) this.foundAttachments = results.data }) }, @@ -549,10 +514,6 @@ fastFilters: this.fastFilters, } - if(showLoading){ - this.working = true - } - //Save initial post data on first load if(this.initialPostData == null){ this.initialPostData = JSON.stringify(postData) @@ -570,8 +531,8 @@ //Perform search - or die this.loadingInProgress = true - axios.post('/api/note/search', postData). - then(response => { + axios.post('/api/note/search', postData) + .then(response => { //Save the number of notes just loaded this.batchOffset += response.data.notes.length @@ -581,49 +542,62 @@ this.commonTags = response.data.tags } - //Either reload all notes with return data or merge return data - if(!mergeExisting){ - this.notes = response.data.notes - } else { - this.notes = this.notes.concat(response.data.notes) - } - - //Go through each note and see which section to display - let textResultsCount = 0 - let pinnedResultsCount = 0 - let normalNotesCount = 0 - response.data.notes.forEach(note => { - - if(note.note_highlights.length > 0){ - textResultsCount++ - return - } - - if(note.pinned == 1){ - pinnedResultsCount++ - return - } - - normalNotesCount++ - }) - - if(!mergeExisting){ - this.containsNormalNotes = normalNotesCount - this.containsPinnednotes = pinnedResultsCount - this.containsTextResults = textResultsCount - } else { - this.containsNormalNotes += normalNotesCount - this.containsPinnednotes += pinnedResultsCount - this.containsTextResults += textResultsCount - } - - this.working = false this.loadingInProgress = false + this.generateNoteCategories(response.data.notes, mergeExisting) return resolve(true) }) }) }, + rebuildNoteCategorise(){ + let currentNotes = [] + Object.keys(this.noteSections).forEach( key => { + this.noteSections[key].forEach( note => { + currentNotes.push(note) + }) + }) + this.generateNoteCategories(currentNotes, false) + }, + generateNoteCategories(notes, mergeExisting){ + // Place each note in a category based on certain attributes and fast filters + + //Reset all sections if we are not merging existing + if(!mergeExisting){ + Object.keys(this.noteSections).forEach( key => { + this.noteSections[key] = [] + }) + } + + //Sort notes into defined sections + notes.forEach(note => { + + if(note.archived == 1 && this.fastFilters.onlyArchived == 1){ + this.noteSections.archived.push(note) + return + } + if(note.shareUsername != null){ + this.noteSections.shared.push(note) + return + } + //Only show sent notes section if shared is selected + if(note.shared == 2 && this.fastFilters.onlyShowSharedNotes == 1){ + this.noteSections.sent.push(note) + return + } + if(note.note_highlights.length > 0){ + this.noteSections.highlights.push(note) + return + } + // Pinned notes are always first, they can appear in the archive + if(note.pinned == 1){ + this.noteSections.pinned.push(note) + return + } + + this.noteSections.notes.push(note) + }) + + }, searchKeyUp(){ let vm = this clearTimeout(vm.searchDebounce) diff --git a/server/helpers/ProcessText.js b/server/helpers/ProcessText.js index 62f6a21..7d0a22f 100644 --- a/server/helpers/ProcessText.js +++ b/server/helpers/ProcessText.js @@ -92,7 +92,7 @@ ProcessText.deduceNoteTitle = (inString) => { //Empty line, may be a list open or close if(cleanLine.length == 0 && (startTags.includes(lineStart) || endTags.includes(lineStart) )){ if(listStart == false){ - charLimit = 400 //Double size for list notes + //charLimit = 400 //Double size for list notes } finalLines.push(lines[i]) totalLines++ diff --git a/server/models/Note.js b/server/models/Note.js index 77d8b6a..a98284e 100644 --- a/server/models/Note.js +++ b/server/models/Note.js @@ -434,6 +434,7 @@ Note.search = (userId, searchQuery, searchTags, fastFilters) => { let textSearchIds = [] let highlights = {} let returnTagResults = false + let searchAllNotes = false if(textSearchResults != null){ textSearchIds = textSearchResults['ids'] @@ -484,11 +485,13 @@ Note.search = (userId, searchQuery, searchTags, fastFilters) => { if(textSearchIds.length > 0){ searchParams.push(textSearchIds) noteSearchQuery += ' AND note.id IN (?)' + searchAllNotes = true } if(fastFilters.noteIdSet && fastFilters.noteIdSet.length > 0){ searchParams.push(fastFilters.noteIdSet) noteSearchQuery += ' AND note.id IN (?)' + searchAllNotes = true } //If tags are passed, use those tags in search @@ -498,12 +501,14 @@ Note.search = (userId, searchQuery, searchTags, fastFilters) => { } //Show archived notes, only if fast filter is set, default to not archived - if(fastFilters.onlyArchived == 1){ - noteSearchQuery += ' AND note.archived = 1' //Show Archived - } else { - noteSearchQuery += ' AND note.archived = 0' //Exclude archived + if(searchAllNotes == false){ + if(fastFilters.onlyArchived == 1){ + noteSearchQuery += ' AND note.archived = 1' //Show Archived + } else { + noteSearchQuery += ' AND note.archived = 0' //Exclude archived + } } - + //Finish up note query noteSearchQuery += ' GROUP BY note.id'