mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
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"; }
 | 
						|
 | 
						|
    getHelp() {
 | 
						|
        return {
 | 
						|
            title: "This contains a list of notes created or updated on this day."
 | 
						|
        };
 | 
						|
    }
 | 
						|
 | 
						|
    getMaxHeight() { return "200px"; }
 | 
						|
 | 
						|
    async isEnabled() {
 | 
						|
        return await super.isEnabled()
 | 
						|
            && await this.tabContext.note.hasLabel("dateNote");
 | 
						|
    }
 | 
						|
 | 
						|
    async refreshWithNote() {
 | 
						|
        const note = this.tabContext.note;
 | 
						|
        // remember which title was when we found the similar notes
 | 
						|
        this.title = note.title;
 | 
						|
        let editedNotes = await server.get('edited-notes/' + await note.getLabelValue("dateNote"));
 | 
						|
 | 
						|
        editedNotes = editedNotes.filter(n => n.noteId !== note.noteId);
 | 
						|
 | 
						|
        if (editedNotes.length === 0) {
 | 
						|
            this.$body.text("No edited notes on this day yet ...");
 | 
						|
            return;
 | 
						|
        }
 | 
						|
 | 
						|
        const noteIds = editedNotes.flatMap(n => n.noteId);
 | 
						|
 | 
						|
        await treeCache.getNotes(noteIds, true); // preload all at once
 | 
						|
 | 
						|
        const $list = $('<ul>');
 | 
						|
 | 
						|
        for (const editedNote of editedNotes) {
 | 
						|
            const $item = $("<li>");
 | 
						|
 | 
						|
            if (editedNote.isDeleted) {
 | 
						|
                $item.append($("<i>").text(editedNote.title + " (deleted)"));
 | 
						|
            }
 | 
						|
            else {
 | 
						|
                $item.append(editedNote.notePath ? await linkService.createNoteLink(editedNote.notePath.join("/"), {showNotePath: true}) : editedNote.title);
 | 
						|
            }
 | 
						|
 | 
						|
            $list.append($item);
 | 
						|
        }
 | 
						|
 | 
						|
        this.$body.empty().append($list);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
export default EditedNotesWidget; |