Implement correct pause state
This commit is contained in:
@ -74,6 +74,9 @@
|
||||
display: inline-block;
|
||||
width: 5em;
|
||||
}
|
||||
.paused {
|
||||
color: #ffa500;
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
body {
|
||||
padding: 10px;
|
||||
@ -120,7 +123,11 @@
|
||||
<a href="/progress?filename={{$filename}}">{{$filename}}</a>
|
||||
</div>
|
||||
<div class="job-info">
|
||||
Progress: <span class="progress-text">{{printf "%5.1f%%" $info.Percentage}}</span> Current file: {{$info.CurrentFile}}
|
||||
Progress: <span class="progress-text">{{printf "%5.1f%%" $info.Percentage}}</span>
|
||||
Current file: {{$info.CurrentFile}}
|
||||
{{if $info.Paused}}
|
||||
<span class="paused">(Paused)</span>
|
||||
{{end}}
|
||||
</div>
|
||||
</li>
|
||||
{{else}}
|
||||
|
@ -127,10 +127,12 @@
|
||||
<div>
|
||||
<button id="abort-button" onclick="abortDownload()">Abort Download</button>
|
||||
<button id="pause-button" onclick="pauseDownload()">Pause Download</button>
|
||||
<button id="resume-button" onclick="resumeDownload()">Resume Download</button>
|
||||
<button id="resume-button" onclick="resumeDownload()" style="display: none;">Resume Download</button>
|
||||
<button id="back-button" onclick="window.location.href='/'">Back to Index</button>
|
||||
</div>
|
||||
<script>
|
||||
let isPaused = false;
|
||||
|
||||
function updateProgress() {
|
||||
fetch('/progress?filename={{.Filename}}', {
|
||||
headers: {
|
||||
@ -143,12 +145,25 @@
|
||||
document.getElementById('progress-bar').style.width = progress + '%';
|
||||
document.getElementById('progress-text').innerText = progress + '%';
|
||||
document.getElementById('currentFile').innerText = 'Current file: ' + (data.CurrentFile || 'None');
|
||||
if (progress < 100) {
|
||||
|
||||
isPaused = data.Paused;
|
||||
updatePauseResumeButtons();
|
||||
|
||||
if (progress < 100 && !isPaused) {
|
||||
setTimeout(updateProgress, 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
updateProgress();
|
||||
|
||||
function updatePauseResumeButtons() {
|
||||
if (isPaused) {
|
||||
document.getElementById('pause-button').style.display = 'none';
|
||||
document.getElementById('resume-button').style.display = 'inline-block';
|
||||
} else {
|
||||
document.getElementById('pause-button').style.display = 'inline-block';
|
||||
document.getElementById('resume-button').style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function abortDownload() {
|
||||
fetch('/abort?filename={{.Filename}}', { method: 'POST' })
|
||||
@ -166,8 +181,8 @@
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
console.log('Pause signal sent. The download will pause soon.');
|
||||
document.getElementById('pause-button').style.display = 'none';
|
||||
document.getElementById('resume-button').style.display = 'inline-block';
|
||||
isPaused = true;
|
||||
updatePauseResumeButtons();
|
||||
} else {
|
||||
alert('Failed to pause the download.');
|
||||
}
|
||||
@ -179,13 +194,16 @@
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
console.log('Resume signal sent. The download will resume soon.');
|
||||
document.getElementById('resume-button').style.display = 'none';
|
||||
document.getElementById('pause-button').style.display = 'inline-block';
|
||||
isPaused = false;
|
||||
updatePauseResumeButtons();
|
||||
updateProgress();
|
||||
} else {
|
||||
alert('Failed to resume the download.');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateProgress();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user