mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	cleanup/fixes of label/relation definition usages in the old style
This commit is contained in:
		| @@ -30,14 +30,6 @@ class Attribute extends Entity { | ||||
|         super(row); | ||||
|  | ||||
|         this.isInheritable = !!this.isInheritable; | ||||
|  | ||||
|         if (this.isDefinition()) { | ||||
|             try { | ||||
|                 this.value = JSON.parse(this.value); | ||||
|             } | ||||
|             catch (e) { | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -66,7 +58,7 @@ class Attribute extends Entity { | ||||
|      * @return {boolean} | ||||
|      */ | ||||
|     isDefinition() { | ||||
|         return this.type === 'label-definition' || this.type === 'relation-definition'; | ||||
|         return this.type === 'label' && (this.name.startsWith('label:') || this.name.startsWith('relation:')); | ||||
|     } | ||||
|  | ||||
|     beforeSaving() { | ||||
|   | ||||
| @@ -9,9 +9,7 @@ const dateUtils = require('../services/date_utils'); | ||||
| const entityChangesService = require('../services/entity_changes.js'); | ||||
|  | ||||
| const LABEL = 'label'; | ||||
| const LABEL_DEFINITION = 'label-definition'; | ||||
| const RELATION = 'relation'; | ||||
| const RELATION_DEFINITION = 'relation-definition'; | ||||
|  | ||||
| /** | ||||
|  * This represents a Note which is a central object in the Trilium Notes project. | ||||
| @@ -302,14 +300,6 @@ class Note extends Entity { | ||||
|         return this.getOwnedAttributes(LABEL, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - label name to filter | ||||
|      * @returns {Attribute[]} all note's label definitions, including inherited ones | ||||
|      */ | ||||
|     getLabelDefinitions(name) { | ||||
|         return this.getAttributes(LABEL_DEFINITION, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - relation name to filter | ||||
|      * @returns {Attribute[]} all note's relations (attributes with type relation), including inherited ones | ||||
| @@ -341,14 +331,6 @@ class Note extends Entity { | ||||
|         return targets; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - relation name to filter | ||||
|      * @returns {Attribute[]} all note's relation definitions including inherited ones | ||||
|      */ | ||||
|     getRelationDefinitions(name) { | ||||
|         return this.getAttributes(RELATION_DEFINITION, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Clear note's attributes cache to force fresh reload for next attribute request. | ||||
|      * Cache is note instance scoped. | ||||
|   | ||||
| @@ -3,9 +3,7 @@ import Attribute from './attribute.js'; | ||||
| import noteAttributeCache from "../services/note_attribute_cache.js"; | ||||
|  | ||||
| const LABEL = 'label'; | ||||
| const LABEL_DEFINITION = 'label-definition'; | ||||
| const RELATION = 'relation'; | ||||
| const RELATION_DEFINITION = 'relation-definition'; | ||||
|  | ||||
| /** | ||||
|  * FIXME: since there's no "full note" anymore we can rename this to Note | ||||
| @@ -243,14 +241,6 @@ class NoteShort { | ||||
|         return this.getAttributes(LABEL, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - label name to filter | ||||
|      * @returns {Attribute[]} all note's label definitions, including inherited ones | ||||
|      */ | ||||
|     getLabelDefinitions(name) { | ||||
|         return this.getAttributes(LABEL_DEFINITION, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - relation name to filter | ||||
|      * @returns {Attribute[]} all note's relations (attributes with type relation), including inherited ones | ||||
| @@ -267,14 +257,6 @@ class NoteShort { | ||||
|         return this.getAttributes(RELATION, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - relation name to filter | ||||
|      * @returns {Attribute[]} all note's relation definitions including inherited ones | ||||
|      */ | ||||
|     getRelationDefinitions(name) { | ||||
|         return this.getAttributes(RELATION_DEFINITION, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} type - attribute type (label, relation, etc.) | ||||
|      * @param {string} name - attribute name | ||||
|   | ||||
| @@ -500,9 +500,7 @@ class ConsistencyChecks { | ||||
|                     FROM attributes | ||||
|                     WHERE isDeleted = 0 | ||||
|                       AND type != 'label' | ||||
|                       AND type != 'label-definition' | ||||
|                       AND type != 'relation' | ||||
|                       AND type != 'relation-definition'`, | ||||
|                       AND type != 'relation'`, | ||||
|             ({attributeId, type}) => { | ||||
|                 if (this.autoFix) { | ||||
|                     const attribute = repository.getAttribute(attributeId); | ||||
|   | ||||
| @@ -464,6 +464,12 @@ function saveNoteRevision(note) { | ||||
|     const msSinceDateCreated = now.getTime() - dateUtils.parseDateTime(note.utcDateCreated).getTime(); | ||||
|  | ||||
|     if (!existingNoteRevisionId && msSinceDateCreated >= noteRevisionSnapshotTimeInterval * 1000) { | ||||
|         const content = note.getContent(); | ||||
|  | ||||
|         if (!content) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         const noteRevision = new NoteRevision({ | ||||
|             noteId: note.noteId, | ||||
|             // title and text should be decrypted now | ||||
| @@ -478,7 +484,7 @@ function saveNoteRevision(note) { | ||||
|             dateCreated: dateUtils.localNowDateTime() | ||||
|         }).save(); | ||||
|  | ||||
|         noteRevision.setContent(note.getContent()); | ||||
|         noteRevision.setContent(content); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user