Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
108 lines (91 sloc) 5.11 KB
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Work Item Watch Dog</title>
<script src="sdk/scripts/VSS.SDK.js"></script>
</head>
<body style="margin: 5px">
<script type="text/javascript">
VSS.init({
explicitNotifyLoaded: true,
usePlatformScripts: true,
usePlatformStyles: true
});
VSS.require(["VSS/Service", "TFS/WorkItemTracking/RestClient", "VSS/Controls", "VSS/Controls/Grids"], function (VSS_Service, TFS_Wit_WebApi, Controls, Grids) {
var projectId = VSS.getWebContext().project.id;
var container = document.getElementById("grid-container");
// Retrieves the Work Item Tracking REST client
var witClient =
VSS_Service.getCollectionClient(TFS_Wit_WebApi.WorkItemTrackingHttpClient);
// Query object containing the WIQL query
var query = {
query: "SELECT [System.Id] FROM WorkItem WHERE [System.State] NOT IN ('Closed','Completed','Resolved','Removed', 'Done')"
};
// Executes the WIQL query against the active project
witClient.queryByWiql(query, projectId).then(
function (result) {
// Generate an array of all open work item ID's
var openWorkItems = result.workItems.map(function (wi) { return wi.id });
var fields = [
"System.Title",
"System.State",
"Microsoft.VSTS.Common.StateChangeDate",
"System.AssignedTo"];
witClient.getWorkItems(openWorkItems, fields).then(
function (workItems) {
// We now have the open work items with field values, time to display these
var options = {
width: "100%",
height: "500px",
// Maps each work item to a flat array with column values
source: workItems.map(function (w) {
return [
w.id,
w.fields["System.Title"],
w.fields["System.State"],
w.fields["Microsoft.VSTS.Common.StateChangeDate"],
w.fields["System.AssignedTo"]];
}),
columns: [
{ text: "id", index: 0, width: 50 },
{ text: "title", index: 1, width: 200 },
{ text: "state", index: 2, width: 100 },
{
text: "last state change",
index: 3,
width: 175,
getCellContents: function (
rowInfo,
dataIndex,
expandedState,
level,
column,
indentIndex,
columnOrder) {
// Calculates the difference between current time and
// StateChangeDate field value in days
var oneDay = 24 * 60 * 60 * 1000;
var changeDate = new Date(this.getColumnValue(dataIndex, column.index));
var today = new Date();
var diffDays = Math.round(Math.abs((changeDate.getTime() - today.getTime()) / (oneDay)));
// If more than 4 days has passed, show in orange
// If more than 10 days has passed, show in red
return $("<div class='grid-cell'/>")
.width(column.width || 100)
.css("color", diffDays < 4 ? "black" : (diffDays < 10 ? "orange" : "red"))
.text(diffDays + " day(s) ago");
}
},
{ text: "assigned", index: 4, width: 250 }
]
};
VSS.notifyLoadSucceeded();
var grid = Controls.create(Grids.Grid, container, options);
});
});
});
</script>
<img src="images/logo.png" width="75"> <span class="hub-title" style="margin-left: 100px;">Watch Dog - No More Stalled Work Items!</span>
<div id="grid-container" style="width: 100%; height: 100%;"></div>
</body>
</html>
You can’t perform that action at this time.