aboutsummaryrefslogtreecommitdiffstats
path: root/lib/logger.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-09-24 12:28:11 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-09-24 12:28:11 +0200
commit4ffd6b9e6b61c9eaa323e4f4d537db5d1a36872d (patch)
tree542c7162a1924149e70a1e0004f4a221d48d4615 /lib/logger.js
parentf31ed4f55d9a33bb39a5e409b36878b5ac4ae470 (diff)
downloadbugzilla-triage-4ffd6b9e6b61c9eaa323e4f4d537db5d1a36872d.tar.gz
Fix Logger object to be self contained and use storage properly
* there is really no other way than using module.storage directly Sucks! * all logger-related logic should go to the module and not be flying around (import TS, clear, isEmpty)
Diffstat (limited to 'lib/logger.js')
-rw-r--r--lib/logger.js72
1 files changed, 53 insertions, 19 deletions
diff --git a/lib/logger.js b/lib/logger.js
index 1936ad5..052364d 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -3,27 +3,69 @@
"use strict";
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");
-function Logger(store, abbsMap) {
+var Logger = exports.Logger = function Logger(abbsMap) {
this.EmptyLogsColor = new Color(0, 255, 0);
this.FullLogsColor = new Color(0, 40, 103);
- this.store = store;
+ if (!myStorage.storage.logs) {
+ myStorage.storage.logs = {};
+ }
+
this.abbsMap = abbsMap;
};
-exports.Logger = Logger;
+Logger.prototype.size = function size() {
+ var size = 0, key;
+ for (key in myStorage.storage.logs) {
+ size++;
+ }
+ console.log("logStore.size = " + size);
+ return size;
+};
+
+Logger.prototype.isEmpty = function isEmpty() {
+ return (this.size() === 0);
+};
+
+Logger.prototype.clearStore = function clearStore(clearLink) {
+ myStorage.storage.logs = {};
+ var size = this.size();
+ clearLink.style.color = this.EmptyLogsColor;
+ clearLink.style.fontWeight = "normal";
+};
+
+Logger.prototype.importOtherStore = function importOtherStore (filename, clearLink) {
+ if (fileMod.exists(filename)) {
+ var otherTS = JSON.parse(fileMod.read(filename));
+ if (otherTS.logs) {
+ for (var rec in otherTS.logs) {
+ myStorage.storage.logs[rec] = otherTS.logs[rec];
+ }
+ } else {
+ console.error("This is not a log file!");
+ }
+ } 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(that) {
+Logger.prototype.addLogRecord = function addLogRecord(page) {
var rec = {};
rec.date = new Date();
- rec.url = that.doc.location.toString();
- rec.title = that.title;
+ rec.url = page.doc.location.toString();
+ rec.title = page.title;
var comment = prompts.prompt(
"Enter comments for this comment");
if (comment && comment.length > 0) {
@@ -33,25 +75,17 @@ Logger.prototype.addLogRecord = function(that) {
var urlStr = urlMod.URL(rec.url).host;
var recKey = dateStr + "+"
+ urlStr
- + "+" + that.bugNo;
+ + "+" + page.bugNo;
- if (this.store[recKey]) {
- this.store[recKey].comment += "<br/>\n" + comment;
+ if (myStorage.storage.logs[recKey]) {
+ myStorage.storage.logs[recKey].comment += "<br/>\n" + comment;
} else {
- this.store[recKey] = rec;
+ myStorage.storage.logs[recKey] = rec;
}
}
return comment;
};
-Logger.prototype.getLength = function () {
- var counter = 0;
- for (var key in this.store) {
- counter += 1;
- }
- return counter;
-};
-
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
@@ -122,5 +156,5 @@ Logger.prototype.createBlankPage = function (ttl, bodyBuildCB) {
Logger.prototype.generateTimeSheet = function(body) {
var doc = body.ownerDocument;
- this.timeSheetRecordsPrinter(body, this.store);
+ this.timeSheetRecordsPrinter(body, myStorage.storage.logs);
};