2018-08-01 15:26:02 +08:00
|
|
|
const eventService = require('./events');
|
|
|
|
const scriptService = require('./script');
|
|
|
|
const treeService = require('./tree');
|
|
|
|
const messagingService = require('./messaging');
|
|
|
|
|
|
|
|
eventService.subscribe(eventService.NOTE_TITLE_CHANGED, async note => {
|
2018-08-07 19:33:10 +08:00
|
|
|
const attributes = await note.getAttributes();
|
|
|
|
const runRelations = attributes.filter(relation => relation.type === 'relation' && relation.name === 'runOnNoteTitleChange');
|
2018-08-01 15:26:02 +08:00
|
|
|
|
2018-08-07 19:33:10 +08:00
|
|
|
for (const relation of runRelations) {
|
2018-08-01 15:26:02 +08:00
|
|
|
const scriptNote = await relation.getTargetNote();
|
|
|
|
|
|
|
|
await scriptService.executeNote(scriptNote, scriptNote, note);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!note.isRoot()) {
|
|
|
|
const parents = await note.getParentNotes();
|
|
|
|
|
|
|
|
for (const parent of parents) {
|
|
|
|
if (await parent.hasLabel("sorted")) {
|
|
|
|
await treeService.sortNotesAlphabetically(parent.noteId);
|
|
|
|
|
|
|
|
messagingService.sendMessageToAllClients({ type: 'refresh-tree' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|