put json content in template

This commit is contained in:
Tykayn 2021-03-02 09:23:33 +01:00 committed by tykayn
parent e6de6a1393
commit c7a04bc8d8
2 changed files with 37 additions and 9 deletions

View File

@ -7,9 +7,11 @@ var fileToOpen = 'gtg_tasks'
// const convertFiles = true;
const convertFiles = false;
const computeDataOnExtract = true;
const json = {
let jsonAllData = {
tasks : {},
stats : {},
projects : {},
tags : {},
}
@ -29,18 +31,41 @@ router.get('/', async function (req, res, next) {
}
// récupérer le contenu des json
fs.readFile(`sources/tags_gtg.json`, "utf-8", function (err, data) {
jsonAllData.tags = require('../sources/tags_gtg.json')
jsonAllData.tasks = require('../sources/gtg_tasks_gtg.json')
if(computeDataOnExtract){
jsonAllData = computeData(jsonAllData)
}else{
console.log('================== calcul de stats désactivé dans index.js ================== ')
}
console.log('json files read' )
res.render('index', {title: "Conversion de GTG tâches", json: jsonAllData})
});
async function readfileJson(fileToOpen){
fs.readFile(`sources/${fileToOpen}`, "utf-8", function (err, data) {
if (err) console.log(err);
json.tags = JSON.parse(data)
console.log('json', json)
res.render('index', {title: "Conversion de GTG tâches", json: json})
console.log('ok ', fileToOpen )
return JSON.parse(data)
});
}
function computeData(jsonAllData){
// trouver le nombre de tâches ayant un tag en particulier
// et rajouter ce nombre à chaque tag, dans countTasks : N
// let tagCountTasks = Object.create(jsonAllData.tags);
});
for(let t of jsonAllData.tasks.project.task ) {
console.log('t', t)
let tags = t["$"].tags
// console.log('tags', tags)
}
return jsonAllData
}
function convertOneXmlToJson(fileToOpen,res){
fs.readFile(`sources/${fileToOpen}.xml`, "utf-8", function (err, data) {
if (err) console.log(err);

View File

@ -3,13 +3,16 @@ extends layout
block content
h1= title
p Welcome to #{title}
section.tasks
h2 #{json.tasks.project.task.length} Tâches
section.tags
h2= Tags
h2 #{json.tags.tagstore.tag.length} Tags
ul.tags
li.head
span.name nom
span.color couleur
span.parent parent
span.tasks tâches
each t in json.tags.tagstore.tag
li
span.name= t['$'].name