From 051adb4e577e39909bd708235dfd7c4869def1a5 Mon Sep 17 00:00:00 2001 From: HeroBlackInk Date: Thu, 8 Jun 2023 12:51:40 +0800 Subject: [PATCH] You can check database in the settings. --- src/cacheOperation.ts | 4 +++- src/settings.ts | 45 +++++++++++++++++++++++++++++++++++++++---- src/syncModule.ts | 7 ++++--- src/taskParser.ts | 6 ++++++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/cacheOperation.ts b/src/cacheOperation.ts index 7da411a..52dcf04 100644 --- a/src/cacheOperation.ts +++ b/src/cacheOperation.ts @@ -29,7 +29,9 @@ export class CacheOperation { return this.settings.fileMetadata[filepath] ?? null } - + async getFileMetadatas(){ + return this.settings.fileMetadata ?? null + } async newEmptyFileMetadata(filepath:string){ const metadatas = this.settings.fileMetadata diff --git a/src/settings.ts b/src/settings.ts index d7a8411..ee12f97 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -207,10 +207,10 @@ export class UltimateTodoistSyncSettingTab extends PluginSettingTab { new Setting(containerEl) - .setName('Scan all tasks in the vault') - .setDesc('Scan tasks in all files in the vault and add `#todoist`. In general, you do not need to perform this operation.') + .setName('Check Database') + .setDesc('Check for possible issues: file renaming not updated, or missed tasks not synchronized.') .addButton(button => button - .setButtonText('Scan') + .setButtonText('Check Database') .onClick(async () => { // Add code here to handle exporting Todoist data if(!this.plugin.settings.apiInitialized){ @@ -218,7 +218,44 @@ export class UltimateTodoistSyncSettingTab extends PluginSettingTab { return } if (!await this.plugin.checkAndHandleSyncLock()) return; + + + try{ + //check renamed files + const metadatas = await this.plugin.cacheOperation.getFileMetadatas() + for (const key in metadatas) { + const value = metadatas[key]; + const newDescription = this.plugin.taskParser.getObsidianUrlFromFilepath(key) + value.todoistTasks.forEach(async(taskId) => { + const taskObject = await this.plugin.cacheOperation.loadTaskFromCacheyID(taskId) + const oldDescription = taskObject.description + if(newDescription != oldDescription){ + console.log('Preparing to update description.') + console.log(oldDescription) + console.log(newDescription) + try{ + await this.plugin.todoistSync.updateTaskDescription(key) + }catch(error){ + console.error(`An error occurred while updating task discription: ${error.message}`); + } + + } + + }); + + } + + //check empty file metadata + + //check calendar format + + + + //check omitted tasks + if(!this.plugin.settings.enableFullVaultSync){ + return + } const files = this.app.vault.getFiles() files.forEach(async (v, i) => { if(v.extension == "md"){ @@ -236,7 +273,7 @@ export class UltimateTodoistSyncSettingTab extends PluginSettingTab { this.plugin.syncLock = false new Notice(`All files have been scanned.`) }catch(error){ - new Notice(`An error occurred while scanning the vault.:${error}`) + console.error(`An error occurred while scanning the vault.:${error}`) this.plugin.syncLock = false } diff --git a/src/syncModule.ts b/src/syncModule.ts index f9387c9..261e3aa 100644 --- a/src/syncModule.ts +++ b/src/syncModule.ts @@ -850,13 +850,14 @@ export class TodoistSync { if(!metadata || !metadata.todoistTasks){ return } - const url = encodeURI(`obsidian://open?vault=${this.app.vault.getName()}&file=${filepath}`) - const description =`[${filepath}](${url})`; + const description = this.taskParser.getObsidianUrlFromFilepath(filepath) let updatedContent = {} updatedContent.description = description try { metadata.todoistTasks.forEach(async(taskId) => { - await this.todoistRestAPI.UpdateTask(taskId,updatedContent) + const updatedTask = await this.todoistRestAPI.UpdateTask(taskId,updatedContent) + updatedTask.path = filepath + this.cacheOperation.updateTaskToCacheByID(updatedTask); }); } catch(error) { diff --git a/src/taskParser.ts b/src/taskParser.ts index 21712dd..f6eca5b 100644 --- a/src/taskParser.ts +++ b/src/taskParser.ts @@ -528,4 +528,10 @@ export class TaskParser { addTodoistTag(str: string): string { return(str +` ${keywords.TODOIST_TAG}`); } + + getObsidianUrlFromFilepath(filepath:string){ + const url = encodeURI(`obsidian://open?vault=${this.app.vault.getName()}&file=${filepath}`) + const obsidianUrl =`[${filepath}](${url})`; + return(obsidianUrl) + } }