|
| 1 | +(function () { |
| 2 | + function getIssuesFromDocument () { |
| 3 | + var list = {}, |
| 4 | + issues = document.querySelectorAll(".issue-marker"); |
| 5 | + |
| 6 | + if (issues) { |
| 7 | + // make issue an array |
| 8 | + issues = Array.prototype.slice.call(issues); |
| 9 | + |
| 10 | + // pluck out the bug data from the DOM object |
| 11 | + issues.forEach(function (issue) { |
| 12 | + |
| 13 | + var bugId = issue.dataset["bug_id"]; |
| 14 | + |
| 15 | + if (bugId){ |
| 16 | + list[bugId] = { |
| 17 | + "bug_status": issue.dataset["bug_status"], |
| 18 | + "short_desc": issue.querySelector(".short-desc").innerText |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | + }) |
| 23 | + } |
| 24 | + |
| 25 | + return list; |
| 26 | + } |
| 27 | + |
| 28 | + // Decorate the issues received from the sever with their state related to the issues in the page (new, changed) |
| 29 | + function setIssueStates (serverIssues, documentIssues) { |
| 30 | + var serverIssue, documentIssue; |
| 31 | + |
| 32 | + if (!serverIssues){ |
| 33 | + throw new TypeError("Missing 'serverIssues' from server. Expected Object, got "+ typeof serverIssues) |
| 34 | + } |
| 35 | + |
| 36 | + if (!documentIssues){ |
| 37 | + throw new TypeError("Missing 'documentIssues' from document. Expected Object, got "+ typeof documentIssues) |
| 38 | + } |
| 39 | + |
| 40 | + for (var bugId in serverIssues){ |
| 41 | + serverIssue = serverIssues[bugId]; |
| 42 | + documentIssue = documentIssues[bugId]; |
| 43 | + |
| 44 | + // is the bug in the doument? |
| 45 | + if (documentIssues[bugId]){ |
| 46 | + |
| 47 | + // bug status has changed. it's an updated issue |
| 48 | + if ( (documentIssue.bug_status !== serverIssue.bug_status) || |
| 49 | + (documentIssue.short_desc !== serverIssue.short_desc) ){ |
| 50 | + |
| 51 | + // changes from NEW->ASSIGNED aren't noteworthy |
| 52 | + if ( ! (documentIssue.bug_status == "NEW" && |
| 53 | + serverIssue.bug_status == "ASSIGNED") ) |
| 54 | + serverIssue.issue_state = "updated"; |
| 55 | + } |
| 56 | + } |
| 57 | + else{ |
| 58 | + // not found in the document. it's a new issue if the bug_status |
| 59 | + // is not RESOLVED |
| 60 | + if (serverIssue.bug_status === "RESOLVED") { |
| 61 | + //why do we want to show resolved issues that |
| 62 | + //have already been removed from the spec? |
| 63 | + |
| 64 | + //serverIssue.issue_state = 'resolved'; |
| 65 | + } else { |
| 66 | + serverIssue.issue_state = "new"; |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + return serverIssues; |
| 72 | + } |
| 73 | + |
| 74 | + // "this" is bound to the "BugzillaTracker" instance |
| 75 | + function renderIssues (serverIssues) { |
| 76 | + |
| 77 | + if (!serverIssues && !serverIssues.length){ |
| 78 | + return; |
| 79 | + } |
| 80 | + |
| 81 | + // get a list of bugs from the document |
| 82 | + var documentIssues = getIssuesFromDocument(); |
| 83 | + |
| 84 | + // get the bugs list with the updated state (not bug status) related to the bugs already in the page |
| 85 | + var issueList = setIssueStates(serverIssues, documentIssues); |
| 86 | + |
| 87 | + var fragment = document.createDocumentFragment(); |
| 88 | + |
| 89 | + for (var issueId in issueList){ |
| 90 | + |
| 91 | + if (issueList[issueId]["issue_state"]){ |
| 92 | + |
| 93 | + // bind the bug data to the bug template |
| 94 | + var issueFragment = this.renderIssue(issueList[issueId]); |
| 95 | + |
| 96 | + var wrapper = document.createElement("div"); |
| 97 | + var trigger = document.createElement("a"); |
| 98 | + trigger.className = "issue-markup-trigger"; |
| 99 | + trigger.href = "#"; |
| 100 | + trigger.innerHTML = "toggle markup" |
| 101 | + |
| 102 | + wrapper.setAttribute("data-issue_state", issueList[issueId]["issue_state"]); |
| 103 | + |
| 104 | + wrapper.appendChild(trigger); |
| 105 | + wrapper.appendChild(issueFragment); |
| 106 | + fragment.appendChild(wrapper); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + var issueListContainer = document.querySelector("#issue-list"); |
| 111 | + issueListContainer.appendChild(fragment); |
| 112 | + |
| 113 | + // show/hide the markup for a bug entry |
| 114 | + issueListContainer.addEventListener("click", toggleMarkup); |
| 115 | + } |
| 116 | + |
| 117 | + function toggleMarkup (e) { |
| 118 | + if (e.target.className && e.target.classList.contains("issue-markup-trigger")){ |
| 119 | + e.preventDefault(); |
| 120 | + |
| 121 | + var parent = e.target.parentNode, |
| 122 | + issueEl = parent.querySelector(".issue-marker"), |
| 123 | + markup = issueEl.outerHTML; |
| 124 | + |
| 125 | + |
| 126 | + parent.classList.toggle("showMarkup"); |
| 127 | + |
| 128 | + // already generated the markup |
| 129 | + if (parent.querySelector("pre")){ |
| 130 | + return |
| 131 | + } |
| 132 | + else{ |
| 133 | + var pre = document.createElement("pre"); |
| 134 | + pre.textContent = markup; |
| 135 | + |
| 136 | + parent.appendChild(pre); |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + function filterIssues (e) { |
| 142 | + if (e.target.name !== "issue-filter"){ |
| 143 | + return |
| 144 | + } |
| 145 | + |
| 146 | + var issueManager = document.querySelector("#issue-manager"); |
| 147 | + |
| 148 | + switch(e.target.value){ |
| 149 | + case "all": |
| 150 | + issueManager.removeAttribute("data-view_state"); |
| 151 | + break; |
| 152 | + |
| 153 | + case "new": |
| 154 | + issueManager.setAttribute("data-view_state", "new"); |
| 155 | + break; |
| 156 | + |
| 157 | + case "updated": |
| 158 | + issueManager.setAttribute("data-view_state", "updated"); |
| 159 | + break; |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + |
| 164 | + window.checkSpecificationIssues = function (product, component) { |
| 165 | + document.addEventListener("DOMContentLoaded", function(){ |
| 166 | + BugzillaTracker.setIssueTemplate(document.querySelector("#issue-template").innerHTML); |
| 167 | + BugzillaTracker.sync({ |
| 168 | + product: product, // e.g., 'CSS' |
| 169 | + component: component // e.g., "Regions", |
| 170 | + }, |
| 171 | + renderIssues); |
| 172 | + |
| 173 | + document.querySelector("#issue-manager form").addEventListener("change", filterIssues) |
| 174 | + }); |
| 175 | + }; |
| 176 | +})(); |
0 commit comments