aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bzpage.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-06-19 22:08:04 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-06-19 22:08:04 +0200
commit87b9c2d6d0a1bda477f15af227d758c5fc3e55e0 (patch)
tree1781a0d60ae99c783add1205722d49da3d2d4143 /lib/bzpage.js
parent76e764fb8e4f9d52dc92e97c6408c169142b104f (diff)
downloadbugzilla-triage-87b9c2d6d0a1bda477f15af227d758c5fc3e55e0.tar.gz
Loads a bug page without crash!!!
There is not jetpack. call in used modules.
Diffstat (limited to 'lib/bzpage.js')
-rw-r--r--lib/bzpage.js109
1 files changed, 46 insertions, 63 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 329165d..042a19e 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -1,11 +1,11 @@
/*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";
var util = require("util");
var apiUtils = require("api-utils");
var simpleStorage = require("simple-storage");
+var preferences = require("preferences-service");
var Color = require("color").Color;
var TriagedDistro = 13;
@@ -16,8 +16,6 @@ var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id=";
// ====================================================================================
// BZPage's methods
var BZPage = function BZPage(doc, config) {
- console.log("doc = " + doc);
- console.log("config = " + config);
var keys = "";
for (var key in config) {
keys += key + ", ";
@@ -32,21 +30,22 @@ var BZPage = function BZPage(doc, config) {
// initialize dynamic properties
this.doc = doc;
this.packages = this.getInstalledPackages(config);
+
if ("commentStrings" in config.gJSONData) {
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;
}
if ("CCmaintainer" in config.gJSONData.constantData) {
this.defBugzillaMaintainerArr = config.gJSONData.constantData.CCmaintainer;
}
+
+ if ("suspiciousComponents" in config.gJSONData.configData) {
+ this.suspiciousComponents = config.gJSONData.configData.suspiciousComponents;
+ }
if ("submitsLogging" in config.gJSONData.configData &&
config.gJSONData.configData.submitsLogging) {
@@ -63,28 +62,21 @@ var BZPage = function BZPage(doc, config) {
this.version = this.getVersion();
this.title = this.doc.getElementById("short_desc_nonedit_display").textContent;
this.CCList = this.getCCList();
-
- this.packages = this.getInstalledPackages();
-
- if ("commentStrings" in config.gJSONData) {
- 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;
- }
-
- if ("CCmaintainer" in config.gJSONData.constantData) {
- this.defBugzillaMaintainerArr = config.gJSONData.constantData.CCmaintainer;
- }
-
- if ("submitsLogging" in config.gJSONData.configData &&
- config.gJSONData.configData.submitsLogging) {
- this.log = config.logger;
- this.setUpLogging();
+
+ // Prepare for query buttons
+ // FIXME getting null for commentArea sometimes
+ var commentArea = this.doc.getElementById("comment_status_commit");
+ if (commentArea) {
+ var brElementPlacer = commentArea.getElementsByTagName("br");
+ console.log("brElementPlacer.length = " + brElementPlacer.length);
+ brElementPlacer = brElementPlacer[0];
+ if (brElementPlacer) {
+ brElementPlacer.setAttribute("id","brElementPlacer_location");
+ brElementPlacer.parentNode.insertBefore(this.doc.createElement("br"),
+ brElementPlacer);
+ }
+ } else {
+ console.log("Cannot find element with 'comment_status_commit' ID!");
}
this.generateButtons();
@@ -102,13 +94,16 @@ BZPage.prototype.getBugId = function getBugId () {
/**
*
*/
-BZPage.prototype.getInstalledPackages = function getInstalledPackages(config) {
+BZPage.prototype.getInstalledPackages = function getInstalledPackages(cfg) {
var installedPackages = {};
- if (config.gJSONData && ("commentPackages" in config.gJSONData)) {
- var enabledPackages = jetpack.storage.settings.enabledPacks.split(/[, ]/);
+
+ if (cfg.gJSONData && ("commentPackages" in cfg.gJSONData)) {
+ // TODO: Temporary hack ... should be replaced by a proper configuration
+ // when replacement for jetpack.storage.settings lands
+ var enabledPackages = cfg.gJSONData.configData.enabledPacks.split(/[, ]/);
enabledPackages.forEach(function (pkg, idx, arr) {
- if (pkg in config.gJSONData.commentPackages) {
- installedPackages[pkg] = config.gJSONData.commentPackages[pkg];
+ if (pkg in cfg.gJSONData.commentPackages) {
+ installedPackages[pkg] = cfg.gJSONData.commentPackages[pkg];
}
});
}
@@ -396,8 +391,12 @@ BZPage.prototype.generateButtons = function generateButtons () {
* @return string
*/
BZPage.prototype.getReporter = function getReporter () {
- return this.doc
- .querySelector("#bz_show_bug_column_2 > table .vcard:first-of-type > a").textContent;
+ var reporterElement = this.doc.
+ querySelector("#bz_show_bug_column_2 > table .vcard:first-of-type > a");
+ if (reporterElement) {
+ return reporterElement.textContent;
+ }
+ return "";
};
/**
@@ -628,36 +627,26 @@ BZPage.prototype.getAttachments = function getAttachments () {
* @return String with the password
*/
BZPage.prototype.getPassword = function getPassword () {
- if (jetpack.storage.settings.BZpassword) {
- return jetpack.storage.settings.BZpassword;
+ if (preferences.isSet("BZpassword")) {
+ return preferences.get("BZpassword",undefined);
} else {
- var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- var password = {
- value : ""
- }; // default the password to pass
- var check = {
- value : true
- }; // default the checkbox to true
- var result = prompts.promptPassword(null, "Title", "Enter password:",
- password, null, check);
- // result is true if OK was pressed, false if cancel was pressed.
- // password.value is
- // set if OK was pressed. The checkbox is not displayed.
- if (result) {
- var passwordText = password.value;
- jetpack.storage.settings.BZpassword = passwordText;
- jetpack.storage.simple.sync();
- return passwordText;
+ var passwordText = util.getPassword();
+ if (passwordText) {
+ preferences.set("BZpassword", passwordText);
}
}
- return null;
};
/**
*
*/
BZPage.prototype.setUpLogging = function setUpLogging () {
+ // Protection against double-call
+ if (this.doc.getElementById("generateTSButton")) {
+ console.log("Logging has been already set up!");
+ return ;
+ }
+
// For adding additional buttons to the top toolbar
var additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions");
var that = this;
@@ -702,17 +691,11 @@ BZPage.prototype.setUpLogging = function setUpLogging () {
var clearLogAElem = this.doc.getElementById("clearLogs");
clearLogAElem.addEventListener("click", function() {
that.log.store = {};
- jetpack.storage.simple.sync();
this.style.color = that.log.EmptyLogsColor;
this.style.fontWeight = "normal";
console.log("this.store wiped out!");
}, false);
- if (!this.log.store) {
- console.log("No this.store defined!");
- this.log.store = {};
- }
-
if (this.log.store.length > 0) {
clearLogAElem.style.color = this.log.FullLogsColor;
clearLogAElem.style.fontWeight = "bolder";