Project tracking (templater, metaedit, and dataview)

The other day, on the discord, I presented my “project tracker”, which allows me to almost automatically update a project according to the number of titles used and compare to a total.

So here is the tutorial to be able to do the same thing.

First of all, here is the frontmatter and the template of a new note :

<%*
const title = tp.file.folder();
const line_start = await tp.system.prompt("Start:");
const nb = await tp.system.prompt("Number:");
const line_end = (parseInt(line_start) + parseInt(nb)) - 1
await tp.file.rename(`[${title}] ${line_start} - ${line_end} `);
_%>

---
nb_tot: <% `${nb}` %>
Journal: <% tp.file.folder() %>
line_start: <% `${line_start}` %>
line_end: <% `${line_end}` %>
date: <% tp.date.tomorrow("DD-MM-YYYY") %>
nb: <% tp.user.count(tp) %>
done: <% tp.user.check(tp, tp.frontmatter.nb, tp.frontmatter.nb_tot) %>

---

Every time I create a new file, it asks me for the start as well as the number that will be my final title total (the total).
The date allows me to predict when I will do this “review”.

Finally, I use two JS scripts: check and count which are :

function check(tp, nb, nb_tot) {
    if (nb >= nb_tot) {
        new Notice("🎉 Well done :D", 5000)
        return "✅"
    } else {
        if (nb === nb_tot/2 ) {
            new Notice ("Half! Keep Going 🦉", 5000)
        }
        new Notice (nb, 5000)
        return "❌"
    }
}
module.exports = check
module.exports = (tp) => {
    return tp.file.content.split("\n").reduce((acc, line) => new RegExp(/^# /).test(line) ? acc + 1 : acc, 0);
}
  • check allows me to automatically put :white_check_mark: or :x: comparing the total number with the number that has been done, while informing me how many I have done & how many I have left.
  • count allows you to calculate the number of titles.

After that, I use a templater command with the metaedit api which allows me to update my frontmatter using a simple command. Usually I use shift + F2 (put through hotkey for templater).

The template is as follows:

<%*
const {update} = app.plugins.plugins["metaedit"].api;
const filePath = tp.file.path(true);
await update("nb", `${tp.user.count(tp)}`, filePath);
await update("done", `${tp.user.check(tp, tp.frontmatter.nb, tp.frontmatter.nb_tot)}`, filePath);
const nb_done = tp.user.count(tp)
%>

Finally, on an index (I use folder note for that), I use dataview :

---
nb: /
Journal: ❌
done: ❌
nb_tot: 0
---
name New file
type note(9. Master 1/Stage/Data/Re-Review/CCM 2010/Journal+Line, split) template
action Stage
templater true

^button-stage

Total::

	let totalDone = 0;
	for (const day of dv.pages('"9. Master 1/Stage/Data/Re-review/CCM 2010"')) {
		if (day.done === "❌") continue;
		totalDone += day.nb;
	}
	
let filled = ""

let gaugeText = " ";
let percent = 0;
const gaugeLength = 50
const completionPercentage = (totalDone / dv.current().Total)
const nbFilledCharacters = gaugeLength * completionPercentage


for (let i = 0 ; i < gaugeLength ; i++) {
	if (i < nbFilledCharacters) {
	gaugeText += """;
	percent += 1
	} 
		else gaugeText += "░";
		percent += 0
}
percent = percent *2
gaugeText += " ";
dv.paragraph("<h4 align="center">" + gaugeText + "<br>" + percent + "</h4>")
dv.table(["File", "Date", "Article"], dv.pages('"9. Master 1/Stage/Data/Re-review/CCM 2010"').where(d => !d.Journal.includes("❌")).sort(d => d.date).sort(d => d.file.name).map(d => [d.file.link, d.date, d.nb, d.done]);
let totalcheck = 0;
for (const d of dv.pages('"9. Master 1/Stage/Data/Re-review/CCM 2010"')) {
	totalcheck += d.nb_tot; 
}

	let totalDone = 0
	for (const day of dv.pages('"9. Master 1/Stage/Data/Re-review/CCM 2010"')) {
		if (day.done === "❌") continue;
		totalDone += day.nb;
	}
const remaining = dv.current().Total - totalDone

dv.paragraph("<h6 align="center\">Predicted: " + totalcheck + "<br> Remaining : " + remaining + "</h6>");

This gives:

Don’t forget to change the folder!

13 Likes

Thanks for so detailed post!

2 Likes

sorry I don’t know why it keep pop out templator parsing error aborting…
is there any setting I didn’t done?
Thanks for this sharing!