aboutsummaryrefslogtreecommitdiffstats
path: root/lib/logger.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-03-02 01:14:36 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-03-02 01:14:36 +0100
commit41ffab7b32df1756e78af92ff68ff40afb75e1d5 (patch)
tree3bcddc3dfaa9f6ad7afbd0cf31f09d6bceb8e208 /lib/logger.js
parent273765aa78125b2106218ad554e6dedad7d2b381 (diff)
parent52bcf6e79eb3085b598a9ca0d21f60879a0e3706 (diff)
downloadbugzilla-triage-41ffab7b32df1756e78af92ff68ff40afb75e1d5.tar.gz
Merge branch 'pageMod' into next
Conflicts: lib/bzpage.js
Diffstat (limited to 'lib/logger.js')
-rw-r--r--lib/logger.js134
1 files changed, 51 insertions, 83 deletions
diff --git a/lib/logger.js b/lib/logger.js
index f64a6e9..94f7031 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -4,44 +4,52 @@
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");
var xrpc = require("xmlrpc");
var myStorage = require("simple-storage");
+var libbz = require("libbugzilla");
-var Logger = exports.Logger = function Logger(abbsMap) {
- this.EmptyLogsColor = new Color(0, 255, 0);
- this.FullLogsColor = new Color(0, 40, 103);
+var EmptyLogsColor = "rgb(0, 255, 0)";
+var FullLogsColor = "rgb(0, 40, 103)";
+var abbsMap = {};
+
+exports.initialize = function initialize(aMap) {
if (!myStorage.storage.logs) {
myStorage.storage.logs = {};
}
+ abbsMap = aMap;
+};
- this.abbsMap = abbsMap;
+exports.addLogRecord = function addLogRecord(rec) {
+ if (myStorage.storage.logs[rec.key]) {
+ myStorage.storage.logs[rec.key].comment += "<br/>\n" + comment;
+ } else {
+ myStorage.storage.logs[rec.key] = rec;
+ }
};
-Logger.prototype.size = function size() {
+function storeSize() {
var size = 0, key;
for (key in myStorage.storage.logs) {
size++;
}
return size;
-};
+}
-Logger.prototype.isEmpty = function isEmpty() {
- return (this.size() === 0);
-};
+function isEmpty() {
+ return (storeSize() === 0);
+}
-Logger.prototype.clearStore = function clearStore(clearLink) {
+exports.clearTimeSheet = function clearTimeSheet() {
myStorage.storage.logs = {};
- var size = this.size();
- clearLink.style.color = this.EmptyLogsColor;
- clearLink.style.fontWeight = "normal";
+ var size = storeSize();
};
-Logger.prototype.importOtherStore = function importOtherStore (filename, clearLink) {
+exports.importTimeSheet = function importTimeSheet() {
+ var filename = prompts.promptFileOpenPicker();
if (fileMod.exists(filename)) {
var otherTS = JSON.parse(fileMod.read(filename));
if (otherTS.logs) {
@@ -54,57 +62,40 @@ Logger.prototype.importOtherStore = function importOtherStore (filename, clearLi
} else {
console.error("File " + filename + " doesn't exist!");
}
- if (this.size() > 0) {
- clearLink.style.color = this.FullLogsColor;
- clearLink.style.fontWeight = "bolder";
- }
};
-Logger.prototype.addLogRecord = function addLogRecord(page) {
- var rec = {};
- rec.date = new Date();
- rec.url = page.doc.location.toString();
- rec.title = page.title;
- var comment = prompts.prompt(
- "Enter comments for this comment");
- if (comment && comment.length > 0) {
- comment = comment.trim();
- rec.comment = comment;
- var dateStr = utilMod.getISODate(rec.date);
- var urlStr = urlMod.URL(rec.url).host;
- var recKey = dateStr + "+"
- + urlStr
- + "+" + page.bugNo;
-
- if (myStorage.storage.logs[recKey]) {
- myStorage.storage.logs[recKey].comment += "<br/>\n" + comment;
- } else {
- myStorage.storage.logs[recKey] = rec;
- }
- }
- return comment;
-};
-
-Logger.prototype.getBugzillaAbbr = function(url) {
+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
- var abbr = this.abbsMap[urlMod.URL(url).host];
- return abbr;
-};
+ return abbsMap[urlMod.URL(url).host];
+}
+
+exports.generateTimeSheet = function generateTimeSheet() {
+ var docHTML = timeSheetRecordsPrinter(myStorage.storage.logs);
+ libbz.openURLInNewTab("data:text/html;charset=utf-8," + docHTML);
+};
-Logger.prototype.timeSheetRecordsPrinter = function(body, records) {
- var that = this;
+function timeSheetRecordsPrinter(records) {
var commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)","g");
// sort the records into temporary array
var tmpArr = [];
+ var outStr = '<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">' +
+ "<html><head><title>Status report</title></head><body>" +
+ "<h1>TimeSheet</h1>\n";
- for ( var i in records) {
+ for (var i in records) {
if (records.hasOwnProperty(i)) {
tmpArr.push( [ i, records[i] ]);
}
}
tmpArr.sort(function(a, b) {
- return a[0] > b[0] ? 1 : -1;
+ if (a[0] > b[0]) {
+ return 1;
+ } else if (a[0] < b[0]) {
+ return -1;
+ } else {
+ return 0;
+ }
});
var currentDay = "";
@@ -113,47 +104,24 @@ Logger.prototype.timeSheetRecordsPrinter = function(body, records) {
var x = rec[1];
var dayStr = utilMod.getISODate(x.date);
var host = urlMod.URL(x.url).host;
- var BZName = that.getBugzillaAbbr(x.url);
+ var BZName = getBugzillaAbbr(x.url);
var bugNo = utilMod.getBugNo(x.url);
if (dayStr != currentDay) {
currentDay = dayStr;
- body.innerHTML += "<hr/><p><strong>" + currentDay
- + "</strong></p>";
+ 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>");
- body.innerHTML += "<p><em><a href='"
+ outStr += "<p><em><a href='"
+ x.url
+ "'>Bug "
+ BZName + "/" + bugNo + ": "
+ x.title
+ "</a>"
- + " </em>\n<br/>" + comment + "</p>";
- });
- };
-
-/**
- *
- */
-Logger.prototype.createBlankPage = function (ttl, bodyBuildCB) {
- var title = ttl || "Yet another untitled page";
- var that = this;
-
- var logTab = tabs.open({
- url: "about:blank",
- inBackground: true,
- onOpen: function (tab) {
- var otherDoc = tab.contentDocument;
- otherDoc.title = title;
- otherDoc.body.innerHTML = "<h1>" + title + "</h1>";
- bodyBuildCB.call(that, otherDoc.body);
- tabs.activeTab = tab;
- }
+ + " </em>\n<br/>" + comment + "</p>\n";
});
-};
-
-Logger.prototype.generateTimeSheet = function(body) {
- var doc = body.ownerDocument;
- this.timeSheetRecordsPrinter(body, myStorage.storage.logs);
-};
+ outStr += "</body></html>";
+ return outStr;
+}