diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-06-08 18:41:08 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-06-08 18:41:08 +0200 |
commit | 7e426ac5faeea1b06de1ae2a024feaddb7f00531 (patch) | |
tree | f0e613f4a50c87efa7fa37c5bd284e1e6b9ee458 /lib | |
parent | 94fe9a684db8182110109b6d3a8ef1bad1075a6b (diff) | |
download | bugzilla-triage-7e426ac5faeea1b06de1ae2a024feaddb7f00531.tar.gz |
First almost working version of main.js
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bzpage.js | 2 | ||||
-rw-r--r-- | lib/main.js | 103 | ||||
-rw-r--r-- | lib/mozillabzpage.js | 4 | ||||
-rw-r--r-- | lib/old-main.js | 106 | ||||
-rw-r--r-- | lib/rhbzpage.js | 4 |
5 files changed, 160 insertions, 59 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js index b02d03c..59790fb 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -14,7 +14,7 @@ var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id="; // ==================================================================================== // BZPage's methods -exports.BZPage = function BZPage(doc) { +exports.BZPage = function BZPage(doc, config) { // constants this.SalmonPink = new Color(255, 224, 176); // RGB 255, 224, 176; HSL 36, 2, // 85 diff --git a/lib/main.js b/lib/main.js index eca533e..1027d72 100644 --- a/lib/main.js +++ b/lib/main.js @@ -16,61 +16,26 @@ var util = require("util"); var logger = require("logger"); var file = require("file"); var myStorage = require("simple-storage").storage; +var browser = require("tab-browser"); +const JSONURL = "http://matej.ceplovi.cz/progs/data/RH_Data-packages.json"; +var myStorage = 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="; - -// ============================================================== -// https://wiki.mozilla.org/Labs/Jetpack/JEP/24 -var manifest = { - settings : [ - { - name : "BZpassword", - type : "password", - label : "Bugzilla password" - }, - { - name : "JSONURL", - type : "text", - label : "Configuration file URL", - "default" : "http://mcepl.fedorapeople.org/scripts/BugZappers_data.json" - }, - { - name : "enabledPacks", - type : "text", - label : "comment packs which should be enabled", - "default" : "" - } - ] -}; -jetpack.future.import("storage.settings"); - - -// TODO we should have an array SpecialFlags instead of multiple Boolean -// variables -var logSubmits = false; -var chipIDsGroupings = []; -var AddrArray = []; -var topRow = {}; -var bottomRow = {}; - -// ///////////////////////////////////////////////////////////////////////////// - -let config = {}; +var config = {}; config.matches = [ "https://bugzilla.redhat.com/show_bug.cgi", "https://bugzilla.mozilla.org/show_bug.cgi" ]; -util.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) { - config.gJSONData = parsedData; +function initialize(callback) { + util.loadJSON(JSONURL, function(parsedData) { + config.gJSONData = parsedData; // Get card translation table - let keys = ""; - for (let key in config.gJSONData) { + var keys = "", key = ""; + for (key in config.gJSONData) { keys += key + " "; } + console.log("loaded JSON object keys: " + keys); + if ("PCIIDsURL" in config.gJSONData.configData) { util.loadJSON(config.gJSONData.configData.PCIIDsURL, function(response) { config.PCI_ID_Array = response; @@ -79,14 +44,44 @@ util.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) { config.logger = new logger.Logger(myStorage.logs, config.gJSONData.constantData.bugzillalabelAbbreviations); + + callback(config); +}, this); + +} + +function isOurPage(window, bugzillaPageModLocation) { + if ("window" in window) { + window = window.window; + } - let callback = function(doc) { - if (config.gJSONData.configData.objectStyle = "RH") { - let curPage = new RHBugzillaPage(doc); - } else if (config.gJSONData.configData.objectStyle = "MoFo") { - let curPage = new MozillaBugzilla(doc); + if (window.location.protocol == "https:") { + // like ["name1": "url1", "name2":"url2"] + // FIXME the real name of bugzillaPageModLocation array + for (var loc in bugzillaPageModLocation) { + if (bugzillaPageModLocation[loc].test(window.location.href)) { + return true; + } } - }; + } + // we haven't found a conforming bugzilla + return false; +} - jetpack.pageMods.add(callback, config); -}, this);
\ No newline at end of file +exports.main = function main(options, callbacks) { + initialize(function (config) { + browser.whenContentLoaded( + function(window) { + if (isOurPage(window)) { + var curPage = {}; + var mycallback = function(doc) { + if (config.gJSONData.configData.objectStyle = "RH") { + curPage = new require("rhbzpage").RHBugzillaPage(doc, config); + } else if (config.gJSONData.configData.objectStyle = "MoFo") { + curPage = new require("mozillabzpage").MozillaBugzilla(doc, config); + } + }; + } + }); + }); +};
\ No newline at end of file diff --git a/lib/mozillabzpage.js b/lib/mozillabzpage.js index 6eaa869..7efaf16 100644 --- a/lib/mozillabzpage.js +++ b/lib/mozillabzpage.js @@ -6,8 +6,8 @@ var utilMod = require("util"); // ============================================================================ // MozillaBugzilla object -exports.MozillaBugzilla = function MozillaBugzilla (doc) { - BZPage.call(this, doc) +exports.MozillaBugzilla = function MozillaBugzilla (doc, config) { + BZPage.call(this, doc, config) }; MozillaBugzilla.prototype = utilMod.heir(BZPage); diff --git a/lib/old-main.js b/lib/old-main.js new file mode 100644 index 0000000..db81448 --- /dev/null +++ b/lib/old-main.js @@ -0,0 +1,106 @@ +/*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 +// +// Links to read through +// http://ehsanakhgari.org/blog/2010-01-07/bugzilla-tweaks-enhanced +// http://hg.mozilla.org/users/ehsan.akhgari_gmail.com/extensions/file/tip/bugzillatweaks +// http://hg.mozilla.org/users/ehsan.akhgari_gmail.com/extensions/file/ecfa0f028b81/bugzillatweaks/lib/main.js +// http://hg.mozilla.org/users/avarma_mozilla.com/atul-packages/file/42ac1e99a107/packages\ +// /facebook-acquaintances/lib/main.js#l11 +// http://ehsanakhgari.org/blog/2010-05-31/my-experience-jetpack-sdk#comment-1253 +// +"use strict"; +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"; + +let config = {}; +config.matches = [ + "https://bugzilla.redhat.com/show_bug.cgi", + "https://bugzilla.mozilla.org/show_bug.cgi" +]; + + +// ============================================================== +// https://wiki.mozilla.org/Labs/Jetpack/JEP/24 +var manifest = { + settings : [ + { + name : "BZpassword", + type : "password", + label : "Bugzilla password" + }, + { + name : "JSONURL", + type : "text", + label : "Configuration file URL", + "default" : "http://mcepl.fedorapeople.org/scripts/BugZappers_data.json" + }, + { + name : "enabledPacks", + type : "text", + label : "comment packs which should be enabled", + "default" : "" + } + ] +}; +jetpack.future.import("storage.settings"); + +// ///////////////////////////////////////////////////////////////////////////// +function isOurPage(window) { + if ("window" in window) { + window = window.window; + } + + if (window.location.protocol == "https:") { + // like ["name1": "url1", "name2":"url2"] + // FIXME the real name of bugzillaPageModLocation array + for (var loc in bugzillaPageModLocation) { + if (bugzillaPageModLocation[loc].test(window.location.href)) { + return true; + } + } + } + // we haven't found a conforming bugzilla + return false; +} + + +function initialize() { + +} + +util.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) { + config.gJSONData = parsedData; + + // Get card translation table + let keys = ""; + for (let key in config.gJSONData) { + keys += key + " "; + } + if ("PCIIDsURL" in config.gJSONData.configData) { + util.loadJSON(config.gJSONData.configData.PCIIDsURL, function(response) { + config.PCI_ID_Array = response; + }); + } + + config.logger = new logger.Logger(myStorage.logs, + config.gJSONData.constantData.bugzillalabelAbbreviations); + + let callback = function(doc) { + if (config.gJSONData.configData.objectStyle = "RH") { + let curPage = new RHBugzillaPage(doc); + } else if (config.gJSONData.configData.objectStyle = "MoFo") { + let curPage = new MozillaBugzilla(doc); + } + }; + + jetpack.pageMods.add(callback, config); +}, this); diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js index 3aefaee..2370e72 100644 --- a/lib/rhbzpage.js +++ b/lib/rhbzpage.js @@ -15,7 +15,7 @@ var clip = require("clipboard"); // ==================================================================================== // RHBugzillaPage object -exports.RHBugzillaPage = function RHBugzillaPage(doc) { +exports.RHBugzillaPage = function RHBugzillaPage(doc, config) { // For identification of graphics card const manuChipStrs = [ [ "ATI Radeon", "ATI", "1002" ], [ "ATI Mobility Radeon", "ATI", "1002" ], @@ -57,7 +57,7 @@ exports.RHBugzillaPage = function RHBugzillaPage(doc) { } // inheritance ... call superobject's constructor - BZPage.call(this,doc); + BZPage.call(this,doc, config); let that = this; this.reqCounter = 0; |