template subtree is now deep-duplicated on template assignment

This commit is contained in:
zadam
2020-11-19 14:29:26 +01:00
parent 314e0a453f
commit 1047aecfbd
2 changed files with 38 additions and 15 deletions

View File

@@ -1,7 +1,7 @@
const eventService = require('./events');
const scriptService = require('./script');
const treeService = require('./tree');
const log = require('./log');
const noteService = require('./notes');
const repository = require('./repository');
const Attribute = require('../entities/attribute');
@@ -58,17 +58,21 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) =>
return;
}
const targetNote = repository.getNote(entity.value);
const templateNote = repository.getNote(entity.value);
if (!targetNote || !targetNote.isStringNote()) {
if (!templateNote) {
return;
}
const targetNoteContent = targetNote.getContent();
if (templateNote.isStringNote()) {
const templateNoteContent = templateNote.getContent();
if (targetNoteContent) {
note.setContent(targetNoteContent);
if (templateNoteContent) {
note.setContent(templateNoteContent);
}
}
noteService.duplicateSubtreeWithoutRoot(templateNote.noteId, note.noteId);
}
else if (entity.type === 'label' && entity.name === 'sorted') {
treeService.sortNotesAlphabetically(entity.noteId);