( plugin: TaskNotesPlugin, task: TaskInfo, projectFile: TFile )
| 65 | } |
| 66 | |
| 67 | export async function addTaskToProject( |
| 68 | plugin: TaskNotesPlugin, |
| 69 | task: TaskInfo, |
| 70 | projectFile: TFile |
| 71 | ): Promise<TaskInfo | null> { |
| 72 | const projectReference = generateLink( |
| 73 | plugin.app, |
| 74 | projectFile, |
| 75 | task.path, |
| 76 | "", |
| 77 | "", |
| 78 | plugin.settings.useFrontmatterMarkdownLinks |
| 79 | ); |
| 80 | const legacyReference = `[[${projectFile.basename}]]`; |
| 81 | const currentProjects = Array.isArray(task.projects) ? task.projects : []; |
| 82 | |
| 83 | if (currentProjects.includes(projectReference) || currentProjects.includes(legacyReference)) { |
| 84 | publishUserNotice( |
| 85 | plugin.emitter, |
| 86 | translate(plugin, "contextMenus.task.organization.notices.alreadyInProject") |
| 87 | ); |
| 88 | return null; |
| 89 | } |
| 90 | |
| 91 | const sanitizedProjects = currentProjects.filter((entry) => entry !== legacyReference); |
| 92 | const updatedProjects = [...sanitizedProjects, projectReference]; |
| 93 | const updatedTask = await plugin.updateTaskProperty(task, "projects", updatedProjects); |
| 94 | |
| 95 | publishUserNotice( |
| 96 | plugin.emitter, |
| 97 | translate(plugin, "contextMenus.task.organization.notices.addedToProject", { |
| 98 | project: projectFile.basename, |
| 99 | }) |
| 100 | ); |
| 101 | return updatedTask; |
| 102 | } |
| 103 | |
| 104 | export async function assignTaskAsSubtask( |
| 105 | plugin: TaskNotesPlugin, |
no test coverage detected