mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 13:39:01 +01:00 
			
		
		
		
	server-ts: Port services/spaced_update
This commit is contained in:
		
							parent
							
								
									915de23e34
								
							
						
					
					
						commit
						16283d4054
					
				@ -15,7 +15,7 @@ const searchService = require('./search/services/search');
 | 
				
			|||||||
const SearchContext = require('./search/search_context');
 | 
					const SearchContext = require('./search/search_context');
 | 
				
			||||||
const becca = require('../becca/becca');
 | 
					const becca = require('../becca/becca');
 | 
				
			||||||
const ws = require('./ws');
 | 
					const ws = require('./ws');
 | 
				
			||||||
const SpacedUpdate = require('./spaced_update.js');
 | 
					const SpacedUpdate = require('./spaced_update');
 | 
				
			||||||
const specialNotesService = require('./special_notes.js');
 | 
					const specialNotesService = require('./special_notes.js');
 | 
				
			||||||
const branchService = require('./branches');
 | 
					const branchService = require('./branches');
 | 
				
			||||||
const exportService = require('./export/zip');
 | 
					const exportService = require('./export/zip');
 | 
				
			||||||
@ -320,7 +320,7 @@ function BackendScriptApi(currentNote, apiParams) {
 | 
				
			|||||||
     * @param {string} [extraOptions.attributes.value] - attribute value
 | 
					     * @param {string} [extraOptions.attributes.value] - attribute value
 | 
				
			||||||
     * @returns {{note: BNote, branch: BBranch}} object contains newly created entities note and branch
 | 
					     * @returns {{note: BNote, branch: BBranch}} object contains newly created entities note and branch
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    this.createNote = (parentNoteId, title, content = "", extraOptions= {}) => {
 | 
					    this.createNote = (parentNoteId, title, content = "", extraOptions = {}) => {
 | 
				
			||||||
        extraOptions.parentNoteId = parentNoteId;
 | 
					        extraOptions.parentNoteId = parentNoteId;
 | 
				
			||||||
        extraOptions.title = title;
 | 
					        extraOptions.title = title;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -340,7 +340,7 @@ function BackendScriptApi(currentNote, apiParams) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return sql.transactional(() => {
 | 
					        return sql.transactional(() => {
 | 
				
			||||||
            const {note, branch} = noteService.createNewNote(extraOptions);
 | 
					            const { note, branch } = noteService.createNewNote(extraOptions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (const attr of extraOptions.attributes || []) {
 | 
					            for (const attr of extraOptions.attributes || []) {
 | 
				
			||||||
                attributeService.createAttribute({
 | 
					                attributeService.createAttribute({
 | 
				
			||||||
@ -352,7 +352,7 @@ function BackendScriptApi(currentNote, apiParams) {
 | 
				
			|||||||
                });
 | 
					                });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return {note, branch};
 | 
					            return { note, branch };
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -369,7 +369,7 @@ function BackendScriptApi(currentNote, apiParams) {
 | 
				
			|||||||
    this.log = message => {
 | 
					    this.log = message => {
 | 
				
			||||||
        log.info(message);
 | 
					        log.info(message);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const {noteId} = this.startNote;
 | 
					        const { noteId } = this.startNote;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.logMessages[noteId] = this.logMessages[noteId] || [];
 | 
					        this.logMessages[noteId] = this.logMessages[noteId] || [];
 | 
				
			||||||
        this.logSpacedUpdates[noteId] = this.logSpacedUpdates[noteId] || new SpacedUpdate(() => {
 | 
					        this.logSpacedUpdates[noteId] = this.logSpacedUpdates[noteId] || new SpacedUpdate(() => {
 | 
				
			||||||
@ -600,7 +600,7 @@ function BackendScriptApi(currentNote, apiParams) {
 | 
				
			|||||||
            launcherNote.removeLabel('iconClass');
 | 
					            launcherNote.removeLabel('iconClass');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return {note: launcherNote};
 | 
					        return { note: launcherNote };
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -1,9 +1,19 @@
 | 
				
			|||||||
 | 
					type Updater = () => void;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SpacedUpdate {
 | 
					class SpacedUpdate {
 | 
				
			||||||
    constructor(updater, updateInterval = 1000) {
 | 
					
 | 
				
			||||||
 | 
					    private updater: Updater;
 | 
				
			||||||
 | 
					    private lastUpdated: number;
 | 
				
			||||||
 | 
					    private changed: boolean;
 | 
				
			||||||
 | 
					    private updateInterval: number;
 | 
				
			||||||
 | 
					    private changeForbidden: boolean;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    constructor(updater: Updater, updateInterval = 1000) {
 | 
				
			||||||
        this.updater = updater;
 | 
					        this.updater = updater;
 | 
				
			||||||
        this.lastUpdated = Date.now();
 | 
					        this.lastUpdated = Date.now();
 | 
				
			||||||
        this.changed = false;
 | 
					        this.changed = false;
 | 
				
			||||||
        this.updateInterval = updateInterval;
 | 
					        this.updateInterval = updateInterval;
 | 
				
			||||||
 | 
					        this.changeForbidden = false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    scheduleUpdate() {
 | 
					    scheduleUpdate() {
 | 
				
			||||||
@ -52,7 +62,7 @@ class SpacedUpdate {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async allowUpdateWithoutChange(callback) {
 | 
					    async allowUpdateWithoutChange(callback: () => void) {
 | 
				
			||||||
        this.changeForbidden = true;
 | 
					        this.changeForbidden = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
@ -64,4 +74,4 @@ class SpacedUpdate {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = SpacedUpdate;
 | 
					export = SpacedUpdate;
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user