From 43d798085c3eb8eb6f7e548343e44df6d36d124c Mon Sep 17 00:00:00 2001 From: Tykayn Date: Fri, 10 Sep 2021 15:41:27 +0200 Subject: [PATCH] convert to orgmode single file --- routes/index.js | 74 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/routes/index.js b/routes/index.js index 20adad8..57b9831 100644 --- a/routes/index.js +++ b/routes/index.js @@ -66,6 +66,7 @@ router.get('/', async function (req, res, next) { console.log('================== calcul de stats désactivé dans index.js ================== ') } exportToMarkdown(res) + exportToOrgmode(res) console.log('json files read') res.render('index', { title: "Conversion de GTG tâches", @@ -102,12 +103,14 @@ function computeData(jsonConvertedData) { jsonAllData.all = gtgData jsonAllData.stats = { - tasksCount : counterOfTasks.length, + tasksCount: counterOfTasks.length, // tasksCount: 0, tasksClosed: 0, tasksOpen: 0, maxTasksCountPerTag: 0, listTags: [], + tagByKey: {}, + listAll: [], listOpen: [], listOpenWeekly: [], listOpenMonthly: [], @@ -122,12 +125,17 @@ function computeData(jsonConvertedData) { jsonAllData.stats.listTags = gtgData.taglist[0].tag console.log('tasks', gtgData.tasklist[0].task); + for (let tagItem of jsonAllData.stats.listTags) { + jsonAllData.stats.tagByKey[tagItem["$"].id] = tagItem["$"] + } for (let taskItem of gtgData.tasklist[0].task) { // count open and closed tasks let now = new Date() + jsonAllData.stats.listAll.push(taskItem) + if (taskItem['$'].status == 'Active') { jsonAllData.stats.listOpen.push(taskItem) let addeddate = new Date(taskItem.addeddate) @@ -342,20 +350,20 @@ function exportToMarkdown(res) { markdownExportData += `\n `; jsonAllData.stats.listOpen.map(elem => { - dataTagsMd += `\n## ${elem.title} `; - dataTagsMd += `\n statut : ${elem['$'].status} `; - dataTagsMd += `\n créé le : ${elem.addeddate} `; - dataTagsMd += `\n modifié le : ${elem.modified} `; - dataTagsMd += `\n prévu pour : ${elem.duedate | ''} `; - dataTagsMd += `\n ${elem.content} `; + dataTagsMd += `\n## ${elem.title} `; + dataTagsMd += `\n statut : ${elem['$'].status} `; + dataTagsMd += `\n créé le : ${elem.addeddate} `; + dataTagsMd += `\n modifié le : ${elem.modified} `; + dataTagsMd += `\n prévu pour : ${elem.duedate | ''} `; + dataTagsMd += `\n ${elem.content} `; }) markdownExportData += `\n--- `; markdownExportData += `\n `; markdownExportData += `\n# Export de toutes les ${jsonAllData.stats.listClosed.length} tâches fermées GTG \n `; markdownExportData += `\n `; - jsonAllData.stats.listClosed.map(elem=>{ - dataTagsMd += `\n * ${elem.title} `; + jsonAllData.stats.listClosed.map(elem => { + dataTagsMd += `\n * ${elem.title} `; }) markdownExportData += `\n `; @@ -391,6 +399,54 @@ 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`; + } + if(elem.$.status === 'Done'){ + orgmodeContent += `DONE`; + } + if(elem.$.status === 'Dismiss'){ + orgmodeContent += `CANCELED`; + } + orgmodeContent += ` ${elem.title} `; + + if (elem.tags[0]) { + + elem.tags[0].tag.map(tag => { + // console.log('tag', tag); + // console.log('jsonAllData.stats.tagByKey[tag]', jsonAllData.stats.tagByKey[tag]); + if (tag) { + + orgmodeContent += `:${jsonAllData.stats.tagByKey[tag].name}: `; + // orgmodeContent += `:${tag}: `; + } + }) + } + }) + + // write file to disk + fs.writeFile(`output/export_tasks.org`, orgmodeContent, `utf8`, (err) => { + + if (err) { + console.log(`Error writing file: ${err}`); + res.send(err) + } else { + console.log(`File \`output/export_tasks.org\` is written successfully!`); + + } + + }); +} + /** * transformToJson * @param xml