Better formatting and tag stripping for note title display

cleaned up interface a bunch
allow for opening of two notes at once
Escape closes note
Added global helper class and time ago function
Time ago function displays on main page and in note
Removed tab button creating tabbed spaces in document
Simplified save text
This commit is contained in:
Max G
2019-07-20 23:07:22 +00:00
parent 61754fe290
commit e6c16f3d37
7 changed files with 204 additions and 61 deletions

View File

@@ -5,7 +5,7 @@ let Notes = module.exports = {}
Notes.create = (userId, noteText) => {
return new Promise((resolve, reject) => {
const created = new Date().toISOString().slice(0, 19).replace('T', ' ')
const created = Math.round((+new Date)/1000)
db.promise()
.query('INSERT INTO notes (user, text, created) VALUES (?,?,?)', [userId, noteText, created])
@@ -18,11 +18,12 @@ Notes.create = (userId, noteText) => {
Notes.update = (userId, noteId, noteText) => {
return new Promise((resolve, reject) => {
const now = new Date().toISOString().slice(0, 19).replace('T', ' ')
const now = Math.round((+new Date)/1000)
db.promise()
.query('UPDATE notes SET text = ?, updated = ? WHERE id = ? AND user = ? LIMIT 1', [noteText, now, noteId, userId])
.then((rows, fields) => {
console.log(rows)
resolve(rows[0])
})
.catch(console.log)
@@ -63,7 +64,7 @@ Notes.search = (userId, searchQuery, searchTags) => {
//Default note lookup gets all notes
let noteSearchQuery = `
SELECT notes.id, SUBSTRING(text, 1, 100) as text
SELECT notes.id, SUBSTRING(text, 1, 200) as text, updated
FROM notes
LEFT JOIN notes_tags ON (notes.id = notes_tags.note_id)
WHERE user = ?`
@@ -81,7 +82,7 @@ Notes.search = (userId, searchQuery, searchTags) => {
}
//Finish up note query
noteSearchQuery += ' GROUP BY notes.id ORDER BY updated DESC, created DESC'
noteSearchQuery += ' GROUP BY notes.id ORDER BY updated DESC, created DESC, id DESC'
//Define return data objects
let returnData = {
@@ -96,10 +97,23 @@ Notes.search = (userId, searchQuery, searchTags) => {
//Push all notes
returnData['notes'] = noteRows[0]
//Pull Tags off of selected notes
//pull out all note ids so we can fetch all tags for those notes
let noteIds = []
returnData['notes'].forEach(note => {
//Grab note ID for finding tags
noteIds.push(note.id)
//Attempt to pull string out of first tag in note
let reg = note.text.match(/<([\w]+)[^>]*>(.*?)<\/\1>/)
if(reg != null){
note.text = reg[2]
}
//Return all notes with HTML tags pulled out
note.text = note.text
.replace(/&[#A-Za-z0-9]+;/g,'') //Rip out all HTML entities
.replace(/<[^>]+>/g, '') //Rip out all HTML tags
})
//If no notes are returned, there are no tags, return empty