mirror of
https://github.com/zadam/trilium.git
synced 2025-11-07 05:46:10 +01:00
label update should trigger parent resort, fixes #3366
This commit is contained in:
@@ -46,6 +46,8 @@ eventService.subscribe([ eventService.ENTITY_CHANGED, eventService.ENTITY_DELETE
|
||||
|
||||
if (entity.type === 'label' && ['sorted', 'sortDirection', 'sortFoldersFirst'].includes(entity.name)) {
|
||||
handleSortedAttribute(entity);
|
||||
} else if (entity.type === 'label') {
|
||||
handleMaybeSortingLabel(entity);
|
||||
}
|
||||
}
|
||||
else if (entityName === 'notes') {
|
||||
@@ -94,6 +96,9 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) =>
|
||||
else if (entity.type === 'label' && entity.name === 'sorted') {
|
||||
handleSortedAttribute(entity);
|
||||
}
|
||||
else if (entity.type === 'label') {
|
||||
handleMaybeSortingLabel(entity);
|
||||
}
|
||||
}
|
||||
else if (entityName === 'branches') {
|
||||
runAttachedRelations(entity.getNote(), 'runOnBranchCreation', entity);
|
||||
@@ -138,6 +143,27 @@ function handleSortedAttribute(entity) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleMaybeSortingLabel(entity) {
|
||||
// check if this label is used for sorting, if yes force re-sort
|
||||
const note = becca.notes[entity.noteId];
|
||||
|
||||
// this will not work on deleted notes, but in that case we don't really need to re-sort
|
||||
if (note) {
|
||||
for (const parentNote of note.getParentNotes()) {
|
||||
console.log("PAR", parentNote.noteId);
|
||||
const sorted = parentNote.getLabelValue("sorted");
|
||||
|
||||
console.log("sorted", sorted);
|
||||
|
||||
if (sorted?.includes(entity.name)) { // hacky check if the sorting is affected by this label
|
||||
console.log("RESIRT!");
|
||||
|
||||
treeService.sortNotesIfNeeded(parentNote.noteId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
eventService.subscribe(eventService.ENTITY_CHANGED, ({ entityName, entity }) => {
|
||||
processInverseRelations(entityName, entity, (definition, note, targetNote) => {
|
||||
// we need to make sure that also target's inverse attribute exists and if not, then create it
|
||||
|
||||
Reference in New Issue
Block a user