@complexpoint, since you are offering. Here are my questions from the move now → done script.
-
I noticed that throughout the program the variable
blnDown
is assigned several different values. I was wondering why, or what was going on. -
I noticed that your program picked the first task tagged with now by doing the following,
lstNow = oOutline.evaluateItemPath(‘//@’ + strTag + ‘[0]’);
When you could have gone with
lstNow = oOutline.evaluateItemPath(‘//@’ + strTag);
and have you program work (at least mine works right in every test I have run.) Can you explain why did you decided to include only the first task with the now tag in your code?
- Around the same part of the code, I also noticed that you obtain the next task by doing the following,
oNext = lstNext.length ? lstNext[0] : null;
I have no clue how does that work, but it accomplishes the trick. It seems as if there should be easier or clearer ways to accomplish this, but I am thinking you had very specific reasons to do it this way. Can you explain to me why you went this route?
- I really do not understand how does this tags the parent project with done when all the tasks inside are done. I mean, I get that when all the task remaining inside the project reach 0, something happens, but I don’t get why you need a
forEach(function(x){...
to set the attribute.
itemProjects(oNow).filter(function(p) {
return tasksRemaining(p).length === 0;
}).forEach(function(x) {
x.setAttribute('data-done', strTime);
});
- All of this is voodoo magic. Could you explain or comment that code.
var oTaggable = (oNext && !oNext.isRoot) ? oNext : (
function() {
var lstDoable = oOutline.evaluateItemPath(
'//* except @done[' + (blnDown ? '0' : '-1') + ']'
);
return lstDoable.length ? lstDoable[0] : null;
}()
);
return oTaggable ? (
oTaggable.setAttribute(strAttrib, ''),
editor.isVisible(
oTaggable
) || editor.makeVisible(oTaggable),
true
) : false;
- I do not understand why this is necessary, or when does it run.
// monadic bind/chain for lists
// [a] -> (a -> [b]) -> [b]
function chain(xs, f) {
return [].concat.apply([], xs.map(f));
}
- I also modified your code so that when the parent project is tagged with done, it does not tag the task with done. I did it like this,
if (oNow.getAttribute('data-type') === 'task') {
if (oNow.parent.hasAttribute('data-done')) {} else {
var strTime = moment().format('YYYY-MM-DD HH:mm');
oNow.setAttribute('data-done', strTime);
}
The problem with this approach is that the script still has to go through all the tasks inside that project instead of jumping to the next task outside that project that doesn’t have a parent with a done tag. Can you give me some clues or examples on how to accomplish exactly that? I was thinking on doing it on the first evaluation with something like the following, but I don’t know if that is possible, so I am using language to describe the query,
lstNow = oOutline.evaluateItemPath(‘//@’ + strTag except when parent is @done);