mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
protect/unprotect tree reports progress via notifications
This commit is contained in:
parent
82bbf4173b
commit
00bb1236ce
@ -4,6 +4,7 @@ import utils from './utils.js';
|
|||||||
import server from './server.js';
|
import server from './server.js';
|
||||||
import protectedSessionHolder from './protected_session_holder.js';
|
import protectedSessionHolder from './protected_session_holder.js';
|
||||||
import infoService from "./info.js";
|
import infoService from "./info.js";
|
||||||
|
import ws from "./ws.js";
|
||||||
|
|
||||||
const $enterProtectedSessionButton = $("#enter-protected-session-button");
|
const $enterProtectedSessionButton = $("#enter-protected-session-button");
|
||||||
const $leaveProtectedSessionButton = $("#leave-protected-session-button");
|
const $leaveProtectedSessionButton = $("#leave-protected-session-button");
|
||||||
@ -117,12 +118,39 @@ async function protectSubtree(noteId, protect) {
|
|||||||
|
|
||||||
await server.put('notes/' + noteId + "/protect/" + (protect ? 1 : 0));
|
await server.put('notes/' + noteId + "/protect/" + (protect ? 1 : 0));
|
||||||
|
|
||||||
infoService.showMessage("Request to un/protect sub tree has finished successfully");
|
|
||||||
|
|
||||||
treeService.reload();
|
treeService.reload();
|
||||||
noteDetailService.reload();
|
noteDetailService.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeToast(message, protectingLabel, text) {
|
||||||
|
return {
|
||||||
|
id: message.taskId,
|
||||||
|
title: protectingLabel + " status",
|
||||||
|
message: text,
|
||||||
|
icon: message.data.protect ? "shield-check" : "shield-close"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.subscribeToMessages(async message => {
|
||||||
|
if (message.taskType !== 'protect-notes') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const protectingLabel = message.data.protect ? "Protecting" : "Unprotecting";
|
||||||
|
|
||||||
|
if (message.type === 'task-error') {
|
||||||
|
infoService.closePersistent(message.taskId);
|
||||||
|
infoService.showError(message.message);
|
||||||
|
} else if (message.type === 'task-progress-count') {
|
||||||
|
infoService.showPersistent(makeToast(message, protectingLabel,protectingLabel + " in progress: " + message.progressCount));
|
||||||
|
} else if (message.type === 'task-succeeded') {
|
||||||
|
const toast = makeToast(message, protectingLabel, protectingLabel + " finished successfully.");
|
||||||
|
toast.closeAfter = 3000;
|
||||||
|
|
||||||
|
infoService.showPersistent(toast);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
protectSubtree,
|
protectSubtree,
|
||||||
enterProtectedSession,
|
enterProtectedSession,
|
||||||
|
@ -102,7 +102,11 @@ async function protectSubtree(req) {
|
|||||||
const note = await repository.getNote(noteId);
|
const note = await repository.getNote(noteId);
|
||||||
const protect = !!parseInt(req.params.isProtected);
|
const protect = !!parseInt(req.params.isProtected);
|
||||||
|
|
||||||
await noteService.protectNoteRecursively(note, protect);
|
const taskContext = new TaskContext(utils.randomString(10), 'protect-notes', {protect});
|
||||||
|
|
||||||
|
await noteService.protectNoteRecursively(note, protect, taskContext);
|
||||||
|
|
||||||
|
taskContext.taskSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setNoteTypeMime(req) {
|
async function setNoteTypeMime(req) {
|
||||||
|
@ -177,11 +177,13 @@ async function createNote(parentNoteId, title, content = "", extraOptions = {})
|
|||||||
return {note, branch};
|
return {note, branch};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function protectNoteRecursively(note, protect) {
|
async function protectNoteRecursively(note, protect, taskContext) {
|
||||||
await protectNote(note, protect);
|
await protectNote(note, protect);
|
||||||
|
|
||||||
|
taskContext.increaseProgressCount();
|
||||||
|
|
||||||
for (const child of await note.getChildNotes()) {
|
for (const child of await note.getChildNotes()) {
|
||||||
await protectNoteRecursively(child, protect);
|
await protectNoteRecursively(child, protect, taskContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ class TaskContext {
|
|||||||
type: 'task-progress-count',
|
type: 'task-progress-count',
|
||||||
taskId: this.taskId,
|
taskId: this.taskId,
|
||||||
taskType: this.taskType,
|
taskType: this.taskType,
|
||||||
|
data: this.data,
|
||||||
progressCount: this.progressCount
|
progressCount: this.progressCount
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -45,6 +46,7 @@ class TaskContext {
|
|||||||
type: 'task-error',
|
type: 'task-error',
|
||||||
taskId: this.taskId,
|
taskId: this.taskId,
|
||||||
taskType: this.taskType,
|
taskType: this.taskType,
|
||||||
|
data: this.data,
|
||||||
message: message
|
message: message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -54,6 +56,7 @@ class TaskContext {
|
|||||||
type: 'task-succeeded',
|
type: 'task-succeeded',
|
||||||
taskId: this.taskId,
|
taskId: this.taskId,
|
||||||
taskType: this.taskType,
|
taskType: this.taskType,
|
||||||
|
data: this.data,
|
||||||
result: result
|
result: result
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user