mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	cleanup
This commit is contained in:
		
							parent
							
								
									47845930f4
								
							
						
					
					
						commit
						842c317568
					
				@ -40,9 +40,6 @@ class Note extends AbstractEntity {
 | 
				
			|||||||
        this.targetRelations = [];
 | 
					        this.targetRelations = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.shaca.notes[this.noteId] = this;
 | 
					        this.shaca.notes[this.noteId] = this;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        /** @param {Note[]|null} */
 | 
					 | 
				
			||||||
        this.ancestorCache = null;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getParentBranches() {
 | 
					    getParentBranches() {
 | 
				
			||||||
@ -93,36 +90,6 @@ class Note extends AbstractEntity {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** @returns {*} */
 | 
					 | 
				
			||||||
    getJsonContent() {
 | 
					 | 
				
			||||||
        const content = this.getContent();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if (!content || !content.trim()) {
 | 
					 | 
				
			||||||
            return null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return JSON.parse(content);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /** @returns {boolean} true if this note is of application/json content type */
 | 
					 | 
				
			||||||
    isJson() {
 | 
					 | 
				
			||||||
        return this.mime === "application/json";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /** @returns {boolean} true if this note is JavaScript (code or attachment) */
 | 
					 | 
				
			||||||
    isJavaScript() {
 | 
					 | 
				
			||||||
        return (this.type === "code" || this.type === "file")
 | 
					 | 
				
			||||||
            && (this.mime.startsWith("application/javascript")
 | 
					 | 
				
			||||||
                || this.mime === "application/x-javascript"
 | 
					 | 
				
			||||||
                || this.mime === "text/javascript");
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /** @returns {boolean} true if this note is HTML */
 | 
					 | 
				
			||||||
    isHtml() {
 | 
					 | 
				
			||||||
        return ["code", "file", "render"].includes(this.type)
 | 
					 | 
				
			||||||
            && this.mime === "text/html";
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /** @returns {boolean} true if the note has string content (not binary) */
 | 
					    /** @returns {boolean} true if the note has string content (not binary) */
 | 
				
			||||||
    isStringNote() {
 | 
					    isStringNote() {
 | 
				
			||||||
        return utils.isStringNote(this.type, this.mime);
 | 
					        return utils.isStringNote(this.type, this.mime);
 | 
				
			||||||
@ -218,16 +185,6 @@ class Note extends AbstractEntity {
 | 
				
			|||||||
        return !!this.getAttributes().find(attr => attr.type === type && attr.name === name);
 | 
					        return !!this.getAttributes().find(attr => attr.type === type && attr.name === name);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    getAttributeCaseInsensitive(type, name, value) {
 | 
					 | 
				
			||||||
        name = name.toLowerCase();
 | 
					 | 
				
			||||||
        value = value ? value.toLowerCase() : null;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return this.getAttributes().find(
 | 
					 | 
				
			||||||
            attr => attr.type === type
 | 
					 | 
				
			||||||
            && attr.name.toLowerCase() === name
 | 
					 | 
				
			||||||
            && (!value || attr.value.toLowerCase() === value));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    getRelationTarget(name) {
 | 
					    getRelationTarget(name) {
 | 
				
			||||||
        const relation = this.getAttributes().find(attr => attr.type === 'relation' && attr.name === name);
 | 
					        const relation = this.getAttributes().find(attr => attr.type === 'relation' && attr.name === name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -444,112 +401,10 @@ class Note extends AbstractEntity {
 | 
				
			|||||||
        return !!this.targetRelations.find(rel => rel.name === 'template');
 | 
					        return !!this.targetRelations.find(rel => rel.name === 'template');
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** @return {Note[]} */
 | 
					 | 
				
			||||||
    getSubtreeNotesIncludingTemplated() {
 | 
					 | 
				
			||||||
        const arr = [[this]];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (const childNote of this.children) {
 | 
					 | 
				
			||||||
            arr.push(childNote.getSubtreeNotesIncludingTemplated());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (const targetRelation of this.targetRelations) {
 | 
					 | 
				
			||||||
            if (targetRelation.name === 'template') {
 | 
					 | 
				
			||||||
                const note = targetRelation.note;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (note) {
 | 
					 | 
				
			||||||
                    arr.push(note.getSubtreeNotesIncludingTemplated());
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return arr.flat();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /** @return {Note[]} */
 | 
					 | 
				
			||||||
    getSubtreeNotes(includeArchived = true) {
 | 
					 | 
				
			||||||
        const noteSet = new Set();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        function addSubtreeNotesInner(note) {
 | 
					 | 
				
			||||||
            if (!includeArchived && note.isArchived) {
 | 
					 | 
				
			||||||
                return;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            noteSet.add(note);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            for (const childNote of note.children) {
 | 
					 | 
				
			||||||
                addSubtreeNotesInner(childNote);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        addSubtreeNotesInner(this);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return Array.from(noteSet);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /** @return {String[]} */
 | 
					 | 
				
			||||||
    getSubtreeNoteIds() {
 | 
					 | 
				
			||||||
        return this.getSubtreeNotes().map(note => note.noteId);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    getDescendantNoteIds() {
 | 
					 | 
				
			||||||
        return this.getSubtreeNoteIds();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    getAncestors() {
 | 
					 | 
				
			||||||
        if (!this.ancestorCache) {
 | 
					 | 
				
			||||||
            const noteIds = new Set();
 | 
					 | 
				
			||||||
            this.ancestorCache = [];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            for (const parent of this.parents) {
 | 
					 | 
				
			||||||
                if (!noteIds.has(parent.noteId)) {
 | 
					 | 
				
			||||||
                    this.ancestorCache.push(parent);
 | 
					 | 
				
			||||||
                    noteIds.add(parent.noteId);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                for (const ancestorNote of parent.getAncestors()) {
 | 
					 | 
				
			||||||
                    if (!noteIds.has(ancestorNote.noteId)) {
 | 
					 | 
				
			||||||
                        this.ancestorCache.push(ancestorNote);
 | 
					 | 
				
			||||||
                        noteIds.add(ancestorNote.noteId);
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return this.ancestorCache;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    getTargetRelations() {
 | 
					    getTargetRelations() {
 | 
				
			||||||
        return this.targetRelations;
 | 
					        return this.targetRelations;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** @return {Note[]} - returns only notes which are templated, does not include their subtrees
 | 
					 | 
				
			||||||
     *                     in effect returns notes which are influenced by note's non-inheritable attributes */
 | 
					 | 
				
			||||||
    getTemplatedNotes() {
 | 
					 | 
				
			||||||
        const arr = [this];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (const targetRelation of this.targetRelations) {
 | 
					 | 
				
			||||||
            if (targetRelation.name === 'template') {
 | 
					 | 
				
			||||||
                const note = targetRelation.note;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if (note) {
 | 
					 | 
				
			||||||
                    arr.push(note);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return arr;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * @param ancestorNoteId
 | 
					 | 
				
			||||||
     * @return {boolean} - true if ancestorNoteId occurs in at least one of the note's paths
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    isDescendantOfNote(ancestorNoteId) {
 | 
					 | 
				
			||||||
        const notePaths = this.getAllNotePaths();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return notePaths.some(path => path.includes(ancestorNoteId));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    get shareId() {
 | 
					    get shareId() {
 | 
				
			||||||
        const sharedAlias = this.getOwnedLabelValue("shareAlias");
 | 
					        const sharedAlias = this.getOwnedLabelValue("shareAlias");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user