-
+
- Show All Attachments
-
+ Back to All
+
Open Note
@@ -47,11 +76,16 @@
export default {
components: {
'attachment-display': require('@/components/AttachmentDisplayCard').default,
+ 'counter':require('@/components/AnimatedCounterComponent.vue').default,
},
data: function(){
return {
+ loading: false,
attachments: [],
- searchParams: {}
+ searchParams: {},
+ loadedAttachmentsOffset: 0,
+ loadingBatchTimeout: null,
+ allLoaded: false,
}
},
beforeCreate: function(){
@@ -59,40 +93,107 @@
// Perform Login check
//
this.$parent.loginGateway()
+
},
mounted: function(){
+ //Load more attachments on scroll
+ window.addEventListener('scroll', this.onScroll)
+
//Mount notes on load if note ID is set
- this.openNoteAttachments()
this.searchAttachments()
},
+ beforeDestroy(){
+
+ //Remove scroll event on destroy
+ window.removeEventListener('scroll', this.onScroll)
+ },
watch:{
$route (to, from){
- //Open or close notes on route change
- this.openNoteAttachments()
+
+ //Reset everything on route change
+ this.reset()
+ //Params are handled by search function
this.searchAttachments()
}
},
methods: {
- openNoteAttachments(){
- if(this.$route.params && this.$route.params.id){
- const inputNoteId = this.$route.params.id
- this.searchParams['noteId'] = inputNoteId
- }
- },
openNote(){
const noteId = this.searchParams['noteId']
this.$router.push('/notes/open/'+noteId)
},
- clearNote(){
- this.$router.push('/attachments/')
- delete this.searchParams.noteId
+ onScroll(){
+
+ clearTimeout(this.loadingBatchTimeout)
+ this.loadingBatchTimeout = setTimeout(() => {
+
+ //Distance to bottom of page
+ const bottomOfWindow =
+ Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop)
+ + window.innerHeight
+
+ //height of page
+ const offsetHeight = this.$refs.content.clientHeight
+
+ //Determine percentage down the page
+ const percentageDown = Math.round( (bottomOfWindow/offsetHeight)*100 )
+
+ //If greater than 80 of the way down the page, load the next batch
+ if(percentageDown >= 80){
+
+ this.searchAttachments()
+ }
+
+ }, 50)
+ },
+ reset(){
+ this.attachments = []
+ this.loading = false
+ this.allLoaded = false
+ this.loadedAttachmentsOffset = 0
},
searchAttachments (){
+ if(this.loading || this.allLoaded){
+ return
+ }
+
+ delete this.searchParams.attachmentType
+ delete this.searchParams.noteId
+
+ //Set attchment type if in URL
+ if(this.$route.params.type){
+ this.searchParams.attachmentType = this.$route.params.type
+ }
+
+ //Set noteId in if in URL
+ if(this.$route.params.id){
+ this.searchParams.noteId = this.$route.params.id
+ }
+
+ //Offset of attchments to load
+ this.searchParams.offset = this.loadedAttachmentsOffset
+
+ if(this.allLoaded){
+ return
+ }
+
+ this.loading = true
axios.post('/api/attachment/search', this.searchParams)
.then( results => {
- this.attachments = results.data
+
+ this.loading = false
+
+ if(results.data.length == 0){
+ this.allLoaded = true
+ return
+ }
+
+ //Load up the results
+ this.attachments.push(...results.data)
+
+ //Grab the next batch
+ this.loadedAttachmentsOffset += results.data.length
})
},
}
diff --git a/client/src/router/index.js b/client/src/router/index.js
index 2f1aa2d..a9bb456 100644
--- a/client/src/router/index.js
+++ b/client/src/router/index.js
@@ -73,8 +73,14 @@ export default new Router({
},
{
path: '/attachments/note/:id',
- name: 'Attachments',
- meta: {title:'Attachments'},
+ name: 'Attachments for Note',
+ meta: {title:'Attachments for Note'},
+ component: AttachmentsPage
+ },
+ {
+ path: '/attachments/type/:type',
+ name: 'Attachments by Type',
+ meta: {title:'Attachments by Type'},
component: AttachmentsPage
},
]
diff --git a/server/helpers/ProcessText.js b/server/helpers/ProcessText.js
index 7d0a22f..d41d6d9 100644
--- a/server/helpers/ProcessText.js
+++ b/server/helpers/ProcessText.js
@@ -40,13 +40,19 @@ ProcessText.deduceNoteTitle = (inString) => {
//Remove inline styles that may be added by editor
inString = inString.replace(/style=".*?"/g,'')
+ // inString = inString.replace('','')
+
+ //Emergency ending tag if truncated. This will help regex find all the lines
+ inString += ''
//Match full line and closing tag or just closing tag
- let lines = inString.match(/[<[a-zA-Z0-9]+>(.*?)<\/[a-zA-Z0-9]+>|<\/[a-zA-Z0-9>]+?>/g)
+ let lines = inString.match(/[<[a-zA-Z0-9]+>(.*?)<\/[a-zA-Z0-9]+>|<\/[a-zA-Z0-9>]+?>/gms)
if(lines == null){ lines = [inString] }
//.match(/[^\r\n]+/g) //Match return or newline
+ // console.log('----------------')
// console.log(lines)
+ // console.log('----------------')
let finalLines = []
@@ -129,6 +135,7 @@ ProcessText.deduceNoteTitle = (inString) => {
//Cut the string down to character limit
const cutString = lines[i].substring(0, lines[i].length+charLimit)
+
//Find last space and cut off everything after it
let cleanCutString = cutString.substring(0, cutString.lastIndexOf(' '))
diff --git a/server/models/Attachment.js b/server/models/Attachment.js
index ea6d42a..2529868 100644
--- a/server/models/Attachment.js
+++ b/server/models/Attachment.js
@@ -43,7 +43,7 @@ Attachment.textSearch = (userId, searchTerm) => {
})
}
-Attachment.search = (userId, noteId, attachmentType) => {
+Attachment.search = (userId, noteId, attachmentType, offset, setSize) => {
return new Promise((resolve, reject) => {
let params = [userId]
@@ -54,13 +54,20 @@ Attachment.search = (userId, noteId, attachmentType) => {
params.push(noteId)
}
- if(Number.isInteger(attachmentType)){
- query += 'AND attachment_type = ? '
- params.push(attachmentType)
+ if(attachmentType == 'links'){
+ query += 'AND attachment_type = 1 '
+ }
+ if(attachmentType == 'files'){
+ query += 'AND attachment_type > 1 '
}
+
query += 'ORDER BY last_indexed DESC '
+ const limitOffset = parseInt(offset, 10) || 0 //Either parse int, or use zero
+ const parsedSetSize = parseInt(setSize, 10) || 20 //Either parse int, or use zero
+ query += ` LIMIT ${limitOffset}, ${parsedSetSize}`
+
db.promise()
.query(query, params)
.then((rows, fields) => {
diff --git a/server/models/Note.js b/server/models/Note.js
index a98284e..e149511 100644
--- a/server/models/Note.js
+++ b/server/models/Note.js
@@ -593,6 +593,15 @@ Note.search = (userId, searchQuery, searchTags, fastFilters) => {
note.attachment_highlights = []
note.tag_highlights = []
+ //Limit number of attachment thumbs to 4
+ if(note.thumbs){
+ //Convert comma delimited string to array
+ let thumbArray = note.thumbs.split(',').reverse()
+ //Limit array to 4 or size of array
+ thumbArray.length = Math.min(thumbArray.length, 4)
+ note.thumbs = thumbArray
+ }
+
//Push in search highlights
if(highlights && highlights[note.id]){
note['note_highlights'] = [highlights[note.id]]
diff --git a/server/routes/attachmentController.js b/server/routes/attachmentController.js
index 015033a..ddbaf23 100644
--- a/server/routes/attachmentController.js
+++ b/server/routes/attachmentController.js
@@ -18,7 +18,7 @@ router.use(function setUserId (req, res, next) {
})
router.post('/search', function (req, res) {
- Attachment.search(userId, req.body.noteId, req.body.attachmentType)
+ Attachment.search(userId, req.body.noteId, req.body.attachmentType, req.body.offset, req.body.setSize)
.then( data => res.send(data) )
})