From 88112016166ac10e7ed2848c9562bed211918748 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Sat, 18 Sep 2010 23:32:09 +0200 Subject: First working version. Missing AJAX-style adding an attachment row to the attachment table. Add createDeadLink function, we don't need to use href='#' --- lib/bzpage.js | 55 +++++++++++++++++++---- lib/rhbzpage.js | 135 +++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 137 insertions(+), 53 deletions(-) diff --git a/lib/bzpage.js b/lib/bzpage.js index cbaae12..96ad655 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -99,7 +99,7 @@ var BZPage = function BZPage(win, config) { if ("killNodes" in config.gJSONData.configData && this.hostname in config.gJSONData.configData.killNodes) { var killConf = config.gJSONData.configData.killNodes[this.hostname]; - util.killNodes(this.doc, killConf[0], killConf[1]) + util.killNodes(this.doc, killConf[0], killConf[1]); } this.setConfigurationButton(); @@ -152,7 +152,7 @@ BZPage.prototype.getRealBugNo = function () { Request({ url: this.win.location.href+"&ctype=xml", onComplete: function() { - if (this.response.status == 200) { + if (this.response.status === 200) { var xmlRepr = this.response.xml; var bugID = parseInt(xmlRepr.getElementsByTagName("bug_id")[0].textContent, 10); if (isNaN(bugID)) { @@ -161,7 +161,7 @@ BZPage.prototype.getRealBugNo = function () { that.bugNo = bugID; console.log("The real bug no. is " + bugID); } - }, + } }).get(); }; @@ -405,6 +405,41 @@ BZPage.prototype.addToCommentsDropdown = function addToCommentsDropdown (pkg, cm select.appendChild(opt); }; +/** + * Create a A element leadink nowhere, but with listener running a callback on the click + * + * @param id String with a id to be added to the element + * @param text String with a string to be added as a textContent of the element + * @param parent Node which is a parent of the object + * @param callback Function to be called after clicking on the link + * @param params Array with parameters of the callback + * @param Boolean breakBefore if there should be a
element before. + * @return none + */ +BZPage.prototype.createDeadLink = function createDeadLink (id, text, parent, callback, params, breakBefore, accesskey) { + var that = this; + var newAElem = this.doc.createElement("a"); + params = util.valToArray(params); + newAElem.setAttribute("id", id); + if (accesskey) { + newAElem.setAttribute("accesskey", accesskey); + } + newAElem.setAttribute("href", ""); + newAElem.textContent = text; + + newAElem.addEventListener("click", function(evt) { + callback.apply(that, params); + evt.stopPropagation(); + evt.preventDefault(); + }, false); + + if (breakBefore) { + parent.appendChild(this.doc.createElement("br")); + } + parent.appendChild(newAElem); +}; + + /** * Generic function to add new button to the page. Actually copies new button * from the old one (in order to have the same look-and-feel, etc. @@ -456,7 +491,7 @@ BZPage.prototype.createNewButton = function createNewButton (location, after, pk .createTextNode("\u00A0"), originalLocation); } } catch (e if e instanceof TypeError) { - console.log("cannot find originalLocation element with id " + location); + console.error("cannot find originalLocation element with id " + location); } }; @@ -500,7 +535,7 @@ BZPage.prototype.generateButtons = function generateButtons () { BZPage.prototype.setConfigurationButton = function setConfigurationButton () { var additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions"); var configurationButtonUI = this.doc.createElement("li"); - configurationButtonUI.innerHTML = "\u00A0-\u00A0" + configurationButtonUI.innerHTML = "\u00A0-\u00A0" + "Triage configuration"; additionalButtons.appendChild(configurationButtonUI); this.doc.getElementById("configurationButton").addEventListener( @@ -898,7 +933,7 @@ BZPage.prototype.setUpLogging = function setUpLogging () { } var generateTimeSheetUI = this.doc.createElement("li"); - generateTimeSheetUI.innerHTML = "\u00A0-\u00A0" + generateTimeSheetUI.innerHTML = "\u00A0-\u00A0" + "Generate TS"; additionalButtons.appendChild(generateTimeSheetUI); this.doc.getElementById("generateTSButton").addEventListener( @@ -911,7 +946,7 @@ BZPage.prototype.setUpLogging = function setUpLogging () { }, false); var ImportTimeSheetUI = this.doc.createElement("li"); - ImportTimeSheetUI.innerHTML = "\u00A0-\u00A0" + ImportTimeSheetUI.innerHTML = "\u00A0-\u00A0" + "Import TS"; additionalButtons.appendChild(ImportTimeSheetUI); this.doc.getElementById("importTSButton").addEventListener( @@ -932,10 +967,12 @@ BZPage.prototype.setUpLogging = function setUpLogging () { } else { console.error("File " + jsonPaths + " doesn't exist!"); } + evt.stopPropagation(); + evt.preventDefault(); }, false); var clearLogsUI = this.doc.createElement("li"); - clearLogsUI.innerHTML = "\u00A0-\u00A0" + clearLogsUI.innerHTML = "\u00A0-\u00A0" + "Clear TS"; additionalButtons.appendChild(clearLogsUI); var clearLogAElem = this.doc.getElementById("clearLogs"); @@ -944,6 +981,8 @@ BZPage.prototype.setUpLogging = function setUpLogging () { this.style.color = that.log.EmptyLogsColor; this.style.fontWeight = "normal"; console.log("this.store wiped out!"); + evt.stopPropagation(); + evt.preventDefault(); }, false); if (this.log.store.length > 0) { diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js index fe77b0c..11471f5 100644 --- a/lib/rhbzpage.js +++ b/lib/rhbzpage.js @@ -15,7 +15,7 @@ var timer = require("timer"); var selection = require("selection"); var tabs = require("tabs"); var NumberOfFrames = require("bzpage").NumberOfFrames; - +var titleParsedAttachment = "Part of the thread where crash happened"; // ==================================================================================== // RHBugzillaPage object @@ -235,12 +235,13 @@ RHBugzillaPage.prototype.centralCommandDispatch = function(cmdLabel, cmdParams) * XML-RPC call yet. */ RHBugzillaPage.prototype.addAttachment = function addAttachment(data, callback) { + console.log("addAttachment // data = " + data + ", callback = " + callback); var msg = new xrpc.XMLRPCMessage("bugzilla.addAttachment"); var that = this; msg.addParameter(this.bugNo); msg.addParameter({ - description: "Interesting part of the thread backtrace where crash happened.", + description: titleParsedAttachment, filename: "parsed-backtrace.txt", // Isn't this weird ... base64 and text/plain??? FIXME // and XML-RPC and text/plain? @@ -258,7 +259,7 @@ RHBugzillaPage.prototype.addAttachment = function addAttachment(data, callback) 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("resp = " + resp[0]); + console.log("attachID = " + parseInt(resp[0].params.param.value.array.data.value.int, 10)) callback.call(that, parseInt(resp[0], 10)); } }, @@ -275,6 +276,7 @@ RHBugzillaPage.prototype.addAttachment = function addAttachment(data, callback) RHBugzillaPage.prototype.pasteBacktraceInComments = function() { // TODO This paragraph looks suspicous ... what is it? // Does it belong to this function? + var that = this; var notedLabel = this.doc.querySelector("label[for='newcc']"); while (notedLabel.firstChild) { var node = notedLabel.removeChild(notedLabel.firstChild); @@ -287,6 +289,7 @@ RHBugzillaPage.prototype.pasteBacktraceInComments = function() { var mainTitle = this.doc .getElementsByClassName("bz_alias_short_desc_container")[0]; + var abrtButton = this.doc.createElement("a"); abrtButton.setAttribute("accesskey", "a"); abrtButton.setAttribute("href", abrtQueryURL); @@ -312,15 +315,14 @@ RHBugzillaPage.prototype.pasteBacktraceInComments = function() { + x[1]; console.log("attURL = " + attURL); console.log("this.btSnippet = " + this.btSnippet); - console.log("btparsed = " + this.idContainsWord("cf_devel_whiteboard", 'btparsed')); + console.log("btparsed = " + this.idContainsWord("status_whiteboard", 'btparsed')); if ((!this.btSnippet) && - (!this.idContainsWord("cf_devel_whiteboard", 'btparsed'))) { + (!this.idContainsWord("status_whiteboard", 'btparsed'))) { var that = this; Request({ url: attURL, onComplete: function() { if (this.response.status == 200) { - console.log("response = " + this.response.text); that.btSnippet = that.parseBacktrace(this.response.text); if (that.btSnippet) { that.addCheckShowLink.call(that,x,that.btSnippet); @@ -331,14 +333,27 @@ RHBugzillaPage.prototype.pasteBacktraceInComments = function() { } }, this); } + // Add "show BT" links + console.log("status_whiteboard = " + this.doc.getElementById('status_whiteboard').value); + if (this.idContainsWord("status_whiteboard", 'btparsed')) { + var ourParsedAtts = this.attachments.filter(function (att) { + return (new RegExp(titleParsedAttachment).test(att[0])); + }); + console.log("ourParsedAtts = " + ourParsedAtts.toSource()); + ourParsedAtts.forEach(function (att) { + that.addShowParsedBTLink(att); + }, that); + } }; RHBugzillaPage.prototype.showAttachment = function showAttachment(id) { + var that = this; Request({ url: "https://" + this.hostname + "/attachment.cgi?id=" + id, onComplete: function () { - var infoWin = this.win.open("", "Check att. " + id, - "width=640,height=640,status=no,location=no"); + var infoWin = that.win.open("", "Check att. " + id, + "width=640,height=640,status=no,location=no,"+ + "titlebar=no,scrollbars=yes,resizable=yes"); var doc = infoWin.document; doc.body.innerHTML = "
"+
                 this.response.text + "
"; @@ -346,30 +361,72 @@ RHBugzillaPage.prototype.showAttachment = function showAttachment(id) { }).get(); }; -RHBugzillaPage.prototype.addNewAttachmentRow = function addNewAttachmentRow(oldRow) { +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. + + + + + Interesting part of the thread backtrace where crash happened. + + + (1.59 KB, + text/plain) + +
+ 2010-09-17 17:27 EDT, + + +
+ + + + no flags + + + + Details + + +*/ + + +/** + * Unfinished ... see above + */ +RHBugzillaPage.prototype.addNewAttachmentRow = function addNewAttachmentRow(old) { var that = this; - var newTRElem = oldRow.cloneNode(true); + var newTRElem = old[4].cloneNode(true); var elem = newTRElem.querySelector("td:last-of-type"); - elem.innerHTML += "
show BT"; + elem.innerHTML += "
show BT"; elem.getElementById("showBacktrace").addEventListener("click", function(evt) { - that.showAttachment.call(that,attID); + that.showAttachment.call(that, attID); },false); oldRow.parentNode.insertBefore(newTRElem,oldRow.nextSibling); }; - -RHBugzillaPage.prototype.addCheckShowLink = function addCheckXorgLogLink(oldElem, snippet) { +/** + * + */ +RHBugzillaPage.prototype.addCheckShowLink = function addCheckShowLink(oldAtt, snippet) { var that = this; - var elem = oldElem[4].querySelector("td:last-of-type"); - elem.innerHTML += "
check"; - var meAElem = that.doc.getElementById("attachBacktraceActivator"); - meAElem.addEventListener("click", function(x) { + 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(oldElem[4]); + // that.addNewAttachmentRow(oldAtt); + that.addStuffToTextBox("status_whiteboard", "btparsed"); + // TODO Doesn't work ... it gets into mid-air collision with comment about + // the new attachment. + // that.doc.forms.namedItem("changeform").submit(); }, false); - }, false); - meAElem.parentNode.removeChild(meAElem); - // this.addStuffToTextBox("status_whiteboard", "btparsed"); + }, [], true); }; /** @@ -390,7 +447,12 @@ RHBugzillaPage.prototype.markBadAttachments = function() { var titleElement = this.doc .getElementsByClassName("bz_alias_short_desc_container")[0]; titleElement.style.backgroundColor = "olive"; - titleElement.appendChild(this.createFixAllButton(badAttachments)); + + this.createDeadLink("fixAllButton", "Fix all", titleElement, function() { + Array.forEach(badAttachments, function(x) { + this.fixAttachById(x[1]); + }, that); + }, [], false, "f"); badAttachments.forEach(function(x, i, a) { this.addTextLink(x); }, this); @@ -541,9 +603,11 @@ RHBugzillaPage.prototype.addCheckXorgLogLink = function addCheckXorgLogLink() { this.XorgLogAttList.forEach(function (row) { var elemS = row[4].getElementsByTagName("td"); var elem = elemS[elemS.length - 1]; - elem.innerHTML += "
check"; + elem.innerHTML += "
check"; elem.addEventListener("click", function(x) { that.analyzeXorgLog(row[1]); + evt.stopPropagation(); + evt.preventDefault(); }, false); }, this); } @@ -812,26 +876,6 @@ RHBugzillaPage.prototype.fixAttachById = function(id, type, email) { this.reqCounter++; }; -/** - * Create a button for fixing all bad attachments. - * - * @param list Array of all bad attachmentss - * @return button fixing all bad Attachments - */ -RHBugzillaPage.prototype.createFixAllButton = function(list) { - var that = this; - var elem = this.doc.createElement("a"); - elem.setAttribute("href", ""); - elem.setAttribute("accesskey", "f"); - elem.innerHTML = "Fix all"; - elem.addEventListener("click", function() { - Array.forEach(list, function(x) { - this.fixAttachById(x[1]); - }, that); - }, false); - return elem; -}; - /** * Add a link to the bad attachment for fixing it. * @@ -949,8 +993,9 @@ RHBugzillaPage.prototype.parseBacktrace = function(ret) { i++; curLine = splitArray[i]; } + return outStr; } - return outStr; + return ""; }; // exports.RHBugzillaPage = apiUtils.publicConstructor(RHBugzillaPage); -- cgit