mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	fix/improve behavior of "sorted" attribute
This commit is contained in:
		| @@ -1198,7 +1198,25 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|         this.clearSelectedNodes(); |         this.clearSelectedNodes(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     canBeMovedUpOrDown(node) { | ||||||
|  |         if (node.data.noteId === 'root') { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         const parentNote = treeCache.getNoteFromCache(node.getParent().data.noteId); | ||||||
|  |  | ||||||
|  |         if (parentNote && parentNote.hasLabel('sorted')) { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     moveNoteUpCommand({node}) { |     moveNoteUpCommand({node}) { | ||||||
|  |         if (!this.canBeMovedUpOrDown(node)) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         const beforeNode = node.getPrevSibling(); |         const beforeNode = node.getPrevSibling(); | ||||||
|  |  | ||||||
|         if (beforeNode !== null) { |         if (beforeNode !== null) { | ||||||
| @@ -1207,7 +1225,12 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     moveNoteDownCommand({node}) { |     moveNoteDownCommand({node}) { | ||||||
|  |         if (!this.canBeMovedUpOrDown(node)) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         const afterNode = node.getNextSibling(); |         const afterNode = node.getNextSibling(); | ||||||
|  |  | ||||||
|         if (afterNode !== null) { |         if (afterNode !== null) { | ||||||
|             branchService.moveAfterBranch([node.data.branchId], afterNode.data.branchId); |             branchService.moveAfterBranch([node.data.branchId], afterNode.data.branchId); | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ const scriptService = require('./script'); | |||||||
| const treeService = require('./tree'); | const treeService = require('./tree'); | ||||||
| const noteService = require('./notes'); | const noteService = require('./notes'); | ||||||
| const repository = require('./repository'); | const repository = require('./repository'); | ||||||
|  | const noteCache = require('./note_cache/note_cache'); | ||||||
| const Attribute = require('../entities/attribute'); | const Attribute = require('../entities/attribute'); | ||||||
|  |  | ||||||
| function runAttachedRelations(note, relationName, originEntity) { | function runAttachedRelations(note, relationName, originEntity) { | ||||||
| @@ -22,11 +23,11 @@ eventService.subscribe(eventService.NOTE_TITLE_CHANGED, note => { | |||||||
|     runAttachedRelations(note, 'runOnNoteTitleChange', note); |     runAttachedRelations(note, 'runOnNoteTitleChange', note); | ||||||
|  |  | ||||||
|     if (!note.isRoot()) { |     if (!note.isRoot()) { | ||||||
|         const parents = note.getParentNotes(); |         const noteFromCache = noteCache.notes[note.noteId]; | ||||||
|  |  | ||||||
|         for (const parent of parents) { |         for (const parentNote of noteFromCache.parents) { | ||||||
|             if (parent.hasOwnedLabel("sorted")) { |             if (parentNote.hasLabel("sorted")) { | ||||||
|                 treeService.sortNotesAlphabetically(parent.noteId); |                 treeService.sortNotesAlphabetically(parentNote.noteId); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -80,6 +81,16 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) => | |||||||
|         } |         } | ||||||
|         else if (entity.type === 'label' && entity.name === 'sorted') { |         else if (entity.type === 'label' && entity.name === 'sorted') { | ||||||
|             treeService.sortNotesAlphabetically(entity.noteId); |             treeService.sortNotesAlphabetically(entity.noteId); | ||||||
|  |  | ||||||
|  |             if (entity.isInheritable) { | ||||||
|  |                 const note = noteCache.notes[entity.noteId]; | ||||||
|  |  | ||||||
|  |                 if (note) { | ||||||
|  |                     for (const noteId of note.subtreeNoteIds) { | ||||||
|  |                         treeService.sortNotesAlphabetically(noteId); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     else if (entityName === 'notes') { |     else if (entityName === 'notes') { | ||||||
|   | |||||||
| @@ -133,6 +133,14 @@ class Note { | |||||||
|         return !!this.attributes.find(attr => attr.type === type && attr.name === name); |         return !!this.attributes.find(attr => attr.type === type && attr.name === name); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     hasLabel(name) { | ||||||
|  |         return this.hasAttribute('label', name); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     hasRelation(name) { | ||||||
|  |         return this.hasAttribute('relation', name); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     getLabelValue(name) { |     getLabelValue(name) { | ||||||
|         const label = this.attributes.find(attr => attr.type === 'label' && attr.name === name); |         const label = this.attributes.find(attr => attr.type === 'label' && attr.name === name); | ||||||
|  |  | ||||||
| @@ -275,6 +283,11 @@ class Note { | |||||||
|         return arr.flat(); |         return arr.flat(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** @return {String[]} */ | ||||||
|  |     get subtreeNoteIds() { | ||||||
|  |         return this.subtreeNotes.map(note => note.noteId); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     get parentCount() { |     get parentCount() { | ||||||
|         return this.parents.length; |         return this.parents.length; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,9 +1,5 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const Note = require('./entities/note'); |  | ||||||
| const Branch = require('./entities/branch'); |  | ||||||
| const Attribute = require('./entities/attribute'); |  | ||||||
|  |  | ||||||
| class NoteCache { | class NoteCache { | ||||||
|     constructor() { |     constructor() { | ||||||
|         this.reset(); |         this.reset(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user