From fcfbd3f7f01df5c67182366dc25e41567addc3b8 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Mon, 19 Jul 2010 15:48:47 +0200 Subject: Add import JSON file to logs --- lib/bzpage.js | 29 +++++++++++++++++++++++++++-- lib/prompts.js | 20 ++++++++++++++++++++ lib/rhbzpage.js | 1 + 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/bzpage.js b/lib/bzpage.js index 9276a2b..9c24256 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -6,6 +6,7 @@ var util = require("util"); var passUtils = require("passwords"); var apiUtils = require("api-utils"); var selfMod = require("self"); +var fileMod = require("file"); var simpleStorage = require("simple-storage"); var preferences = require("preferences-service"); var prompts = require("prompts"); @@ -781,7 +782,7 @@ BZPage.prototype.setUpLogging = function setUpLogging () { var generateTimeSheetUI = this.doc.createElement("li"); generateTimeSheetUI.innerHTML = "\u00A0-\u00A0" - + "Generate timesheet"; + + "Generate TS"; additionalButtons.appendChild(generateTimeSheetUI); this.doc.getElementById("generateTSButton").addEventListener( "click", @@ -792,9 +793,33 @@ BZPage.prototype.setUpLogging = function setUpLogging () { evt.preventDefault(); }, false); + var ImportTimeSheetUI = this.doc.createElement("li"); + ImportTimeSheetUI.innerHTML = "\u00A0-\u00A0" + + "Import TS"; + additionalButtons.appendChild(ImportTimeSheetUI); + this.doc.getElementById("importTSButton").addEventListener( + "click", + function(evt) { + var otherTS = {}, thisTS = that.log.store; + + jsonPaths = prompts.promptFileOpenPicker(that.win); + if (fileMod.exists(jsonPaths)) { + otherTS = JSON.parse(fileMod.read(jsonPaths)); + if (otherTS.logs) { + for (var rec in otherTS.logs) { + thisTS[rec] = otherTS.logs[rec]; + } + } else { + console.error("This is not a log file!"); + } + } else { + console.error("File " + jsonPaths + " doesn't exist!"); + } + }, false); + var clearLogsUI = this.doc.createElement("li"); clearLogsUI.innerHTML = "\u00A0-\u00A0" - + "Clear logs"; + + "Clear TS"; additionalButtons.appendChild(clearLogsUI); var clearLogAElem = this.doc.getElementById("clearLogs"); clearLogAElem.addEventListener("click", function() { diff --git a/lib/prompts.js b/lib/prompts.js index ac21c49..8f7942e 100644 --- a/lib/prompts.js +++ b/lib/prompts.js @@ -80,3 +80,23 @@ exports.promptYesNoCancel = function promptOKNoCancel(prompt) { return null; } }; + +/** + * + * documentation is https://developer.mozilla.org/en/NsIFilePicker + */ +exports.promptFileOpenPicker = function promptFilePicker (win) { + var fp = Cc["@mozilla.org/filepicker;1"] + .createInstance(Ci.nsIFilePicker); + fp.init(win, "JSON File Open", Ci.nsIFilePicker.modeOpen); + fp.appendFilter("JSON files", "*.json"); + fp.appendFilters(Ci.nsIFilePicker.filterAll); + fp.filterIndex = 0; + var res = fp.show(); + + if (res === Ci.nsIFilePicker.returnOK || + res === Ci.nsIFilePicker.returnReplace ) { + return fp.file.path + } + return null; +}; \ No newline at end of file diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js index 6782241..340e1fd 100644 --- a/lib/rhbzpage.js +++ b/lib/rhbzpage.js @@ -112,6 +112,7 @@ var RHBugzillaPage = function RHBugzillaPage(win, config) { // TODO Get compiz bugs as well if (this.constantData.PCI_ID_Array && + (this.XorgLogAttList[0]) && (this.maintCCAddr === "xgl-maint@redhat.com")) { // Add find chip magic button var whiteboard_string = this.doc.getElementById("status_whiteboard").value; -- cgit