add bootstrap CSS

This commit is contained in:
Davide Alberani 2019-08-16 20:54:49 +02:00
parent b318b9c46a
commit 54200ef718
6 changed files with 82 additions and 26 deletions

54
dist/index.html vendored
View file

@ -1,22 +1,52 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/static/css/iziToast.min.css"> <link rel="stylesheet" type="text/css" href="/static/css/iziToast.min.css">
<script src="/static/js/jquery-3.4.1.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/iziToast.min.js"></script> <script src="/static/js/iziToast.min.js"></script>
<script src="/static/js/httprint.js"></script> <script src="/static/js/httprint.js"></script>
<title>HTTPrint</title> <title>HTTPrint</title>
</head> </head>
<body> <body>
<h1>Upload a file to print</h1> <div class="container">
<div class="row">
File to print: <input id="upload-file" type="file" /> <div class="col-sm">
<br> <div class="jumbotron jumbotron-fluid">
<br> <div class="container">
Number of copies: <input id="copies" type="number" min="1" max="10" value="1" /> <h1 class="display-4">HTTPrint</h1>
<br> <p class="lead">Upload and print a file.</p>
<br> Instructions:
<button onClick="uploadFile();">print</button> <ol>
<li>Upload a file, select the number of copies and click the "print" button</li>
<li>Write down the code you will receive</li>
<li>head to the printer</li>
<li>insert the code in the touchpad</li>
</ol>
</div>
</div>
<div class="form-group">
<label for="upload-file">File to print</label>
<input id="upload-file" type="file" class="form-control-file">
</div>
<div class="form-group">
<label for="copies">Number of copies</label>
<input id="copies" type="number" min="1" max="10" value="1" class="form-control">
</div>
<button id="print-btn" class="btn-lg btn-primary">print</button>
</div>
</div>
</div>
<footer class="footer mt-auto py-3">
<div class="container">
<span class="text-muted">
HTTPrint <a href="https://github.com/alberanid/httprint">https://github.com/alberanid/httprint</a>
</span>
</div>
</footer>
</body> </body>
</html> </html>

7
dist/static/css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

7
dist/static/js/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,11 +1,11 @@
function uploadFile() { function uploadFile() {
let photo = document.getElementById("upload-file").files[0]; let photo = document.getElementById("upload-file").files[0];
let copies = document.getElementById('copies').value; let copies = document.getElementById("copies").value;
let formData = new FormData(); let formData = new FormData();
formData.append("file", photo); formData.append("file", photo);
formData.append("copies", copies); formData.append("copies", copies);
var uploadField = document.getElementById('upload-file'); var uploadField = document.getElementById("upload-file");
fetch("/api/upload", {method: "POST", body: formData}) fetch("/api/upload", {method: "POST", body: formData})
.then(function(response) { .then(function(response) {
return response.json(); return response.json();
@ -14,8 +14,8 @@ function uploadFile() {
if (reply && !reply.error) { if (reply && !reply.error) {
iziToast.success({ iziToast.success({
title: "DONE!", title: "DONE!",
message: reply.message, message: reply.message || "file sent to printer",
position: 'topCenter', position: "topCenter",
timeout: false, timeout: false,
closeOnEscape: true, closeOnEscape: true,
layout: 2 layout: 2
@ -23,20 +23,29 @@ function uploadFile() {
} else { } else {
iziToast.error({ iziToast.error({
title: "ERROR!", title: "ERROR!",
message: reply.message, message: reply.message || "unable to print file",
position: 'topCenter', position: "topCenter",
layout: 2 layout: 2
}); });
} }
uploadField.value = null; uploadField.value = null;
}) })
.catch(function(err) { .catch(function(err) {
console.log(err);
iziToast.error({ iziToast.error({
title: "ERROR!", title: "ERROR!",
message: "failed to send file", message: "failed to send file",
position: 'topCenter', position: "topCenter",
layout: 2 layout: 2
}); });
uploadField.value = null; uploadField.value = null;
}); });
} }
document.addEventListener("DOMContentLoaded", function(event) {
let pbutton = document.getElementById("print-btn");
pbutton.addEventListener("click", function(event) {
uploadFile();
});
});

2
dist/static/js/jquery-3.4.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -241,10 +241,11 @@ class UploadHandler(BaseHandler):
failure = True failure = True
out = out.decode('utf-8', errors='ignore') out = out.decode('utf-8', errors='ignore')
pages = int(re_pages.findall(out)[0]) pages = int(re_pages.findall(out)[0])
if pages * copies > self.cfg.max_pages and self.cfg.check_pdf_pages: if pages * copies > self.cfg.max_pages and self.cfg.check_pdf_pages and not failure:
self.build_error('too many pages to print (%d)' % (pages * copies)) self.build_error('too many pages to print (%d)' % (pages * copies))
failure = True failure = True
except Exception: except Exception:
if not failure:
self.build_error('unable to get PDF information') self.build_error('unable to get PDF information')
failure = True failure = True
pass pass