Fix #38: Add a loading message with progress on end-user interface
This commit is contained in:
parent
34c0d03587
commit
4449d488c9
@ -17,6 +17,8 @@ Access raw data with: <?php echoUrl('channels/'); ?>.
|
|||||||
<input type="submit" id="search-only-captions" value="Search only captions">
|
<input type="submit" id="search-only-captions" value="Search only captions">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
Progress: <span id="progress"></span>
|
||||||
|
|
||||||
<ul id="channels">
|
<ul id="channels">
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@ -36,8 +38,8 @@ Access raw data with: <?php echoUrl('channels/'); ?>.
|
|||||||
|
|
||||||
function treatLine(line) {
|
function treatLine(line) {
|
||||||
console.log(line);
|
console.log(line);
|
||||||
if (line.startsWith('alert:')) {
|
if (line.startsWith('progress:')) {
|
||||||
alert(line.replace('alert:', ''));
|
document.getElementById('progress').innerHTML = line.replace('progress:', '');
|
||||||
} else {
|
} else {
|
||||||
var channelsDom = document.getElementById('channels');
|
var channelsDom = document.getElementById('channels');
|
||||||
const channelFileParts = line.split('/');
|
const channelFileParts = line.split('/');
|
||||||
|
@ -28,10 +28,10 @@ def write(s):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit(e)
|
sys.exit(e)
|
||||||
|
|
||||||
# Unclear if `os.listdir` takes a lot of time, as it's a generator.
|
|
||||||
# As `zipgrep` doesn't support arguments to stop on first match for each file, we proceed manually to keep a good theoretical complexity.
|
# As `zipgrep` doesn't support arguments to stop on first match for each file, we proceed manually to keep a good theoretical complexity.
|
||||||
for file in os.listdir(path):
|
files = [file for file in os.listdir(path) if file.endswith('.zip')]
|
||||||
if file.endswith('.zip'):
|
for fileIndex, file in enumerate(files):
|
||||||
|
write(f'progress:{fileIndex + 1} / {len(files)}')
|
||||||
zip = zipfile.ZipFile(path + file)
|
zip = zipfile.ZipFile(path + file)
|
||||||
for fileInZip in zip.namelist():
|
for fileInZip in zip.namelist():
|
||||||
if searchOnlyCaptions and not fileInZip.endswith('.vtt'):
|
if searchOnlyCaptions and not fileInZip.endswith('.vtt'):
|
||||||
|
@ -96,7 +96,6 @@ class MyProcess implements MessageComponentInterface
|
|||||||
if (preg_match("/^[a-zA-Z0-9-_ ]+$/", $msg) !== 1) {
|
if (preg_match("/^[a-zA-Z0-9-_ ]+$/", $msg) !== 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$from->send('alert:Started searching...');
|
|
||||||
$client = $this->clients->offsetGet($from);
|
$client = $this->clients->offsetGet($from);
|
||||||
// If a previous request was received, we execute the new one with another client for simplicity otherwise with current file deletion approach, we can't tell the worker `search.py` that we don't care about its execution anymore.
|
// If a previous request was received, we execute the new one with another client for simplicity otherwise with current file deletion approach, we can't tell the worker `search.py` that we don't care about its execution anymore.
|
||||||
if ($client->pid !== null) {
|
if ($client->pid !== null) {
|
||||||
@ -138,7 +137,6 @@ class MyProcess implements MessageComponentInterface
|
|||||||
} else {
|
} else {
|
||||||
// We don't need the periodic timer anymore, as the worker finished its work and acknowledged that `websocket.php` completely read its output.
|
// We don't need the periodic timer anymore, as the worker finished its work and acknowledged that `websocket.php` completely read its output.
|
||||||
$this->loop->cancelTimer($client->timer);
|
$this->loop->cancelTimer($client->timer);
|
||||||
$from->send('alert:Search finished!');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user