227 lines
8.8 KiB
JavaScript
227 lines
8.8 KiB
JavaScript
var _apiUrl = null;
|
|
|
|
function compareFunction(a, b) {
|
|
if (a.TimeCriticality === null || b.TimeCriticality === null) {
|
|
var aPollValue = a.PollValue.split('-');
|
|
var bPollValue = b.PollValue.split('-');
|
|
return bPollValue[0].trim() - aPollValue[0].trim() || b.State[0] - a.State[0] || bPollValue[bPollValue.length - 1].trim()[0] - aPollValue[aPollValue.length - 1].trim()[0] || b.ParentId - a.ParentId || a.Id - b.Id;
|
|
} else {
|
|
return b.TimeCriticality - a.TimeCriticality || b.State[0] - a.State[0] || 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 getInversePriority(priority) {
|
|
var result;
|
|
if (priority == null || priority === 0)
|
|
result = "0.000";
|
|
else if (priority === 1)
|
|
result = "3.000";
|
|
else if (priority === 2)
|
|
result = "2.000";
|
|
else if (priority === 3)
|
|
result = "1.000";
|
|
else
|
|
result = "0.000";
|
|
return result;
|
|
}
|
|
|
|
function getPollValue(description, priority, priorityDisplay, pollValue) {
|
|
var result;
|
|
if (pollValue === undefined || pollValue.Records.length === undefined || pollValue.Records.length === 0 || pollValue.Average === null)
|
|
result = getInversePriority(priority) + ' - ' + priorityDisplay + ' - *Priority';
|
|
else if (pollValue.Average > 2)
|
|
result = `${pollValue.Average} - 1-High (Most ${description}) - ${pollValue.Count} Vote(s)`;
|
|
else if (pollValue.Average > 1)
|
|
result = `${pollValue.Average} - 2-Medium - ${pollValue.Count} Vote(s)`;
|
|
else if (pollValue.Average > 0)
|
|
result = `${pollValue.Average} - 3-Low - ${pollValue.Count} Vote(s)`;
|
|
else
|
|
result = getInversePriority(priority) + ' - ' + priorityDisplay + ' - *Priority';
|
|
return result;
|
|
}
|
|
|
|
function getWorkItems(data, dataB, description) {
|
|
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.State !== 'Active' && workItem.State !== 'New')
|
|
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 (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"]);
|
|
var priority = getPriority(workItem["WorkItemType"], workItem["Priority"]);
|
|
workItem["PollValue"] = getPollValue(description, workItem["Priority"], priority, dataB[workItem.Id]);
|
|
workItem["Priority"] = priority;
|
|
workItems.push(workItem);
|
|
}
|
|
workItems.sort(compareFunction);
|
|
return workItems;
|
|
}
|
|
|
|
function sendValue(element, page, id) {
|
|
var body = { time: new Date().getTime(), id: id, page: page, value: element.value };
|
|
$.post(_apiUrl + "save", body)
|
|
.done(function (msg) {
|
|
console.log("Posted value of " + element.value + " for " + id + " on page " + page + " " + msg);
|
|
})
|
|
.fail(function (xhr, textStatus, errorThrown) {
|
|
alert(textStatus);
|
|
});
|
|
}
|
|
|
|
function setWorkItems(workItems, page, description, th) {
|
|
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>State</th><th>Value</th><th>Up</th><th>Down</th><th>Poll Value</th><th>" + th + "</th></tr>";
|
|
const element = document.getElementById("HeaderGrid");
|
|
for (var i = 0; i < workItems.length; i++) {
|
|
record = workItems[i];
|
|
var length = record.TimeCriticality === null ? "" : record.TimeCriticality.toString().length;
|
|
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.ParentTitle +
|
|
"</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.State +
|
|
"</td><td>" +
|
|
'<select onchange="sendValue(this, \'' + page + '\', ' + record.Id + ')">' +
|
|
'<option value="9">Unknown</option>' +
|
|
'<option value="1">High (Most ' + description + ')</option>' +
|
|
'<option value="2">Medium</option>' +
|
|
'<option value="3">Low</option>' +
|
|
"</select>" +
|
|
"</td><td><a href='#' class='up'>Up</a>" +
|
|
"</td><td><a href='#' class='down'>Down</a>" +
|
|
"</td><td>" + record.PollValue +
|
|
"</td><td>" + length + " - " + record.TimeCriticality +
|
|
"</td></tr>";
|
|
}
|
|
element.innerHTML = html.replaceAll(">null<", "> <");
|
|
}
|
|
|
|
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, page, description, th, urlB) {
|
|
_apiUrl = apiUrl;
|
|
updateSite();
|
|
$.getJSON(urlB, { _: new Date().getTime() }, function (dataB) {
|
|
$.getJSON(url, { _: new Date().getTime() }, function (data) {
|
|
var workItems = getWorkItems(data, dataB, description);
|
|
console.log(data.length);
|
|
if (data.length > 0)
|
|
console.log(data[0]);
|
|
setWorkItems(workItems, page, description, th);
|
|
$(".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);
|
|
} |