165 lines
5.9 KiB
JavaScript

var _apiUrl = null;
function compareFunction(a, b) {
return a.WeightedShortestJobFirst - b.WeightedShortestJobFirst || b.ParentId - a.ParentId || a.Id - b.Id;
}
function showOne(rowData) {
if (rowData == null)
return;
var data = [];
data.push({ name: "Edit in ADO", value: '<a target="_blank" href="https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/' + rowData["Id"] + '">Edit in ADO ' + rowData["Id"] + '</a>' });
for (const property in rowData) {
if (rowData[property] == null)
continue;
data.push({ name: property, value: rowData[property].toString() });
}
$("#AllGrid").igGrid({
autoGenerateColumns: true,
dataSource: data,
width: "100%",
showHeader: false,
});
}
function loadOne() {
var selectedRow = $("#HeaderGrid").data("igGridSelection").selectedRow();
if (selectedRow == null)
return;
var rowData = $("#HeaderGrid").data("igGrid").dataSource.dataView()[selectedRow.index];
showOne(rowData);
}
function detailSelectionChangedRunInfo(evt, ui) {
if (ui.row.index === 0)
return;
var rowData = ui.owner.grid.dataSource.dataView()[ui.row.index];
showOne(rowData);
}
function getState(state) {
var result;
if (state == null)
result = "9-Null";
else if (state === "New")
result = `1-${state}`;
else if (state === "Active")
result = `2-${state}`;
else if (state === "Resolved")
result = `3-${state}`;
else if (state === "Closed")
result = `4-${state}`;
else if (state === "Removed")
result = `5-${state}`;
else
result = `8-${state}`;
return result;
}
function getPriority(workItemType, priority) {
var result;
if (workItemType === "Bug")
result = "0-Bug";
else if (priority == null || priority === 0)
result = "9-Null";
else if (priority === 1)
result = `${priority}-High`;
else if (priority === 2)
result = `${priority}-Med`;
else if (priority === 3)
result = `${priority}-Low`;
else if (priority === 4)
result = `${priority}-TBD`;
else
result = "8-Not";
return result;
}
function getWorkItems(data) {
var parent;
var workItem;
var workItems = [];
for (var i = data.length - 1; i > -1; i--) {
parent = data[i].Parent;
workItem = data[i].WorkItem;
if (workItem.WorkItemType !== 'Feature')
continue;
if (workItem.Tags != null && workItem.Tags.includes("Ignore"))
continue;
if ((window.location.href.indexOf('=LEO') > -1 && workItem.AreaPath !== 'ART SPS\\LEO') || (window.location.href.indexOf('=MES') > -1 && workItem.AreaPath !== 'ART SPS\\MES'))
continue;
if (workItem["WeightedShortestJobFirst"] === null)
workItem["WeightedShortestJobFirst"] = 9999999;
if (parent === null) {
workItem["ParentId"] = 9999999;
workItem["ParentTitle"] = null;
workItem["ParentState"] = null;
}
else {
workItem["ParentId"] = parent["Id"];
workItem["ParentTitle"] = parent["Title"];
workItem["ParentState"] = getState(parent["State"]);
}
workItem["State"] = getState(workItem["State"])
workItem["Priority"] = getPriority(workItem["WorkItemType"], workItem["Priority"])
workItems.push(workItem);
}
workItems.sort(compareFunction);
return workItems;
}
function setWorkItems(workItems) {
var record;
var html = "<tr><th>Parent Id</th><th>Parent Title</th><th>Id</th><th>Requester</th><th>Title</th><th>Assigned To</th><th>System(s)</th><th>WSJF</th><th>Value</th><th>Up</th><th>Down</th></tr>";
const element = document.getElementById("HeaderGrid");
for (var i = 0; i < workItems.length; i++) {
record = workItems[i];
html += "<tr><td>" + '<a target="_blank" href="https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/' + record.ParentId + '">' + record.ParentId + "</a>" +
"</td><td>" + record.Title +
"</td><td>" + '<a target="_blank" href="https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/' + record.Id + '">' + record.Id + "</a>" +
"</td><td>" + record.Requester +
"</td><td>" + record.Title +
"</td><td>" + record.AssignedTo +
"</td><td>" + record.Tags +
"</td><td>" + record.WeightedShortestJobFirst +
"</td><td>&nbsp;" +
"</td><td><a href='#' class='up'>Up</a></td><td><a href='#' class='down'>Down</a></td></tr>";
}
element.innerHTML = html.replaceAll(">null<", ">&nbsp;<");
}
function updateSite() {
if (window.location.href.indexOf('=LEO') > -1) {
document.title = document.title.replace("Infineon", "HiRel (Leominster)");
document.getElementById("siteHeader").innerText = "HiRel (Leominster)";
}
else if (window.location.href.indexOf('=MES') > -1) {
document.title = document.title.replace("Infineon", "Mesa");
document.getElementById("siteHeader").innerText = "Mesa";
}
else {
document.title = document.title.replace("Infineon", "Infineon");
document.getElementById("siteHeader").innerText = "Infineon";
}
}
function initIndex(url, apiUrl) {
_apiUrl = apiUrl;
updateSite();
$.getJSON(url, { _: new Date().getTime() }, function (data) {
var workItems = getWorkItems(data);
console.log(data.length);
if (data.length > 0)
console.log(data[0]);
setWorkItems(workItems);
$(".up,.down").click(function () {
var row = $(this).parents("tr:first");
if ($(this).is(".up")) {
row.insertBefore(row.prev());
} else {
row.insertAfter(row.next());
}
});
});
$("#HeaderGrid").on("dblclick", "tr", loadOne);
}