Skip to content

Commit

Permalink
Don't add costs from archived cards, Add 'remove cost' button
Browse files Browse the repository at this point in the history
  • Loading branch information
System committed Jul 25, 2017
1 parent 015c543 commit 63bd0fa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
Empty file added .glitch-assets
Empty file.
60 changes: 32 additions & 28 deletions client.js
Expand Up @@ -10,8 +10,6 @@ var getBadges = function(t){
return t.card('id')
.then(function(id) {
return costs && costs[id.id] ? [{
// its best to use static badges unless you need your badges to refresh
// you can mix and match between static and dynamic
text: `Cost: ${costs[id.id]}`,
color: (costs[id.id] == 0) ? 'red' : null
}] : [];
Expand All @@ -29,19 +27,29 @@ var cardButtonCallback = function(t){
title: 'Set Cost...',
items: function(t, options) {
var newCost = parseFloat(options.search).toFixed(2)
return [
{
text: !Number.isNaN(parseFloat(options.search)) ? `Set Cost to ${newCost}` : `(Enter a number to set cost.)`,
var buttons = [{
text: !Number.isNaN(parseFloat(options.search)) ? `Set Cost to ${newCost}` : `(Enter a number to set cost.)`,
callback: function(t) {
if (newCost != 'NaN') {
var newCosts = costs ? costs : {};
newCosts[id.id] = newCost;
t.set('board','shared','costs',newCosts);
}
return t.closePopup();
}
}];
if (costs[id.id]) {
buttons.push({
text: 'Remove cost.',
callback: function(t) {
if (newCost != 'NaN') {
var newCosts = costs ? costs : {};
newCosts[id.id] = newCost;
t.set('board','shared','costs',newCosts);
}
var newCosts = costs ? costs : {};
delete newCosts[id.id];
t.set('board','shared','costs',newCosts);
return t.closePopup();
}
}
];
});
}
return buttons;
},
search: {
placeholder: 'Enter Cost',
Expand All @@ -60,15 +68,18 @@ TrelloPowerUp.initialize({
return t.get('board', 'shared', 'costs')
.then(function(costs){
var totalCost = 0;
for (var cost in costs) {
totalCost = +totalCost + +costs[cost];
}
return [{
// we can either provide a button that has a callback function
// that callback function should probably open a popup, overlay, or boardBar
icon: SIGMA_ICON,
text: `Total Cost: ${totalCost.toFixed(2)}`,
}];
return t.cards('id').then(cards => {
var activeIds = cards.map(card => {return card.id;});
for (var cost in costs) {
if (activeIds.indexOf(cost) > -1) {
totalCost = +totalCost + +costs[cost];
}
}
return [{
icon: SIGMA_ICON,
text: `Total Cost: ${totalCost.toFixed(2)}`,
}];
});
});
},
'card-badges': function(t, options){
Expand All @@ -91,12 +102,5 @@ TrelloPowerUp.initialize({

});
});

return t.get('board', 'shared', 'cost')
.then(function(cost){
console.log(cost[t.card('id')]);


});
},
});
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -61,7 +61,7 @@ <h2>Costello: Costs for Trello 🚀</h2>
</p>

<p>
Now when you look at the Power-Ups for any board in that team, this Power-Up will be available. Enable it and you'll be able to set costs for cards when you open them. If you'd like to add functionality, you can fork this <a href="https://glitch.com/~trello-costs">Glitch project</a> and edit the source as you please.
Now when you look at the Power-Ups for any board in that team, this Power-Up will be available. Enable it and you'll be able to set costs for cards when you open them. If you'd like to add functionality, you can fork this <a href="https://glitch.com/~trello-costello">Glitch project</a> and edit the source as you please.
</p>

</body>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Expand Up @@ -2,7 +2,7 @@
"name": "Costello",
"details":"Add costs to cards & view the sum in your board bar.",
"icon": {
"url": "https://cdn.glitch.com/2442c68d-7b6d-4b69-9d13-feab530aa88e%2Fglitch-icon.svg?1489773457908"
"url": "./sigma.svg"
},
"author": "webrender",
"capabilities": [
Expand Down

0 comments on commit 63bd0fa

Please sign in to comment.