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: 'Edit in ADO ' + rowData["Id"] + '' }); 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 updateRecordCoD(workItem) { if (workItem === null || workItem["RiskReductionMinusOpportunityEnablement"] === null || workItem["TimeCriticality"] === null || workItem["BusinessValue"] === null) workItem["CoD"] === 0; else workItem["CoD"] === workItem["RiskReductionMinusOpportunityEnablement"] + workItem["TimeCriticality"] + workItem["BusinessValue"]; } function updateRecordOther(workItem, dataB, description) { 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; } 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, dataB, description) { var parent; var workItem; var records = []; for (var i = 0; i < data.length; 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; updateRecordCoD(parent); updateRecordCoD(workItem); updateRecordParent(parent, workItem); updateRecordOther(workItem, dataB, description); records.push(workItem); } records.sort(compareFunction); return records; } 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 setRecords(workItems, page, description, th) { var record; var html = "Parent IdParent TitleIdRequesterTitleAssigned ToSystem(s)StateValueUpDownPoll Value" + th + ""; 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 += "" + '' + record.ParentId + "" + "" + record.ParentTitle + "" + '' + record.Id + "" + "" + record.Requester + "" + record.Title + "" + record.AssignedTo + "" + record.Tags + "" + record.State + "" + '" + "Up" + "Down" + "" + record.PollValue + "" + length + " - " + record.TimeCriticality + ""; } 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 records = getRecords(data, dataB, description); console.log(data.length); if (data.length > 0) console.log(data[0]); setRecords(records, 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); }