mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	fix relations in attributes
This commit is contained in:
		
							parent
							
								
									a55d3530e9
								
							
						
					
					
						commit
						49989695ff
					
				@ -1,6 +1,8 @@
 | 
			
		||||
import noteDetailService from '../services/note_detail.js';
 | 
			
		||||
import server from '../services/server.js';
 | 
			
		||||
import infoService from "../services/info.js";
 | 
			
		||||
import treeUtils from "../services/tree_utils.js";
 | 
			
		||||
import linkService from "../services/link.js";
 | 
			
		||||
 | 
			
		||||
const $dialog = $("#attributes-dialog");
 | 
			
		||||
const $saveAttributesButton = $("#save-attributes-button");
 | 
			
		||||
@ -53,10 +55,10 @@ function AttributesModel() {
 | 
			
		||||
        });
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    function prepareAttributes(attributes) {
 | 
			
		||||
    async function showAttributes(attributes) {
 | 
			
		||||
        for (const attr of attributes) {
 | 
			
		||||
            attr.labelValue = attr.type === 'label' ? attr.value : '';
 | 
			
		||||
            attr.relationValue = attr.type === 'relation' ? attr.value : '';
 | 
			
		||||
            attr.relationValue = attr.type === 'relation' ? (await treeUtils.getNoteTitle(attr.value) + " (" + attr.value + ")") : '';
 | 
			
		||||
            attr.labelDefinition = (attr.type === 'label-definition' && attr.value) ? attr.value : {
 | 
			
		||||
                labelType: "text",
 | 
			
		||||
                multiplicityType: "singlevalue",
 | 
			
		||||
@ -80,7 +82,7 @@ function AttributesModel() {
 | 
			
		||||
 | 
			
		||||
        const attributes = await server.get('notes/' + noteId + '/attributes');
 | 
			
		||||
 | 
			
		||||
        prepareAttributes(attributes);
 | 
			
		||||
        await showAttributes(attributes);
 | 
			
		||||
 | 
			
		||||
        // attribute might not be rendered immediatelly so could not focus
 | 
			
		||||
        setTimeout(() => $(".attribute-name:last").focus(), 100);
 | 
			
		||||
@ -139,7 +141,7 @@ function AttributesModel() {
 | 
			
		||||
                attr.value = attr.labelValue;
 | 
			
		||||
            }
 | 
			
		||||
            else if (attr.type === 'relation') {
 | 
			
		||||
                attr.value = attr.relationValue;
 | 
			
		||||
                attr.value = treeUtils.getNoteIdFromNotePath(linkService.getNotePathFromLabel(attr.relationValue));
 | 
			
		||||
            }
 | 
			
		||||
            else if (attr.type === 'label-definition') {
 | 
			
		||||
                attr.value = attr.labelDefinition;
 | 
			
		||||
@ -156,7 +158,7 @@ function AttributesModel() {
 | 
			
		||||
 | 
			
		||||
        const attributes = await server.put('notes/' + noteId + '/attributes', attributesToSave);
 | 
			
		||||
 | 
			
		||||
        prepareAttributes(attributes);
 | 
			
		||||
        await showAttributes(attributes);
 | 
			
		||||
 | 
			
		||||
        infoService.showMessage("Attributes have been saved.");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -263,7 +263,7 @@ async function loadAttributes() {
 | 
			
		||||
                    $attributeListInner.append(utils.formatLabel(attribute) + " ");
 | 
			
		||||
                }
 | 
			
		||||
                else if (attribute.type === 'relation') {
 | 
			
		||||
                    $attributeListInner.append(attribute.name + " = ");
 | 
			
		||||
                    $attributeListInner.append(attribute.name + "=");
 | 
			
		||||
                    $attributeListInner.append(await linkService.createNoteLink(attribute.value));
 | 
			
		||||
                    $attributeListInner.append(" ");
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@ import utils from "./utils.js";
 | 
			
		||||
import Branch from "../entities/branch.js";
 | 
			
		||||
import NoteShort from "../entities/note_short.js";
 | 
			
		||||
import infoService from "./info.js";
 | 
			
		||||
import messagingService from "./messaging.js";
 | 
			
		||||
import server from "./server.js";
 | 
			
		||||
 | 
			
		||||
class TreeCache {
 | 
			
		||||
@ -48,7 +49,9 @@ class TreeCache {
 | 
			
		||||
 | 
			
		||||
        return noteIds.map(noteId => {
 | 
			
		||||
            if (!this.notes[noteId]) {
 | 
			
		||||
                throw new Error(`Can't find note ${noteId}`);
 | 
			
		||||
                messagingService.logError(`Can't find note ${noteId}`);
 | 
			
		||||
 | 
			
		||||
                return `[unknown ${noteId}]`;
 | 
			
		||||
            }
 | 
			
		||||
            else {
 | 
			
		||||
                return this.notes[noteId];
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user