Hi everyone,
this code is support to do something very simple: add a “Cleanup” button to a board. When clicked, it finds all cards that have a tomato (pomodoro) emoji in their name. It parses the name and replaces parts of the text. Then tries to save the new name using t.set… and that’s what I can’t get to work.
The powerup is finding the cards. It is generating the new name I want. But the call to t.set() does not seem to do anything.
I tried putting all t.set promises in an array and returning it as a promise.all response, didn’t make any difference.
I’m obviously missing something extremely basic……………
……… can you let PLEASE let me know what it is?
Thanks!
//THIS ALL WORKS ALL THE WAY TO……
window.TrelloPowerUp.initialize({
'board-buttons': function(t, opts) {
return [{
text: 'Clean Up',
callback: function(t) {
return t.cards('id', 'name').then(function(cards) {
var promises = [];
for (var i = 0; i < cards.length; i++) {
if (cards[i]["name"].match("🍅")) {
var card = cards[i];
var title = card["name"];
var matches = title.match(/\[(\d+)\]/);
var sets = 0;
if (matches) { //not the first pomodoro for this task
sets += parseInt(matches[1]);
}
title = title.replace(/\s* \[[0-9.]+\]/, ''); //remove previous total of pomodoros from title
matches = title.match(/^([^ ]+) 🍅\s*/); //get number of pomodoros
if (!matches || typeof matches[1] === 'undefined') { //something's missing
reject("failed to parse " + title);
}
sets += Math.ceil(matches[1]);
title = title.replace(matches[0], "") + " [" + sets + "]";
//……………TO HERE: (the following line does not seem to do ANYTHING, ARRRH!!
promises.push(t.set(card["id"], "shared", "name", title).catch(function(err){console.log(err);}));
// WHYYYYYYYYYY :(
}
}
//Note - this DOES print "finished running"… even though nothing seems to be saved
return Promise.all(promises).then(function(result){console.log("finished running")});
});
},
condition: 'edit'
}];
}
});