diff --git a/app.js b/app.js index 3f895fd25..fc95b4b70 100644 --- a/app.js +++ b/app.js @@ -11,31 +11,11 @@ const options = require('./services/options'); const log = require('./services/log'); const utils = require('./services/utils'); -const indexRoute = require('./routes/index'); -const loginRoute = require('./routes/login'); -const logoutRoute = require('./routes/logout'); -const migrationRoute = require('./routes/migration'); - -// API routes -const treeApiRoute = require('./routes/api/tree'); -const notesApiRoute = require('./routes/api/notes'); -const notesMoveApiRoute = require('./routes/api/notes_move'); -const statusApiRoute = require('./routes/api/status'); -const noteHistoryApiRoute = require('./routes/api/note_history'); -const recentChangesApiRoute = require('./routes/api/recent_changes'); -const settingsApiRoute = require('./routes/api/settings'); -const passwordApiRoute = require('./routes/api/password'); -const migrationApiRoute = require('./routes/api/migration'); -const syncApiRoute = require('./routes/api/sync'); -const loginApiRoute = require('./routes/api/login'); - const dataDir = require('./services/data_dir'); const sessionSecret = require('./services/session_secret'); const db = require('sqlite'); -const config = require('./services/config'); - db.open(dataDir.DOCUMENT_PATH, { Promise }).then(async () => { if (!await options.getOption('document_id')) { await options.setOption('document_id', utils.randomString(32)); @@ -80,22 +60,7 @@ app.use(session({ app.use(favicon(__dirname + '/public/images/app-icons/favicon.ico')); -app.use('/', indexRoute); -app.use('/login', loginRoute); -app.use('/logout', logoutRoute); -app.use('/migration', migrationRoute); - -app.use('/api/tree', treeApiRoute); -app.use('/api/notes', notesApiRoute); -app.use('/api/notes', notesMoveApiRoute); -app.use('/api/status', statusApiRoute); -app.use('/api/notes-history', noteHistoryApiRoute); -app.use('/api/recent-changes', recentChangesApiRoute); -app.use('/api/settings', settingsApiRoute); -app.use('/api/password', passwordApiRoute); -app.use('/api/migration', migrationApiRoute); -app.use('/api/sync', syncApiRoute); -app.use('/api/login', loginApiRoute); +require('./routes/routes').register(app); // catch 404 and forward to error handler app.use((req, res, next) => { diff --git a/public/javascripts/add_link.js b/public/javascripts/add_link.js index a39abf848..cd94ebe23 100644 --- a/public/javascripts/add_link.js +++ b/public/javascripts/add_link.js @@ -62,13 +62,8 @@ $("#insert-link-form").submit(() => { // when click on link popup, in case of internal link, just go the the referenced note instead of default behavior // of opening the link in new window/tab -$(document).on('click', 'div.popover-content a, div.ui-tooltip-content', e => { - goToInternalNote(e); -}); - -$(document).on('dblclick', '.note-editable a, div.ui-tooltip-content', e => { - goToInternalNote(e); -}); +$(document).on('click', 'div.popover-content a, div.ui-tooltip-content', goToInternalNote); +$(document).on('dblclick', '.note-editable a, div.ui-tooltip-content', goToInternalNote); function goToInternalNote(e, callback) { const targetUrl = $(e.target).attr("href"); diff --git a/public/javascripts/event_log.js b/public/javascripts/event_log.js new file mode 100644 index 000000000..e3ece7a4a --- /dev/null +++ b/public/javascripts/event_log.js @@ -0,0 +1,42 @@ +async function showEventLog() { + $("#event-log-dialog").dialog({ + modal: true, + width: 800, + height: 700 + }); + + const result = await $.ajax({ + url: baseApiUrl + 'event-log', + type: 'GET', + error: () => error("Error getting event log.") + }); + + const eventLogList = $("#event-log-list"); + eventLogList.html(''); + + for (const event of result) { + const dateTime = formatDateTime(getDateFromTS(event.date_added)); + + if (event.note_id) { + const noteLink = $("", { + href: 'app#' + event.note_id, + text: event.note_title + }).prop('outerHTML'); + + console.log(noteLink); + + event.comment = event.comment.replace('', noteLink); + } + + const eventEl = $('
  • ').html(dateTime + " - " + event.comment); + + + eventLogList.append(eventEl); + } +} + +$(document).on('click', '#event-log-dialog a', e => { + goToInternalNote(e, () => { + $("#event-log-dialog").dialog('close'); + }); +}); \ No newline at end of file diff --git a/public/javascripts/recent_changes.js b/public/javascripts/recent_changes.js index fd3362794..540355c3d 100644 --- a/public/javascripts/recent_changes.js +++ b/public/javascripts/recent_changes.js @@ -21,7 +21,7 @@ function showRecentChanges() { } - let dateDay = getDateFromTS(row.date_modified); + let dateDay = getDateFromTS(row.date_modified_to); dateDay.setHours(0); dateDay.setMinutes(0); dateDay.setSeconds(0); @@ -49,7 +49,7 @@ function showRecentChanges() { const dayEl = $('
    ').append($('').html(formatDate(dateDay))).append(changesListEl); for (const change of dayChanges) { - const formattedTime = formatTime(getDateFromTS(change.date_modified)); + const formattedTime = formatTime(getDateFromTS(change.date_modified_to)); const noteLink = $("", { href: 'app#' + change.note_id, @@ -57,7 +57,7 @@ function showRecentChanges() { }); const revLink = $("", { - href: "javascript: showNoteHistoryDialog('" + change.note_id + "', " + change.id + ");", + href: "javascript: showNoteHistoryDialog('" + change.note_id + "', '" + change.note_history_id + "');", text: 'rev' }); diff --git a/routes/api/event_log.js b/routes/api/event_log.js new file mode 100644 index 000000000..d75ba4f75 --- /dev/null +++ b/routes/api/event_log.js @@ -0,0 +1,24 @@ +"use strict"; + +const express = require('express'); +const router = express.Router(); +const sql = require('../../services/sql'); + +router.get('', async (req, res, next) => { + await deleteOld(); + + const result = await sql.getResults("SELECT e.id, e.note_id, e.comment, e.date_added, n.note_title " + + "FROM event_log e LEFT JOIN notes n ON e.note_id = n.note_id ORDER BY date_added DESC"); + + res.send(result); +}); + +async function deleteOld() { + const cutoffId = await sql.getSingleValue("SELECT id FROM event_log ORDER BY id DESC LIMIT 1000, 1"); + + if (cutoffId) { + await sql.execute("DELETE FROM event_log WHERE id < ?", [cutoffId]); + } +} + +module.exports = router; \ No newline at end of file diff --git a/routes/api/recent_changes.js b/routes/api/recent_changes.js index 79375f210..06c970100 100644 --- a/routes/api/recent_changes.js +++ b/routes/api/recent_changes.js @@ -6,7 +6,7 @@ const sql = require('../../services/sql'); const auth = require('../../services/auth'); router.get('/', auth.checkApiAuth, async (req, res, next) => { - const recentChanges = await sql.getResults("select * from notes_history order by date_modified desc limit 1000"); + const recentChanges = await sql.getResults("select * from notes_history order by date_modified_to desc limit 1000"); res.send(recentChanges); }); diff --git a/routes/routes.js b/routes/routes.js new file mode 100644 index 000000000..fb9994f55 --- /dev/null +++ b/routes/routes.js @@ -0,0 +1,42 @@ +const indexRoute = require('./index'); +const loginRoute = require('./login'); +const logoutRoute = require('./logout'); +const migrationRoute = require('./migration'); + +// API routes +const treeApiRoute = require('./api/tree'); +const notesApiRoute = require('./api/notes'); +const notesMoveApiRoute = require('./api/notes_move'); +const statusApiRoute = require('./api/status'); +const noteHistoryApiRoute = require('./api/note_history'); +const recentChangesApiRoute = require('./api/recent_changes'); +const settingsApiRoute = require('./api/settings'); +const passwordApiRoute = require('./api/password'); +const migrationApiRoute = require('./api/migration'); +const syncApiRoute = require('./api/sync'); +const loginApiRoute = require('./api/login'); +const eventLogRoute = require('./api/event_log'); + +function register(app) { + app.use('/', indexRoute); + app.use('/login', loginRoute); + app.use('/logout', logoutRoute); + app.use('/migration', migrationRoute); + + app.use('/api/tree', treeApiRoute); + app.use('/api/notes', notesApiRoute); + app.use('/api/notes', notesMoveApiRoute); + app.use('/api/status', statusApiRoute); + app.use('/api/notes-history', noteHistoryApiRoute); + app.use('/api/recent-changes', recentChangesApiRoute); + app.use('/api/settings', settingsApiRoute); + app.use('/api/password', passwordApiRoute); + app.use('/api/migration', migrationApiRoute); + app.use('/api/sync', syncApiRoute); + app.use('/api/login', loginApiRoute); + app.use('/api/event-log', eventLogRoute); +} + +module.exports = { + register +}; \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index 36fb35c01..afcbd999d 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -15,6 +15,7 @@ +
    @@ -213,6 +214,10 @@ + + +