Add debug information inside the HTML page, with a button to switch it

on/off
This commit is contained in:
mossroy 2013-01-02 12:59:07 +01:00
parent 4425806fe0
commit 1383f74640
2 changed files with 65 additions and 38 deletions

View File

@ -38,10 +38,9 @@ License:
<body>
<h1>Evopedia</h1>
<div id="openLocalFiles" style="display: none;">
<br />
Please select the file titles.idx :<br /> <input type="file"
id="titleFile" /><br /> Please select the files wikipedia_*.dat from
the same dump :<br /> <input type="file" id="dataFiles" multiple />
<br /> Please select the file titles.idx :<br /> <input type="file"
id="titleFile" /><br /> Please select the files wikipedia_*.dat
from the same dump :<br /> <input type="file" id="dataFiles" multiple />
</div>
<br /> Find titles from the prefix :
<input type="text" id="prefix" value="" onkeyup="onKeyUpPrefix(event)" />&nbsp;
@ -50,40 +49,43 @@ License:
<br /> Choose a title from the filtered list :
<select id="titleList" onchange="updateOffsetsFromTitle(this.value)"></select>
<br />
<table>
<tr>
<th>&nbsp;</th>
<th>Original offsets</th>
<th>Redirect offsets</th>
</tr>
<tr>
<td>File number</td>
<td><input type="text" id="filenumber" value="" /></td>
<td><input type="text" id="redirectfilenumber" value="" /></td>
</tr>
<tr>
<td>Blockstart</td>
<td><input type="text" id="blockstart" value="" /></td>
<td><input type="text" id="redirectblockstart" value="" /></td>
</tr>
<tr>
<td>Blockoffset</td>
<td><input type="text" id="blockoffset" value="" /></td>
<td><input type="text" id="redirectblockoffset" value="" /></td>
</tr>
<tr>
<td>Length</td>
<td><input type="text" id="length" value="" /></td>
<td><input type="text" id="redirectlength" value="" /></td>
</tr>
</table>
<input type="button" id="toggleDebug" value="Switch debug on/off"
onclick="switchDebugOnOff()" />
<input type="button" id="readData" value="Read article from dump"
onclick="readArticleFromHtmlForm(dataFiles)" />
<br />
<div id="debugZone" style="display: none;">
<table>
<tr>
<th>&nbsp;</th>
<th>Original offsets</th>
<th>Redirect offsets</th>
</tr>
<tr>
<td>File number</td>
<td><input type="text" id="filenumber" value="" /></td>
<td><input type="text" id="redirectfilenumber" value="" /></td>
</tr>
<tr>
<td>Blockstart</td>
<td><input type="text" id="blockstart" value="" /></td>
<td><input type="text" id="redirectblockstart" value="" /></td>
</tr>
<tr>
<td>Blockoffset</td>
<td><input type="text" id="blockoffset" value="" /></td>
<td><input type="text" id="redirectblockoffset" value="" /></td>
</tr>
<tr>
<td>Length</td>
<td><input type="text" id="length" value="" /></td>
<td><input type="text" id="redirectlength" value="" /></td>
</tr>
</table>
<textarea id="debugTextarea" cols="80" rows="10">&nbsp;</textarea>
</div>
<!-- TODO : add CSS styles -->
<div id="articleContent">&nbsp;</div>
<hr />
<textarea id="debugZone" cols="80" rows="20">&nbsp;</textarea>
<script type="text/javascript" src="evopedia.js"></script>
</body>

View File

@ -49,6 +49,32 @@ else {
};
}
var debugOn = false;
/**
* Print the given string inside the debug zone
* @param string
*/
function debug(string) {
if (debugOn) {
document.getElementById("debugTextarea").value+=string+"\n";
}
}
/**
* Switch debug mode On/Off
*/
function switchDebugOnOff() {
if (debugOn == true) {
debugOn = false;
document.getElementById("debugZone").style.display="none";
}
else {
debugOn = true;
document.getElementById("debugZone").style.display="block";
}
}
/**
* Set the Offsets HTML fields from the selected title
*/
@ -126,7 +152,7 @@ function recursivePrefixSearch(titleFile, reader, prefix, lo, hi) {
newLineIndex++;
}
var title = utf8ByteArrayToString(byteArray,i+15,newLineIndex);
//alert("title found : "+title);
debug("title found : "+title);
if (title.localeCompare(prefix)<0) {
lo = mid;
}
@ -135,13 +161,13 @@ function recursivePrefixSearch(titleFile, reader, prefix, lo, hi) {
}
recursivePrefixSearch(titleFile, reader, prefix, lo, hi);
};
//alert("Reading the file from "+mid+" to "+(mid+256)+" because lo="+lo+" and hi="+hi);
debug("Reading the file from "+mid+" to "+(mid+256)+" because lo="+lo+" and hi="+hi);
// Read the file as a binary string
reader.readAsArrayBuffer(blob);
}
else {
// We found the closest title
//alert ("Found the closest title near index "+lo);
debug ("Found the closest title near index "+lo);
readTitlesBeginningAtIndexStartingWithPrefix(titleFile,prefix,lo);
}
}
@ -246,6 +272,7 @@ function readTitlesBeginningAtIndexStartingWithPrefix(titleFile,prefix,startInde
title = utf8ByteArrayToString(byteArray,i+15,newLineIndex);
// Skip the first title
if (titleNumber>=0 && title) {
debug("Found title : escape1="+escape1+" escape2="+escape2+" filenumber="+filenumber+" blockstart="+blockstart+" blockoffset="+blockoffset+" length="+length+" title="+title);
// TODO : check if the title starts with prefix, and return if it does not
comboTitleList.options[titleNumber] = new Option (title, filenumber+"|"+blockstart+"|"+blockoffset+"|"+length);
}
@ -335,8 +362,6 @@ function readArticleFromOffset(dataFile, blockstart, blockoffset, length) {
htmlArticle = decodeURIComponent(escape(htmlArticle));
document.getElementById('articleContent').innerHTML = htmlArticle;
// For testing purpose
//document.getElementById('debugZone').value = htmlArticle;
};
// TODO : should be improved by reading the file chunks by chunks until the article is found,