Browse Source

add bootstrap CSS

Davide Alberani 4 years ago
parent
commit
54200ef718

+ 46 - 16
dist/index.html

@@ -1,22 +1,52 @@
 <!DOCTYPE html>
-<html>
+<html lang="en">
 <head>
-    <meta charset="utf-8" />
-    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
-    <link rel="stylesheet" type="text/css" href="/static/css/iziToast.min.css">
-    <script src="/static/js/iziToast.min.js"></script>
-    <script src="/static/js/httprint.js"></script>
-    <title>HTTPrint</title>
+  <meta 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">
+  <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/httprint.js"></script>
+  <title>HTTPrint</title>
 </head>
 <body>
-    <h1>Upload a file to print</h1>
-
-    File to print: <input id="upload-file" type="file" />
-    <br>
-    <br>
-    Number of copies: <input id="copies" type="number" min="1" max="10" value="1" />
-    <br>
-    <br>
-    <button onClick="uploadFile();">print</button>
+  <div class="container">
+    <div class="row">
+      <div class="col-sm">
+        <div class="jumbotron jumbotron-fluid">
+          <div class="container">
+            <h1 class="display-4">HTTPrint</h1>
+            <p class="lead">Upload and print a file.</p>
+            Instructions:
+            <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>
 </html>

File diff suppressed because it is too large
+ 5 - 0
dist/static/css/bootstrap.min.css


File diff suppressed because it is too large
+ 5 - 0
dist/static/js/bootstrap.min.js


+ 16 - 7
dist/static/js/httprint.js

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

File diff suppressed because it is too large
+ 1 - 0
dist/static/js/jquery-3.4.1.min.js


+ 4 - 3
httprint.py

@@ -241,12 +241,13 @@ class UploadHandler(BaseHandler):
                     failure = True
                 out = out.decode('utf-8', errors='ignore')
                 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))
                     failure = True
             except Exception:
-                self.build_error('unable to get PDF information')
-                failure = True
+                if not failure:
+                    self.build_error('unable to get PDF information')
+                    failure = True
                 pass
         if failure:
             for fn in glob.glob(pname + '*'):

Some files were not shown because too many files changed in this diff