diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-09-21 11:29:10 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-09-21 11:29:10 +0200 |
commit | c1a5120e976d18072e80a6086ff0a6a8ef83cb88 (patch) | |
tree | 8fd855913382548c107abdae460aea04a6b1e488 | |
parent | a2f2d22a11b83909de93312856eb3d4c90a68e0b (diff) | |
download | bugzilla-triage-c1a5120e976d18072e80a6086ff0a6a8ef83cb88.tar.gz |
Adding parsed backtraces seems to be functional. Yuhooo! \o/
* rhbzpage.addNewAttachmentRow finally beaten into submission
* util.parseXMLfromString ... it is better to hide this
-rw-r--r-- | lib/bzpage.js | 1 | ||||
-rw-r--r-- | lib/main.js | 1 | ||||
-rw-r--r-- | lib/rhbzpage.js | 94 | ||||
-rw-r--r-- | lib/util.js | 16 |
4 files changed, 60 insertions, 52 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js index f386868..269f4fa 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -762,7 +762,6 @@ BZPage.prototype.getOptionTableCell = function getOptionTableCell(tableId, label label = label.trim().replace(cleanLabelRE,"$1").toLowerCase(); var rows = this.doc.getElementById(tableId).getElementsByTagName("tr"); - console.log("rows.length = " + rows.length); var ourLine = Array.filter(rows, function(row) { var curLabel = row.getElementsByTagName("td")[0].textContent.toLowerCase(); curLabel = curLabel.replace(cleanLabelRE,"$1"); diff --git a/lib/main.js b/lib/main.js index 25498d6..a5700d6 100644 --- a/lib/main.js +++ b/lib/main.js @@ -40,7 +40,6 @@ function isOurPage(window, matchingURLs) { function skipThisPage(doc) { var stemURL = "https://HOSTNAME/show_bug.cgi?id="; var titleElems = doc.getElementsByTagName("title"); - console.log("titleElems.length = " + titleElems.length); var titleStr = titleElems[0].textContent; var REArr = new RegExp("[bB]ug\\s+([0-9]+)").exec(titleStr); var hostname = doc.location.hostname; diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js index d3056f3..c3d86ba 100644 --- a/lib/rhbzpage.js +++ b/lib/rhbzpage.js @@ -83,8 +83,6 @@ var RHBugzillaPage = function RHBugzillaPage(win, config) { this.parsedAttachments = this.attachments.filter(function (att) { return (new RegExp(titleParsedAttachment).test(att[0])); }); - console.log("ourParsedAtts = " + this.parsedAttachments.toSource()); - if (this.constantData.defaultAssignee) { this.setDefaultAssignee(); @@ -241,8 +239,7 @@ RHBugzillaPage.prototype.centralCommandDispatch = function(cmdLabel, cmdParams) * This has to stay in RHBugzillaPage because upstream doesn't have addAttachment * XML-RPC call yet. */ -RHBugzillaPage.prototype.addAttachment = function addAttachment(data, callback) { - console.log("addAttachment // data = " + data + ", callback = " + callback); +RHBugzillaPage.prototype.addAttachment = function addAttachment(data, callback, param) { var msg = new xrpc.XMLRPCMessage("bugzilla.addAttachment"); var that = this; @@ -261,11 +258,11 @@ RHBugzillaPage.prototype.addAttachment = function addAttachment(data, callback) url: this.constantData.XMLRPCData[this.hostname].url, onComplete: function() { if (this.response.status == 200) { - var respStr = this.response.text; // bug 270553 - respStr = respStr.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551 - var resp = new XML(respStr); - console.log("attachID = " + parseInt(resp[0].params.param.value.array.data.value.int, 10)) - callback.call(that, parseInt(resp[0], 10)); + console.log("this.response = " + this.response); + var resp = util.parseXMLfromString(this.response.text); + var newAttachID = parseInt(resp.params.param.value.array.data.value.int, 10); + console.log("attachID = " + newAttachID); + callback.call(that, param, newAttachID, data.length); } }, content: msg.xml(), @@ -376,54 +373,53 @@ RHBugzillaPage.prototype.showAttachment = function showAttachment(id) { * @param att Attachment object */ RHBugzillaPage.prototype.addShowParsedBTLink = function addShowParsedBTLink(att) { + var elem = att[4].querySelector("td:last-of-type"); this.createDeadLink("showParsedBacktraceWindow-" + att[1], "showBT", elem, this.showAttachment, att[1], true); }; -/* TODO -This is the HTML of a row with the full backtrace. We should -change its clone in addNewAttachmentRow to have correct values. - -<tr class="bz_contenttype_text_plain"> - <td valign="top"> - <a title="View the content of the attachment" href="attachment.cgi?id=448126" name="a8"> - <b>Interesting part of the thread backtrace where crash happened.</b></a> +/** + * Unfinished ... see above + */ +RHBugzillaPage.prototype.addNewAttachmentRow = function addNewAttachmentRow(origAtt, newAttId, newAttSize) { + var that = this; + var oldAddBTLink = this.doc.getElementById("attachBacktraceActivator"); + oldAddBTLink.parentNode.removeChild(oldAddBTLink); + var newTRElem = origAtt[4].cloneNode(true); - <span class="bz_attach_extra_info"> - (1.59 KB, - text/plain) + // fix number of the attachment + newTRElem.innerHTML = newTRElem.innerHTML.replace(origAtt[1], newAttId); + console.log("newTRElem = " + newTRElem.innerHTML); - <br> - <a title="Go to the comment associated with the attachment" href="#attach_448126">2010-09-17 17:27 EDT</a>, -<span class="vcard redhat_user"><a title="Matej Cepl <mcepl@redhat.com>" href="mailto:mcepl@redhat.com" class="email"> <span class="fn">Matej Cepl</span></a> -</span> - </span> - </td> + var aElements = newTRElem.getElementsByTagName("a"); + aElements[0].setAttribute("name","parsed-backtrace.txt"); + aElements[0].getElementsByTagName("b")[0].textContent = titleParsedAttachment; - <td valign="top" class="bz_attach_flags"> - <i>no flags</i> - </td> + var sizeSpan = newTRElem.getElementsByClassName("bz_attach_extra_info")[0]; + sizeSpan.textContent = "(" + (newAttSize / 1024).toFixed(2) + " KB, text/plain)"; - <td valign="top"> - <a href="attachment.cgi?id=448126&action=edit">Details</a> - </td> - </tr> -*/ + // aElements[1].textContent = new Date().toString(); TODO we should add eventually, but not pressing + var vcardSpan = newTRElem.getElementsByClassName("vcard")[0]; + if (vcardSpan !== undefined) { + console.log("vcardSpan = " + vcardSpan); + var vcardSpanClassList = vcardSpan.classList; + if (/@redhat\.com/.test(this.login) && !vcardSpanClassList.contains("redhat_user")) { + vcardSpanClassList.add("redhat_user"); + } + var vcardAElem = vcardSpan.getElementsByTagName("a")[0]; + vcardAElem.setAttribute("title", this.login); + vcardAElem.setAttribute("href", "mailto:" + this.login); + vcardAElem.className = "email"; + vcardAElem.innerHTML="<span class='fn'>" + this.login + "</span>"; + } -/** - * Unfinished ... see above - */ -RHBugzillaPage.prototype.addNewAttachmentRow = function addNewAttachmentRow(old) { - return null; // TODO make this working - var that = this; - var newTRElem = old[4].cloneNode(true); var elem = newTRElem.querySelector("td:last-of-type"); - elem.innerHTML += "<br/><a id='showBacktrace' href=''>show BT</a>"; - elem.getElementById("showBacktrace").addEventListener("click", function(evt) { - that.showAttachment.call(that, attID); - },false); - oldRow.parentNode.insertBefore(newTRElem,oldRow.nextSibling); + console.log("elem.innerHTML = " + elem.innerHTML); + this.createDeadLink("showBacktrace", "show BT", elem, + this.showAttachment, newAttId, false); + + origAtt[4].parentNode.insertBefore(newTRElem, origAtt[4].nextSibling); }; /** @@ -437,9 +433,9 @@ RHBugzillaPage.prototype.addCheckShowLink = function addCheckShowLink(oldAtt, sn var that = this; var elem = oldAtt[4].querySelector("td:last-of-type"); this.createDeadLink("attachBacktraceActivator", "add parsed BT", elem, function(x) { - that.addAttachment.call(that, snippet, function () { - that.addNewAttachmentRow(oldAtt); - }, false); + // pass function and parameters as two separate parameters, the function to be called from + // addAttachment + that.addAttachment.call(that, snippet, this.addNewAttachmentRow, oldAtt); }, [], true); }; diff --git a/lib/util.js b/lib/util.js index b258c5f..f9a14c7 100644 --- a/lib/util.js +++ b/lib/util.js @@ -41,7 +41,7 @@ var getParamsFromURL = exports.getParamsFromURL = function getParamsFromURL (url if (!url || (url.toString().length === 0)) { throw new Error("Missing URL value!"); } - + if (!(url instanceof urlMod.URL)) { url = new urlMod.URL(url.toString(), base); } @@ -61,6 +61,20 @@ var getParamsFromURL = exports.getParamsFromURL = function getParamsFromURL (url }; /** + * parse XML object out of string working around various bugs in Gecko implementation + * see https://developer.mozilla.org/en/E4X for more information + * + * @param inStr String with unparsed XML string + * @return XML object + */ +exports.parseXMLfromString = function parseXMLfromString (inStuff) { + // if (typeof inStuff !== 'string') In future we should recognize this.response + // and get just .text property out of it. TODO + var respStr = inStuff.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551 + return new XML(respStr); +}; + +/** * Get a bug no from URL ... fails with aliases * It should theoretically belong to bzpage.js, but we don't have * unit tests there yet, so keeping here. |