var _apiUrl = null; function compareFunction(a, b) { return a.Priority[0] - b.Priority[0] || 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 getTimeCriticality(workItemType, timeCriticality) { var result; if (workItemType === "Bug") result = "0-Bug"; else if (timeCriticality == null || timeCriticality === 0) result = "9-Null"; else if (timeCriticality === 1) result = `${timeCriticality}-QSM`; else if (timeCriticality === 2) result = `${timeCriticality}-Qual`; else if (timeCriticality === 3) result = `${timeCriticality}-Eff`; 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.IterationPath !== 'ART SPS') continue; if (workItem.Tags != null && workItem.Tags.includes("Ignore")) continue; if ((document.title.indexOf('HiRel') > -1 && workItem.AreaPath !== 'ART SPS\\LEO') || (document.title.indexOf('Mesa') > -1 && workItem.AreaPath !== 'ART SPS\\MES')) continue; if (parent === null) { workItem["ParentId"] = null; 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"]) workItem["TimeCriticality"] = getTimeCriticality(workItem["WorkItemType"], workItem["TimeCriticality"]) workItems.push(workItem); } workItems.sort(compareFunction); return workItems; } function sendValue(element, page, id) { $.post(_apiUrl + "save", { time: new Date().getTime(), id: id, page: page, value: element.value }, function (data) { console.log("Posted value of " + element.value + " for " + id + " on page " + page); }); } function setWorkItems(workItems) { var record; var html = "Parent IdParent TitleIdRequesterTitleAssigned ToSystem(s)Value"; const element = document.getElementById("HeaderGrid"); for (var i = 0; i < workItems.length; i++) { record = workItems[i]; html += "" + '' + record.ParentId + "" + "" + record.ParentTitle + "" + '' + record.Id + "" + "" + record.Requester + "" + record.Title + "" + record.AssignedTo + "" + record.Tags + "" + '' + ""; } element.innerHTML = html.replaceAll(">null<", "> <"); } function initIndex(url, apiUrl) { _apiUrl = apiUrl; $.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); }); $("#HeaderGrid").on("dblclick", "tr", loadOne); }