1
0
Fork 0

Clean up templates and add a neat little spinner

This commit is contained in:
Sebastian Schulze 2022-03-23 22:34:47 +01:00
parent 0609defed6
commit ba52751672
Signed by: bascht
GPG key ID: 5BCB1D3B4D38A35A
4 changed files with 51 additions and 18 deletions

View file

@ -6,7 +6,7 @@ import (
"strings"
)
func Process(basedir string, document *Document) string {
func Process(basedir string, document *Document) {
// time.Sleep(5 * time.Second)
fmt.Println("STARTING SCAN OF "+document.Name+" with %v to "+basedir, document.Args())
@ -25,6 +25,7 @@ func Process(basedir string, document *Document) string {
commands = append(commands, Command{Name: "convert", Args: []string{"-verbose", filepath.Join(basedir, document.FullName() + "*tif"), filepath.Join(basedir, document.FullName()+"_input.pdf")}})
commands = append(commands, Command{Name: "convert", Args: []string{"-verbose", filepath.Join(basedir, document.FullName() + "-1.tif"), filepath.Join(basedir, "downloads", document.FullName()+".thumbnail.jpg")}})
commands = append(commands, Command{Name: "ocrmypdf", Args: []string{"--language=deu", filepath.Join(basedir, document.FullName()+"_input.pdf"), filepath.Join(basedir, "downloads", document.FullName()+".pdf")}})
commands = append(commands, Command{Name: "cp", Args: []string{filepath.Join(basedir, "downloads", document.FullName()+".pdf"), "/mnt/himbeerkompott/home/bascht/Documents/Scans"}})
<- document.Events
document.Events <- Event{Message: "Geht los", Type: "info"}
@ -43,10 +44,15 @@ func Process(basedir string, document *Document) string {
// done <- true
}()
command.Wait()
if command.cmd.ProcessState.ExitCode() != 0 {
document.Events <- Event{Message: "The command did not run successfully :-(", Type: "error" }
close(document.Events)
return
}
}
document.Events <- Event{Message: "Starting to copy", Type: "info"}
document.Events <- Event{Message: "Scan finished successfully", Type: "done" }
// // Open original file
// original, err := os.Open(filepath.Join(basedir, document.FullNameWithExtension()))
// if err != nil {
@ -73,5 +79,4 @@ func Process(basedir string, document *Document) string {
// fmt.Printf("Bytes Written: %d\n", bytesWritten)
close(document.Events)
return filepath.Join(basedir, document.FullNameWithExtension())
}

View file

@ -10,7 +10,7 @@
<body>
<div class="container">
<h1><a href="/scan/">Scan</a></h1>
<h1><a href="/scan/">🍓Scanberry</a></h1>
{{embed}}
</div>

View file

@ -1,6 +1,4 @@
<h3><a href="/downloads/{{ .FullNameWithExtension }}">{{ .FullNameWithExtension }}</a></h3>
<img src="/downloads/{{ .FullName }}.thumbnail.jpg">
<a href="/downloads/{{ .FullNameWithExtension }}">{{.FullNameWithExtension}}</a>
<a href="/scan">
Zurück
</a>
<a href="/scan"> Back </a>

View file

@ -1,9 +1,34 @@
<style>
.show {
transition: opacity 400ms;
display: show;
}
.hide {
opacity: 0;
display: none;
}
.loading {
display: flex;
justify-content: center;
}
/* https://dev.to/dcodeyt/how-to-create-a-css-only-loading-spinner-5fh5 */
.loading::after {
content: "";
width: 20px;
height: 20px;
border: 5px solid #dddddd;
border-top-color: #0076d1;
border-radius: 50%;
animation: loading 1s ease infinite;
}
@keyframes loading {
to {
transform: rotate(1turn);
}
}
</style>
<script type="text/javascript">
@ -39,22 +64,27 @@
eventList.appendChild(newElement);
}
}
if (event.data == "stopped") {
showStatus("done")
document.getElementById("spinner").remove()
evtSource.close();
}
});
});
</script>
<h3>Status {{ .full_name }}</h3>
<div class="hide status" data-name="waiting"></div>
<div class="hide status" data-name="done"></div>
<div class="hide status" data-name="scanimage">📃</div>
<div class="hide status" data-name="ocrmypdf">👀</div>
<pre id="list"></pre>
<div style="float: right" id="spinner" class="loading loading--full-height"></div>
<div class="hide status" data-name="waiting">⌛ Processing</div>
<div class="hide status" data-name="convert">⌛ Converting</div>
<div class="hide status" data-name="done">✅ Scan was successful</div>
<div class="hide status" data-name="scanimage">📃 Scanning the document</div>
<div class="hide status" data-name="ocrmypdf">👀 Running OCR</div>
<div class="hide status" data-name="error">❌ Scan failed, please check the log</div>
<details>
<summary>Detailed log output</summary>
<pre id="list"></pre>
</details>
<a href="/show/{{ .id }}" class="hide status" data-name="done">{{.FullNameWithExtension}}</a>
<a href="/scan">
Zurück
</a>
<hr>
<a href="/scan">Back</a>