refactoring

This commit is contained in:
zadam
2023-06-01 00:07:57 +02:00
parent b5cfc28912
commit ae42e0efc7
4 changed files with 56 additions and 77 deletions

View File

@@ -54,11 +54,10 @@ function deriveMime(type, mime) {
}
function copyChildAttributes(parentNote, childNote) {
const hasAlreadyTemplate = childNote.hasRelation('template');
for (const attr of parentNote.getAttributes()) {
if (attr.name.startsWith("child:")) {
const name = attr.name.substr(6);
const hasAlreadyTemplate = childNote.hasRelation('template');
if (hasAlreadyTemplate && attr.type === 'relation' && name === 'template') {
// if the note already has a template, it means the template was chosen by the user explicitly
@@ -174,7 +173,7 @@ function createNewNote(params) {
// TODO: think about what can happen if the note already exists with the forced ID
// I guess on DB it's going to be fine, but becca references between entities
// might get messed up (two Note instance for the same ID existing in the references)
// might get messed up (two note instances for the same ID existing in the references)
note = new BNote({
noteId: params.noteId, // optionally can force specific noteId
title: params.title,
@@ -195,7 +194,7 @@ function createNewNote(params) {
}
finally {
if (!isEntityEventsDisabled) {
// re-enable entity events only if there were previously enabled
// re-enable entity events only if they were previously enabled
// (they can be disabled in case of import)
cls.enableEntityEvents();
}
@@ -215,27 +214,14 @@ function createNewNote(params) {
copyChildAttributes(parentNote, note);
eventService.emit(eventService.ENTITY_CREATED, { entityName: 'notes', entity: note });
eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'notes', entity: note });
triggerNoteTitleChanged(note);
eventService.emit(eventService.ENTITY_CREATED, {
entityName: 'notes',
entity: note
});
eventService.emit(eventService.ENTITY_CREATED, {
entityName: 'note_contents',
entity: note
});
eventService.emit(eventService.ENTITY_CREATED, {
entityName: 'branches',
entity: branch
});
eventService.emit(eventService.CHILD_NOTE_CREATED, {
childNote: note,
parentNote: parentNote
});
// note_contents doesn't use "created" event
eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'note_contents', entity: note });
eventService.emit(eventService.ENTITY_CREATED, { entityName: 'branches', entity: branch });
eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'branches', entity: branch });
eventService.emit(eventService.CHILD_NOTE_CREATED, { childNote: note, parentNote: parentNote });
log.info(`Created new note '${note.noteId}', branch '${branch.branchId}' of type '${note.type}', mime '${note.mime}'`);