This commit is contained in:
Tykayn 2022-07-20 18:45:29 +02:00 committed by tykayn
parent 3bdbd54c10
commit a6d82ba652
1 changed files with 101 additions and 23 deletions

124
app.js
View File

@ -4,6 +4,15 @@ const stats = {
countAllTasks: 0, countAllTasks: 0,
tasksByDay: {} tasksByDay: {}
} }
// const enableFilterByTag = true;
const enableFilterByTag = false;
const filterByTag = "work";
// const outputFileName = "work_report";
const outputFileName = "all_tasks_report";
let countExcluded = 0;
let countIncluded = 0;
// prendre le json source représentant les tâches DONE // prendre le json source représentant les tâches DONE
console.log(' ### lecture de source/emacs_json.json'); console.log(' ### lecture de source/emacs_json.json');
@ -27,26 +36,63 @@ function sortTasksFromJson(statObject) {
return console.log(err); return console.log(err);
} }
let dataTransformed = JSON.parse(data); let dataTransformed = JSON.parse(data);
console.log('data keys ', Object.keys(dataTransformed)) // console.log('data keys ', Object.keys(dataTransformed))
if (dataTransformed["contents"]) { if (dataTransformed["contents"]) {
countTasks = dataTransformed["contents"].length countTasks = dataTransformed["contents"].length
stats.countAllTasks = countTasks; stats.countAllTasks = countTasks;
console.log('yes data !', countTasks) console.log('yes data ! tasks:', countTasks)
console.log('first', dataTransformed["contents"][0])
dataTransformed["contents"].forEach((elem) => { dataTransformed["contents"].forEach((elem, index) => {
if (elem['title'] && elem['title'][0]) {
console.log(' - ', elem['title'][0]) // console.log('tâche ', index)
// évacuer les sous tâches
// if (elem['contents']) {
// console.log('content ception, on évacue')
// countExcluded++;
// return;
// }
// filtrer par tag les tâches
if (enableFilterByTag) {
console.log('filtre activé', filterByTag)
if (!elem['drawer'] || !elem['properties']['tags']) {
console.log('on vire cette tâche n\'ayant pas de drawer :', elem)
countExcluded++;
return;
} else if (
elem['properties'] &&
typeof elem['properties']['tags'] !== "undefined" &&
elem['properties']['tags'].indexOf(filterByTag) === -1
) {
console.log('on vire cette tâche ayant les itags :', elem['drawer']['ARCHIVE_ITAGS'])
countExcluded++;
return;
}
} else {
console.log(' - filtre désactivé')
} }
if (elem['properties'] && elem['properties']['closed']) { // après le filtre, on range les tâches
if (elem['properties']) {
console.log(' - ref ', elem['ref'])
let title = elem['properties']['raw-value']; let title = elem['properties']['raw-value'];
let tags = elem['tags'] ? elem['tags'] : []; let tags = elem['tags'] ? elem['tags'] : [];
let closeDate = elem['properties']['closed']['end']; let closeDate = 'Indéfini';
let todoKeyword = elem['drawer']['ARCHIVE_TODO']; let todoKeyword = 'DONE';
let itags = elem['drawer']['ARCHIVE_ITAGS']; if (elem['properties']['closed']) {
closeDate = elem['properties']['closed']['end'];
} else if (elem['drawer'] && elem['drawer']['ARCHIVE_TIME']) {
closeDate = elem['drawer']['ARCHIVE_TIME'];
}
if (elem['drawer'] && elem['drawer']['ARCHIVE_TODO']) {
todoKeyword = elem['drawer']['ARCHIVE_TODO'];
}
// jour, 11 premiers caractères // jour, 11 premiers caractères
@ -55,25 +101,24 @@ function sortTasksFromJson(statObject) {
stats.tasksByDay[day] = [] stats.tasksByDay[day] = []
} }
stats.tasksByDay[day].push({ stats.tasksByDay[day].push({
todoKeyword,
title, title,
day,
closeDate, closeDate,
tags, tags,
todoKeyword,
day,
itags
}) })
// console.log(' ' + title) // console.log(' ' + title)
countIncluded++;
} else { } else {
console.log('no', elem['properties']['raw-value']) console.log('no', elem['properties']['raw-value'])
} }
}) })
// console.log('element', dataTransformed["contents"]["0"])
} else { } else {
console.log('no content') console.log('no content')
} }
// console.log(data); // console.log(data);
console.log('tâches inclues:', countIncluded)
writeHtmlOutput() writeHtmlOutput()
}); });
@ -87,6 +132,11 @@ function writeHtmlOutput() {
console.log('writeHtmlOutput', stats.countAllTasks) console.log('writeHtmlOutput', stats.countAllTasks)
let daysListRef = Object.keys(stats.tasksByDay).sort() let daysListRef = Object.keys(stats.tasksByDay).sort()
let filterInfo = ``
if (enableFilterByTag) {
filterInfo = `<p class="is-info">Contenu filtré sur le tag: ${filterByTag}. ${countExcluded} tâches exclues, ${countIncluded} tâches inclues sur le total de ${countExcluded + countIncluded}</p>`
}
let htmlOut = ` let htmlOut = `
<html> <html>
<head> <head>
@ -99,9 +149,14 @@ function writeHtmlOutput() {
</style> </style>
</head> </head>
<body> <body>
<div id="report_days" class="container content"> <div id="report_days" class="container content">
<h1 class="title is-1">Feuille de rapport d'activité</h1>
<p class="subtitle is-1">par <a href="https://www.cipherbliss.com">Tykayn</a> </p>
${filterInfo}
` `
daysListRef.forEach((dayRefString) => { daysListRef.reverse().forEach((dayRefString) => {
let tasksOfTheDay = ''; let tasksOfTheDay = '';
@ -110,14 +165,21 @@ function writeHtmlOutput() {
if ('DONE' !== dayObj.todoKeyword) { if ('DONE' !== dayObj.todoKeyword) {
graphicKeyword = dayObj.todoKeyword; graphicKeyword = dayObj.todoKeyword;
} }
let tagDisplay = '';
if (dayObj.tags.length) {
tagDisplay = ` <p class="archived-tags tag is-light is-primary">
${dayObj.tags.join(' ')}
</p>
`
}
tasksOfTheDay += ` <li> tasksOfTheDay += ` <li>
<h2 class="subtitle is-1"> <h2>
<span class="keyword"> ${graphicKeyword}</span> <span class="keyword"> ${graphicKeyword}</span>
<span class="title"> ${dayObj.title} </span> <span class="title"> ${dayObj.title} </span>
</h2> </h2>
<p class="tag is-light is-primary"> ${tagDisplay}
${dayObj.itags}
</p>
</li>` </li>`
}) })
htmlOut += ` htmlOut += `
@ -127,7 +189,7 @@ function writeHtmlOutput() {
<span class="day-ref"> <span class="day-ref">
${dayRefString} ${dayRefString}
</span> </span>
<span class="counter pull-right badge"> <span class="counter pull-right tag is-success is-light">
${stats.tasksByDay[dayRefString].length} ${stats.tasksByDay[dayRefString].length}
</span> </span>
</h1> </h1>
@ -141,8 +203,20 @@ function writeHtmlOutput() {
</div> ` </div> `
}) })
htmlOut += ` htmlOut += `
<div class="box">
<h1 class="title is-1">
Tadam, c'est tout!
</h1>
<p>
Source: <a href="https://forge.chapril.org/tykayn/org-report-stats">org-report-stats</a>
<br>
Contactez-moi: <a href="https://www.cipherbliss.com/contact">par un de ces moyens</a>
</p>
</div> </div>
</div>
</body> </body>
</html> </html>
` `
@ -153,12 +227,16 @@ function writeHtmlOutput() {
} }
console.log('wrote output json', data) console.log('wrote output json', data)
}) })
fs.writeFile('output/output.html', htmlOut, function (err, data) { fs.writeFile('output/output_' + outputFileName + '.html', htmlOut, function (err, data) {
if (err) { if (err) {
return console.log(err); return console.log(err);
} }
console.log('wrote output html', data) console.log('wrote output html ' + outputFileName, data)
}) })
if (enableFilterByTag) {
console.log('excluded tasks by tag filter ', countExcluded)
}
} }