mirror of
https://github.com/zadam/trilium.git
synced 2024-12-26 01:01:26 +08:00
added event log dialog
This commit is contained in:
parent
e35c2dd4ad
commit
3892666961
8 changed files with 121 additions and 47 deletions
37
app.js
37
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) => {
|
||||
|
|
|
@ -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");
|
||||
|
|
42
public/javascripts/event_log.js
Normal file
42
public/javascripts/event_log.js
Normal file
|
@ -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 = $("<a>", {
|
||||
href: 'app#' + event.note_id,
|
||||
text: event.note_title
|
||||
}).prop('outerHTML');
|
||||
|
||||
console.log(noteLink);
|
||||
|
||||
event.comment = event.comment.replace('<note>', noteLink);
|
||||
}
|
||||
|
||||
const eventEl = $('<li>').html(dateTime + " - " + event.comment);
|
||||
|
||||
|
||||
eventLogList.append(eventEl);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on('click', '#event-log-dialog a', e => {
|
||||
goToInternalNote(e, () => {
|
||||
$("#event-log-dialog").dialog('close');
|
||||
});
|
||||
});
|
|
@ -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 = $('<div>').append($('<b>').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 = $("<a>", {
|
||||
href: 'app#' + change.note_id,
|
||||
|
@ -57,7 +57,7 @@ function showRecentChanges() {
|
|||
});
|
||||
|
||||
const revLink = $("<a>", {
|
||||
href: "javascript: showNoteHistoryDialog('" + change.note_id + "', " + change.id + ");",
|
||||
href: "javascript: showNoteHistoryDialog('" + change.note_id + "', '" + change.note_history_id + "');",
|
||||
text: 'rev'
|
||||
});
|
||||
|
||||
|
|
24
routes/api/event_log.js
Normal file
24
routes/api/event_log.js
Normal file
|
@ -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;
|
|
@ -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);
|
||||
});
|
||||
|
|
42
routes/routes.js
Normal file
42
routes/routes.js
Normal file
|
@ -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
|
||||
};
|
|
@ -15,6 +15,7 @@
|
|||
<button class="btn btn-xs" onclick="showRecentChanges();">Recent changes</button>
|
||||
<button class="btn btn-xs" onclick="showRecentNotes();">Recent notes</button>
|
||||
<button class="btn btn-xs" onclick="showJumpToNote();">Jump to note</button>
|
||||
<button class="btn btn-xs" onclick="showEventLog();">Event log</button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
@ -213,6 +214,10 @@
|
|||
<div id="recent-changes-dialog" title="Recent changes" style="display: none; padding: 20px;">
|
||||
</div>
|
||||
|
||||
<div id="event-log-dialog" title="Event log" style="display: none; padding: 20px;">
|
||||
<ul id="event-log-list"></ul>
|
||||
</div>
|
||||
|
||||
<div id="tooltip" style="display: none;"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
@ -275,6 +280,7 @@
|
|||
<script src="javascripts/settings.js"></script>
|
||||
<script src="javascripts/note_history.js"></script>
|
||||
<script src="javascripts/recent_changes.js"></script>
|
||||
<script src="javascripts/event_log.js"></script>
|
||||
|
||||
<script src="javascripts/status.js"></script>
|
||||
<script src="javascripts/sync.js"></script>
|
||||
|
|
Loading…
Reference in a new issue