sharing WIP

This commit is contained in:
zadam
2021-12-20 17:30:47 +01:00
parent 16d97b95af
commit 3860028a9e
25 changed files with 342 additions and 203 deletions

View File

@@ -11,6 +11,12 @@ const becca = require("../becca/becca");
const beccaService = require("../becca/becca_service");
function cloneNoteToParent(noteId, parentBranchId, prefix) {
if (parentBranchId === 'share') {
const specialNotesService = require('./special_notes');
// share root note is created lazily
specialNotesService.getShareRoot();
}
const parentBranch = becca.getBranch(parentBranchId);
if (isNoteDeleted(noteId) || isNoteDeleted(parentBranch.noteId)) {

View File

@@ -118,6 +118,7 @@ function createNewNote(params) {
note.setContent(params.content);
const branch = new Branch({
branchId: params.branchId,
noteId: note.noteId,
parentNoteId: params.parentNoteId,
notePosition: params.notePosition !== undefined ? params.notePosition : getNewNotePosition(params.parentNoteId),
@@ -540,7 +541,7 @@ function deleteBranch(branch, deleteId, taskContext) {
branch.markAsDeleted(deleteId);
const note = branch.getNote();
const notDeletedBranches = note.getBranches();
const notDeletedBranches = note.getParentBranches();
if (notDeletedBranches.length === 0) {
for (const childBranch of note.getChildBranches()) {
@@ -785,7 +786,7 @@ function duplicateSubtree(origNoteId, newParentNoteId) {
const origNote = becca.notes[origNoteId];
// might be null if orig note is not in the target newParentNoteId
const origBranch = origNote.getBranches().find(branch => branch.parentNoteId === newParentNoteId);
const origBranch = origNote.getParentBranches().find(branch => branch.parentNoteId === newParentNoteId);
const noteIdMapping = getNoteIdMapping(origNote);

View File

@@ -206,11 +206,12 @@ function getShareRoot() {
if (!shareRoot) {
shareRoot = noteService.createNewNote({
branchId: 'share',
noteId: 'share',
title: 'share',
title: 'Shared notes',
type: 'text',
content: '',
parentNoteId: getHiddenRoot().noteId
parentNoteId: 'root'
}).note;
}
@@ -223,7 +224,7 @@ function createMissingSpecialNotes() {
getSinglesNoteRoot();
getSinglesNoteRoot();
getGlobalNoteMap();
getShareRoot();
// share root is not automatically created since it's visible in the tree and many won't need it/use it
const hidden = getHiddenRoot();
@@ -238,5 +239,6 @@ module.exports = {
saveSqlConsole,
createSearchNote,
saveSearchNote,
createMissingSpecialNotes
createMissingSpecialNotes,
getShareRoot
};

View File

@@ -173,7 +173,7 @@ function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, folder
let position = 10;
for (const note of notes) {
const branch = note.getBranches().find(b => b.parentNoteId === parentNoteId);
const branch = note.getParentBranches().find(b => b.parentNoteId === parentNoteId);
sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?",
[position, branch.branchId]);