From d5f5588729a9d40d193651436560899336341c1a Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Fri, 11 Jun 2010 22:42:25 +0200 Subject: Even more brutal --- lib/logger.js | 108 -------------------------------------------------- lib/main.js | 43 ++++++-------------- lib/mozillabzpage.js | 14 ------- lib/puvodni/logger.js | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 153 deletions(-) delete mode 100644 lib/logger.js delete mode 100644 lib/mozillabzpage.js create mode 100644 lib/puvodni/logger.js diff --git a/lib/logger.js b/lib/logger.js deleted file mode 100644 index cc3f213..0000000 --- a/lib/logger.js +++ /dev/null @@ -1,108 +0,0 @@ -// Released under the MIT/X11 license -// http://www.opensource.org/licenses/mit-license.php -"use strict"; -var urlMod = require("url"); -var urilMod = require("util"); - -var Logger = exports.Logger = function Logger(store, abbsMap) { - - this.store = store; - this.abbsMap = abbsMap; -}; - -Logger.prototype.addLogRecord = function(that) { - let rec = {}; - rec.date = new Date(); - rec.url = that.doc.location.toString(); - rec.title = that.title; - let comment = jetpack.tabs.focused.contentWindow.prompt( - "Enter comments for this comment"); - if (comment && comment.length > 0) { - comment = comment.trim(); - rec.comment = comment; - let recKey = utilMod.getISODate(rec.date) + "+" - + urlMod.parse(rec.url).host - + "+" + that.bugNo; - let clearLogAElem = that.doc.getElementById("clearLogs"); - clearLogAElem.style.fontWeight = "bolder"; - if (this.store[recKey]) { - this.store[recKey].comment += "
\n" + comment; - } else { - this.store[recKey] = rec; - } - jetpack.storage.simple.sync(); - return rec; - } else { - return comment; - } -}; - -Logger.prototype.getBugzillaAbbr = function(url) { - // for https://bugzilla.redhat.com/show_bug.cgi?id=579123 get RH - // for https://bugzilla.mozilla.org/show_bug.cgi?id=579123 get MoFo - var abbr = this.abbsMap[urlMod.parse(url).host]; - return abbr; -} - -Logger.prototype.timeSheetRecordsPrinter = function(body, records) { - let that = this; - let commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)","g"); - // sort the records into temporary array - let tmpArr = []; - - for ( let i in records) { - if (records.hasOwnProperty(i)) { - tmpArr.push( [ i, records[i] ]); - } - } - tmpArr.sort(function(a, b) { - return a[0] > b[0] ? 1 : -1; - }); - - let currentDay = ""; - // now print the array - tmpArr.forEach(function(rec) { - let x = rec[1]; - let dayStr = utilMod.getISODate(x.date); - let host = urlMod.parse(x.url).host; - let BZName = that.getBugzillaAbbr(x.url); - let bugNo = utilMod.getBugNo(x.url); - if (dayStr != currentDay) { - currentDay = dayStr; - body.innerHTML += "

" + currentDay - + "

"; - } - // replace "bug ####" with a hyperlink to the current bugzilla - let comment = x.comment.replace(commentBugRE, - "$&"); - body.innerHTML += "

Bug " - + BZName + "/" + bugNo + ": " - + x.title - + "" - + " \n
" + comment + "

"; - }); -}; - -/** - * - */ -Logger.prototype.createBlankPage = function (ttl, bodyBuildCB) { - let title = ttl || "Yet another untitled page"; - let that = this; - - let logTab = jetpack.tabs.open("about:blank"); - jetpack.tabs.onReady(function() { - let otherDoc = logTab.contentDocument; - otherDoc.title = title; - otherDoc.body.innerHTML = "

" + title + "

"; - bodyBuildCB.call(that, otherDoc.body); - logTab.focus(); - }); -}; - -Logger.prototype.generateTimeSheet = function(body) { - let doc = body.ownerDocument; - this.timeSheetRecordsPrinter(body, this.store); -}; diff --git a/lib/main.js b/lib/main.js index 3364971..30c5b81 100644 --- a/lib/main.js +++ b/lib/main.js @@ -17,34 +17,21 @@ 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 JSONURL = "http://matej.ceplovi.cz/progs/data/RH_Data-packages.json"; var config = {}; -function initialize(callback) { - util.loadJSON(JSONURL, function(parsedData) { - config.gJSONData = parsedData; +var matches = [ + "https://bugzilla.redhat.com/show_bug.cgi.*", + "https://bugzilla.mozilla.org/show_bug.cgi.*" +]; - var keys = "", key = ""; - for (key in config.gJSONData) { - keys += key + " "; - } - console.log("loaded JSON object keys: " + keys); - - // Get card translation table - 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); - - callback(config); -}, this); +function initialize(callback) { + util.loadJSON(JSONURL, function(parsedData) { + config = {}; + callback(config); + }, this); } // TODO: sometime in the future we should include @@ -70,14 +57,8 @@ exports.main = function main(options, callbacks) { browser.whenContentLoaded( function(window) { var doc = window.document; - if (isOurPage(window, config.gJSONData.configData.matches)) { - console.log("dump config:\n" + config); - var curPage = {}; - 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); - } + if (isOurPage(window, matches)) { + var curPage = new require("rhbzpage").RHBugzillaPage(doc, config); } else { console.log("Not our page: " + window.location.href); } diff --git a/lib/mozillabzpage.js b/lib/mozillabzpage.js deleted file mode 100644 index 7efaf16..0000000 --- a/lib/mozillabzpage.js +++ /dev/null @@ -1,14 +0,0 @@ -// Released under the MIT/X11 license -// http://www.opensource.org/licenses/mit-license.php -"use strict"; -var utilMod = require("util"); - -// ============================================================================ -// MozillaBugzilla object - -exports.MozillaBugzilla = function MozillaBugzilla (doc, config) { - BZPage.call(this, doc, config) -}; - -MozillaBugzilla.prototype = utilMod.heir(BZPage); -MozillaBugzilla.prototype.constructor = MozillaBugzilla; diff --git a/lib/puvodni/logger.js b/lib/puvodni/logger.js new file mode 100644 index 0000000..cc3f213 --- /dev/null +++ b/lib/puvodni/logger.js @@ -0,0 +1,108 @@ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php +"use strict"; +var urlMod = require("url"); +var urilMod = require("util"); + +var Logger = exports.Logger = function Logger(store, abbsMap) { + + this.store = store; + this.abbsMap = abbsMap; +}; + +Logger.prototype.addLogRecord = function(that) { + let rec = {}; + rec.date = new Date(); + rec.url = that.doc.location.toString(); + rec.title = that.title; + let comment = jetpack.tabs.focused.contentWindow.prompt( + "Enter comments for this comment"); + if (comment && comment.length > 0) { + comment = comment.trim(); + rec.comment = comment; + let recKey = utilMod.getISODate(rec.date) + "+" + + urlMod.parse(rec.url).host + + "+" + that.bugNo; + let clearLogAElem = that.doc.getElementById("clearLogs"); + clearLogAElem.style.fontWeight = "bolder"; + if (this.store[recKey]) { + this.store[recKey].comment += "
\n" + comment; + } else { + this.store[recKey] = rec; + } + jetpack.storage.simple.sync(); + return rec; + } else { + return comment; + } +}; + +Logger.prototype.getBugzillaAbbr = function(url) { + // for https://bugzilla.redhat.com/show_bug.cgi?id=579123 get RH + // for https://bugzilla.mozilla.org/show_bug.cgi?id=579123 get MoFo + var abbr = this.abbsMap[urlMod.parse(url).host]; + return abbr; +} + +Logger.prototype.timeSheetRecordsPrinter = function(body, records) { + let that = this; + let commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)","g"); + // sort the records into temporary array + let tmpArr = []; + + for ( let i in records) { + if (records.hasOwnProperty(i)) { + tmpArr.push( [ i, records[i] ]); + } + } + tmpArr.sort(function(a, b) { + return a[0] > b[0] ? 1 : -1; + }); + + let currentDay = ""; + // now print the array + tmpArr.forEach(function(rec) { + let x = rec[1]; + let dayStr = utilMod.getISODate(x.date); + let host = urlMod.parse(x.url).host; + let BZName = that.getBugzillaAbbr(x.url); + let bugNo = utilMod.getBugNo(x.url); + if (dayStr != currentDay) { + currentDay = dayStr; + body.innerHTML += "

" + currentDay + + "

"; + } + // replace "bug ####" with a hyperlink to the current bugzilla + let comment = x.comment.replace(commentBugRE, + "$&"); + body.innerHTML += "

Bug " + + BZName + "/" + bugNo + ": " + + x.title + + "" + + " \n
" + comment + "

"; + }); +}; + +/** + * + */ +Logger.prototype.createBlankPage = function (ttl, bodyBuildCB) { + let title = ttl || "Yet another untitled page"; + let that = this; + + let logTab = jetpack.tabs.open("about:blank"); + jetpack.tabs.onReady(function() { + let otherDoc = logTab.contentDocument; + otherDoc.title = title; + otherDoc.body.innerHTML = "

" + title + "

"; + bodyBuildCB.call(that, otherDoc.body); + logTab.focus(); + }); +}; + +Logger.prototype.generateTimeSheet = function(body) { + let doc = body.ownerDocument; + this.timeSheetRecordsPrinter(body, this.store); +}; -- cgit