add toast for succes and failed upload

This commit is contained in:
Niklas Müller 2024-03-11 10:56:29 +01:00
parent 10456d984e
commit 8f7008c910
6 changed files with 64 additions and 2 deletions

View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-square" viewBox="0 0 16 16">
<path d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/>
<path d="M10.97 4.97a.75.75 0 0 1 1.071 1.05l-3.992 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425z"/>
</svg>

After

Width:  |  Height:  |  Size: 433 B

4
static/img/x-square.svg Normal file
View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-square" viewBox="0 0 16 16">
<path d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2z"/>
<path d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708"/>
</svg>

After

Width:  |  Height:  |  Size: 491 B

View File

@ -75,9 +75,17 @@ const vueInstance = new Vue({
});
// eslint-disable-next-line no-unused-vars
dropzone.on('complete', (file, xhr, formData) => {
dropzone.on('success', (file, xhr, formData) => {
pdf_uploaded = true;
document.getElementById('btn-group-download').style.display = 'flex';
// eslint-disable-next-line no-undef
bootstrap.Toast.getOrCreateInstance(document.getElementById('success-upload-toast')).show();
});
// eslint-disable-next-line no-unused-vars
dropzone.on('error', (file, xhr, formData) => {
// eslint-disable-next-line no-undef
bootstrap.Toast.getOrCreateInstance(document.getElementById('warn-upload-toast')).show();
});
},
},

View File

@ -151,6 +151,14 @@ const vueInstance = new Vue({
pdf_uploaded = true;
document.getElementById('btn-group-download').style.display = 'flex';
this.display_pages();
// eslint-disable-next-line no-undef
bootstrap.Toast.getOrCreateInstance(document.getElementById('success-upload-toast')).show();
});
// eslint-disable-next-line no-unused-vars
dropzone.on('error', (file, xhr, formData) => {
// eslint-disable-next-line no-undef
bootstrap.Toast.getOrCreateInstance(document.getElementById('warn-upload-toast')).show();
});
},
},

View File

@ -75,9 +75,17 @@ const vueInstance = new Vue({
});
// eslint-disable-next-line no-unused-vars
dropzone.on('complete', (file, xhr, formData) => {
dropzone.on('success', (file, xhr, formData) => {
pdf_uploaded = true;
document.getElementById('btn-group-download').style.display = 'flex';
// eslint-disable-next-line no-undef
bootstrap.Toast.getOrCreateInstance(document.getElementById('success-upload-toast')).show();
});
// eslint-disable-next-line no-unused-vars
dropzone.on('error', (file, xhr, formData) => {
// eslint-disable-next-line no-undef
bootstrap.Toast.getOrCreateInstance(document.getElementById('warn-upload-toast')).show();
});
},
},

View File

@ -67,5 +67,35 @@
</footer>
<script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
<!-- Toasts -->
<div class="toast-container position-fixed top-0 end-0 p-3">
<!-- Success uploading PDF -->
<div id="success-upload-toast" class="toast text-bg-success" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="{{ url_for('static', filename='img/check-square.svg') }}" class="rounded me-2" alt="Success">
<strong class="me-auto">Upload Success</strong>
<small></small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
The File was successfully uploaded.
</div>
</div>
<!-- Warning uploading PDF -->
<div id="warn-upload-toast" class="toast text-bg-warning" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<img src="{{ url_for('static', filename='img/x-square.svg') }}" class="rounded me-2" alt="Success">
<strong class="me-auto">Upload Failed</strong>
<small></small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
There was a problem uploading the file. Please reload the page and try again.
</div>
</div>
</div>
<div class="toast-container position-fixed top-0 end-0 p-3">
</div>
</body>
</html>