mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	date notes are now created with template relations
This commit is contained in:
		@@ -195,6 +195,8 @@ class Note extends Entity {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @returns {Promise<Attribute[]>} attributes belonging to this specific note (excludes inherited attributes)
 | 
			
		||||
     *
 | 
			
		||||
     * This method can be significantly faster than the getAttributes()
 | 
			
		||||
     */
 | 
			
		||||
    async getOwnedAttributes(type, name) {
 | 
			
		||||
        let query = `SELECT * FROM attributes WHERE isDeleted = 0 AND noteId = ?`;
 | 
			
		||||
@@ -215,6 +217,8 @@ class Note extends Entity {
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @returns {Promise<Attribute>} attribute belonging to this specific note (excludes inherited attributes)
 | 
			
		||||
     *
 | 
			
		||||
     * This method can be significantly faster than the getAttribute()
 | 
			
		||||
     */
 | 
			
		||||
    async getOwnedAttribute(type, name) {
 | 
			
		||||
        const attrs = await this.getOwnedAttributes(type, name);
 | 
			
		||||
 
 | 
			
		||||
@@ -35,6 +35,9 @@ export default class NoteTypeContext {
 | 
			
		||||
            () => ["file", "image", "search"].includes(this.ctx.note.type));
 | 
			
		||||
 | 
			
		||||
        this.$noteTypeDesc.text(await this.findTypeTitle(this.ctx.note.type, this.ctx.note.mime));
 | 
			
		||||
 | 
			
		||||
        this.$executeScriptButton.toggle(this.ctx.note.mime.startsWith('application/javascript'));
 | 
			
		||||
        this.$renderButton.toggle(this.ctx.note.type === 'render');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** actual body is rendered lazily on note-type button click */
 | 
			
		||||
@@ -87,9 +90,6 @@ export default class NoteTypeContext {
 | 
			
		||||
 | 
			
		||||
            this.$noteTypeDropdown.append($mimeLink);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.$executeScriptButton.toggle(this.ctx.note.mime.startsWith('application/javascript'));
 | 
			
		||||
        this.$renderButton.toggle(this.ctx.note.type === 'render');
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async findTypeTitle(type, mime) {
 | 
			
		||||
 
 | 
			
		||||
@@ -72,6 +72,15 @@ async function createLabel(noteId, name, value = "") {
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function createRelation(noteId, name, targetNoteId) {
 | 
			
		||||
    return await createAttribute({
 | 
			
		||||
        noteId: noteId,
 | 
			
		||||
        type: 'relation',
 | 
			
		||||
        name: name,
 | 
			
		||||
        value: targetNoteId
 | 
			
		||||
    });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function createAttribute(attribute) {
 | 
			
		||||
    return await new Attribute(attribute).save();
 | 
			
		||||
}
 | 
			
		||||
@@ -114,6 +123,7 @@ module.exports = {
 | 
			
		||||
    getNotesWithLabels,
 | 
			
		||||
    getNoteWithLabel,
 | 
			
		||||
    createLabel,
 | 
			
		||||
    createRelation,
 | 
			
		||||
    createAttribute,
 | 
			
		||||
    getAttributeNames,
 | 
			
		||||
    isAttributeType,
 | 
			
		||||
 
 | 
			
		||||
@@ -67,6 +67,12 @@ async function getYearNote(dateStr, rootNote) {
 | 
			
		||||
 | 
			
		||||
        await attributeService.createLabel(yearNote.noteId, YEAR_LABEL, yearStr);
 | 
			
		||||
        await attributeService.createLabel(yearNote.noteId, 'sorted');
 | 
			
		||||
 | 
			
		||||
        const yearTemplateAttr = await rootNote.getOwnedAttribute('relation', 'yearTemplate');
 | 
			
		||||
 | 
			
		||||
        if (yearTemplateAttr) {
 | 
			
		||||
            await attributeService.createRelation(yearNote.noteId, 'template', yearTemplateAttr.value);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return yearNote;
 | 
			
		||||
@@ -83,6 +89,10 @@ async function getMonthNoteTitle(rootNote, monthNumber, dateObj) {
 | 
			
		||||
 | 
			
		||||
/** @return {Promise<Note>} */
 | 
			
		||||
async function getMonthNote(dateStr, rootNote) {
 | 
			
		||||
    if (!rootNote) {
 | 
			
		||||
        rootNote = await getRootCalendarNote();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const monthStr = dateStr.substr(0, 7);
 | 
			
		||||
    const monthNumber = dateStr.substr(5, 2);
 | 
			
		||||
 | 
			
		||||
@@ -103,6 +113,12 @@ async function getMonthNote(dateStr, rootNote) {
 | 
			
		||||
 | 
			
		||||
        await attributeService.createLabel(monthNote.noteId, MONTH_LABEL, monthStr);
 | 
			
		||||
        await attributeService.createLabel(monthNote.noteId, 'sorted');
 | 
			
		||||
 | 
			
		||||
        const monthTemplateAttr = await rootNote.getOwnedAttribute('relation', 'monthTemplate');
 | 
			
		||||
 | 
			
		||||
        if (monthTemplateAttr) {
 | 
			
		||||
            await attributeService.createRelation(monthNote.noteId, 'template', monthTemplateAttr.value);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return monthNote;
 | 
			
		||||
@@ -141,6 +157,12 @@ async function getDateNote(dateStr) {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        await attributeService.createLabel(dateNote.noteId, DATE_LABEL, dateStr.substr(0, 10));
 | 
			
		||||
 | 
			
		||||
        const dateTemplateAttr = await rootNote.getOwnedAttribute('relation', 'dateTemplate');
 | 
			
		||||
 | 
			
		||||
        if (dateTemplateAttr) {
 | 
			
		||||
            await attributeService.createRelation(dateNote.noteId, 'template', dateTemplateAttr.value);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return dateNote;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user