From dc9d8d175bb274befb290d6ad29106da36e5f3bd Mon Sep 17 00:00:00 2001 From: Tykayn Date: Fri, 10 Sep 2021 16:27:07 +0200 Subject: [PATCH] add subtask orgmode --- routes/index.js | 63 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/routes/index.js b/routes/index.js index 57b9831..588c314 100644 --- a/routes/index.js +++ b/routes/index.js @@ -110,6 +110,7 @@ function computeData(jsonConvertedData) { maxTasksCountPerTag: 0, listTags: [], tagByKey: {}, + taskByKey: {}, listAll: [], listOpen: [], listOpenWeekly: [], @@ -130,6 +131,8 @@ function computeData(jsonConvertedData) { } for (let taskItem of gtgData.tasklist[0].task) { + + jsonAllData.stats.taskByKey[taskItem["$"].id] = taskItem // count open and closed tasks let now = new Date() @@ -402,26 +405,25 @@ function exportToMarkdown(res) { function exportToOrgmode(res) { - console.log('jsonAllData.stats.tagByKey', jsonAllData.stats.tagByKey); let orgmodeContent = `# Tâches exportées `; - jsonAllData.stats.listAll.map(elem => { - orgmodeContent += `\n*`; - if(elem.$.status === 'Active'){ - orgmodeContent += `TODO`; + jsonAllData.stats.listAll.map(taskItem => { + orgmodeContent += `\n* `; + if (taskItem.$.status === 'Active') { + orgmodeContent += `TODO`; } - if(elem.$.status === 'Done'){ + if (taskItem.$.status === 'Done') { orgmodeContent += `DONE`; } - if(elem.$.status === 'Dismiss'){ + if (taskItem.$.status === 'Dismiss') { orgmodeContent += `CANCELED`; } - orgmodeContent += ` ${elem.title} `; + orgmodeContent += ` ${taskItem.title} `; - if (elem.tags[0]) { - - elem.tags[0].tag.map(tag => { + if (taskItem.tags[0]) { + orgmodeContent += ` `; + taskItem.tags[0].tag.map(tag => { // console.log('tag', tag); // console.log('jsonAllData.stats.tagByKey[tag]', jsonAllData.stats.tagByKey[tag]); if (tag) { @@ -431,6 +433,45 @@ function exportToOrgmode(res) { } }) } + + if (taskItem.$.dates) { + console.log('elem.$.dates', taskItem.$.dates); + orgmodeContent += `\n `; + if (taskItem.$.dates[0].added) { + orgmodeContent += `CREATED ${taskItem.title} `; + } + } + + if (taskItem.content) { + orgmodeContent += `\n`; + taskItem.content.map(content =>{ + orgmodeContent += `\n ${content} `; + }) + orgmodeContent += `\n ______`; + } + + if ( + // typeof elem.subtasks[0] === typeof Object && + taskItem.subtasks[0].sub.length) { + let listSubTasks = taskItem.subtasks[0].sub + orgmodeContent += `\n `; + listSubTasks.map(subtaskid => { + + let subTask = jsonAllData.stats.taskByKey[subtaskid] + console.log('subTask', subTask); + orgmodeContent += `\n * `; + if (taskItem.$.status === 'Active') { + orgmodeContent += `TODO`; + } + if (taskItem.$.status === 'Done') { + orgmodeContent += `DONE`; + } + if (taskItem.$.status === 'Dismiss') { + orgmodeContent += `CANCELED`; + } + orgmodeContent += ` => ${subTask.title} `; + }) + } }) // write file to disk