Compare commits

...

10 commits

Author SHA1 Message Date
Bianca Fürstenau
9e49770b99 Ignore secret 2025-03-05 02:04:26 +01:00
Bianca Fürstenau
185fd938c1 Refactor a bit 2025-03-05 00:34:23 +01:00
Bianca Fürstenau
f18a360982 Move tauri-sys to proper repo 2025-03-04 16:44:41 +01:00
Bianca Fürstenau
99f20ae465 Run instructions 2025-02-26 11:34:11 +01:00
Bianca Fürstenau
18814f18e0 Add Cash 2025-02-26 07:28:13 +01:00
Bianca Fürstenau
8a25a5fa82 Lotsa Leptos 2025-02-22 16:00:00 +01:00
Bianca Fürstenau
49a9810fd8 Something running 2025-02-22 07:09:34 +01:00
Bianca Fürstenau
e03a16d13e Minimal Leptos setup 2025-02-21 22:30:20 +01:00
Bianca Fürstenau
1e77a7d831 Wrap swap 2025-02-21 22:29:31 +01:00
Bianca Fürstenau
16abbc83f1 Add some setup instructions 2025-02-20 09:48:38 +01:00
33 changed files with 1670 additions and 691 deletions

7
.gitignore vendored
View file

@ -9,3 +9,10 @@ gen/
# Generated by `cargo tauri icon`
# will have various versions of the app icon
icons/
# Generated by Trunk
# will have the files to be served over http
www/
# Secret
src/server/cloud_user.txt

1352
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,28 +5,44 @@ description = "Buchhaltung für „Darmstadt sagt Nein zur Bezahlkarte!“"
authors = ["Bianca Fürstenau"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
tauri = ["server"]
leptos = []
server = [
"dep:tauri",
"dep:tauri-plugin-opener",
"dep:tauri-plugin-fs",
"dep:rusqlite",
"dep:rand",
"dep:chrono",
"dep:tokio",
"dep:curl",
"dep:openssl",
"dep:ring-compat",
]
[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "bkbh_lib"
name = "bkbh"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
leptos = { version = "^0.7", features = ["csr"] }
leptos_router = { version = "^0.7" }
tauri-sys = { git = "ssh://git@gitea.mathebau.de:3022/Peter/tauri-sys.git", branch = "v2", features = ["core"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
rusqlite = {version = "^0.33", features = ["backup", "bundled"] }
rand = {version = "^0.8"}
chrono = {version = "^0.4"}
tokio = {version = "^1.43"}
tauri-plugin-fs = {version = "2"}
curl = {version = "^0.4"}
openssl = {version = "^0.10", features = ["vendored"] }
ring-compat = {version = "^0.8", features = ["signature", "rand_core"] }
serde_json = { version = "1" }
tauri = { version = "2", features = [], optional = true }
tauri-plugin-opener = { version = "2", optional = true }
tauri-plugin-fs = {version = "2", optional = true}
rusqlite = {version = "^0.33", features = ["backup", "bundled"], optional = true }
rand = {version = "^0.8", optional = true}
chrono = {version = "^0.4", optional = true}
tokio = {version = "^1.43", optional = true}
curl = {version = "^0.4", optional = true}
openssl = {version = "^0.10", features = ["vendored"], optional = true}
ring-compat = {version = "^0.8", features = ["signature", "rand_core"], optional = true}
console_error_panic_hook = {version = "0.1.7"}

35
README.md Normal file
View file

@ -0,0 +1,35 @@
# Setup
```bash
git clone …
cargo tauri android init
git restore gen/android/app/build.gradle.kts
cargo tauri img/icon.svg
# Set up gen/android/keystore.properties
```
# Run
## Linux Development
Tauri does not seem to support
specifying the binary
to be run in a config,
so we have to do it
on the command line.
```bash
cargo tauri dev -- --bin tauri
```
## Android Development
Tauri does not seem to support
specifying the Cargo features
of the library for mobile
in a config,
so we have to do it
on the command line.
```bash
NDK_HOME=<path> ANDROID_HOME=<path> cargo tauri android dev --features tauri
```

9
Trunk.toml Normal file
View file

@ -0,0 +1,9 @@
[build]
target = "trunk.html"
html_output = "index.html"
dist = "www"
[serve]
port = 1420
open = false
ws_protocol = "ws"

View file

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 7 KiB

After

Width:  |  Height:  |  Size: 7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

Before After
Before After

View file

@ -1,3 +1,7 @@
fn main() {
tauri_build::build()
if cfg!(feature = "tauri") {
tauri_build::build();
} else {
println!("cargo::rustc-check-cfg=cfg(mobile)");
}
}

9
src/bin/leptos.rs Normal file
View file

@ -0,0 +1,9 @@
use leptos::prelude::*;
use bkbh::leptos::cafe::Cafe;
fn main() {
console_error_panic_hook::set_once();
leptos::mount::mount_to_body(
|| view! { <Cafe /> }
);
}

View file

@ -2,5 +2,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
bkbh_lib::run()
bkbh::run()
}

23
src/commands.rs Normal file
View file

@ -0,0 +1,23 @@
use tauri_sys::Error;
use tauri_sys::core::invoke;
use crate::types::*;
use std::collections::HashMap;
#[derive(serde::Serialize)]
pub struct Swap {
store: Store,
acc: i64,
}
pub async fn swap(store: Store, acc: i64) -> Result<(), Error> {
let args = Swap { store, acc };
invoke("swap", &args).await
}
#[derive(serde::Serialize)]
pub struct Inventory {
data: HashMap<String, String>,
}
pub async fn inventory(data: HashMap<String, String>) -> Result<(), Error> {
let args = Inventory { data };
invoke("inventory", &args).await
}

184
src/leptos/cafe.rs Normal file
View file

@ -0,0 +1,184 @@
use leptos::prelude::*;
use crate::commands::*;
use leptos::task::spawn_local;
use leptos::web_sys::FormData;
use leptos::form::FromFormData;
use std::collections::HashMap;
use crate::types::*;
#[component]
pub fn Cafe() -> impl IntoView {
view! {
<SwapButton
store=Store::Aldi
/>
<div
id="cafe-inventory"
>
<InvForm />
</div>
}
}
#[component]
fn StoreLogo(store: Store) -> impl IntoView {
view! {
<img
src=format!("assets/{}.svg", Into::<String>::into(&store))
class="logo"
// FIXME: Implement fmt trait for Store
alt=format!("{:?}", store)
/>
}
}
#[component]
fn SwapButton(store: Store) -> impl IntoView {
view! {
<button
on:click=move |_| {
spawn_local(async move {
swap(store, 0).await.unwrap();
});
}
class="column"
>
<StoreLogo store=store />
</button>
}
}
#[component]
fn StoreInput(store: Store) -> impl IntoView {
let txt = format!("{}", Into::<String>::into(&store));
view! {
<div
class="labelled-input"
>
<label
for=txt.clone()
>
<StoreLogo store=store />
</label>
<input
type="number"
name=txt.clone()
id=txt.clone()
min=0
/>
</div>
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
struct Cash(i64);
impl std::str::FromStr for Cash {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
let split: Vec<&str> = s.split(".").collect();
let i = i64::from_str(split.get(0).ok_or(())?)
.map_err(|e| println!("{:?}", e))?;
let f = match split.get(1) {
None => 0,
Some(fs) => i64::from_str(
&format!("00{}", fs)[0..2]
)
.map_err(|e| println!("{:?}", e))?,
};
Ok(Cash(i*100+f))
}
}
#[component]
fn CashInput(value: RwSignal<String>) -> impl IntoView {
let txt = "cash";
view! {
<div
class="labelled-input"
>
<label
for=txt.clone()
>
<img
src="assets/cash.svg"
class="logo"
alt="Bargeld"
/>
</label>
<input
type="number"
name=txt.clone()
id=txt.clone()
min=0
step=0.01
bind:value=value
on:change=move |_| {
println!("{:?}", value.get());
}
/>
</div>
}
}
#[component]
fn AccRadio(acc: Account) -> impl IntoView {
let txt = format!("{}", Into::<String>::into(&acc));
let id = format!("acc-{}", txt);
view! {
<div
class="labelled-input"
>
<input
type="radio"
name="acc"
id=id.clone()
value=txt
required
/>
<label
for=id.clone()
>
// FIXME: Implement fmt trait for Account
{format!("{:?}", acc)}
</label>
</div>
}
}
#[component]
fn SubmitButton() -> impl IntoView {
view! {
<button
type="submit"
class="shout"
>
"Senden"
</button>
}
}
#[component]
fn InvForm() -> impl IntoView {
let cash = RwSignal::new(String::from("0.00"));
view! {
<form
on:submit=move |ev| {
ev.prevent_default();
let data = FromFormData::from_event(ev.as_ref()).unwrap();
spawn_local(async move {inventory(data).await;});
}
>
<AccRadio acc=Account::Sumpf />
<AccRadio acc=Account::Heinersyndikat />
<StoreInput store=Store::Aldi />
<StoreInput store=Store::Dm />
<StoreInput store=Store::Lidl />
<StoreInput store=Store::Rewe />
<StoreInput store=Store::Tegut />
<CashInput value=cash />
<SubmitButton />
</form>
}
}

1
src/leptos/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod cafe;

View file

@ -1,184 +1,18 @@
use chrono::offset::Utc;
use rusqlite::{types::ToSqlOutput, ToSql};
use tauri::{Manager, State};
use tauri_plugin_fs::FsExt;
use tokio::sync::Mutex;
use std::collections::HashMap;
mod app_state;
mod data_door;
use app_state::AppState;
#[derive(Clone, Copy, Debug)]
enum Store {
Aldi,
Edeka,
Dm,
Lidl,
Rewe,
Tegut,
}
#[derive(Clone, Copy, Debug)]
enum Account {
Sumpf,
Heinersyndikat,
}
struct Inventory {
acc: Account,
cash: i64,
vouchers: Vec<VoucherInventory>,
}
#[derive(Debug)]
struct VoucherInventory {
store: Store,
count: i64,
}
impl TryFrom<&str> for Store {
type Error = ();
fn try_from(s: &str) -> Result<Self, Self::Error> {
match s {
"aldi" => Ok(Store::Aldi),
"edeka" => Ok(Store::Edeka),
"dm" => Ok(Store::Dm),
"lidl" => Ok(Store::Lidl),
"rewe" => Ok(Store::Rewe),
"tegut" => Ok(Store::Tegut),
_ => Err(()),
}
}
}
impl TryFrom<&str> for Account {
type Error = ();
fn try_from(s: &str) -> Result<Self, Self::Error> {
match s {
"sumpf" => Ok(Account::Sumpf),
"hs" => Ok(Account::Heinersyndikat),
_ => Err(()),
}
}
}
impl ToSql for Store {
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
match self {
Store::Aldi => 0.to_sql(),
Store::Edeka => 1.to_sql(),
Store::Dm => 2.to_sql(),
Store::Lidl => 3.to_sql(),
Store::Rewe => 4.to_sql(),
Store::Tegut => 5.to_sql(),
}
}
}
impl ToSql for Account {
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
match self {
Account::Sumpf => 0.to_sql(),
Account::Heinersyndikat => 1.to_sql(),
}
}
}
fn parse_inventory(data: HashMap<String, String>) -> Result<Inventory, ()> {
let a = data.get("cafe-inventory-acc").ok_or(())?;
let acc: Account = Account::try_from(a.as_ref())?;
let mut vouchers = Vec::new();
for s in ["aldi", "dm", "lidl", "rewe", "tegut"] {
let Ok(store) = s.try_into() else {
println!("Did not find '{}' in inventory data.", s);
continue;
};
match data.get(&format!("cafe-inventory-{}", s)) {
None => (),
Some(c) => {
let c = if c == "" {"0"} else {c};
let Ok(count) = c.parse() else {
println!("Invalid count '{}' for '{}' in inventory data.", c, s);
continue;
};
let v = VoucherInventory { store, count };
vouchers.push(v);
},
}
}
unimplemented!()
}
#[tauri::command]
async fn inventory(
data: HashMap<String, String>,
state: State<'_, Mutex<AppState>>,
) -> Result<(), ()> {
let now = Utc::now().timestamp();
let state = state.lock().await;
let inv = parse_inventory(data)?;
for v in inv.vouchers {
state.db.execute(
"INSERT INTO voucher_inventory VALUES ()",
(
inv.acc,
v.store,
v.count,
now,
),
)
.map_err(|e| println!("{:?}", e))?;
};
Ok(())
}
#[tauri::command]
async fn swap(
store: &str,
acc: i64,
state: State<'_, Mutex<AppState>>,
) -> Result<(), ()> {
let state = state.lock().await;
let store: Store = store.try_into()?;
state.db.execute(
"INSERT INTO swap VALUES (?1, ?2, ?3, ?4, ?5)",
(
store,
acc,
i64::from_ne_bytes(state.id.to_ne_bytes()),
Utc::now().timestamp(),
false,
),
)
.map_err(|e| println!("{:?}", e))?;
Ok(())
}
#[tauri::command]
async fn count(state: State<'_, Mutex<AppState>>) -> Result<String, ()> {
let state = state.lock().await;
let mut stmt =
state.db.prepare("SELECT COUNT(*) FROM swap")
.map_err(|e| println!("{:?}", e))?;
let mut rows = stmt.query([]).map_err(|e| println!("{:?}", e))?;
let row = rows.next().map_err(|e| println!("{:?}", e))?;
let row = match row {
Some(r) => Ok(r),
None => {
println!("No rows");
Err(())
}
}?;
let cnt: u64 = row.get(0).map_err(|e| println!("{:?}", e))?;
Ok(cnt.to_string())
}
pub mod commands;
#[cfg(feature = "server")]
pub mod server;
#[cfg(feature = "leptos")]
pub mod leptos;
pub mod types;
#[cfg(all(feature = "tauri", feature="server"))]
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
use tauri::{Manager, State};
use tauri_plugin_fs::FsExt;
use server::app_state::AppState;
use tokio::sync::Mutex;
let state = AppState::new();
tauri::Builder::default()
.plugin(tauri_plugin_fs::init())
@ -190,11 +24,11 @@ pub fn run() {
Ok(())
})
.invoke_handler(tauri::generate_handler![
swap,
count,
inventory,
data_door::pull_data,
data_door::push_data,
server::swap,
server::count,
server::inventory,
server::data_door::pull_data,
server::data_door::push_data,
])
.run(tauri::generate_context!())
.expect("error while running tauri application");

View file

@ -6,7 +6,7 @@ use ring_compat::signature::ed25519::SigningKey;
use tauri::{Manager, State};
use tokio::sync::Mutex;
use crate::app_state::AppState;
use crate::server::app_state::AppState;
#[derive(Debug)]
struct Collector(Vec<u8>, Vec<u8>, usize);

100
src/server/mod.rs Normal file
View file

@ -0,0 +1,100 @@
use chrono::offset::Utc;
use std::collections::HashMap;
use tokio::sync::Mutex;
use tauri::State;
use crate::types::*;
pub mod app_state;
pub mod data_door;
use app_state::AppState;
fn parse_inventory(data: HashMap<String, String>) -> Result<Inventory, ()> {
let a = data.get("cafe-inventory-acc").ok_or(())?;
let acc: Account = Account::try_from(a.as_ref())?;
let mut vouchers = Vec::new();
for s in ["aldi", "dm", "lidl", "rewe", "tegut"] {
let Ok(store) = s.try_into() else {
println!("Did not find '{}' in inventory data.", s);
continue;
};
match data.get(&format!("cafe-inventory-{}", s)) {
None => (),
Some(c) => {
let c = if c == "" {"0"} else {c};
let Ok(count) = c.parse() else {
println!("Invalid count '{}' for '{}' in inventory data.", c, s);
continue;
};
let v = VoucherInventory { store, count };
vouchers.push(v);
},
}
}
unimplemented!()
}
#[tauri::command]
pub async fn inventory(
data: HashMap<String, String>,
state: State<'_, Mutex<AppState>>,
) -> Result<(), ()> {
println!("{:?}", data);
let now = Utc::now().timestamp();
let state = state.lock().await;
let inv = parse_inventory(data)?;
for v in inv.vouchers {
state.db.execute(
"INSERT INTO voucher_inventory VALUES ()",
(
inv.acc,
v.store,
v.count,
now,
),
)
.map_err(|e| println!("{:?}", e))?;
};
Ok(())
}
#[tauri::command]
pub async fn swap(
store: Store,
acc: i64,
state: State<'_, Mutex<AppState>>,
) -> Result<(), ()> {
let state = state.lock().await;
state.db.execute(
"INSERT INTO swap VALUES (?1, ?2, ?3, ?4, ?5)",
(
store,
acc,
i64::from_ne_bytes(state.id.to_ne_bytes()),
Utc::now().timestamp(),
false,
),
)
.map_err(|e| println!("{:?}", e))?;
Ok(())
}
#[tauri::command]
pub async fn count(state: State<'_, Mutex<AppState>>) -> Result<String, ()> {
let state = state.lock().await;
let mut stmt =
state.db.prepare("SELECT COUNT(*) FROM swap")
.map_err(|e| println!("{:?}", e))?;
let mut rows = stmt.query([]).map_err(|e| println!("{:?}", e))?;
let row = rows.next().map_err(|e| println!("{:?}", e))?;
let row = match row {
Some(r) => Ok(r),
None => {
println!("No rows");
Err(())
}
}?;
let cnt: u64 = row.get(0).map_err(|e| println!("{:?}", e))?;
Ok(cnt.to_string())
}

106
src/types.rs Normal file
View file

@ -0,0 +1,106 @@
#[cfg(feature = "server")]
use rusqlite::{types::ToSqlOutput, ToSql};
use serde::{Serialize, Deserialize};
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum Store {
Aldi,
Edeka,
Dm,
Lidl,
Rewe,
Tegut,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum Account {
Sumpf,
Heinersyndikat,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Inventory {
pub acc: Account,
pub cash: i64,
pub vouchers: Vec<VoucherInventory>,
}
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub struct VoucherInventory {
pub store: Store,
pub count: i64,
}
impl Into<String> for &Store {
fn into(self) -> String {
String::from(match *self {
Store::Aldi => "aldi",
Store::Edeka => "edeka",
Store::Dm => "dm",
Store::Lidl => "lidl",
Store::Rewe => "rewe",
Store::Tegut => "tegut",
})
}
}
impl TryFrom<&str> for Store {
type Error = ();
fn try_from(s: &str) -> Result<Self, Self::Error> {
match s {
"aldi" => Ok(Store::Aldi),
"edeka" => Ok(Store::Edeka),
"dm" => Ok(Store::Dm),
"lidl" => Ok(Store::Lidl),
"rewe" => Ok(Store::Rewe),
"tegut" => Ok(Store::Tegut),
_ => Err(()),
}
}
}
impl TryFrom<&str> for Account {
type Error = ();
fn try_from(s: &str) -> Result<Self, Self::Error> {
match s {
"sumpf" => Ok(Account::Sumpf),
"hs" => Ok(Account::Heinersyndikat),
_ => Err(()),
}
}
}
impl Into<String> for &Account {
fn into(self) -> String {
String::from(match *self {
Account::Sumpf => "sumpf",
Account::Heinersyndikat => "hs",
})
}
}
#[cfg(feature = "server")]
impl ToSql for Store {
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
match self {
Store::Aldi => 0.to_sql(),
Store::Edeka => 1.to_sql(),
Store::Dm => 2.to_sql(),
Store::Lidl => 3.to_sql(),
Store::Rewe => 4.to_sql(),
Store::Tegut => 5.to_sql(),
}
}
}
#[cfg(feature = "server")]
impl ToSql for Account {
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput<'_>> {
match self {
Account::Sumpf => 0.to_sql(),
Account::Heinersyndikat => 1.to_sql(),
}
}
}

View file

@ -106,7 +106,8 @@ input[type=number] {
}
input[type=radio] {
height: 60%;
width: 100%;
height: 7mm;
}
button:hover {

View file

@ -4,7 +4,11 @@
"version": "0.1.0",
"identifier": "de.mathebau.bkbh",
"build": {
"frontendDist": "www"
"beforeDevCommand": "cd bkbh && trunk serve",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "cd bkbh && trunk build",
"frontendDist": "www",
"features": ["tauri"]
},
"app": {
"withGlobalTauri": true,

13
trunk.html Normal file
View file

@ -0,0 +1,13 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<link data-trunk rel="scss" href="styles.scss" />
<link data-trunk rel="copy-dir" href="assets" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Darmstadt sagt Nein zur Bezahlkartei!</title>
<link data-trunk rel="rust" href="." data-bin="leptos" data-cargo-features="leptos" data-wasm-opt="4" data-weak-refs />
</head>
<body>
</body>
</html>

View file

@ -1,188 +0,0 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="styles.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Darmstadt sagt Nein zur Bezahlkartei!</title>
<script type="module" src="main.js" defer></script>
</head>
<body>
<div class="v-container" id="cafe" style="display: none">
<div id="cafe-voucher" style="display: none">
<h1 class="shout">
Sumpf
</h1>
<div class="h-container">
<form class="column" id="cafe-voucher-aldi">
<button type="submit">
<img
src="assets/aldi.svg"
class="logo"
alt="ALDI-Süd-Logo"
/>
</button>
</form>
<form class="column" id="cafe-voucher-dm">
<button type="submit">
<img
src="assets/dm.svg"
class="logo"
alt="dm-Logo"
/>
</button>
</form>
<form class="column" id="cafe-voucher-lidl">
<button type="submit">
<img
src="assets/lidl.svg"
class="logo"
alt="Lidl-Logo"
/>
</button>
</form>
<form class="column" id="cafe-voucher-rewe">
<button type="submit">
<img
src="assets/rewe.svg"
class="logo"
alt="Rewe-Logo"
/>
</button>
</form>
<form class="column" id="cafe-voucher-tegut">
<button type="submit">
<img
src="assets/tegut.svg"
class="logo"
alt="Tegut-Logo"
/>
</button>
</form>
</div>
</div>
<div id="cafe-inventory" style="display: none">
<form>
<div style="display: contents">
<div class="labelled-input">
<input type="radio" id="cafe-inventory-acc-sumpf" name="cafe-inventory-acc" value="sumpf" required>
<label for="cafe-inventory-acc-sumpf">Sumpf</label>
</div>
<div class="labelled-input">
<input type="radio" id="cafe-inventory-acc-hs" name="cafe-inventory-acc" value="hs" required>
<label for="cafe-inventory-acc-hs">Heinersyndikat</label>
</div>
</div>
<div style="display: contents">
<div class="labelled-input" id="cafe-inventory-aldi">
<label for="cafe-inventory-aldi">
<img
src="assets/aldi.svg"
class="logo"
alt="ALDI-Süd-Logo"
/>
</label>
<input type="number" name="cafe-inventory-aldi" min="0">
</div>
<div class="labelled-input" id="cafe-inventory-dm">
<label for="cafe-inventory-dm">
<img
src="assets/dm.svg"
class="logo"
alt="dm-Logo"
/>
</label>
<input type="number" name="cafe-inventory-dm" min="0">
</div>
<div class="labelled-input" id="cafe-inventory-lidl">
<label for="cafe-inventory-lidl">
<img
src="assets/lidl.svg"
class="logo"
alt="Lidl-Logo"
/>
</label>
<input type="number" name="cafe-inventory-lidl" min="0">
</div>
<div class="labelled-input" id="cafe-inventory-rewe">
<label for="cafe-inventory-rewe">
<img
src="assets/rewe.svg"
class="logo"
alt="Rewe-Logo"
/>
</label>
<input type="number" name="cafe-inventory-rewe" min="0">
</div>
<div class="labelled-input" id="cafe-inventory-tegut">
<label for="cafe-inventory-tegut">
<img
src="assets/tegut.svg"
class="logo"
alt="Tegut-Logo"
/>
</label>
<input type="number" name="cafe-inventory-tegut" min="0">
</div>
</div>
<div class="labelled-input" id="cafe-inventory-cash">
<label for="cafe-inventory-cash">
<img
src="assets/cash.svg"
class="logo"
alt="Bargeld"
/>
</label>
<input type="number" name="cafe-inventory-cash" min="0" step=".01">
</div>
<button type="submit" class="shout">
Senden
</button>
</form>
</div>
<div class="v-container nav" id="cafe-nav">
<form id="cafe-nav-inventory">
<button type="submit">
<span class="shout">
Bestand
</span>
</button>
</form>
<form id="cafe-nav-voucher">
<button type="submit">
<span class="shout">
Annahme
</span>
</button>
</form>
</div>
</div>
<div id="angel">
<div>
<form class="h-container">
</form>
</div>
</div>
<div class="v-container nav" id="nav">
<form class="column" id="nav-cafe">
<button type="submit">
<img
src="assets/cafe.svg"
class="logo"
alt="Tauschcafé"
/>
</button>
</form>
<form class="column" id="nav-angel">
<button type="submit">
<img
src="assets/angel.svg"
class="logo"
alt="Botengang"
/>
</button>
</form>
</div>
</body>
</html>

View file

@ -1,67 +0,0 @@
const { invoke } = window.__TAURI__.core;
let callbacks = {
'#nav-cafe': () => activate("", "cafe", ["angel"]),
'#nav-angel': () => activate("", "angel", ["cafe"]),
'#cafe-nav-inventory': () => activate("cafe-", "inventory", ["voucher"]),
'#cafe-nav-voucher': () => activate("cafe-", "voucher", ["inventory"]),
'#cafe-inventory form': () => inventory(),
'#cafe-voucher-aldi': () => swap("aldi"),
'#cafe-voucher-dm': () => swap("dm"),
'#cafe-voucher-lidl': () => swap("lidl"),
'#cafe-voucher-rewe': () => swap("rewe"),
'#cafe-voucher-tegut': () => swap("tegut"),
}
let stores = [
"aldi",
"dm",
"lidl",
"rewe",
"tegut",
]
async function increment(el) {
var el = document.querySelector(el+" input");
let v = parseInt(el.value, 10);
v = isNaN(v) ? 0 : v;
v++;
el.value = v;
}
async function inventory() {
const form = document.querySelector("#cafe-inventory form");
const fd = new FormData(form);
const obj = Object.fromEntries(fd);
await invoke("inventory", { data: obj });
}
async function swap(s) {
await invoke("swap", { store: s, acc: 1 });
document.querySelector("h1").textContent = await invoke("count", {});
}
async function activate(ctx, el, nels) {
document.querySelector("#"+ctx+el).style.display = "";
for (const nel of nels) {
document.querySelector("#"+ctx+nel).style.display = "none";
}
document.querySelector("#"+ctx+"nav").classList.remove("v-container");
document.querySelector("#"+ctx+"nav").classList.add("h-container");
}
window.addEventListener("DOMContentLoaded", () => {
for (let key in callbacks) {
if (callbacks.hasOwnProperty(key)) {
document.querySelector(key).addEventListener("submit", (e) => {
e.preventDefault();
callbacks[key]();
});
}
}
for (const store of stores) {
document.querySelector("#cafe-inventory-"+store+" label").addEventListener("click", (e) => {
e.preventDefault();
increment("#cafe-inventory-"+store);
});
}
});