aboutsummaryrefslogtreecommitdiffstats
path: root/lib/logger.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-05-31 19:03:04 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-05-31 19:03:04 +0200
commit2447e31a804eb7d7fe5ef01b974cba3b615e0594 (patch)
treef4487a9c0c10b476caa3c74f9871bd3e6617472d /lib/logger.js
parent951ef0d578130106e303e5586f53404a900ccf9c (diff)
downloadbugzilla-triage-2447e31a804eb7d7fe5ef01b974cba3b615e0594.tar.gz
First attempt to split main script into modules.
Diffstat (limited to 'lib/logger.js')
-rw-r--r--lib/logger.js108
1 files changed, 108 insertions, 0 deletions
diff --git a/lib/logger.js b/lib/logger.js
new file mode 100644
index 0000000..ba9afc8
--- /dev/null
+++ b/lib/logger.js
@@ -0,0 +1,108 @@
+// Released under the MIT/X11 license
+// http://www.opensource.org/licenses/mit-license.php
+"use strict";
+
+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) {
+ 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 = hlpr.getISODate(rec.date) + "+" + hlpr.getHost(rec.url)
+ + "+" + that.bugNo;
+ let clearLogAElem = that.doc.getElementById("clearLogs");
+ clearLogAElem.style.color = this.FullLogsColor;
+ clearLogAElem.style.fontWeight = "bolder";
+ if (this.store[recKey]) {
+ this.store[recKey].comment += "<br/>\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[hlpr.getHost(url)];
+ 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 = hlpr.getISODate(x.date);
+ let host = hlpr.getHost(x.url);
+ let BZName = that.getBugzillaAbbr(x.url);
+ let bugNo = hlpr.getBugNo(x.url);
+ if (dayStr != currentDay) {
+ currentDay = dayStr;
+ body.innerHTML += "<hr/><p><strong>" + currentDay
+ + "</strong></p>";
+ }
+ // replace "bug ####" with a hyperlink to the current bugzilla
+ let comment = x.comment.replace(commentBugRE,
+ "<a href='http://"+host+"/show_bug.cgi?id=$1'>$&</a>");
+ body.innerHTML += "<p><em><a href='"
+ + x.url
+ + "'>Bug "
+ + BZName + "/" + bugNo + ": "
+ + x.title
+ + "</a>"
+ + " </em>\n<br/>" + comment + "</p>";
+ });
+};
+
+/**
+ *
+ */
+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 = "<h1>" + title + "</h1>";
+ bodyBuildCB.call(that, otherDoc.body);
+ logTab.focus();
+ });
+};
+
+Logger.prototype.generateTimeSheet = function(body) {
+ let doc = body.ownerDocument;
+ this.timeSheetRecordsPrinter(body, this.store);
+};