import linkService from '../../services/link.js'; import utils from '../../services/utils.js'; import server from '../../services/server.js'; import treeService from "../../services/tree.js"; import froca from "../../services/froca.js"; import appContext from "../../components/app_context.js"; import hoistedNoteService from "../../services/hoisted_note.js"; import BasicWidget from "../basic_widget.js"; import dialogService from "../../services/dialog.js"; import toastService from "../../services/toast.js"; import ws from "../../services/ws.js"; const TPL = ` `; export default class RecentChangesDialog extends BasicWidget { doRender() { this.$widget = $(TPL); this.$content = this.$widget.find(".recent-changes-content"); this.$eraseDeletedNotesNow = this.$widget.find(".erase-deleted-notes-now-button"); this.$eraseDeletedNotesNow.on("click", () => { server.post('notes/erase-deleted-notes-now').then(() => { this.refresh(); toastService.showMessage("Deleted notes have been erased."); }); }); } async showRecentChangesEvent({ancestorNoteId}) { this.ancestorNoteId = ancestorNoteId; await this.refresh(); utils.openDialog(this.$widget); } async refresh() { if (!this.ancestorNoteId) { this.ancestorNoteId = hoistedNoteService.getHoistedNoteId(); } const recentChangesRows = await server.get(`recent-changes/${this.ancestorNoteId}`); // preload all notes into cache await froca.getNotes(recentChangesRows.map(r => r.noteId), true); this.$content.empty(); if (recentChangesRows.length === 0) { this.$content.append("No changes yet ..."); } const groupedByDate = this.groupByDate(recentChangesRows); for (const [dateDay, dayChanges] of groupedByDate) { const $changesList = $('