176 lines
4.0 KiB
HTML
176 lines
4.0 KiB
HTML
<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>
|