diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-01-28 16:38:36 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-01-31 20:33:33 +0100 |
commit | 4a0bcc39b1e1b49dcaa0aa2ab674c6f1ba51e9e5 (patch) | |
tree | 642411d3b3b433e8903e0bbbbf46004a37477b58 | |
parent | 83a7d703cbabd6e514a6d8a948b39325b59e9f58 (diff) | |
download | bugzilla-triage-4a0bcc39b1e1b49dcaa0aa2ab674c6f1ba51e9e5.tar.gz |
Tons of fixes, we are almost in state that the primitive run is possible.
TOOD:
* The most important part is we have to run libbz.initialize() and wait
until it is done.
-rw-r--r-- | data/bzpage.js | 16 | ||||
-rw-r--r-- | data/color.js | 4 | ||||
-rw-r--r-- | data/rhbzpage.js | 13 | ||||
-rw-r--r-- | data/util.js | 100 | ||||
-rw-r--r-- | lib/libbugzilla.js | 36 | ||||
-rw-r--r-- | lib/logger.js | 5 | ||||
-rw-r--r-- | lib/main.js | 37 |
7 files changed, 84 insertions, 127 deletions
diff --git a/data/bzpage.js b/data/bzpage.js index 086fe44..11b38c7 100644 --- a/data/bzpage.js +++ b/data/bzpage.js @@ -7,7 +7,6 @@ var BTSPrefNS = "bugzilla-triage.setting."; // Shared contstants var NumberOfFrames = 7; -exports.NumberOfFrames = NumberOfFrames; // constants var SalmonPink = new Color(255, 224, 176); // RGB 255, 224, 176; HSL 36, 2, @@ -18,7 +17,7 @@ var ReporterColor = new Color(255, 255, 166); // RGB 255, 255, 166; HSL 60, 2, // global variables var constantData = {}; // This should be probably eliminated ASAP or // or done by other means. TODO -var submitHandlerInstalled = false; // for setUpLogging +var submitHandlerInstalled = false; // for setUpLogging // ============================================ /** * object to pack messaging. Use as in @@ -28,8 +27,10 @@ var submitHandlerInstalled = false; // for setUpLogging })); */ function Message(cmd, data) { + console.log("Message: cmd = " + cmd + ", data = " + data); this.cmd = cmd; this.data = data; + console.log("Message JSONified: " + JSON.stringify(this)); } function log(msg) { @@ -44,7 +45,6 @@ var NotLoggedinException = function NotLoggedinException (message) { NotLoggedinException.prototype.toString = function () { return this.name + ': "' + this.message + '"'; }; -exports.NotLoggedinException = NotLoggedinException; /** * central handler processing messages from the main script. @@ -368,7 +368,7 @@ function createNewButton (location, after, cmdObj) { } /** - * Generate button based on + * Generate button based on */ function generateButtons (pkgs) { var topRowPosition = "topRowPositionID"; @@ -866,7 +866,7 @@ function queryInNewTab(text, component, product) { * function this.queryInNewTab, and run it. */ function queryForSelection() { - var text = getSelection(); + var text = getSelection(); if (!text) { postMessage(new Message("GetClipboard", "queryLocal")); } else { @@ -923,7 +923,7 @@ function startup() { // TODO Probably could be ignored ... used only once on line 973 of rhbzpage.js // if (parseAbrtBacktraces && this.RE.Abrt.test(this.title)) { - this.title = document.getElementById("short_desc_nonedit_display").textContent; + // title = document.getElementById("short_desc_nonedit_display").textContent; // So, now we know we are logged in, so we can get to // the real work. @@ -933,5 +933,7 @@ function startup() { checkComments(); var login = getLogin(); - postMessage(new Message("GetInstalledPackages", window.location)); + postMessage(new Message("GetInstalledPackages", window.location.href)); } + +startup(); diff --git a/data/color.js b/data/color.js index 574ad19..c6cdc71 100644 --- a/data/color.js +++ b/data/color.js @@ -6,7 +6,7 @@ // originally from // http://www.mjijackson.com/2008/02\ // /rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript -var Color = exports.Color = function Color(r, g, b) { +function Color(r, g, b) { this.Luminosity = 0.85; this.Desaturated = 0.4; @@ -19,7 +19,7 @@ var Color = exports.Color = function Color(r, g, b) { this.g = g; this.b = b; } -}; +} Color.prototype.update = function(r, g, b) { this.r = r; diff --git a/data/rhbzpage.js b/data/rhbzpage.js index ba55ed6..ee10466 100644 --- a/data/rhbzpage.js +++ b/data/rhbzpage.js @@ -2,7 +2,6 @@ // Released under the MIT/X11 license // http://www.opensource.org/licenses/mit-license.php "use strict"; -var NumberOfFrames = require("bzpage").NumberOfFrames; var titleParsedAttachment = "Part of the thread where crash happened"; // ==================================================================================== // RHBugzillaPage object @@ -18,6 +17,18 @@ nonTestedFunction getDefaultAssignee() { this.getComponent()).toLowerCase(); } + +function removeDuplicates (arr) { + for (var i = 0; i < arr.length; i++) { + for (var j = i + 1; j < arr.length; j++) { + if (arr[i] == arr[j]) { + arr.splice (j, 1); + } + } + } + return arr; +} + /** * Set default assignee * diff --git a/data/util.js b/data/util.js index 4612b66..e6871eb 100644 --- a/data/util.js +++ b/data/util.js @@ -1,53 +1,21 @@ -/*global exports: false, require: false, console: false, Cc: false, Ci: false */ +/*global console: false */ /*jslint onevar: false */ // Released under the MIT/X11 license // http://www.opensource.org/licenses/mit-license.php "use strict"; // ============================================================== -var Cc = require("chrome").Cc; -var Ci = require("chrome").Ci; -var urlMod = require("url"); - -/** - * Function for the management of the prototypal inheritace - * David Flanagan, Javascript: The Definitve Guide, - * IV. edition, O'Reilly, 2006, p. 168 - * - * @param superobject - * @return new object, it needs new prototype.constructor - * - * <pre> - * function Father(x) { - * this.family = x; - * } - * - * function Son(x,w) { - * Father.call(this,x); - * this.wife = w; - * } - * Son.prototype = heir(Father); - * Son.prototype.constructor = Son; - * </pre> - */ -exports.heir = function heir(p) { - function F() {}; - F.prototype = p.prototype; - return new F(); -}; - /** * get parameters of URL as an object (name, value) */ -var getParamsFromURL = exports.getParamsFromURL = function getParamsFromURL (url, base) { +function getParamsFromURL (url, base) { if (!url || (url.toString().length === 0)) { throw new Error("Missing URL value!"); } - if (!(url instanceof urlMod.URL)) { - url = new urlMod.URL(url.toString(), base); - } + var aElem = document.createElement("a"); + aElem.href = url; - var paramsArr = url.path.split("?"); + var paramsArr = url.pathname.split("?"); if (paramsArr.length === 1) { return {}; } @@ -59,7 +27,7 @@ var getParamsFromURL = exports.getParamsFromURL = function getParamsFromURL (url params[s[0]] = s[1]; }); return params; -}; +} /** * parse XML object out of string working around various bugs in Gecko implementation @@ -68,12 +36,12 @@ var getParamsFromURL = exports.getParamsFromURL = function getParamsFromURL (url * @param inStr String with unparsed XML string * @return XML object */ -exports.parseXMLfromString = function parseXMLfromString (inStuff) { +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 @@ -83,12 +51,12 @@ exports.parseXMLfromString = function parseXMLfromString (inStuff) { * @param url String with URL to be analyzed * @return String with the bug ID (hopefully number, but not for aliases) */ -exports.getBugNo = function getBugNo(url) { +function getBugNo(url) { var params = getParamsFromURL(url); if (params && params.id) { return params.id; } -}; +} /** * format date to be in ISO format (just day part) @@ -96,14 +64,14 @@ exports.getBugNo = function getBugNo(url) { * @param date * @return string with the formatted date */ -exports.getISODate = function getISODate(dateStr) { +function getISODate(dateStr) { function pad(n) { return n < 10 ? '0' + n : n; } var date = new Date(dateStr); return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()); -}; +} /** * Check whether an item is member of the list. Idea is just to make long if @@ -113,7 +81,7 @@ exports.getISODate = function getISODate(dateStr) { * @param list list * @return position of the string in the list, or -1 if none found. */ -var isInList = exports.isInList = function isInList(mbr, list) { +function isInList(mbr, list) { if (!list) { return false; } @@ -129,12 +97,12 @@ var isInList = exports.isInList = function isInList(mbr, list) { * If something else than Array or String is passed to the function * the result will be untouched actual argument of the call. */ -var valToArray = exports.valToArray = function valToArray(val) { +function valToArray(val) { var isArr = val && val.constructor && val.constructor.name === "Array"; return isArr ? val : [val]; -}; +} /** * Merges two comma separated string as a list and returns new string @@ -143,7 +111,7 @@ var valToArray = exports.valToArray = function valToArray(val) { * @param value String/Array with other values * @return String with merged lists */ -exports.addCSVValue = function addCSVValue(str, value) { +function addCSVValue(str, value) { var parts = (str.trim().length > 0 ? str.split(/[,\s]+/) : []); if (!value) { return str; @@ -156,7 +124,7 @@ exports.addCSVValue = function addCSVValue(str, value) { // value is an array already parts = parts.join(",").split(","); return parts.join(", "); -}; +} /** * Treats comma separated string as a list and removes one item from it @@ -165,7 +133,7 @@ exports.addCSVValue = function addCSVValue(str, value) { * @param value String with the value to be removed from str * @return String with the resulting list comma separated */ -exports.removeCSVValue = function removeCSVValue(str, value) { +function removeCSVValue(str, value) { str = str.trim(); var parts = str ? str.split(/[,\s]+/) : []; var valueArr = value instanceof Array ? value : value.split(/[,\s]+/); @@ -173,7 +141,7 @@ exports.removeCSVValue = function removeCSVValue(str, value) { return (!isInList(e, valueArr)); }); return parts.join(", "); -}; +} /** * select element of the array where regexp in the first element matches second @@ -183,8 +151,7 @@ exports.removeCSVValue = function removeCSVValue(str, value) { * @param chosingMark String by which the element of array is to be matched * @return Object chosen element */ -var filterByRegexp = exports.filterByRegexp = - function filterByRegexp(list, chosingMark) { +function filterByRegexp(list, chosingMark) { var chosenPair = []; if (list.length > 0) { chosenPair = list.filter(function (pair) { @@ -196,7 +163,7 @@ var filterByRegexp = exports.filterByRegexp = } else { return ""; } -}; +} /** * remove elements from the page based on their IDs @@ -209,7 +176,7 @@ var filterByRegexp = exports.filterByRegexp = * TODO remove parameter could be replaced by function which would * do actual activity. */ -exports.killNodes = function killNodes(doc, target, remove) { +function killNodes(doc, target, remove) { target = target.trim(); var targetArr = target instanceof Array ? target : target.split(/[,\s]+/); targetArr.forEach(function(x) { @@ -220,25 +187,4 @@ exports.killNodes = function killNodes(doc, target, remove) { x.style.display = "none"; } }); -}; - -exports.getObjectKeys = function getObjectKeys(obj) { - var keys = []; - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - keys.push(key); - } - } - return keys; -}; - -exports.removeDuplicates = function removeDuplicates (arr) { - for (var i = 0; i < arr.length; i++) { - for (var j = i + 1; j < arr.length; j++) { - if (arr[i] == arr[j]) { - arr.splice (j, 1); - } - } - } - return arr; -}; +} diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js index ceea270..e074072 100644 --- a/lib/libbugzilla.js +++ b/lib/libbugzilla.js @@ -7,7 +7,7 @@ var preferences = require("preferences-service"); var prompts = require("prompts"); var clipboard = require("clipboard"); var tabs = require("tabs"); -var logger = require("logger"); +//var logger = require("logger"); var passUtils = require("passwords"); var Request = require("request").Request; @@ -18,6 +18,16 @@ var BTSPassRealm = "BTSXMLRPCPass"; var config = {}; +function Message(cmd, data) { + console.log("Message: cmd = " + cmd + ", data = " + data); + this.cmd = cmd; + this.data = data; +} + +function log(msg) { + postMessage(new Message("LogMessage", msg)); +} + /** * parse XML object out of string working around various bugs in Gecko implementation * see https://developer.mozilla.org/en/E4X for more information @@ -115,8 +125,12 @@ exports.changeJSONURL = function changeJSONURL() { exports.getInstalledPackages = function getInstalledPackages(location, callback) { var installedPackages = {}; var enabledPackages = []; + + console.log("location = " + location.toString()); + console.log("location = " + typeof location); // Collect enabled packages per hostname (plus default ones) + console.log("getInstalledPackages: config = " + config.toSource()); if (config.gJSONData && ("commentPackages" in config.gJSONData)) { if ("enabledPackages" in config.gJSONData.configData) { var epObject = config.gJSONData.configData.enabledPackages; @@ -135,9 +149,12 @@ exports.getInstalledPackages = function getInstalledPackages(location, callback) } } + console.log("getInstalledPackages: enabledPackages = " + enabledPackages.toSource()); + // TODO To be decided, whether we cannot just eliminate packages in // installedPackages and having it just as a plain list of all cmdObjects. enabledPackages.forEach(function (pkg, idx, arr) { + console.log("getInstalledPackages: pkg = " + pkg); if (pkg in config.gJSONData.commentPackages) { installedPackages[pkg] = config.gJSONData.commentPackages[pkg]; } @@ -145,14 +162,20 @@ exports.getInstalledPackages = function getInstalledPackages(location, callback) } // Expand commentIdx properties into full comments - installedPackages.forEach(function (pkg) { - pkg.forEach(function (cmdObj) { + console.log("before // installedPackages = " + installedPackages.toSource()); + var cmdObj = {}; + for (var pkgKey in installedPackages) { + for (var cmdObjKey in installedPackages[pkgKey]) { + cmdObj = installedPackages[pkgKey][cmdObjKey]; if ("commentIdx" in cmdObj) { cmdObj.comment = config.commentStrings[cmdObj.commentIdx]; delete cmdObj.commentIdx; } - }); - }); + } + } + + console.log("after // installedPackages = " + installedPackages.toSource()); + callback(new Message("CreateButtons", { instPkgs: installedPackages, constData: config.constantData @@ -264,10 +287,11 @@ function initialize() { if ("killNodes" in config.gJSONData.configData && window.location.hostname in config.gJSONData.configData.killNodes) { var killConf = config.gJSONData.configData.killNodes[window.location.hostname]; - util.killNodes(config.doc, killConf[0], killConf[1]); + killNodes(config.doc, killConf[0], killConf[1]); } } + callback(); } }).get(); } diff --git a/lib/logger.js b/lib/logger.js index f64a6e9..cbe670d 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -4,7 +4,6 @@ var urlMod = require("url"); var utilMod = require("util"); var fileMod = require("file"); -var Color = require("color").Color; var tabs = require("tabs"); var prompts = require("prompts"); var apiUtils = require("api-utils"); @@ -12,8 +11,8 @@ var xrpc = require("xmlrpc"); var myStorage = require("simple-storage"); var Logger = exports.Logger = function Logger(abbsMap) { - this.EmptyLogsColor = new Color(0, 255, 0); - this.FullLogsColor = new Color(0, 40, 103); + this.EmptyLogsColor = rgb(0, 255, 0); + this.FullLogsColor = rgb(0, 40, 103); if (!myStorage.storage.logs) { myStorage.storage.logs = {}; diff --git a/lib/main.js b/lib/main.js index cbb3ba6..0afa67d 100644 --- a/lib/main.js +++ b/lib/main.js @@ -41,35 +41,8 @@ function skipThisPage(doc) { } } - -/* -exports.main = function main(options, callbacks) { - initialize(function (config) { - browser.whenContentLoaded( - function(window) { - // is this good for anything? - if ("window" in window) { window = window.window; } - - if (isOurPage(window, config.matches)) { - try { - var curPage = new config.objConstructor(window, config); - } catch (ex) { - if (ex instanceof require("bzpage").NotLoggedinException) { - return ; // Bail out if the user is not logged in - } else { - throw ex; // rethrow the exception otherwise - } - } - } else if (isOurPage(window, config.skipMatches)) { - skipThisPage(window.document); - } - } - ); - }); -}; - -*/ var messageHandler = exports.messageHandler = function messageHandler(worker, msg) { + console.log("messageHandler: msg = " + msg.toSource()); switch (msg.cmd) { case "LogMessage": console.log(msg.data); @@ -79,6 +52,7 @@ var messageHandler = exports.messageHandler = function messageHandler(worker, ms break; case "GetInstalledPackages": // send message with packages back + console.log("msg = " + msg.toSource()); libbz.getInstalledPackages(msg.data, function (pkgsMsg) { worker.postMessage(pkgsMsg); }); @@ -106,17 +80,18 @@ var contentScriptLibraries = { "bugzilla.redhat.com": [ self.data.url("util.js"), self.data.url("color.js"), - self.data.url("bzpage.js"), - self.data.url("rhbzpage.js") + self.data.url("bzpage.js") +// self.data.url("rhbzpage.js") ] }; +libbz.initialize(); pageMod.PageMod({ include: [ "https://bugzilla.redhat.com/show_bug.cgi?id=*" ], contentScriptWhen: 'ready', - // contentScriptFile: contentScriptLibraries["bugzilla.redhat.com"], + contentScriptFile: contentScriptLibraries["bugzilla.redhat.com"], onAttach: function onAttach(worker, msg) { console.log("worker: " + worker); worker.on('message', function (msg) { |