mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
added "edited notes on date" widget
This commit is contained in:
parent
e828ef370d
commit
b069436039
2
db/migrations/0144__edited_notes_widget.sql
Normal file
2
db/migrations/0144__edited_notes_widget.sql
Normal file
@ -0,0 +1,2 @@
|
||||
INSERT INTO options (name, value, utcDateCreated, utcDateModified, isSynced)
|
||||
VALUES ('editedNotesWidget', '{"enabled":true,"expanded":true,"position":5}', '2018-07-29T18:31:00.874Z', '2018-07-29T18:31:00.874Z', 0);
|
@ -52,7 +52,8 @@ export default class SidebarOptions {
|
||||
{name: 'noteInfo', title: 'Note info'},
|
||||
{name: 'noteRevisions', title: 'Note revisions'},
|
||||
{name: 'whatLinksHere', title: 'What links here'},
|
||||
{name: 'similarNotes', title: 'Similar notes'}
|
||||
{name: 'similarNotes', title: 'Similar notes'},
|
||||
{name: 'editedNotes', title: 'Edited notes (only on day note)'}
|
||||
].map(widget => {
|
||||
widget.option = this.parseJsonSafely(options[widget.name + 'Widget']) || {
|
||||
enabled: true,
|
||||
|
@ -66,7 +66,8 @@ class Sidebar {
|
||||
import("../widgets/note_revisions.js"),
|
||||
import("../widgets/attributes.js"),
|
||||
import("../widgets/what_links_here.js"),
|
||||
import("../widgets/similar_notes.js")
|
||||
import("../widgets/similar_notes.js"),
|
||||
import("../widgets/edited_notes.js"),
|
||||
])).map(m => m.default);
|
||||
|
||||
const options = await optionsService.waitForOptions();
|
||||
|
51
src/public/javascripts/widgets/edited_notes.js
Normal file
51
src/public/javascripts/widgets/edited_notes.js
Normal file
@ -0,0 +1,51 @@
|
||||
import StandardWidget from "./standard_widget.js";
|
||||
import linkService from "../services/link.js";
|
||||
import server from "../services/server.js";
|
||||
import treeCache from "../services/tree_cache.js";
|
||||
|
||||
class EditedNotesWidget extends StandardWidget {
|
||||
getWidgetTitle() { return "Edited notes on this day"; }
|
||||
|
||||
getMaxHeight() { return "200px"; }
|
||||
|
||||
async isEnabled() {
|
||||
return await this.ctx.note.hasLabel("dateNote");
|
||||
}
|
||||
|
||||
async doRenderBody() {
|
||||
// remember which title was when we found the similar notes
|
||||
this.title = this.ctx.note.title;
|
||||
|
||||
let editedNotes = await server.get('edited-notes/' + await this.ctx.note.getLabelValue("dateNote"));
|
||||
|
||||
editedNotes = editedNotes.filter(note => note.noteId !== this.ctx.note.noteId);
|
||||
|
||||
if (editedNotes.length === 0) {
|
||||
this.$body.text("No edited notes on this day yet ...");
|
||||
return;
|
||||
}
|
||||
|
||||
const noteIds = editedNotes.flatMap(note => note.notePath);
|
||||
|
||||
await treeCache.getNotes(noteIds); // preload all at once
|
||||
|
||||
const $list = $('<ul>');
|
||||
|
||||
for (const editedNote of editedNotes) {
|
||||
const note = await treeCache.getNote(editedNote.noteId);
|
||||
|
||||
if (!note) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const $item = $("<li>")
|
||||
.append(editedNote.notePath ? await linkService.createNoteLinkWithPath(editedNote.notePath.join("/")) : editedNote.title);
|
||||
|
||||
$list.append($item);
|
||||
}
|
||||
|
||||
this.$body.empty().append($list);
|
||||
}
|
||||
}
|
||||
|
||||
export default EditedNotesWidget;
|
@ -26,7 +26,10 @@ class StandardWidget {
|
||||
this.ctx = ctx;
|
||||
// construct in camelCase
|
||||
this.widgetName = this.constructor.name.substr(0, 1).toLowerCase() + this.constructor.name.substr(1);
|
||||
this.widgetOptions = options.getJson(this.widgetName) || {};
|
||||
this.widgetOptions = options.getJson(this.widgetName) || {
|
||||
expanded: true
|
||||
};
|
||||
|
||||
this.state = sidebarState.widgets.find(s => s.name === this.widgetName) || {
|
||||
expanded: this.widgetOptions.expanded
|
||||
};
|
||||
|
@ -1,12 +1,34 @@
|
||||
"use strict";
|
||||
|
||||
const repository = require('../../services/repository');
|
||||
const noteCacheService = require('../../services/note_cache');
|
||||
|
||||
async function getNoteRevisions(req) {
|
||||
const noteId = req.params.noteId;
|
||||
return await repository.getEntities("SELECT * FROM note_revisions WHERE noteId = ? order by utcDateModifiedTo desc", [noteId]);
|
||||
}
|
||||
|
||||
async function getEditedNotesOnDate(req) {
|
||||
const date = req.params.date;
|
||||
|
||||
const notes = await repository.getEntities(`
|
||||
select distinct notes.*
|
||||
from notes
|
||||
left join note_revisions using (noteId)
|
||||
where substr(notes.dateCreated, 0, 11) = ?
|
||||
or substr(notes.dateModified, 0, 11) = ?
|
||||
or substr(note_revisions.dateModifiedFrom, 0, 11) = ?`, [date, date, date]);
|
||||
|
||||
for (const note of notes) {
|
||||
const notePath = noteCacheService.getNotePath(note.noteId);
|
||||
|
||||
note.notePath = notePath ? notePath.notePath : null;
|
||||
}
|
||||
|
||||
return notes;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getNoteRevisions
|
||||
getNoteRevisions,
|
||||
getEditedNotesOnDate
|
||||
};
|
@ -30,6 +30,7 @@ const ALLOWED_OPTIONS = [
|
||||
'noteRevisionsWidget',
|
||||
'whatLinksHereWidget',
|
||||
'similarNotesWidget',
|
||||
'editedNotesWidget',
|
||||
'codeNotesMimeTypes'
|
||||
];
|
||||
|
||||
|
@ -135,6 +135,8 @@ function register(app) {
|
||||
apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap);
|
||||
apiRoute(PUT, '/api/notes/:noteId/change-title', notesApiRoute.changeTitle);
|
||||
|
||||
apiRoute(GET, '/api/edited-notes/:date', noteRevisionsApiRoute.getEditedNotesOnDate);
|
||||
|
||||
apiRoute(PUT, '/api/notes/:noteId/clone-to/:parentNoteId', cloningApiRoute.cloneNoteToParent);
|
||||
apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter);
|
||||
|
||||
|
@ -4,7 +4,7 @@ const build = require('./build');
|
||||
const packageJson = require('../../package');
|
||||
const {TRILIUM_DATA_DIR} = require('./data_dir');
|
||||
|
||||
const APP_DB_VERSION = 143;
|
||||
const APP_DB_VERSION = 144;
|
||||
const SYNC_VERSION = 10;
|
||||
const CLIPPER_PROTOCOL_VERSION = "1.0";
|
||||
|
||||
|
@ -340,6 +340,7 @@ function getNotePath(noteId) {
|
||||
noteId: noteId,
|
||||
branchId: childParentToBranchId[`${noteId}-${parentNoteId}`],
|
||||
title: noteTitle,
|
||||
notePath: retPath,
|
||||
path: retPath.join('/')
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user