aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bugzillaBugTriage.js191
1 files changed, 112 insertions, 79 deletions
diff --git a/bugzillaBugTriage.js b/bugzillaBugTriage.js
index 171f8fc..a62c630 100644
--- a/bugzillaBugTriage.js
+++ b/bugzillaBugTriage.js
@@ -172,6 +172,20 @@ console.log("Now we are calling XMLHTTPRequest to load xmlrpc.js");
req.send("");
//==============================================================
+/**
+ * format date to be in ISO format (just day part)
+ * @param date
+ * @return string with the formatted date
+ */
+function getISODate(dateStr){
+ function pad(n){
+ return n<10 ? '0'+n : n;
+ }
+ var date = new Date(dateStr);
+ return date.getFullYear()+'-'
+ + pad(date.getMonth()+1)+'-'
+ + pad(date.getDate());
+}
/**
* select element of the array where regexp in the first element matches second parameter
@@ -224,69 +238,18 @@ isInList = function(mbr, list) {
return (list.indexOf(mbr) !== -1);
};
-writeALine = function(filename,text) {
-
-// jetpack.tabs.focused.contentWindow.wrappedJSObject.netscape.security.
-// this.netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-// var fileContractId = "@mozilla.org/file/local;1";
-// var fileInterface = Components.interfaces.nsILocalFile;
-// netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-// var localFileClass = Components.classes[fileContractId];
-// var file = localFileClass.createInstance(fileInterface);
-// var desk = Components.classes["@mozilla.org/file/directory_service;1"]
-// .getService(Components.interfaces.nsIProperties)
-// .get("Desk", Components.interfaces.nsIFile);
-
-// try {
-// desk.append(name);
-// } catch (exp) {
-// alert("Bad file name");
-// return;
-// }
-
-// name = desk.path;
-
-// try {
-// file.initWithPath(name);
-// } catch (exp) {
-// alert("Bad file name");
-// return;
-// }
-
-// try {
-// file.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420);
-// } catch (exp) {
-// //
-// }
-
-// var stream = Components.classes["@mozilla.org/network/file-output-stream;1"]
-// .createInstance(Components.interfaces.nsIFileOutputStream);
-
-// try {
-// stream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
-// } catch (exp) {
-// alert("Cannot create file");
-// return;
-// }
-
-// stream.write(data, data.length);
-// stream.close();
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+function createBlankPage (ttl,bodyBuildCB) {
+ var title = ttl || "Yet another untitled page";
+ var that = this;
+
+ var logTab = jetpack.tabs.open("about:blank");
+ jetpack.tabs.onReady(function() {
+ var otherDoc = logTab.contentDocument;
+ otherDoc.title = title;
+ otherDoc.body.innerHTML = "<h1>"+title+"</h1>";
+ bodyBuildCB.call(that,otherDoc.body);
+ logTab.focus();
+ });
}
// ============================================================================
@@ -1377,7 +1340,6 @@ BzPage.prototype.fixAttachById = function(id,type,email) {
msg.addParameter({'attach_id':id, 'mime_type':type, 'nomail':!email});
msg.addParameter(this.login);
msg.addParameter(this.password);
- console.log("testing XMLRPCMessage:\n" + msg.xml());
var req = new XMLHttpRequest();
var that = this;
@@ -1715,6 +1677,69 @@ BzPage.prototype.buildButtons = function (above,below) {
}
};
+BzPage.prototype.addLogRecord = function () {
+ var rec = {};
+ rec.date = new Date();
+ rec.bugId = this.bugNo;
+ var comment = jetpack.tabs.focused.contentWindow.
+ prompt("Enter comments for this comment");
+ if (comment.length > 0) {
+ rec.comment = comment;
+ var recKey = getISODate(rec.date)+"+"+rec.bugId;
+ if (myStorage.logs[recKey]) {
+ myStorage.logs[recKey].comment += "\n"+comment;
+ } else {
+ myStorage.logs[recKey] = rec;
+ }
+ jetpack.storage.simple.sync();
+ }
+};
+
+BzPage.prototype.timeSheetRecordsPrinter = function (body,records) {
+ // 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 = getISODate(x.date);
+ if (dayStr != currentDay) {
+ currentDay = dayStr;
+ body.innerHTML += "<hr/><p><strong>" + currentDay +
+ "</strong></p>";
+ }
+ body.innerHTML += "<p><em><a href='https://bugzilla.redhat.com/show_bug.cgi?id="+
+ x.bugId + "'>Bug "+x.bugId+"</a>"+
+ " </em>\n<br/>" + x.comment + "</p>";
+ });
+};
+
+BzPage.prototype.generateTimeSheet = function (body) {
+ var doc = body.ownerDocument;
+ var newButton = doc.createElement("input");
+ var newP = doc.createElement("p");
+ body.appendChild(newP);
+ newP.appendChild(newButton);
+ newButton.setAttribute("type","button");
+ newButton.value = "Clear the store";
+ newButton.setAttribute("id","clearThePage");
+ newButton.addEventListener("click",function (evt) {
+ myStorage.logs = {};
+ body.innerHTML = "";
+ }, false);
+
+ var currentDay = "";
+ this.timeSheetRecordsPrinter(body,myStorage.logs);
+};
+
///////////////////////////////////////////////////////////////////////////////
function BzPage(doc) {
this.dok = doc;
@@ -1726,9 +1751,6 @@ function BzPage(doc) {
textContent.split("\n");
this.login = loginArr[loginArr.length-1].trim();
- // the following is quite awful brutal hack
-// console.log("on __parent__ navigator.online = " +
-// jetpack.__parent__.navigator.onLine);
if (myStorage.BZpassword) {
this.password = myStorage.BZpassword;
} else {
@@ -1847,18 +1869,6 @@ function BzPage(doc) {
}
, false);
}
-
- // logging all submits for timesheet
- if (logSubmits) {
- var that = this;
- this.dok.forms.namedItem("changeform").addEventListener("submit",
- function () {
- // write the record to the log
- var logTime = this.getLogTime();
- console.log("today's date is " + logTime);
- console.log(logTime + ": " + that.bugNo);
- },false);
- }
this.setBranding();
this.checkComments();
@@ -1895,6 +1905,29 @@ function BzPage(doc) {
addEventListener('submit', function (evt) {
that.submitCallback.call(that, evt)},
false);
+
+ // logging all submits for timesheet
+ if (logSubmits) {
+ this.dok.forms.namedItem("changeform").addEventListener("submit",
+ function () {that.addLogRecord();}
+ ,false);
+
+ var generateTimeSheetUI = this.dok.createElement("li");
+ generateTimeSheetUI.innerHTML =
+ "\u00A0-\u00A0<a href='#' id='generateTSButton'>" +
+ "Generate timesheet</a>";
+ additionalButtons.appendChild(generateTimeSheetUI);
+ this.dok.getElementById("generateTSButton").
+ addEventListener("click",function (evt) {
+ createBlankPage.call(that,"TimeSheet",that.generateTimeSheet);
+ evt.stopPropagation();
+ evt.preventDefault();
+ }, false);
+
+ if (!myStorage.logs) {
+ myStorage.logs = {};
+ }
+ }
}
var callback = function (doc) {