Skip to content

Commit

Permalink
beheben mehrerer kleiner Fehler
Browse files Browse the repository at this point in the history
  • Loading branch information
hmt committed Feb 25, 2020
1 parent 175c644 commit 4491aa2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/components/Autocomplete.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
const key = e => {
if (e.key === "ArrowDown") selected += 1;
else if (e.key === "ArrowUp") selected -= 1;
else if (e.key === "Enter") {
else if (e.key === "Enter" && selected >= 0) {
show_selected(res[selected]);
return;
} else return;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Einstellungen.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let datensatz_schueler = "",
datensatz_medien = "",
datensatz_sonstige = {nichtschueler: 1},
datensatz_sonstige = {nichtschueler: 1, memo: ''},
warten;
const update_sonstige = () => {
Expand Down Expand Up @@ -37,11 +37,11 @@
const jahr = values[0].jahr
const schueler_values = Object.values(schueler)
.map(
a => `(${a[0]}, ${a[1]}, "${a[2]}", "${a[3]}", "${a[4]}")`
a => `(${a[0]}, ${a[1]}, '${a[2]}', '${a[3]}', '${a[4]}')`
)
.join(",");
const kurszugehoerigkeit_values = values
.map(v => `(${v.id}, "${v.kurs_lehrer|''}", "${v.kurs||''}")`)
.map(v => `(${v.id}, '${v.kurs_lehrer||''}', '${v.kurs||''}')`)
.join(",");
const query = [
`DELETE FROM schueler WHERE NOT EXISTS ( SELECT * FROM ausleihe WHERE ausleihe.schueler_id = schueler.id)`,
Expand Down
9 changes: 4 additions & 5 deletions src/components/Medien.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import Scanner from "./Scanner.svelte";
import Medium from "./Medien.svelte";
import Medium from "./Medium.svelte";
import Schueler from "./Schueler.svelte";
import { view, db, print, medien } from "./../stores.js";
import { group_by } from "./../helpers.js";
Expand Down Expand Up @@ -55,7 +55,7 @@
}
let selected,
suche = "",
modal = false,
modal,
neuer_titel = "",
add = false;
Expand All @@ -79,7 +79,6 @@
};
const focus = node => node.focus();
update();
$: medien_filter = group_by(
$medien.filter(
m =>
Expand Down Expand Up @@ -136,8 +135,8 @@
{#each Object.entries(medien_filter) as [n, m], i}
<tr
class="pointer"
on:mouseover={() => (selected = n)}
on:click={() => (modal = true)}>
on:click={_=> modal = true}
on:mouseover={() => (selected = n)}>
<td>{m[0].medien_id}</td>
<td>{m[0].medien_name}</td>
<td>
Expand Down
1 change: 1 addition & 0 deletions src/components/Medium.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script>
console.log('Medium')
import { db } from "./../stores.js";
export let medium = [];
export let modal;
Expand Down
14 changes: 8 additions & 6 deletions src/components/Scanner.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script>
import { configData, db, scan_status } from "./../stores.js";
import { DontBubbleException } from './../exceptions.js'
import { onDestroy } from 'svelte';
import { onDestroy } from 'svelte';
import { focus } from './../helpers.js';
onDestroy(() => $scan_status = {})
export let scaninterface
Expand All @@ -26,7 +27,6 @@
}
if (event.key === 'Escape') {
barcode_manuell = !barcode_manuell
barcode_input = ''
}
if (
event.key === "Enter" &&
Expand Down Expand Up @@ -58,29 +58,30 @@
`
)
.get(barcode);
console.log(res);
console.log('Ergebnis Barcodesuche in DB: ', res || '– nichts gefunden –');
if (!res) {
try {
zuordnung(barcode);
console.log(e, "Medium zugeordnet");
} catch (e) {
medium = $db.prepare(`SELECT * FROM medienbezeichnung`).all();
registrieren = true
console.log(e, "Zuordnung ist hier nicht möglich, Medium registrieren");
console.log(e, "Barcode unbekannt; Medium registrieren");
return
}
} else if (res.ausleihe_id) {
try {
rueckgabe(res);
console.log(e, "Medium zurückgegeben");
} catch (e) {
if (e instanceof DontBubbleException) return
console.log(e, "Rückgabe ist hier nicht möglich");
}
} else {
try {
ausleihe(res);
console.log(e, "Medium ausgeliehen");
} catch (e) {
if (e instanceof DontBubbleException) return
console.log("Ausleihe ist hier nicht möglich");
}
}
try {
Expand Down Expand Up @@ -131,6 +132,7 @@
class="input"
type="text"
bind:value={barcode}
use:focus
on:keydown={e => {if (e.key === 'Enter') { barcode_manuell=false; scan()}}} />
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/Schueler.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import * as notifier from './../notifier.js'
import { view, schueler, db, medien, print } from './../stores.js';
import { group_by } from './../helpers.js'
function update () {
$medien = $db.prepare(`
SELECT a.*, x.*, m.*, a.id AS ausleihe_id
Expand Down
2 changes: 1 addition & 1 deletion src/getter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { schueler, db } from "./stores.js";
const res = get(db)
.prepare(
`
SELECT s.*, k.kurs, k.kurs_lehrer
SELECT DISTINCT s.*, k.kurs, k.kurs_lehrer
FROM kurszugehoerigkeit AS k
LEFT JOIN schueler AS s ON (k.schild_id = s.schild_id)
WHERE k.kurs = ? AND s.klasse = ? AND s.jahr = ?
Expand Down
28 changes: 16 additions & 12 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
export const group_by = (array, key) => {
return array.reduce((result, currentValue) => {
(result[currentValue[key]] = result[currentValue[key]] || []).push(
currentValue
);
return result;
}, {});
};
export const chunk = (arr, size) => arr.reduce((chunks, el, i) => (i % size
? chunks[chunks.length - 1].push(el)
: chunks.push([el])) && chunks, []
)
export const focus = node => node.focus();
export const group_by = (array, key) => {
return array.reduce((result, currentValue) => {
(result[currentValue[key]] = result[currentValue[key]] || []).push(
currentValue
);
return result;
}, {});
};
export const chunk = (arr, size) =>
arr.reduce(
(chunks, el, i) =>
(i % size ? chunks[chunks.length - 1].push(el) : chunks.push([el])) &&
chunks,
[]
);

0 comments on commit 4491aa2

Please sign in to comment.