aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-09-01 14:31:03 +0200
committerMatěj Cepl <mcepl@redhat.com>2011-09-01 14:32:54 +0200
commit3c1055ba0f1024133d5ffe5e98d95d00f3b97cbe (patch)
treed80dbba979c978b2f0a0962e99a114b6a14da28e
parent66eae433f98e8c9aed47200d96161d2404402cc1 (diff)
downloadbugzilla-triage-3c1055ba0f1024133d5ffe5e98d95d00f3b97cbe.tar.gz
Better MVC separation ... generating time sheet in content script.
-rw-r--r--data/lib/bzpage.js3
-rw-r--r--data/lib/logging-front.js65
-rw-r--r--lib/libbugzilla.js5
-rw-r--r--lib/logger.js93
-rw-r--r--lib/main.js7
5 files changed, 78 insertions, 95 deletions
diff --git a/data/lib/bzpage.js b/data/lib/bzpage.js
index d4c393f..43cf5cb 100644
--- a/data/lib/bzpage.js
+++ b/data/lib/bzpage.js
@@ -30,6 +30,9 @@ self.on('message', function onMessage(msg) {
case "queryLocal":
queryInNewTab(msg.data, getComponent(), getProduct(), equivalentComponents);
break;
+ case "ReturningLogData":
+ timeSheetRecordsPrinter(msg.data, new Date());
+ break;
case "CreateButtons":
constantData = msg.data.constData;
config = msg.data.config;
diff --git a/data/lib/logging-front.js b/data/lib/logging-front.js
index 2f85a51..5874561 100644
--- a/data/lib/logging-front.js
+++ b/data/lib/logging-front.js
@@ -57,7 +57,7 @@ function setUpLogging() {
// (id, text, parent, callback, params, before, covered, accesskey)
createDeadLink("generateTSButton", "Generate TS",
additionalButtons, function(evt) {
- self.postMessage(new Message("GenerateTS"));
+ self.postMessage(new Message("GetTSData"));
}, [], "dash", "li");
createDeadLink("clearLogs", "Clear TS", additionalButtons,
@@ -78,3 +78,66 @@ function setUpLogging() {
* clearLogAElem.style.fontWeight = "bolder"; }
*/
}
+
+
+function getBugzillaAbbr(url) {
+ // Abbreviations are in constantData.BugzillaAbbreviations
+ // for https://bugzilla.redhat.com/show_bug.cgi?id=579123 get RH
+ // for https://bugzilla.mozilla.org/show_bug.cgi?id=579123 get MoFo
+ return constantData.BugzillaAbbreviations[parseURL(url).host];
+}
+
+function timeSheetRecordsPrinter(records, date) {
+ var commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)", "g");
+ // sort the records into temporary array
+ var tmpArr = [];
+ var dateStr = getISODate(date);
+ var outStr = "data:text/html;charset=utf-8," +
+ '<!DOCTYPE html>' + "<html><head>\n" +
+ "<meta charset='utf-8'/>\n" + "<title>TimeSheet-" +
+ dateStr + "</title>\n</head>\n<body>\n" +
+ "<h1>TimeSheet</h1>\n";
+
+ for ( var i in records) {
+ if (records.hasOwnProperty(i)) {
+ tmpArr.push([
+ i, records[i]
+ ]);
+ }
+ }
+ tmpArr.sort(function(a, b) {
+ if (a[0] > b[0]) {
+ return 1;
+ }
+ else if (a[0] < b[0]) {
+ return -1;
+ }
+ else {
+ return 0;
+ }
+ });
+
+ var currentDay = "";
+ // now print the array
+ tmpArr.forEach(function(rec) {
+ var x = rec[1];
+ var dayStr = getISODate(x.date);
+ var host = parseURL(x.url).host;
+ var BZName = getBugzillaAbbr(x.url);
+ var bugNo = getBugNo(x.url);
+ if (dayStr != currentDay) {
+ currentDay = dayStr;
+ outStr += "<hr/><p><strong>" + currentDay
+ + "</strong></p>\n";
+ }
+ // replace "bug ####" with a hyperlink to the current bugzilla
+ var comment = x.comment.replace(commentBugRE,
+ "<a href='http://" + host
+ + "/show_bug.cgi?id=$1'>$&</a>");
+ outStr += "<p><em><a href='" + x.url + "'>Bug " + BZName
+ + "/" + bugNo + ": " + x.title + "</a>"
+ + " </em>\n<br/>" + comment + "</p>\n";
+ });
+ outStr += "</body></html>";
+ self.postMessage(new Message("OpenURLinTab", outStr));
+};
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index d366ada..62df80b 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -387,6 +387,8 @@ exports.initialize = function initialize(config, callback) {
JSON.parse(selfMod.data.load("newUpstreamBug.json"));
config.constantData.ProfessionalProducts =
JSON.parse(selfMod.data.load("professionalProducts.json"));
+ config.constantData.BugzillaAbbreviations =
+ JSON.parse(selfMod.data.load("bugzillalabelAbbreviations.json"));
}
if ("CCmaintainer" in config.constantData) {
@@ -401,8 +403,7 @@ exports.initialize = function initialize(config, callback) {
if ("submitsLogging" in config.gJSONData.configData &&
config.gJSONData.configData.submitsLogging) {
- logger.initialize(JSON.parse(selfMod.data.load(
- "bugzillalabelAbbreviations.json")));
+ logger.initialize();
}
}
callback();
diff --git a/lib/logger.js b/lib/logger.js
index ed9ac47..cafef32 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -1,26 +1,19 @@
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
"use strict";
-var urlMod = require("url");
-var utilMod = require("util");
var fileMod = require("file");
-var tabs = require("tabs");
var prompts = require("prompts");
-var apiUtils = require("api-utils");
-var xrpc = require("xmlrpc");
var myStorage = require("simple-storage");
-var libbz = require("libbugzilla");
var EmptyLogsColor = "rgb(0, 255, 0)";
var FullLogsColor = "rgb(0, 40, 103)";
var abbsMap = {};
-exports.initialize = function initialize(aMap) {
+exports.initialize = function initialize() {
if (!myStorage.storage.logs) {
myStorage.storage.logs = {};
}
- abbsMap = aMap;
};
exports.addLogRecord = function addLogRecord(rec) {
@@ -34,21 +27,12 @@ exports.addLogRecord = function addLogRecord(rec) {
}
};
-function storeSize() {
- var size = 0, key;
- for (key in myStorage.storage.logs) {
- size++;
- }
- return size;
-}
-
-function isEmpty() {
- return (storeSize() === 0);
-}
+exports.getAllRecords = function getAllRecords() {
+ return myStorage.storage.logs;
+};
exports.clearTimeSheet = function clearTimeSheet() {
myStorage.storage.logs = {};
- var size = storeSize();
};
exports.importTimeSheet = function importTimeSheet() {
@@ -69,72 +53,3 @@ exports.importTimeSheet = function importTimeSheet() {
}
};
-function getBugzillaAbbr(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
- return abbsMap[urlMod.URL(url).host];
-}
-
-exports.generateTimeSheet = function generateTimeSheet() {
- var docHTML = timeSheetRecordsPrinter(myStorage.storage.logs,
- new Date());
- libbz.openURLInNewTab("data:text/html;charset=utf-8,"
- + docHTML);
-};
-
-var timeSheetRecordsPrinter = exports.timeSheetRecordsPrinter = function timeSheetRecordsPrinter(
- records, date) {
- var commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)", "g");
- // sort the records into temporary array
- var tmpArr = [];
- var dateStr = date.getFullYear() + "-"
- + xrpc.leadingZero(date.getMonth() + 1) + "-"
- + xrpc.leadingZero(date.getDate());
- var outStr = '<!DOCTYPE html>' + "<html><head>\n"
- + "<meta charset='utf-8'/>\n" + "<title>TimeSheet-"
- + dateStr + "</title>\n</head>\n<body>\n"
- + "<h1>TimeSheet</h1>\n";
-
- for ( var i in records) {
- if (records.hasOwnProperty(i)) {
- tmpArr.push([
- i, records[i]
- ]);
- }
- }
- tmpArr.sort(function(a, b) {
- if (a[0] > b[0]) {
- return 1;
- }
- else if (a[0] < b[0]) {
- return -1;
- }
- else {
- return 0;
- }
- });
-
- var currentDay = "";
- // now print the array
- tmpArr.forEach(function(rec) {
- var x = rec[1];
- var dayStr = utilMod.getISODate(x.date);
- var host = urlMod.URL(x.url).host;
- var BZName = getBugzillaAbbr(x.url);
- var bugNo = utilMod.getBugNo(x.url);
- if (dayStr != currentDay) {
- currentDay = dayStr;
- outStr += "<hr/><p><strong>" + currentDay
- + "</strong></p>\n";
- }
- // replace "bug ####" with a hyperlink to the current bugzilla
- var comment = x.comment.replace(commentBugRE,
- "<a href='http://" + host
- + "/show_bug.cgi?id=$1'>$&</a>");
- outStr += "<p><em><a href='" + x.url + "'>Bug " + BZName
- + "/" + bugNo + ": " + x.title + "</a>"
- + " </em>\n<br/>" + comment + "</p>\n";
- });
- outStr += "</body></html>";
- return outStr;
-};
diff --git a/lib/main.js b/lib/main.js
index 643ef36..6a5e58c 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -42,15 +42,16 @@ var messageHandler = exports.messageHandler = function messageHandler(
case "AddLogRecord":
logger.addLogRecord(msg.data);
break;
- case "GenerateTS":
- logger.generateTimeSheet();
- break;
case "ClearTS":
logger.clearTimeSheet();
break;
case "ImportTS":
logger.importTimeSheet();
break;
+ case "GetTSData":
+ worker.postMessage(new Message("ReturningLogData",
+ logger.getAllRecords()));
+ break;
case "GetInstalledPackages":
// send message with packages back
libbz.getInstalledPackages(msg.data, function(pkgsMsg) {