From 2b95e7ae6cb53f987931de8f567870b9e69cdf9a Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Sat, 5 Jun 2010 01:13:12 +0200 Subject: Unfinished mess of everything, unworking. --- lib/bzpage.js | 54 +++--------- lib/main.js | 20 ++--- lib/offline-support.js | 153 +++++++++++++++++++++++++++++++++ lib/rhbzpage.js | 227 ++++++++++--------------------------------------- lib/util.js | 22 +++++ 5 files changed, 237 insertions(+), 239 deletions(-) create mode 100644 lib/offline-support.js (limited to 'lib') diff --git a/lib/bzpage.js b/lib/bzpage.js index bad7b5e..8f11eb5 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -3,13 +3,13 @@ // Released under the MIT/X11 license // http://www.opensource.org/licenses/mit-license.php "use strict"; -var utilMod = require("util"); +var util = require("util"); +var simpleStorage = require("simple-storage"); var TriagedDistro = 13; var NumberOfFrames = 7; var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi"; var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id="; -var myStorage = jetpack.storage.simple; // ==================================================================================== // BZPage's methods @@ -20,20 +20,6 @@ exports.BZPage = function BZPage(doc) { // 85 this.ReporterColor = new Color(255, 255, 166); // RGB 255, 255, 166; HSL 60, 2, // 83 - this.RE = { - Comment: new RegExp("^\\s*#"), // unsused - BlankLine: new RegExp("^\\s*$"), // unused - // nová řádka - // [ 65.631] (--) intel(0): Chipset: "845G" - Chipset: new RegExp("^\\s*\\[?[ 0-9.]*\\]?\\s*\\(--\\) "+ - "([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$"), - ATIgetID: new RegExp("^.*\\(ChipID = 0x([0-9a-fA-F]+)\\).*$"), - Abrt: new RegExp("^\\s*\\[abrt\\]"), - signalHandler: new RegExp("^\\s*#[0-9]*\\s*"), - frameNo: new RegExp("^\\s*#([0-9]*)\\s") - }; - - // initialize dynamic properties this.doc = doc; this.packages = this.getInstalledPackages(); @@ -41,7 +27,11 @@ exports.BZPage = function BZPage(doc) { this.commentStrings = config.gJSONData.commentStrings; } + if ("constantData" in config.gJSONData) { + // this is wrong, I shouldn't bother anybody with my Xorg data, and + // I should load it from URL + // var stuff = JSON.parse(self.data.load("chiIDsGroupings.json")); this.constantData = config.gJSONData.constantData; } @@ -56,7 +46,7 @@ exports.BZPage = function BZPage(doc) { } this.submitHandlerInstalled = false; - this.bugNo = utilMod.getBugNo(this.doc.location.toString()); + this.bugNo = util.getBugNo(this.doc.location.toString()); this.reporter = this.getReporter(); this.product = this.getOptionValue("product"); this.component = this.getOptionValue("component"); @@ -451,28 +441,6 @@ BZPage.prototype.clickMouse = function(targetID) { this.doc.getElementById(targetID).dispatchEvent(localEvent); }; -/** - * select element of the array where regexp in the first element matches second - * parameter of this function - * - * @param list Array with regexps and return values - * @param chosingMark String by which the element of array is to be matched - * @return Object chosen element - */ -BZPage.prototype.filterByRegexp = function(list, chosingMark) { - let chosenPair = []; - if (list.length > 0) { - chosenPair = list.filter(function(pair) { - return new RegExp(pair.regexp, "i").test(chosingMark); - }); - } - if (chosenPair.length > 0) { - return chosenPair[0].addr; - } else { - return ""; - } -}; - /** * Add object to the text box (comment box or status whiteboard) * @@ -487,7 +455,7 @@ BZPage.prototype.addStuffToTextBox = function(id, stuff) { stuff = textBox.value ? "\n\n" + stuff : stuff; textBox.value += stuff; } else { - textBox.value = utilMod.addCSVValue(textBox.value,stuff); + textBox.value = util.addCSVValue(textBox.value,stuff); } }; @@ -499,7 +467,7 @@ BZPage.prototype.addStuffToTextBox = function(id, stuff) { */ BZPage.prototype.removeStuffFromTextBox = function(id, stuff) { let changedElement = this.getElementById(id); - changedElement.value = utilMod.removeCSVValue(changedElement.value,stuff); + changedElement.value = util.removeCSVValue(changedElement.value,stuff); } /** @@ -587,7 +555,7 @@ BZPage.prototype.getLogin = function () { * @return String with the maintainer's email address */ BZPage.prototype.getDefaultBugzillaMaintainer = function(component) { - let address = this.filterByRegexp(this.defBugzillaMaintainerArr, component); + let address = util.filterByRegexp(this.defBugzillaMaintainerArr, component); return address; } @@ -724,7 +692,7 @@ BZPage.prototype.addToCCList = function(who) { this.doc.getElementById("addselfcc").checked = true; } else { this.clickMouse("cc_edit_area_showhide"); - if (!utilMod.isInList(who, this.CCList)) { + if (!util.isInList(who, this.CCList)) { this.addStuffToTextBox("newcc",who); } } diff --git a/lib/main.js b/lib/main.js index 03bc69d..eca533e 100644 --- a/lib/main.js +++ b/lib/main.js @@ -12,19 +12,15 @@ // http://ehsanakhgari.org/blog/2010-05-31/my-experience-jetpack-sdk#comment-1253 // "use strict"; -var utilMod = require("util"); -var logMod = require("logger"); - -jetpack.future.import("pageMods"); -jetpack.future.import("storage.simple"); -jetpack.future.import("selection"); -jetpack.future.import("clipboard"); +var util = require("util"); +var logger = require("logger"); +var file = require("file"); +var myStorage = require("simple-storage").storage; var TriagedDistro = 13; var NumberOfFrames = 7; var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi"; var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id="; -var myStorage = jetpack.storage.simple; // ============================================================== // https://wiki.mozilla.org/Labs/Jetpack/JEP/24 @@ -67,7 +63,7 @@ config.matches = [ "https://bugzilla.redhat.com/show_bug.cgi", "https://bugzilla.mozilla.org/show_bug.cgi" ]; -utilMod.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) { +util.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) { config.gJSONData = parsedData; // Get card translation table @@ -76,12 +72,12 @@ utilMod.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) { keys += key + " "; } if ("PCIIDsURL" in config.gJSONData.configData) { - utilMod.loadJSON(config.gJSONData.configData.PCIIDsURL, function(response) { + util.loadJSON(config.gJSONData.configData.PCIIDsURL, function(response) { config.PCI_ID_Array = response; }); } - config.logger = new logMod.Logger(myStorage.logs, + config.logger = new logger.Logger(myStorage.logs, config.gJSONData.constantData.bugzillalabelAbbreviations); let callback = function(doc) { @@ -93,4 +89,4 @@ utilMod.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) { }; jetpack.pageMods.add(callback, config); -}, this); +}, this); \ No newline at end of file diff --git a/lib/offline-support.js b/lib/offline-support.js new file mode 100644 index 0000000..4849bd3 --- /dev/null +++ b/lib/offline-support.js @@ -0,0 +1,153 @@ +/*jslint onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */ +/*global jetpack */ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php +"use strict"; + +/* Offline supporting functions */ +/** + * + * @todo FIXME this probably makes a closure and a memory leak name='changeform' + * investigate + * https://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion + * + *
+ * + * Reading + * http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13 + * random notes: - 17.13.3 provides all steps necessary - enctype != + * application/x-www-form-urlencoded => SHOULD fails (no further questions + * needed) - http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1. is + * nice explanation (albeit quite dated) - on multiple values + * http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.6.1 - + * příliš jednoduché + * http://www.innovation.ch/java/HTTPClient/emulating_forms.html - + */ +RHBugzillaPage.prototype.serializeForm = function(form) { + let serialForm = { + dataOut : "", + name : form.name, + method : form.method, + acceptCharset : form.acceptCharset, + action : form.action, // TODO shouldn't we get a non-relative URL? + enctype : form.enctype, + cookie : this.doc.cookie, + autocomplete : form.getAttribute("autocomplete"), + bugNo : this.bugNo + }; + + function genURIElement(sName, sValue) { + return encodeURIComponent(sName) + "=" + encodeURIComponent(sValue); + } + + /** + * @param o + * control to be serialized + * @return String with the serialized control + */ + function serializeControl(element) { + let val = element.value; + // console.log("val.toSource() = " + val.toSource()); + /* + * on HTMLSelectElement we have an attribute 'type' of type DOMString, + * readonly The type of this form control. This is the string + * "select-multiple" when the multiple attribute is true and the string + * "select-one" when false. + */ + if ((val == null) || (val == undefined) || (val == "")) { + return; + } else if (val instanceof Array) { + return val.map(function(x) { + return genURIElement(element.name, x.value); + }).join("&"); + } else if (val instanceof String) { + return genURIElement(element.name, val); + } else { // assume HTMLCollection + return Array.map(val, function(x) { + return genURIElement(element.name, x.value); + }).join("&"); + } + } + + serialForm.dataOut = Array.filter(form.elements,function(el) { + return !el.disabled && el.name && + // FIXME shouldn't I just add && el.value here? + (el.checked || /select|textarea/i.test(el.nodeName) || + /text|hidden|password|search/i.test(el.type)); + }).map(serializeControl).join("&"); + return serialForm; +}; + +//RHBugzillaPage.prototype.submitCallback = function(evt) { +// console.log("Submit Callback!"); +// if (jetpack.__parent__.navigator.onLine) { +// let serForm = this +// .serializeForm(jetpack.tabs.focused.contentWindow.document.forms +// .namedItem("changeform")); +//// console.log("serForm:\n" + serForm.toSource()); +// } else { +// let serForm = this +// .serializeForm(jetpack.tabs.focused.contentWindow.document.forms +// .namedItem("changeform")); +// myStorage.forms[this.bugNo] = serForm; +// evt.stopPropagation(); +// evt.preventDefault(); +// } +//}; + +/** + * + * + * Yes, this is correct, this is NOT method of RHBugzillaPage! + */ +/*function onlineCallback() { + function deserializeAndSend(formData) { + // FIXME notImplemented + // is it enough to just + // run XMLHttpRequest? Probably yes, this is just a form + // and this is just a HTTP request + // it is probably better to get already processed + // application/x-www-form-urlencoded + // see http://htmlhelp.com/reference/html40/forms/form.html for details + // and also https://developer.mozilla.org/en/AJAX/Getting_Started + // what's? + // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference\ + // /Global_Functions/encodeURI & co. + // this seems to be also interesting + // https://developer.mozilla.org/en/Code_snippets/Post_data_to_window + console.error("Sending bugs not implemented yet!"); + return ""; // FIXME check other HTTP headers to be set + + let bugID = formData.bugNo; + let req = new XMLHttpRequest(); + req.open("POST", formData.action, true); + // FIXME co očekávám za odpověď? req.overrideMimeType("text/xml"); + // * Accept-Encoding + // * Accept-Language + // * Accept (MIME types) + req.setRequestHeader("Connection", "keep-alive"); + req.setRequestHeader("Keep-Alive", 300); + req.setRequestHeader("Content-Type", formData.enctype); + req.setRequestHeader("Referer", bugURL + bugID); + req.setRequestHeader("Accept-Charset", formData.acceptCharset); + req.setRequestHeader("Cookie", formData.cookie); + req.onreadystatechange = function(aEvt) { + if (req.readyState == 4) { + if (req.status == 200) { + console.log("Sent form for bug " + bugID); + delete myStorage.forms[bugID]; + } else { + console.error("Sending form for bug " + bugID + "failed!"); + } + } + }; + req.send(formData.data); + } + + if (myStorage.forms.length > 0) { + myStorage.forms.forEach(function(x) { + deserializeAndSend(x); + }); + } +} +*/ \ No newline at end of file diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js index f318528..c885699 100644 --- a/lib/rhbzpage.js +++ b/lib/rhbzpage.js @@ -3,7 +3,7 @@ // Released under the MIT/X11 license // http://www.opensource.org/licenses/mit-license.php "use strict"; -var utilMod = require("util"); +var util = require("util"); var xrpc = require("xmlrpc"); var xhr = require("xhr"); // var TriagedDistro = 13; @@ -29,6 +29,20 @@ exports.RHBugzillaPage = function RHBugzillaPage(doc) { // HSL // 120, 0, 23 this.RHITColor = new Color(102, 0, 102); // RGB 102, 0, 102; HSL 300, 0, 20 + + this.RE = { + Comment: new RegExp("^\\s*#"), // unsused + BlankLine: new RegExp("^\\s*$"), // unused + // new line + // [ 65.631] (--) intel(0): Chipset: "845G" + Chipset: new RegExp("^\\s*\\[?[ 0-9.]*\\]?\\s*\\(--\\) "+ + "([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$"), + ATIgetID: new RegExp("^.*\\(ChipID = 0x([0-9a-fA-F]+)\\).*$"), + Abrt: new RegExp("^\\s*\\[abrt\\]"), + signalHandler: new RegExp("^\\s*#[0-9]*\\s*"), + frameNo: new RegExp("^\\s*#([0-9]*)\\s") + }; + // END OF CONSTANTS // Prepare for query buttons @@ -104,7 +118,7 @@ exports.RHBugzillaPage = function RHBugzillaPage(doc) { } } // END OF RHBugzillaPage CONSTRUCTOR -RHBugzillaPage.prototype = utilMod.heir(BZPage); +RHBugzillaPage.prototype = util.heir(BZPage); RHBugzillaPage.prototype.constructor = RHBugzillaPage; /** @@ -114,7 +128,7 @@ RHBugzillaPage.prototype.constructor = RHBugzillaPage; * we haven't set it up. */ RHBugzillaPage.prototype.getDefaultAssignee = function() { - return this.filterByRegexp(this.constantData.defaultAssignee, + return util.filterByRegexp(this.constantData.defaultAssignee, this.component).toLowerCase(); } @@ -199,153 +213,6 @@ RHBugzillaPage.prototype.centralCommandDispatch = function(cmdLabel, cmdParams) }; -/* Offline supporting functions */ -/** - * - * @todo FIXME this probably makes a closure and a memory leak name='changeform' - * investigate - * https://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion - * - * - * - * Reading - * http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13 - * random notes: - 17.13.3 provides all steps necessary - enctype != - * application/x-www-form-urlencoded => SHOULD fails (no further questions - * needed) - http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1. is - * nice explanation (albeit quite dated) - on multiple values - * http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.6.1 - - * příliš jednoduché - * http://www.innovation.ch/java/HTTPClient/emulating_forms.html - - */ -RHBugzillaPage.prototype.serializeForm = function(form) { - let serialForm = { - dataOut : "", - name : form.name, - method : form.method, - acceptCharset : form.acceptCharset, - action : form.action, // TODO shouldn't we get a non-relative URL? - enctype : form.enctype, - cookie : this.doc.cookie, - autocomplete : form.getAttribute("autocomplete"), - bugNo : this.bugNo - }; - - function genURIElement(sName, sValue) { - return encodeURIComponent(sName) + "=" + encodeURIComponent(sValue); - } - - /** - * @param o - * control to be serialized - * @return String with the serialized control - */ - function serializeControl(element) { - let val = element.value; - // console.log("val.toSource() = " + val.toSource()); - /* - * on HTMLSelectElement we have an attribute 'type' of type DOMString, - * readonly The type of this form control. This is the string - * "select-multiple" when the multiple attribute is true and the string - * "select-one" when false. - */ - if ((val == null) || (val == undefined) || (val == "")) { - return; - } else if (val instanceof Array) { - return val.map(function(x) { - return genURIElement(element.name, x.value); - }).join("&"); - } else if (val instanceof String) { - return genURIElement(element.name, val); - } else { // assume HTMLCollection - return Array.map(val, function(x) { - return genURIElement(element.name, x.value); - }).join("&"); - } - } - - serialForm.dataOut = Array.filter(form.elements,function(el) { - return !el.disabled && el.name && - // FIXME shouldn't I just add && el.value here? - (el.checked || /select|textarea/i.test(el.nodeName) || - /text|hidden|password|search/i.test(el.type)); - }).map(serializeControl).join("&"); - return serialForm; -}; - -//RHBugzillaPage.prototype.submitCallback = function(evt) { -// console.log("Submit Callback!"); -// if (jetpack.__parent__.navigator.onLine) { -// let serForm = this -// .serializeForm(jetpack.tabs.focused.contentWindow.document.forms -// .namedItem("changeform")); -//// console.log("serForm:\n" + serForm.toSource()); -// } else { -// let serForm = this -// .serializeForm(jetpack.tabs.focused.contentWindow.document.forms -// .namedItem("changeform")); -// myStorage.forms[this.bugNo] = serForm; -// evt.stopPropagation(); -// evt.preventDefault(); -// } -//}; - -/** - * - * - * Yes, this is correct, this is NOT method of RHBugzillaPage! - */ -/*function onlineCallback() { - function deserializeAndSend(formData) { - // FIXME notImplemented - // is it enough to just - // run XMLHttpRequest? Probably yes, this is just a form - // and this is just a HTTP request - // it is probably better to get already processed - // application/x-www-form-urlencoded - // see http://htmlhelp.com/reference/html40/forms/form.html for details - // and also https://developer.mozilla.org/en/AJAX/Getting_Started - // what's? - // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference\ - // /Global_Functions/encodeURI & co. - // this seems to be also interesting - // https://developer.mozilla.org/en/Code_snippets/Post_data_to_window - console.error("Sending bugs not implemented yet!"); - return ""; // FIXME check other HTTP headers to be set - - let bugID = formData.bugNo; - let req = new XMLHttpRequest(); - req.open("POST", formData.action, true); - // FIXME co očekávám za odpověď? req.overrideMimeType("text/xml"); - // * Accept-Encoding - // * Accept-Language - // * Accept (MIME types) - req.setRequestHeader("Connection", "keep-alive"); - req.setRequestHeader("Keep-Alive", 300); - req.setRequestHeader("Content-Type", formData.enctype); - req.setRequestHeader("Referer", bugURL + bugID); - req.setRequestHeader("Accept-Charset", formData.acceptCharset); - req.setRequestHeader("Cookie", formData.cookie); - req.onreadystatechange = function(aEvt) { - if (req.readyState == 4) { - if (req.status == 200) { - console.log("Sent form for bug " + bugID); - delete myStorage.forms[bugID]; - } else { - console.error("Sending form for bug " + bugID + "failed!"); - } - } - }; - req.send(formData.data); - } - - if (myStorage.forms.length > 0) { - myStorage.forms.forEach(function(x) { - deserializeAndSend(x); - }); - } -} -*/ /* Bugzilla functions. */ RHBugzillaPage.prototype.ProfessionalProducts = [ @@ -394,7 +261,7 @@ RHBugzillaPage.prototype.pasteBacktraceInComments = function() { attURL = "https://bugzilla.redhat.com/attachment.cgi?id=" + x[1]; if (!this.btSnippet) { - let btRaw = utilMod.loadText(attURL, function(ret) { + let btRaw = util.loadText(attURL, function(ret) { this.btSnippet = this.parseBacktrace(ret); if (this.btSnippet) { this.addStuffToTextBox("comment", this.btSnippet); @@ -414,7 +281,7 @@ RHBugzillaPage.prototype.markBadAttachments = function() { let badMIMEArray = [ "application/octet-stream", "text/x-log", "undefined" ]; let badAttachments = this.attachments.filter(function(att, idx, arr) { - return (utilMod.isInList(att[2], badMIMEArray)); + return (util.isInList(att[2], badMIMEArray)); }); if (badAttachments.length > 0) { @@ -514,7 +381,7 @@ RHBugzillaPage.prototype.setBranding = function() { } // we should make visible whether maintCCAddr is in CCList - if (utilMod.isInList(this.maintCCAddr, this.CCList)) { + if (util.isInList(this.maintCCAddr, this.CCList)) { let ccEditBoxElem = this.doc.getElementById("cc_edit_area_showhide"); // ccEditBoxElem.textContent = "*"+ccEditBoxElem.textContent; ccEditBoxElem.style.color = "navy"; @@ -526,7 +393,7 @@ RHBugzillaPage.prototype.setBranding = function() { let compElems; let suspiciousComponents = config.gJSONData.configData.suspiciousComponents; if (suspiciousComponents - && utilMod.isInList(this.component, suspiciousComponents) + && util.isInList(this.component, suspiciousComponents) && (compElems = this.doc .getElementById("bz_component_edit_container"))) { compElems.style.background = "red none"; @@ -545,7 +412,7 @@ RHBugzillaPage.prototype.fillInWhiteBoard = function(iLine, driverStr) { let that = this; function groupIDs(manStr, cardStrID) { - let outStr = that.filterByRegexp(chipIDsGroupings, manStr + "," + cardStrID); + let outStr = util.filterByRegexp(chipIDsGroupings, manStr + "," + cardStrID); if (outStr.length === 0) { outStr = "UNGROUPED_" + manStr + "/" + cardStrID; } @@ -623,6 +490,7 @@ RHBugzillaPage.prototype.fillInWhiteBoard = function(iLine, driverStr) { * @return None */ RHBugzillaPage.prototype.fillInChipMagic = function () { + let that = this; let XorgLogURL = ""; let XorgLogAttID = ""; let XorgLogFound = false; @@ -643,34 +511,25 @@ RHBugzillaPage.prototype.fillInChipMagic = function () { attURL = "https://bugzilla.redhat.com/attachment.cgi?id="+XorgLogAttID; that = this; - let req = new xhrMod.XMLHttpRequest(); - req.open("GET",attURL,true); - req.onreadystatechange = function (aEvt) { - if (req.readyState == 4) { - if (req.status == 200) { - let ret = req.responseText; - let interestingLineArr = ret.split("\n"). - filter(function (v,i,a) { - return this.RE.Chipset.test(v); - }); - if (interestingLineArr.length >0) { - interestingArray = this.RE.Chipset.exec(interestingLineArr[0]); - interestingLine = interestingArray[2]. - replace(/[\s"]+/g," ").trim(); - // Persuade createNewButton to have mercy and to actually add - // non-default button - this.constantData.chipMagicTrigger = true; - this.chipMagicInterestingLine = interestingLine+"\t"+interestingArray[1] - .toUpperCase(); - this.createNewButton("status_whiteboard", true, "rh-xorg", "chipMagic"); - } - } else { - throw "Getting attachment " + attURL + "failed!"; - } + // parse Xorg.0.log + util.loadText(attURL, function(ret){ + let interestingLineArr = ret.split("\n"). + filter(function (v,i,a) { + return that.RE.Chipset.test(v); + }); + if (interestingLineArr.length >0) { + // TODO we are parsing only the first found line; is it alright? + interestingArray = that.RE.Chipset.exec(interestingLineArr[0]); + interestingLine = interestingArray[2]. + replace(/[\s"]+/g," ").trim(); + // Persuade createNewButton to have mercy and to actually add + // non-default button + that.constantData.chipMagicTrigger = true; + that.chipMagicInterestingLine = interestingLine+"\t"+interestingArray[1] + .toUpperCase(); + that.createNewButton("status_whiteboard", true, "rh-xorg", "chipMagic"); } - }; - req.send(""); - + }); this.XorgLogAttListIndex++; }; @@ -750,7 +609,7 @@ RHBugzillaPage.prototype.queryUpstream = function() { if (text) { let text = encodeURIComponent(text.trim()); let queryUpstreamBugsURLArray = this.constantData.queryUpstreamBug; - let url = this.filterByRegexp(queryUpstreamBugsURLArray, this.component); + let url = util.filterByRegexp(queryUpstreamBugsURLArray, this.component); jetpack.tabs.open(url + text); } } @@ -759,7 +618,7 @@ RHBugzillaPage.prototype.queryUpstream = function() { * */ RHBugzillaPage.prototype.sendBugUpstream = function() { - let url = this.filterByRegexp(this.constantData.newUpstreamBug, this + let url = util.filterByRegexp(this.constantData.newUpstreamBug, this .getOptionValue("component")); let ret = jetpack.tabs.open(url); diff --git a/lib/util.js b/lib/util.js index b6691af..3ce50c5 100644 --- a/lib/util.js +++ b/lib/util.js @@ -49,6 +49,28 @@ var isInList = exports.isInList = function isInList(mbr, list) { return (list.indexOf(mbr) !== -1); }; +/** + * select element of the array where regexp in the first element matches second + * parameter of this function + * + * @param list Array with regexps and return values + * @param chosingMark String by which the element of array is to be matched + * @return Object chosen element + */ +exports.filterByRegexp = function filterByRegexp(list, chosingMark) { + let chosenPair = []; + if (list.length > 0) { + chosenPair = list.filter(function(pair) { + return new RegExp(pair.regexp, "i").test(chosingMark); + }); + } + if (chosenPair.length > 0) { + return chosenPair[0].addr; + } else { + return ""; + } +}; + /** * format date to be in ISO format (just day part) * -- cgit