diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-03-23 20:18:23 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-03-23 20:18:23 +0100 |
commit | 2e5993bc9bd0d468f4e9d12dd39e0548ba9adda1 (patch) | |
tree | f31a0d612efbfa5beb78e4718768c55c650f14d8 /lib/logger.js | |
parent | c662ccddab2cbcc6d13f49a21c04a6aea808f457 (diff) | |
download | bugzilla-triage-2e5993bc9bd0d468f4e9d12dd39e0548ba9adda1.tar.gz |
Fix indentation and else for Mozilla coding guidelines.
Diffstat (limited to 'lib/logger.js')
-rw-r--r-- | lib/logger.js | 170 |
1 files changed, 88 insertions, 82 deletions
diff --git a/lib/logger.js b/lib/logger.js index 07f42ba..4411a72 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -1,4 +1,5 @@ -// Released under the MIT/X11 license +/ +Released under the MIT/X11 license // http://www.opensource.org/licenses/mit-license.php "use strict"; var urlMod = require("url"); @@ -17,113 +18,118 @@ var FullLogsColor = "rgb(0, 40, 103)"; var abbsMap = {}; exports.initialize = function initialize(aMap) { - if (!myStorage.storage.logs) { - myStorage.storage.logs = {}; - } - abbsMap = aMap; + if (!myStorage.storage.logs) { + myStorage.storage.logs = {}; + } + abbsMap = aMap; }; 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; - } + if (myStorage.storage.logs[rec.key]) { + myStorage.storage.logs[rec.key].comment += "<br/>\n" + comment; + } + else { + myStorage.storage.logs[rec.key] = rec; + } }; function storeSize() { - var size = 0, key; - for (key in myStorage.storage.logs) { - size++; - } - return size; + var size = 0, key; + for (key in myStorage.storage.logs) { + size++; + } + return size; } function isEmpty() { - return (storeSize() === 0); + return (storeSize() === 0); } exports.clearTimeSheet = function clearTimeSheet() { - myStorage.storage.logs = {}; - var size = storeSize(); + myStorage.storage.logs = {}; + var size = storeSize(); }; exports.importTimeSheet = function importTimeSheet() { - var filename = prompts.promptFileOpenPicker(); - 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!"); + var filename = prompts.promptFileOpenPicker(); + 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!"); + } }; 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]; + // 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); - libbz.openURLInNewTab("data:text/html;charset=utf-8," + docHTML); + var docHTML = timeSheetRecordsPrinter(myStorage.storage.logs); + libbz.openURLInNewTab("data:text/html;charset=utf-8," + docHTML); }; 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>' + - "<html><head>\n"+ - "<meta charset='utf-8'/>\n"+ - "<title>Status report</title>\n</head>\n<body>\n" + - "<h1>TimeSheet</h1>\n"; + var commentBugRE = new RegExp("[bB]ug\\s+([0-9]+)","g"); + // sort the records into temporary array + var tmpArr = []; + var outStr = '<!DOCTYPE html>' + + "<html><head>\n"+ + "<meta charset='utf-8'/>\n"+ + "<title>Status report</title>\n</head>\n<body>\n" + + "<h1>TimeSheet</h1>\n"; - for (var i in records) { - if (records.hasOwnProperty(i)) { - tmpArr.push( [ i, records[i] ]); - } + 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; } - 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; + 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; } |