Added code for reading estimates
This commit is contained in:
16
README.md
16
README.md
@@ -1,2 +1,14 @@
|
||||
# trello-estimates-dashboard
|
||||
Small HTML / JS app to sum the estimates entered in trello
|
||||
# Trello estimates dashboard
|
||||
|
||||
Small Javascript application to sum the estimates entered in Trello.
|
||||
Estimates are written somwhere inside Description field in the form of:
|
||||
`Estimate: X` where X can be any whole number.
|
||||
|
||||
Estimates are summed by label and by list and total number of hours is colorfully written in front of the label list name.
|
||||
`?` instead of number of hours marks those labels that don't have any cards with estimates entered.
|
||||
|
||||
|
||||
Code as taken from:
|
||||
http://blog.getcorrello.com/2015/10/14/build-your-own-dashboard-on-the-trello-api/
|
||||
and modified.
|
||||
(Thanks for the nice blog post!)
|
||||
|
||||
175
index.html
Normal file
175
index.html
Normal file
@@ -0,0 +1,175 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>A Trello Dashboard</title>
|
||||
<link rel="stylesheet" media="screen" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Trello Estimates Dashboard</h1>
|
||||
|
||||
<section>
|
||||
<p>This small tool reads descriptions of cards and looks for:
|
||||
<quoute>Estimate: [number]</quote> line and sums the estimates.
|
||||
</p>
|
||||
|
||||
<p>Number is expected to be amount of hours estimated, and it must be a whole number.</p>
|
||||
</section>
|
||||
|
||||
|
||||
<form class="form-horizontal" id="boards_form">
|
||||
<div class="form-group">
|
||||
<label class="control-label">Choose your board</label>
|
||||
<select class="form-control" id="boards">
|
||||
<option> - select - </option>
|
||||
</select>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h2> Total hours by label </h2>
|
||||
<div id="labels"> (select board first)</div>
|
||||
|
||||
<h2> Total hours by list </h2>
|
||||
<div id="lists"> (select board first) </div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script src="http://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
|
||||
<script src="https://api.trello.com/1/client.js?key=f13dd6c2dcc65f48b9a56c6d420e32e7"></script>
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var initialValues = function() {
|
||||
return {
|
||||
lists: {},
|
||||
labels: {}
|
||||
};
|
||||
};
|
||||
|
||||
var values = initialValues();
|
||||
|
||||
var loadedBoards = function(boards) {
|
||||
$.each(boards, function(index, value) {
|
||||
$('#boards')
|
||||
.append($("<option></option>")
|
||||
.attr("value", value.id)
|
||||
.text(value.name));
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
var loadBoards = function() {
|
||||
//Get the users boards
|
||||
Trello.get(
|
||||
'/members/me/boards/',
|
||||
loadedBoards,
|
||||
function() {
|
||||
console.log("Failed to load boards");
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var loadedLabels = function(labels) {
|
||||
$.each(labels, function(index, label) {
|
||||
values.labels[label.id] = 0;
|
||||
|
||||
var label = $("<p><span id='label_" + label.id + "' class='badge' style='background:" + label.color + ";'>?</span> " + label.name + "</p>");
|
||||
$('#labels').append(label)
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
var loadedLists = function(lists) {
|
||||
$.each(lists, function(index, list) {
|
||||
values.lists[list.id] = 0;
|
||||
var label = $("<p><span id='list_" + list.id + "' class='badge' style='background: purple" + ";'>?</span> " + list.name + "</p>");
|
||||
$('#lists').append(label)
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
var getHours = function(desc) {
|
||||
var hours = 0;
|
||||
var estimateRE = /Estimate:\s+(\d+)/m;
|
||||
var matches = desc.match(estimateRE);
|
||||
if (matches && matches[1]) {
|
||||
hours = parseInt(matches[1]);
|
||||
}
|
||||
|
||||
return hours;
|
||||
}
|
||||
|
||||
|
||||
var loadedCards = function(cards) {
|
||||
if (!cards) return;
|
||||
|
||||
$.each(cards, function(index, card) {
|
||||
var hours = getHours(card.desc);
|
||||
values.lists[card.idList] += hours;
|
||||
$("#list_" + card.idList).html("" + values.lists[card.idList] + "h");
|
||||
if (!card.idLabels) return true;
|
||||
$.each(card.idLabels, function(_index, labelId) {
|
||||
|
||||
values.labels[labelId] += hours;
|
||||
$("#label_" + labelId).html("" + values.labels[labelId] + "h");
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
var changedBoard = function() {
|
||||
|
||||
var boardId = $("option:selected", this).val();
|
||||
|
||||
$('#labels').empty();
|
||||
$('#lists').empty();
|
||||
values = initialValues();
|
||||
|
||||
Trello.get(
|
||||
'/boards/' + boardId + '/lists',
|
||||
loadedLists,
|
||||
function() {
|
||||
console.log("Failed to load lists");
|
||||
}
|
||||
)
|
||||
|
||||
Trello.get(
|
||||
'/boards/' + boardId + '/labels',
|
||||
loadedLabels,
|
||||
function() {
|
||||
console.log("Failed to load labels");
|
||||
}
|
||||
);
|
||||
|
||||
Trello.get(
|
||||
'/boards/' + boardId + '/cards?fields=idList,idLabels,desc',
|
||||
loadedCards,
|
||||
function() {
|
||||
console.log("Failed to load labels");
|
||||
}
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
$('#boards').change(changedBoard);
|
||||
|
||||
Trello.authorize({
|
||||
type: "popup",
|
||||
name: "Trello Estimates",
|
||||
scope: {
|
||||
read: true,
|
||||
write: false
|
||||
},
|
||||
expiration: "never",
|
||||
success: loadBoards,
|
||||
error: function() {
|
||||
console.log("Failed authentication");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user