- Du hast am {$inventory.at(-1).timestamp} auf deinem aktuellen Gerät eine Inventur gestartet.
+ Du hast am {$inventory.at(-1).inventoryStartedAt} auf deinem aktuellen Gerät eine Inventur gestartet.
Klicke oben rechts auf Reset, wenn du deinen Fortschritt löschen möchtest.
diff --git a/src/lib/List.svelte b/src/components/List.svelte
similarity index 93%
rename from src/lib/List.svelte
rename to src/components/List.svelte
index 7910830..b7a375f 100644
--- a/src/lib/List.svelte
+++ b/src/components/List.svelte
@@ -6,12 +6,12 @@
import Drink from "./Drink.svelte";
import Info from "./Info.svelte";
import { activeCategory, drinks, inventory } from "../stores/inventory.js";
- import inventoryApi from "../stores/api";
+ import inventoryApi from "../lib/api";
$: filteredDrinks = $drinks.filter(drink => drink.type == $activeCategory);
onMount(async () => {
- $inventory = await inventoryApi.load();
+ $inventory = await inventoryApi.load("drinks");
})
diff --git a/src/lib/Navbar.svelte b/src/components/Navbar.svelte
similarity index 100%
rename from src/lib/Navbar.svelte
rename to src/components/Navbar.svelte
diff --git a/src/lib/Success.svelte b/src/components/Success.svelte
similarity index 100%
rename from src/lib/Success.svelte
rename to src/components/Success.svelte
diff --git a/src/lib/api.ts b/src/lib/api.ts
new file mode 100644
index 0000000..94cb571
--- /dev/null
+++ b/src/lib/api.ts
@@ -0,0 +1,60 @@
+const backendProtocol = "http"
+const backendHost = "localhost"
+const backendPort = "8151"
+const backendEndpoint = "drinks"
+
+export default class inventoryApi {
+ static async save(key: string, value: any) {
+ localStorage.setItem(key, JSON.stringify(value));
+ }
+
+ static async load(key: string) {
+ return JSON.parse(localStorage.getItem(key) || "[]");
+ }
+
+ static async reset() {
+ localStorage.removeItem("drinks")
+ window.location.reload();
+ }
+
+ static async sendResultToBackend(inventory: any, name: string, comment: string) {
+ let result = {
+ inventory: inventory,
+ name: name,
+ comment: comment,
+ timestamp: await inventoryApi.createTimestamp()
+ }
+
+ try {
+ await fetch(backendProtocol+"://"+backendHost+":"+backendPort+"/"+backendEndpoint, {
+ method: "POST",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify(result),
+ })
+ } catch(err) {
+ console.log(err)
+ alert("Ergebnis konnte nicht abgeschickt werden. Check mal die Dev-Console und/oder gib bitte kurz in der Gastro-Gruppe Bescheid...")
+ }
+ }
+
+ static async createTimestamp() {
+ let _unixTime = Date.now();
+ let _date = new Date(_unixTime).toLocaleDateString();
+ let _time = new Date(_unixTime).toLocaleTimeString();
+
+ return _date + " um " + _time
+ }
+
+ static async saveNameAndComment(name: string, comment: string) {
+ let performingPerson = {
+ name: name,
+ comment: comment
+ }
+
+ inventoryApi.save("performingPerson", performingPerson)
+ }
+
+}
\ No newline at end of file
diff --git a/src/stores/api.js b/src/stores/api.js
deleted file mode 100644
index 73fed81..0000000
--- a/src/stores/api.js
+++ /dev/null
@@ -1,14 +0,0 @@
-export default class inventoryApi {
- static async save(drinks) {
- localStorage.setItem("drinks", JSON.stringify(drinks));
- }
-
- static async load() {
- return JSON.parse(localStorage.getItem("drinks") || "[]");
- }
-
- static async reset() {
- localStorage.removeItem("drinks");
- window.location.reload();
- }
-}
\ No newline at end of file
diff --git a/src/stores/inventory.js b/src/stores/inventory.ts
similarity index 100%
rename from src/stores/inventory.js
rename to src/stores/inventory.ts