mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	Merge remote-tracking branch 'origin/stable'
This commit is contained in:
		
						commit
						89f117da5b
					
				@ -115,9 +115,9 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        const $input = $("<input>")
 | 
					        const $input = $("<input>")
 | 
				
			||||||
            .prop("tabindex", 200 + definitionAttr.position)
 | 
					            .prop("tabindex", 200 + definitionAttr.position)
 | 
				
			||||||
            .prop("attribute-id", valueAttr.noteId === this.noteId ? valueAttr.attributeId : '') // if not owned, we'll force creation of a new attribute instead of updating the inherited one
 | 
					            .attr("data-attribute-id", valueAttr.noteId === this.noteId ? valueAttr.attributeId : '') // if not owned, we'll force creation of a new attribute instead of updating the inherited one
 | 
				
			||||||
            .prop("attribute-type", valueAttr.type)
 | 
					            .attr("data-attribute-type", valueAttr.type)
 | 
				
			||||||
            .prop("attribute-name", valueAttr.name)
 | 
					            .attr("data-attribute-name", valueAttr.name)
 | 
				
			||||||
            .prop("value", valueAttr.value)
 | 
					            .prop("value", valueAttr.value)
 | 
				
			||||||
            .addClass("form-control")
 | 
					            .addClass("form-control")
 | 
				
			||||||
            .addClass("promoted-attribute-input")
 | 
					            .addClass("promoted-attribute-input")
 | 
				
			||||||
@ -230,7 +230,7 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (definition.multiplicity === "multi") {
 | 
					        if (definition.multiplicity === "multi") {
 | 
				
			||||||
            const addButton = $("<span>")
 | 
					            const $addButton = $("<span>")
 | 
				
			||||||
                .addClass("bx bx-plus pointer")
 | 
					                .addClass("bx bx-plus pointer")
 | 
				
			||||||
                .prop("title", "Add new attribute")
 | 
					                .prop("title", "Add new attribute")
 | 
				
			||||||
                .on('click', async () => {
 | 
					                .on('click', async () => {
 | 
				
			||||||
@ -246,12 +246,28 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
                    $new.find('input').trigger('focus');
 | 
					                    $new.find('input').trigger('focus');
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const removeButton = $("<span>")
 | 
					            const $removeButton = $("<span>")
 | 
				
			||||||
                .addClass("bx bx-trash pointer")
 | 
					                .addClass("bx bx-trash pointer")
 | 
				
			||||||
                .prop("title", "Remove this attribute")
 | 
					                .prop("title", "Remove this attribute")
 | 
				
			||||||
                .on('click', async () => {
 | 
					                .on('click', async () => {
 | 
				
			||||||
                    if (valueAttr.attributeId) {
 | 
					                    const attributeId = $input.attr("data-attribute-id");
 | 
				
			||||||
                        await server.remove("notes/" + this.noteId + "/attributes/" + valueAttr.attributeId, this.componentId);
 | 
					
 | 
				
			||||||
 | 
					                    if (attributeId) {
 | 
				
			||||||
 | 
					                        await server.remove("notes/" + this.noteId + "/attributes/" + attributeId, this.componentId);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    // if it's the last one the create new empty form immediately
 | 
				
			||||||
 | 
					                    const sameAttrSelector = `input[data-attribute-type='${valueAttr.type}'][data-attribute-name='${valueName}']`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (this.$widget.find(sameAttrSelector).length <= 1) {
 | 
				
			||||||
 | 
					                        const $new = await this.createPromotedAttributeCell(definitionAttr, {
 | 
				
			||||||
 | 
					                            attributeId: "",
 | 
				
			||||||
 | 
					                            type: valueAttr.type,
 | 
				
			||||||
 | 
					                            name: valueName,
 | 
				
			||||||
 | 
					                            value: ""
 | 
				
			||||||
 | 
					                        }, valueName);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        $wrapper.after($new);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    $wrapper.remove();
 | 
					                    $wrapper.remove();
 | 
				
			||||||
@ -259,9 +275,9 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            $multiplicityCell
 | 
					            $multiplicityCell
 | 
				
			||||||
                .append("  ")
 | 
					                .append("  ")
 | 
				
			||||||
                .append(addButton)
 | 
					                .append($addButton)
 | 
				
			||||||
                .append("  ")
 | 
					                .append("  ")
 | 
				
			||||||
                .append(removeButton);
 | 
					                .append($removeButton);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $wrapper;
 | 
					        return $wrapper;
 | 
				
			||||||
@ -275,7 +291,7 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
        if ($attr.prop("type") === "checkbox") {
 | 
					        if ($attr.prop("type") === "checkbox") {
 | 
				
			||||||
            value = $attr.is(':checked') ? "true" : "false";
 | 
					            value = $attr.is(':checked') ? "true" : "false";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else if ($attr.prop("attribute-type") === "relation") {
 | 
					        else if ($attr.attr("data-attribute-type") === "relation") {
 | 
				
			||||||
            const selectedPath = $attr.getSelectedNotePath();
 | 
					            const selectedPath = $attr.getSelectedNotePath();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            value = selectedPath ? treeService.getNoteIdFromNotePath(selectedPath) : "";
 | 
					            value = selectedPath ? treeService.getNoteIdFromNotePath(selectedPath) : "";
 | 
				
			||||||
@ -285,13 +301,13 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const result = await server.put(`notes/${this.noteId}/attribute`, {
 | 
					        const result = await server.put(`notes/${this.noteId}/attribute`, {
 | 
				
			||||||
            attributeId: $attr.prop("attribute-id"),
 | 
					            attributeId: $attr.attr("data-attribute-id"),
 | 
				
			||||||
            type: $attr.prop("attribute-type"),
 | 
					            type: $attr.attr("data-attribute-type"),
 | 
				
			||||||
            name: $attr.prop("attribute-name"),
 | 
					            name: $attr.attr("data-attribute-name"),
 | 
				
			||||||
            value: value
 | 
					            value: value
 | 
				
			||||||
        }, this.componentId);
 | 
					        }, this.componentId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $attr.prop("attribute-id", result.attributeId);
 | 
					        $attr.attr("data-attribute-id", result.attributeId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    entitiesReloadedEvent({loadResults}) {
 | 
					    entitiesReloadedEvent({loadResults}) {
 | 
				
			||||||
 | 
				
			|||||||
@ -65,6 +65,7 @@ const BUILTIN_ATTRIBUTES = [
 | 
				
			|||||||
    { type: 'relation', name: 'renderNote', isDangerous: true }
 | 
					    { type: 'relation', name: 'renderNote', isDangerous: true }
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** @returns {Note[]} */
 | 
				
			||||||
function getNotesWithLabel(name, value) {
 | 
					function getNotesWithLabel(name, value) {
 | 
				
			||||||
    const query = formatAttrForSearch({type: 'label', name, value}, true);
 | 
					    const query = formatAttrForSearch({type: 'label', name, value}, true);
 | 
				
			||||||
    return searchService.searchNotes(query, {
 | 
					    return searchService.searchNotes(query, {
 | 
				
			||||||
@ -74,6 +75,7 @@ function getNotesWithLabel(name, value) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: should be in search service
 | 
					// TODO: should be in search service
 | 
				
			||||||
 | 
					/** @returns {Note|null} */
 | 
				
			||||||
function getNoteWithLabel(name, value) {
 | 
					function getNoteWithLabel(name, value) {
 | 
				
			||||||
    // optimized version (~20 times faster) without using normal search, useful for e.g. finding date notes
 | 
					    // optimized version (~20 times faster) without using normal search, useful for e.g. finding date notes
 | 
				
			||||||
    const attrs = becca.findAttributes('label', name);
 | 
					    const attrs = becca.findAttributes('label', name);
 | 
				
			||||||
 | 
				
			|||||||
@ -25,15 +25,6 @@ function createNote(parentNote, noteTitle) {
 | 
				
			|||||||
    }).note;
 | 
					    }).note;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getNoteStartingWith(parentNoteId, startsWith) {
 | 
					 | 
				
			||||||
    const noteId = sql.getValue(`SELECT notes.noteId FROM notes JOIN branches USING(noteId) 
 | 
					 | 
				
			||||||
                                    WHERE parentNoteId = ? AND title LIKE '${startsWith}%'
 | 
					 | 
				
			||||||
                                    AND notes.isDeleted = 0 AND isProtected = 0 
 | 
					 | 
				
			||||||
                                    AND branches.isDeleted = 0`, [parentNoteId]);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return becca.getNote(noteId);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/** @returns {Note} */
 | 
					/** @returns {Note} */
 | 
				
			||||||
function getRootCalendarNote() {
 | 
					function getRootCalendarNote() {
 | 
				
			||||||
    let rootNote = attributeService.getNoteWithLabel(CALENDAR_ROOT_LABEL);
 | 
					    let rootNote = attributeService.getNoteWithLabel(CALENDAR_ROOT_LABEL);
 | 
				
			||||||
@ -164,12 +155,6 @@ function getDateNote(dateStr) {
 | 
				
			|||||||
    const monthNote = getMonthNote(dateStr, rootNote);
 | 
					    const monthNote = getMonthNote(dateStr, rootNote);
 | 
				
			||||||
    const dayNumber = dateStr.substr(8, 2);
 | 
					    const dayNumber = dateStr.substr(8, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    dateNote = getNoteStartingWith(monthNote.noteId, dayNumber);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (dateNote) {
 | 
					 | 
				
			||||||
        return dateNote;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const dateObj = dateUtils.parseLocalDate(dateStr);
 | 
					    const dateObj = dateUtils.parseLocalDate(dateStr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const noteTitle = getDateNoteTitle(rootNote, dayNumber, dateObj);
 | 
					    const noteTitle = getDateNoteTitle(rootNote, dayNumber, dateObj);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user