www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 581a8df4b9b358f74a0fc243ba9da8a1759bec25
parent 983f5023bcd428dcf5eeb0e07754d9079fa00944
Author: Simon Kornblith <simon@simonster.com>
Date:   Mon, 20 Jun 2011 05:43:54 +0000

Show debug output for translators and allow running all translators or only individual translators


Diffstat:
Mchrome/content/zotero/tools/testTranslators/testTranslators.css | 29++++++++++++++++++++++++++++-
Mchrome/content/zotero/tools/testTranslators/testTranslators.js | 137+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mchrome/content/zotero/tools/testTranslators/translatorTester.js | 2+-
3 files changed, 153 insertions(+), 15 deletions(-)

diff --git a/chrome/content/zotero/tools/testTranslators/testTranslators.css b/chrome/content/zotero/tools/testTranslators/testTranslators.css @@ -46,6 +46,33 @@ td, th { background-color: #ececec; } -.status-pending { +.status-pending, .status-running { background-color: #9FF; +} + +tr.output-displayed > td { + background-color: #b4d5ff !important; +} + +#translator-box { + position: absolute; + top: 0; + bottom: 25%; + left: 0; + right: 0; + padding: 5px; + overflow: scroll; +} + +#output-box { + position: absolute; + top: 75%; + bottom: 0; + left: 0; + right: 0; + padding: 5px; + white-space: pre; + overflow: scroll; + font-family: Monaco, Courier, monospace; + font-size: 10px; } \ No newline at end of file diff --git a/chrome/content/zotero/tools/testTranslators/testTranslators.js b/chrome/content/zotero/tools/testTranslators/testTranslators.js @@ -23,11 +23,43 @@ ***** END LICENSE BLOCK ***** */ -const NUM_CONCURRENT_TESTS = 6; +const NUM_CONCURRENT_TESTS = 1; const TRANSLATOR_TYPES = ["Web", "Import", "Export", "Search"]; const TABLE_COLUMNS = ["Translator", "Supported", "Status", "Pending", "Succeeded", "Failed", "Unknown"]; var translatorTables = {}; var translatorTestViewsToRun = {}; +var translatorBox; +var outputBox; +var allOutputView; +var currentOutputView; + +/** + * Handles adding debug output to the output box + * @param {HTMLElement} el An element to add class="selected" to when this outputView is displayed + */ +var OutputView = function(el) { + this._output = []; + this._el = el; +} + +/** + * Sets whether this output is currently displayed in the output box + * @param {Boolean} isDisplayed + */ +OutputView.prototype.setDisplayed = function(isDisplayed) { + this.isDisplayed = isDisplayed; + if(this.isDisplayed) outputBox.textContent = this._output.join("\n\n"); + if(this._el) this._el.className = (isDisplayed ? "output-displayed" : "output-hidden"); + currentOutputView = this; +} + +/** + * Adds output to the output view + */ +OutputView.prototype.addOutput = function(msg, level) { + this._output.push(msg); + if(this.isDisplayed) outputBox.textContent = this._output.join("\n\n"); +} /** * Encapsulates a set of tests for a specific translator and type @@ -74,20 +106,57 @@ var TranslatorTestView = function(translator, type) { // append to table translatorTables[type].appendChild(row); + // create output view and debug function + var outputView = new OutputView(row); + var debug = function(obj, msg, level) { + outputView.addOutput(msg, level); + allOutputView.addOutput(msg, level); + } + + // put click handler on row to allow display of debug output + row.addEventListener("click", function(e) { + // don't run deselect click event handler + e.stopPropagation(); + + currentOutputView.setDisplayed(false); + outputView.setDisplayed(true); + }, false); + // create translator tester and update status based on what it knows - this._translatorTester = new Zotero_TranslatorTester(translator, type); + this._translatorTester = new Zotero_TranslatorTester(translator, type, debug); this.updateStatus(this._translatorTester); this.hasTests = !!this._translatorTester.tests.length; + this.isRunning = false; } /** * Changes the displayed status of a translator */ -TranslatorTestView.prototype.updateStatus = function(obj) { +TranslatorTestView.prototype.updateStatus = function(obj, status) { + while(this._status.hasChildNodes()) { + this._status.removeChild(this._status.firstChild); + } + if(obj.tests.length) { if(obj.pending.length) { - this._status.className = "status-pending"; - this._status.textContent = "Pending"; + if(this.isRunning) { + this._status.className = "status-running"; + this._status.textContent = "Running"; + } else if(status && status === "pending") { + this._status.className = "status-pending"; + this._status.textContent = "Pending"; + } else { + // show link to start + var me = this; + var a = document.createElement("a"); + a.href = "#"; + a.addEventListener("click", function(e) { + e.preventDefault(); + me.runTests(); + }, false); + a.textContent = "Run"; + this._status.appendChild(a); + } } else if(obj.failed.length) { this._status.className = "status-failed"; this._status.textContent = "Failed"; @@ -113,10 +182,17 @@ TranslatorTestView.prototype.updateStatus = function(obj) { * Runs test for this translator */ TranslatorTestView.prototype.runTests = function(doneCallback) { + if(this.isRunning) return; + this.isRunning = true; + + // show as running + this.updateStatus(this._translatorTester); + + // set up callback var me = this; var newCallback = function(obj, test, status, message) { me.updateStatus(obj); - if(obj.pending.length === 0) { + if(obj.pending.length === 0 && doneCallback) { doneCallback(); } }; @@ -132,6 +208,27 @@ function load(event) { // initialize Zotero.initInject(); } + + // create translator box + translatorBox = document.createElement("div"); + translatorBox.id = "translator-box"; + document.body.appendChild(translatorBox); + + // create output box + outputBox = document.createElement("div"); + outputBox.id = "output-box"; + document.body.appendChild(outputBox); + + // set click handler for translator box to display all output, so that when the user clicks + // outside of a translator, it will revert to this state + translatorBox.addEventListener("click", function(e) { + currentOutputView.setDisplayed(false); + allOutputView.setDisplayed(true); + }, false); + + // create output view for all output and display + allOutputView = new OutputView(); + allOutputView.setDisplayed(true); for(var i in TRANSLATOR_TYPES) { var displayType = TRANSLATOR_TYPES[i]; @@ -139,8 +236,26 @@ function load(event) { // create header var h1 = document.createElement("h1"); - h1.appendChild(document.createTextNode(displayType+" Translators")); - document.body.appendChild(h1); + h1.appendChild(document.createTextNode(displayType+" Translators ")); + + // create "run all" + var runAll = document.createElement("a"); + runAll.href = "#"; + runAll.appendChild(document.createTextNode("(Run)")); + runAll.addEventListener("click", new function() { + var type = translatorType; + return function(e) { + e.preventDefault(); + for(var i in translatorTestViewsToRun[type]) { + var testView = translatorTestViewsToRun[type][i]; + testView.updateStatus(testView._translatorTester, "pending"); + } + runTranslatorTests(type); + } + }, false); + h1.appendChild(runAll); + + translatorBox.appendChild(h1); // create table var translatorTable = document.createElement("table"); @@ -157,7 +272,7 @@ function load(event) { // append to document translatorTable.appendChild(headings); - document.body.appendChild(translatorTable); + translatorBox.appendChild(translatorTable); // get translators, with code for unsupported translators Zotero.Translators.getAllForType(translatorType, new function() { @@ -181,10 +296,6 @@ function haveTranslators(translators, type) { translatorTestViewsToRun[type].push(translatorTestView); } } - - for(var i=0; i<NUM_CONCURRENT_TESTS; i++) { - runTranslatorTests(type); - } } /** diff --git a/chrome/content/zotero/tools/testTranslators/translatorTester.js b/chrome/content/zotero/tools/testTranslators/translatorTester.js @@ -119,7 +119,7 @@ Zotero_TranslatorTester.prototype.runTests = function(testDoneCallback, recursiv } if(!this.pending.length) { // always call testDoneCallback once if there are no tests - if(!recursiveRun) testDoneCallback(this, null, "unknown", "No tests present"); + if(!recursiveRun && testDoneCallback) testDoneCallback(this, null, "unknown", "No tests present"); return; }