// 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 Color = require("color").Color;
var tabs = require("tabs");
var Logger = exports.Logger = function Logger(store, abbsMap) {
this.EmptyLogsColor = new Color(0, 255, 0);
this.FullLogsColor = new Color(0, 40, 103);
this.store = store;
this.abbsMap = abbsMap;
};
Logger.prototype.addLogRecord = function(that) {
var rec = {};
rec.date = new Date();
rec.url = that.doc.location.toString();
rec.title = that.title;
var comment = tabs.activeTab.contentWindow.prompt(
"Enter comments for this comment");
if (comment && comment.length > 0) {
comment = comment.trim();
rec.comment = comment;
var recKey = utilMod.getISODate(rec.date) + "+"
+ urlMod.parse(rec.url).host
+ "+" + that.bugNo;
console.log("rec = " + rec.toSource());
var clearLogAElem = that.doc.getElementById("clearLogs");
if (clearLogAElem.style.color != this.FullLogsColor) {
clearLogAElem.style.color = this.FullLogsColor;
clearLogAElem.style.fontWeight = "bolder";
}
if (this.store[recKey]) {
this.store[recKey].comment += "
\n" + comment;
} else {
this.store[recKey] = rec;
}
}
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) {
var that = this;
var commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)","g");
// sort the records into temporary array
var tmpArr = [];
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;
});
var currentDay = "";
// now print the array
tmpArr.forEach(function(rec) {
var x = rec[1];
var dayStr = utilMod.getISODate(x.date);
var host = urlMod.parse(x.url).host;
var BZName = that.getBugzillaAbbr(x.url);
var bugNo = utilMod.getBugNo(x.url);
if (dayStr != currentDay) {
currentDay = dayStr;
body.innerHTML += "
" + currentDay + "
"; } // replace "bug ####" with a hyperlink to the current bugzilla var comment = x.comment.replace(commentBugRE, "$&"); body.innerHTML += "Bug "
+ BZName + "/" + bugNo + ": "
+ x.title
+ ""
+ " \n
" + comment + "