aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bzpage.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-08-19 23:13:19 -0400
committerMatěj Cepl <mcepl@redhat.com>2010-08-19 23:13:19 -0400
commit7d881cf6e9d5e5589827ecc5c17bdfa78fe2b513 (patch)
tree391a9c2bfaa17ab5d94aea04b9d12b6e281a662a /lib/bzpage.js
parent33fcda043c9639220cd27429410be128363a69c1 (diff)
downloadbugzilla-triage-7d881cf6e9d5e5589827ecc5c17bdfa78fe2b513.tar.gz
Actually really fix #43 and simplification of collecting information.0.20
Release 0.20
Diffstat (limited to 'lib/bzpage.js')
-rw-r--r--lib/bzpage.js95
1 files changed, 30 insertions, 65 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 0212eac..de03107 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -104,10 +104,6 @@ var BZPage = function BZPage(win, config) {
this.submitHandlerInstalled = false;
this.bugNo = util.getBugNo(this.doc.location.toString());
- this.reporter = this.getReporter();
- this.product = this.getOptionValue("product");
- this.component = this.getOptionValue("component");
- this.version = this.getVersion();
this.title = this.doc.getElementById("short_desc_nonedit_display").textContent;
this.CCList = this.getCCList();
@@ -496,8 +492,9 @@ BZPage.prototype.setConfigurationButton = function setConfigurationButton () {
};
/*
- * From <a href="mailto:email"> element diggs out just plain email
- * address
+ * From <a> element diggs out just plain email address
+ * Note that bugzilla.gnome.org doesn't have mailto: url but
+ * https://bugzilla.gnome.org/page.cgi?id=describeuser.html&login=mcepl%40redhat.com
*
* @param aElement Element with href attribute or something else
* @return String with the address or null
@@ -505,9 +502,11 @@ BZPage.prototype.setConfigurationButton = function setConfigurationButton () {
*/
BZPage.prototype.parseMailto = function parseMailto(aElement) {
var emailStr = "", hrefStr = "";
+ // use url utils
if (aElement) {
hrefStr = decodeURIComponent(aElement.getAttribute("href"));
emailStr = hrefStr.split(":")[1];
+ //
if (emailStr === undefined) {
var params = util.getParamsFromURL("https://" + this.hostname + "/" + hrefStr);
emailStr = decodeURI(params['login']);
@@ -523,33 +522,25 @@ BZPage.prototype.parseMailto = function parseMailto(aElement) {
* @return string
*/
BZPage.prototype.getReporter = function getReporter () {
- var reporterElement = this.doc.
- querySelector("#bz_show_bug_column_2 > table .vcard:first-of-type > a");
+ var reporterElement = this.getOptionTableCell("bz_show_bug_column_2", "Reported");
// RH Bugzilla after upgrade to 3.6.2 moved the information to other column
if (!reporterElement) {
- reporterElement = this.doc.
- querySelector("#bz_show_bug_column_1 > table .vcard:first-of-type > a");
+ reporterElement = this.getOptionTableCell("bz_show_bug_column_1", "Reported", true);
}
+ // Maemo calls the label "Reporter" and it doesn't have ids on table columns ... TODO(maemo)
+
return this.parseMailto(reporterElement);
};
-/**
- * Get the current version of the Fedora release ... even if changed meanwhile
- * by bug triager.
- *
- * @return string (integer for released Fedora, float for RHEL, rawhide)
- */
-BZPage.prototype.getVersion = function getVersion () {
- var verStr = this.getOptionValue("version").toLowerCase();
- var verNo = 0;
- if (/rawhide/.test(verStr)) {
- verNo = 999;
- } else {
- verNo = Number(verStr);
+BZPage.prototype.getComponent = function getComponent() {
+ var elem = this.doc.getElementById("component");
+ if (elem) {
+ return elem.value;
}
- return verNo;
+ return null;
};
+
BZPage.prototype.commentsWalker = function commentsWalker (fce) {
var comments = this.doc.getElementById("comments").getElementsByClassName(
"bz_comment");
@@ -564,10 +555,11 @@ BZPage.prototype.commentsWalker = function commentsWalker (fce) {
*/
BZPage.prototype.checkComments = function checkComments () {
var that = this;
+ var reporterRE = new RegExp(this.getReporter());
this.commentsWalker(function(x) {
var email = that.parseMailto(x.getElementsByClassName("vcard")[0]
.getElementsByTagName("a")[0]);
- if (new RegExp(that.reporter).test(email)) {
+ if (reporterRE.test(email)) {
x.style.backgroundColor = that.ReporterColor.toString();
}
});
@@ -683,7 +675,7 @@ BZPage.prototype.idContainsWord = function idContainsWord (id, str) {
// For those who don't have particular element at all or if it is empty
return false;
}
- return (kwd.trim().indexOf(str) !== -1);
+ return (util.isInList(str, kwd.trim().split(/,\s*/)));
};
/**
@@ -697,42 +689,28 @@ BZPage.prototype.hasKeyword = function hasKeyword (str) {
};
/**
+
+@return Element with the href attribute containng the information
*/
BZPage.prototype.getOptionTableCell = function getOptionTableCell(tableId, label) {
- var cleanLabelRE = /^\s*([^. :]*):?\s*$/;
- label = label.replace(cleanLabelRE,"$1").toLowerCase();
+ var cleanLabelRE = /^\s*([^.:]*):?\s*$/;
+ label = label.trim().replace(cleanLabelRE,"$1").toLowerCase();
+
var rows = this.doc.getElementById(tableId).getElementsByTagName("tr");
var ourLine = Array.filter(rows, function(row) {
var curLabel = row.getElementsByTagName("td")[0].textContent.toLowerCase();
curLabel = curLabel.replace(cleanLabelRE,"$1");
- return (curLabel === label);
+ return (curLabel === label); // maybe this could be a RE match instead
});
+
if (ourLine.length > 0) {
- return ourLine[0].getElementsByTagName("td")[1].textContent;
+ return ourLine[0].getElementsByTagName("td")[1].
+ getElementsByTagName("a")[0];
}
return null;
};
/**
- *
- */
-BZPage.prototype.getOptionValue = function getOptionValue (id) {
- // Some special bugs don't have version for example
- var element = this.doc.getElementById(id);
- if (element) {
- return element.value;
- } else {
- // this doesn't work on bugzilla.gnome.org
- element = this.getOptionTableCell("bug_summary", id);
- if (element) {
- return element;
- }
- throw new Error("Failed to find element with id = " + id);
- return null;
- }
-};
-
-/**
* Set the bug to NEEDINFO state
*
* Working function.
@@ -749,25 +727,12 @@ BZPage.prototype.setNeedinfoReporter = function setNeedinfoReporter () {
*
*/
BZPage.prototype.getOwner = function getOwner () {
- var priorityParent = this.doc.querySelector("label[for~='target_milestone']")
- .parentNode.parentNode.parentNode;
- var assigneeAElement = priorityParent.querySelector("tr:nth-of-type(1) a.email");
+ // TODO(maemo) doesn't work on maemo
+ var assigneeAElement = this.getOptionTableCell("bz_show_bug_column_1","Assigned To");
return this.parseMailto(assigneeAElement);
};
/**
- * Get login of the currently logged-in user.
- *
- * @return String with the login name of the currently logged-in user
- */
-BZPage.prototype.getLogin = function getLogin () {
- var lastLIElement = this.doc.querySelector("#header ul.links li:last-of-type");
- var loginArr = lastLIElement.textContent.split("\n");
- var loginStr = loginArr[loginArr.length - 1].trim();
- return loginStr;
-};
-
-/**
* Return maintainer which is per default by bugzilla
* (which is not necessarily the one who is default maintainer per component)
*
@@ -967,7 +932,7 @@ BZPage.prototype.queryInNewTab = function(text, component, product) {
BZPage.prototype.queryForSelection = function() {
var text = this.getSelectionOrClipboard();
if (text) {
- this.queryInNewTab(text, this.component);
+ this.queryInNewTab(text, this.getComponent());
}
};