2024-10-23 20:54:14 -07:00

196 lines
7.3 KiB
JavaScript

function compareFunction(a, b) {
if (a.ParentCoD === null || b.ParentCoD === null) {
return b.ParentCoD - a.ParentCoD || b.Id - a.Id;
} else {
return 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 updateRecordCoD(workItem) {
if (workItem !== null) {
if (workItem.Effort === null)
workItem.Effort = 10123;
if (workItem.BusinessValue === null)
workItem.BusinessValue = 99999;
if (workItem.TimeCriticality === null)
workItem.TimeCriticality = 99999;
if (workItem.RiskReductionMinusOpportunityEnablement === null)
workItem.RiskReductionMinusOpportunityEnablement = 99999;
workItem.CoD = workItem.RiskReductionMinusOpportunityEnablement + workItem.TimeCriticality + workItem.BusinessValue;
}
}
function updateRecordOther(workItem) {
workItem["State"] = getState(workItem["State"]);
workItem["Priority"] = getPriority(workItem["WorkItemType"], workItem["Priority"]);
}
function updateRecordParent(parent, workItem) {
if (parent === null) {
workItem["ParentId"] = 9999999;
workItem["ParentTitle"] = null;
workItem["ParentState"] = null;
workItem["ParentCoD"] = 9999999;
}
else {
workItem["ParentId"] = parent["Id"];
workItem["ParentCoD"] = parent["CoD"];
workItem["ParentTitle"] = parent["Title"];
workItem["ParentState"] = getState(parent["State"]);
}
}
function getRecords(data) {
var parent;
var workItem;
var records = [];
for (var i = 0; i < data.length; i++) {
parent = data[i].Parent;
workItem = data[i].WorkItem;
if (workItem.Tags != null && workItem.Tags.includes("Ignore"))
continue;
if (workItem.WorkItemType !== 'User Story' && workItem.WorkItemType !== 'Bug')
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;
updateRecordCoD(parent);
updateRecordCoD(workItem);
updateRecordOther(workItem);
updateRecordParent(parent, workItem);
records.push(workItem);
}
records.sort(compareFunction);
return records;
}
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) {
updateSite();
$.getJSON(url, { _: new Date().getTime() }, function (data) {
var records = getRecords(data);
console.log(data.length);
if (data.length > 0)
console.log(data[0]);
$("#HeaderGrid").igGrid({
autoGenerateColumns: false,
dataSource: records,
height: "100%",
primaryKey: "Id",
width: "100%",
columns: [
{ key: "Violation", dataType: "string", hidden: true },
{ headerText: "Parent Id", key: "ParentId", dataType: "string" },
{ headerText: "Parent State", key: "ParentState", dataType: "string" },
{ headerText: "Parent CoD", key: "ParentCoD", dataType: "string" },
{ key: "Id", dataType: "number" },
{ key: "Requester", dataType: "string" },
{ headerText: "Assigned To", key: "AssignedTo", dataType: "string" },
{ key: "Title", dataType: "string", width: "20%" },
{ headerText: "System(s)", key: "Tags", dataType: "string" },
{ key: "Priority", dataType: "string" },
{ key: "State", dataType: "string" },
{ key: "ParentTitle", dataType: "string", hidden: true },
{ key: "AreaPath", dataType: "string", hidden: true },
{ key: "ChangedDate", dataType: "string", hidden: true },
{ key: "CommentCount", dataType: "number", hidden: true },
{ key: "CreatedDate", dataType: "string", hidden: true },
{ key: "Description", dataType: "string", hidden: true },
{ key: "IterationPath", dataType: "string", hidden: true },
{ key: "Revision", dataType: "number", hidden: true },
{ key: "WorkItemType", dataType: "string", hidden: true },
],
features: [
{ name: "Sorting", type: "local" },
{ name: "Filtering", type: "local" },
{ name: "Selection", mode: "row", multipleSelection: false, rowSelectionChanging: detailSelectionChangedRunInfo },
{ name: "Paging", type: "local", recordCountKey: "TotalRows", pageSize: 10, pageSizeUrlKey: "pageSize", "pageIndexUrlKey": "page", showPageSizeDropDown: true },
],
});
});
$("#HeaderGrid").on("dblclick", "tr", loadOne);
}