Browse Source

Edit multiple files at once

better-rectangles
Tissevert 8 months ago
parent
commit
c3ba3e2853
4 changed files with 76 additions and 16 deletions
  1. +11
    -2
      gui.css
  2. +13
    -3
      index.html
  3. +0
    -1
      src/ALTO.js
  4. +52
    -10
      src/Main.js

+ 11
- 2
gui.css View File

@ -8,7 +8,11 @@ html, body {
border-bottom: 1px solid #ccc;
}
#thresholdInput {
#fileNumber {
width: 4em;
}
#wcThreshold {
width: 3.5em;
}
@ -37,13 +41,18 @@ html, body {
#workzone p {
font-size: 0.9em;
margin: 0;
white-space: nowrap;
}
.String.lowQuality {
background: #a4ddfd;
}
.String.lowQuality.deleted {
background: #fdd;
}
.String.deleted {
text-decoration: line-through;
opacity: 0.5;
color: red;
}

+ 13
- 3
index.html View File

@ -8,9 +8,19 @@
</head>
<body>
<div id="toolbar">
<label for="inputFile">Charger un fichier ALTO</label><input id="filePicker" type="file" name="inputFile" accept="text/xml,.xml"/>
<label for="wcThreshold">Seuil de qualité</label><input id="thresholdInput" name="wcThreshold" type="number" min="0" max="1" step="0.01" value="0.5"/>
<input id="editMode" type="checkbox" name="setEditMode"/><label for="setEditMode">Éditer</label>
<span>
<label for="inputFiles">Charger des fichiers ALTO</label><input id="inputFiles" type="file" name="inputFiles" accept="text/xml,.xml" multiple/>
</span>
<span>
<label for="fileNumber">#</label><input id="fileNumber" type="number" name="fileNumber" min="0" max="0" step="1" value="0"/>
<span id="fileName"></span>
</span>
<span>
<label for="wcThreshold">Seuil de qualité</label><input id="wcThreshold" name="wcThreshold" type="number" min="0" max="1" step="0.01" value="0.25"/>
</span>
<span>
<input id="editMode" type="checkbox" name="editMode"/><label for="editMode">Éditer</label>
</span>
</div>
<div id="workzone">
</div>


+ 0
- 1
src/ALTO.js View File

@ -1,7 +1,6 @@
import * as Element from ALTO.Element;
import * as Dom from UnitJS.Dom;
return {
display: display,
load: load


+ 52
- 10
src/Main.js View File

@ -4,33 +4,51 @@ import ALTO;
var workzone = document.getElementById('workzone');
workzone.style.width = Element.printSpace.pxWidth + 'px';
var filePicker = document.getElementById('filePicker');
var thresholdInput = document.getElementById('thresholdInput');
var inputFiles = document.getElementById('inputFiles');
var fileNumber = document.getElementById('fileNumber');
var fileName = document.getElementById('fileName');
var wcThreshold = document.getElementById('wcThreshold');
var editMode = document.getElementById('editMode');
var currentALTOFile = null;
var deletedWords = {};
filePicker.addEventListener('change', function() {
inputFiles.addEventListener('change', function() {
fileNumber.value = 0;
syncPageNumber();
updatePageNumber();
loadCurrentFile();
});
wcThreshold.addEventListener('change', refresh);
editMode.addEventListener('change', syncEditMode);
fileNumber.addEventListener('change', updatePageNumber);
window.addEventListener('keydown', function(e) {
switch(e.keyCode) {
case 0x25: moveFile(-1); break;
case 0x27: moveFile(+1); break;
}
});
syncEditMode();
syncPageNumber();
function loadCurrentFile() {
Async.run(
Async.bind(
ALTO.load(filePicker.files[0]),
ALTO.load(inputFiles.files[fileNumber.value]),
Async.map(function(ALTOFile) {
currentALTOFile = ALTOFile;
refresh();
})
)
);
});
thresholdInput.addEventListener('change', refresh);
syncEditMode();
editMode.addEventListener('change', syncEditMode);
}
function refresh() {
ALTO.display(currentALTOFile, {
workzone: workzone,
deletedWords: deletedWords,
qualityThreshold: thresholdInput.value,
qualityThreshold: wcThreshold.value,
callbacks: {
wordEdit: wordEdit
}
@ -41,6 +59,30 @@ function syncEditMode() {
workzone.className = editMode.checked ? "editMode" : "";
}
function syncPageNumber() {
fileNumber.max = inputFiles.files.length-1;
fileName.textContent = inputFiles.files[fileNumber.value].name;
}
function updatePageNumber() {
if(fileNumber.checkValidity()) {
gotoFile(fileNumber.value);
}
}
function moveFile(delta) {
var n = 1*fileNumber.value + delta;
if(n >= fileNumber.min && n <= fileNumber.max) {
fileNumber.value = n;
gotoFile(n);
}
}
function gotoFile(n) {
fileName.textContent = inputFiles.files[n].name;
loadCurrentFile();
}
function wordEdit(e) {
if(editMode.checked) {
var wordId = e.target.id;


Loading…
Cancel
Save