mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	moving from inherited attribute queries to owned one where it makes sense
This commit is contained in:
		| @@ -278,6 +278,14 @@ class Note extends Entity { | ||||
|         return await this.getAttributes(LABEL, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - label name to filter | ||||
|      * @returns {Promise<Attribute[]>} all note's labels (attributes with type label), excluding inherited ones | ||||
|      */ | ||||
|     async getOwnedLabels(name) { | ||||
|         return await this.getOwnedAttributes(LABEL, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - label name to filter | ||||
|      * @returns {Promise<Attribute[]>} all note's label definitions, including inherited ones | ||||
| @@ -294,6 +302,14 @@ class Note extends Entity { | ||||
|         return await this.getAttributes(RELATION, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - relation name to filter | ||||
|      * @returns {Promise<Attribute[]>} all note's relations (attributes with type relation), excluding inherited ones | ||||
|      */ | ||||
|     async getOwnedRelations(name) { | ||||
|         return await this.getOwnedAttributes(RELATION, name); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param {string} [name] - relation name to filter | ||||
|      * @returns {Promise<Note[]>} | ||||
|   | ||||
| @@ -15,7 +15,7 @@ async function findClippingNote(todayNote, pageUrl) { | ||||
|     const notes = await todayNote.getDescendantNotesWithLabel('pageUrl', pageUrl); | ||||
|  | ||||
|     for (const note of notes) { | ||||
|         if (await note.getLabelValue('clipType') === 'clippings') { | ||||
|         if (await note.getOwnedLabelValue('clipType') === 'clippings') { | ||||
|             return note; | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -27,31 +27,6 @@ async function getNote(req) { | ||||
|     return note; | ||||
| } | ||||
|  | ||||
| async function getChildren(req) { | ||||
|     const parentNoteId = req.params.parentNoteId; | ||||
|     const parentNote = await repository.getNote(parentNoteId); | ||||
|  | ||||
|     if (!parentNote) { | ||||
|         return [404, `Note ${parentNoteId} has not been found.`]; | ||||
|     } | ||||
|  | ||||
|     const ret = []; | ||||
|  | ||||
|     for (const childNote of await parentNote.getChildNotes()) { | ||||
|         ret.push({ | ||||
|             noteId: childNote.noteId, | ||||
|             title: childNote.title, | ||||
|             relations: (await childNote.getRelations()).map(relation => { return { | ||||
|                 attributeId: relation.attributeId, | ||||
|                 name: relation.name, | ||||
|                 targetNoteId: relation.value | ||||
|             }; }) | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     return ret; | ||||
| } | ||||
|  | ||||
| async function createNote(req) { | ||||
|     const params = Object.assign({}, req.body); // clone | ||||
|     params.parentNoteId = req.params.parentNoteId; | ||||
| @@ -198,7 +173,6 @@ module.exports = { | ||||
|     sortNotes, | ||||
|     protectSubtree, | ||||
|     setNoteTypeMime, | ||||
|     getChildren, | ||||
|     getRelationMap, | ||||
|     changeTitle, | ||||
|     duplicateNote | ||||
|   | ||||
| @@ -90,7 +90,7 @@ async function getUserThemes() { | ||||
|     const ret = []; | ||||
|  | ||||
|     for (const note of notes) { | ||||
|         let value = await note.getLabelValue('appTheme'); | ||||
|         let value = await note.getOwnedLabelValue('appTheme'); | ||||
|  | ||||
|         if (!value) { | ||||
|             value = note.title.toLowerCase().replace(/[^a-z0-9]/gi, '-'); | ||||
|   | ||||
| @@ -128,7 +128,6 @@ function register(app) { | ||||
|     apiRoute(PUT, '/api/notes/:noteId', notesApiRoute.updateNote); | ||||
|     apiRoute(DELETE, '/api/notes/:noteId', notesApiRoute.deleteNote); | ||||
|     apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote); | ||||
|     apiRoute(GET, '/api/notes/:parentNoteId/children', notesApiRoute.getChildren); | ||||
|     apiRoute(PUT, '/api/notes/:noteId/sort', notesApiRoute.sortNotes); | ||||
|     apiRoute(PUT, '/api/notes/:noteId/protect/:isProtected', notesApiRoute.protectSubtree); | ||||
|     apiRoute(PUT, /\/api\/notes\/(.*)\/type\/(.*)\/mime\/(.*)/, notesApiRoute.setNoteTypeMime); | ||||
|   | ||||
| @@ -81,7 +81,7 @@ async function getYearNote(dateStr, rootNote) { | ||||
| } | ||||
|  | ||||
| async function getMonthNoteTitle(rootNote, monthNumber, dateObj) { | ||||
|     const pattern = await rootNote.getLabelValue("monthPattern") || "{monthNumberPadded} - {month}"; | ||||
|     const pattern = await rootNote.getOwnedLabelValue("monthPattern") || "{monthNumberPadded} - {month}"; | ||||
|     const monthName = MONTHS[dateObj.getMonth()]; | ||||
|  | ||||
|     return pattern | ||||
| @@ -127,7 +127,7 @@ async function getMonthNote(dateStr, rootNote) { | ||||
| } | ||||
|  | ||||
| async function getDateNoteTitle(rootNote, dayNumber, dateObj) { | ||||
|     const pattern = await rootNote.getLabelValue("datePattern") || "{dayInMonthPadded} - {weekDay}"; | ||||
|     const pattern = await rootNote.getOwnedLabelValue("datePattern") || "{dayInMonthPadded} - {weekDay}"; | ||||
|     const weekDay = DAYS[dateObj.getDay()]; | ||||
|  | ||||
|     return pattern | ||||
|   | ||||
| @@ -16,7 +16,7 @@ async function exportToOpml(taskContext, branch, version, res) { | ||||
|         const branch = await repository.getBranch(branchId); | ||||
|         const note = await branch.getNote(); | ||||
|  | ||||
|         if (!note.isStringNote() || await note.hasLabel('excludeFromExport')) { | ||||
|         if (!note.isStringNote() || await note.hasOwnedLabel('excludeFromExport')) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -79,7 +79,7 @@ async function exportToTar(taskContext, branch, format, res) { | ||||
|     async function getNoteMeta(branch, parentMeta, existingFileNames) { | ||||
|         const note = await branch.getNote(); | ||||
|  | ||||
|         if (await note.hasLabel('excludeFromExport')) { | ||||
|         if (await note.hasOwnedLabel('excludeFromExport')) { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -27,7 +27,7 @@ eventService.subscribe(eventService.NOTE_TITLE_CHANGED, async note => { | ||||
|         const parents = await note.getParentNotes(); | ||||
|  | ||||
|         for (const parent of parents) { | ||||
|             if (await parent.hasLabel("sorted")) { | ||||
|             if (await parent.hasOwnedLabel("sorted")) { | ||||
|                 await treeService.sortNotesAlphabetically(parent.noteId); | ||||
|             } | ||||
|         } | ||||
| @@ -119,7 +119,7 @@ eventService.subscribe(eventService.ENTITY_CHANGED, async ({ entityName, entity | ||||
| eventService.subscribe(eventService.ENTITY_DELETED, async ({ entityName, entity }) => { | ||||
|     await processInverseRelations(entityName, entity, async (definition, note, targetNote) => { | ||||
|         // if one inverse attribute is deleted then the other should be deleted as well | ||||
|         const relations = await targetNote.getRelations(definition.inverseRelation); | ||||
|         const relations = await targetNote.getOwnedRelations(definition.inverseRelation); | ||||
|         let deletedSomething = false; | ||||
|  | ||||
|         for (const relation of relations) { | ||||
|   | ||||
| @@ -40,7 +40,7 @@ async function executeBundle(bundle, apiParams = {}) { | ||||
|     const ctx = new ScriptContext(bundle.allNotes, apiParams); | ||||
|  | ||||
|     try { | ||||
|         if (await bundle.note.hasLabel('manualTransactionHandling')) { | ||||
|         if (await bundle.note.hasOwnedLabel('manualTransactionHandling')) { | ||||
|             return await execute(ctx, script); | ||||
|         } | ||||
|         else { | ||||
| @@ -117,7 +117,7 @@ async function getScriptBundle(note, root = true, scriptEnv = null, includedNote | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     if (!root && await note.hasLabel('disableInclusion')) { | ||||
|     if (!root && await note.hasOwnedLabel('disableInclusion')) { | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user