nightly - 2025-09-25
This commit is contained in:
@@ -1,9 +1,25 @@
|
||||
<script>
|
||||
import { browser } from "$app/environment";
|
||||
import hotkeys from "hotkeys-js";
|
||||
|
||||
let {
|
||||
prefix,
|
||||
pagerForm = $bindable(),
|
||||
functions
|
||||
} = $props()
|
||||
|
||||
if (browser) {
|
||||
hotkeys.filter = function(event) {return true}
|
||||
hotkeys('alt+n', function(event) {event.preventDefault(); functions.nextPage(); return false});
|
||||
hotkeys('alt+b', function(event) {event.preventDefault(); functions.prevPage(); return false});
|
||||
hotkeys('alt+j', function(event) {event.preventDefault(); functions.duplicateDown(); return false});
|
||||
hotkeys('alt+u', function(event) {event.preventDefault(); functions.duplicateUp(); return false});
|
||||
hotkeys('alt+l', function(event) {event.preventDefault(); functions.gotoNext(); return false});
|
||||
hotkeys('alt+o', function(event) {event.preventDefault(); functions.gotoPrev(); return false});
|
||||
hotkeys('alt+c', function(event) {event.preventDefault(); functions.copy(); return false});
|
||||
hotkeys('alt+v', function(event) {event.preventDefault(); functions.paste(); return false});
|
||||
hotkeys('alt+s', function(event) {event.preventDefault(); functions.saveAll(); return false});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div id="formheader" class="{prefix.color}">
|
||||
@@ -15,21 +31,21 @@
|
||||
<button class="styled" onclick={functions.refreshPage}>Refresh</button>
|
||||
</div>
|
||||
<div class="flex-row">
|
||||
<button class="styled" tabindex="-1" onclick={functions.prevPage}>Prev Page</button>
|
||||
<button class="styled" tabindex="-1" onclick={functions.nextPage}>Next Page</button>
|
||||
<button class="styled" title="Alt + B" tabindex="-1" onclick={functions.prevPage}>Prev Page</button>
|
||||
<button class="styled" title="Alt + N" tabindex="-1" onclick={functions.nextPage}>Next Page</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-row-space tb-margin">
|
||||
<div class="flex-row">
|
||||
<button class="styled" tabindex="-1" onclick={functions.duplicateDown}>Duplicate Down</button>
|
||||
<button class="styled" tabindex="-1" onclick={functions.duplicateUp}>Duplicate Up</button>
|
||||
<button class="styled" tabindex="-1" onclick={functions.gotoNext}>Next</button>
|
||||
<button class="styled" tabindex="-1" onclick={functions.gotoPrev}>Previous</button>
|
||||
<button class="styled" tabindex="-1" onclick={functions.copy}>Copy</button>
|
||||
<button class="styled" tabindex="-1" onclick={functions.paste}>Paste</button>
|
||||
<button class="styled" title="Alt + J" tabindex="-1" onclick={functions.duplicateDown}>Duplicate Down</button>
|
||||
<button class="styled" title="Alt + U" tabindex="-1" onclick={functions.duplicateUp}>Duplicate Up</button>
|
||||
<button class="styled" title="Alt + L" tabindex="-1" onclick={functions.gotoNext}>Next</button>
|
||||
<button class="styled" title="Alt + O" tabindex="-1" onclick={functions.gotoPrev}>Previous</button>
|
||||
<button class="styled" title="Alt + C" tabindex="-1" onclick={functions.copy}>Copy</button>
|
||||
<button class="styled" title="Alt + V" tabindex="-1" onclick={functions.paste}>Paste</button>
|
||||
</div>
|
||||
<div class="flex-row">
|
||||
<button class="styled" tabindex="-1" onclick={functions.saveAll}>Save All</button>
|
||||
<button class="styled" title="Alt + S" tabindex="-1" onclick={functions.saveAll}>Save All</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
43
webapp/src/routes/api/baskets/+server.js
Normal file
43
webapp/src/routes/api/baskets/+server.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import { env } from "$env/dynamic/private";
|
||||
import { db } from "$lib/server/db";
|
||||
import { baskets } from "$lib/server/db/schema";
|
||||
|
||||
export async function GET() {
|
||||
if (env.TAM3_REMOTE) {
|
||||
const res = await fetch(`${env.TAM3_REMOTE}/api/baskets/?api_key=${env.TAM3_REMOTE_KEY}`);
|
||||
if (!res.ok) {
|
||||
return new Response(JSON.stringify({"detail": "Unable to fetch Baskets"}), {status: res.status, statusText: res.statusText})
|
||||
};
|
||||
const data = await res.json();
|
||||
return new Response(JSON.stringify(data), {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
status: 200,
|
||||
statusText: "Baskets fetched successfully."
|
||||
})
|
||||
} else {
|
||||
const data = await db.select().from(baskets);
|
||||
return new Response(JSON.stringify(data), {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
status: 200,
|
||||
statusText: "Baskets loaded successfully."
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST({ request }) {
|
||||
const i_baskets = await request.json();
|
||||
for (let basket of i_baskets) {
|
||||
await db.insert(baskets).values({prefix: basket.prefix, b_id: basket.b_id, description: basket.description, donors: basket.donors, winning_ticket: basket.winning_ticket})
|
||||
.onConflictDoUpdate({target: [baskets.prefix, baskets.b_id], set: {description: basket.description, donors: basket.donors, winning_ticket: basket.winning_ticket}})
|
||||
};
|
||||
if (env.TAM3_REMOTE) {
|
||||
const res = await fetch(`${env.TAM3_REMOTE}/api/baskets/?api_key=${env.TAM3_REMOTE_KEY}`, {
|
||||
body: JSON.stringify([...i_baskets]), method: 'POST', headers: {'Content-Type': 'application/json'}
|
||||
});
|
||||
if (!res.ok) {
|
||||
return new Response(JSON.stringify({details: "Issue posting baskets to remote."}), {status: res.status, statusText: res.statusText})
|
||||
};
|
||||
const data = await res.json();
|
||||
};
|
||||
return new Response(JSON.stringify({details: "Posted baskets successfully."}), {status: 200, statusText: "Posted baskets successfully."})
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { env } from "$env/dynamic/private";
|
||||
import { db } from "$lib/server/db";
|
||||
import { baskets } from "$lib/server/db/schema";
|
||||
import { eq, and } from "drizzle-orm";
|
||||
|
||||
export async function GET({ params }) {
|
||||
let n_b_from = parseInt(params.b_from), n_b_to = parseInt(params.b_to);
|
||||
if (env.TAM3_REMOTE) {
|
||||
const res = await fetch(`${env.TAM3_REMOTE}/api/baskets/${n_b_from}/${n_b_to}/?api_key=${env.TAM3_REMOTE_KEY}`);
|
||||
if (!res.ok) {
|
||||
return new Response(JSON.stringify({detail: "Unable to fetch baskets"}), {status: res.status, statusText: res.statusText});
|
||||
};
|
||||
const data = await res.json();
|
||||
return new Response(JSON.stringify(data), {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
status: 200,
|
||||
statusText: "Baskets fetched successfully"
|
||||
})
|
||||
} else {
|
||||
let r_dict = {};
|
||||
for (let i=n_b_from; i <= n_b_to; i++) {
|
||||
let data = await db.select().from(baskets).where(and(eq(baskets.prefix, params.prefix), eq(baskets.b_id, i)));
|
||||
if (data[0]) {
|
||||
r_dict[i] = {...data[0]};
|
||||
} else {
|
||||
r_dict[i] = {prefix: params.prefix, b_id: i, description: "", donors: "", winning_ticket: 0, changed: false};
|
||||
}
|
||||
};
|
||||
return new Response(JSON.stringify(Object.values(r_dict)), {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
status: 200,
|
||||
statusText: "Baskets loaded successfully."
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ export async function GET() {
|
||||
|
||||
export async function POST({ request }) {
|
||||
const { name, color, weight } = await request.json();
|
||||
console.log({name, color, weight})
|
||||
await db.insert(prefixes).values({name: name, color: color, weight: weight}).onConflictDoUpdate({target: prefixes.name, set: {color: color, weight: weight}});
|
||||
if (env.TAM3_REMOTE) {
|
||||
const res = await fetch(`${env.TAM3_REMOTE}/api/prefixes/?api_key=${env.TAM3_REMOTE_KEY}`, {
|
||||
|
||||
6
webapp/src/routes/baskets/[prefix]/+page.js
Normal file
6
webapp/src/routes/baskets/[prefix]/+page.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export async function load({ fetch, params }) {
|
||||
const { prefix } = await params;
|
||||
const res = await fetch(`/api/prefixes/${prefix}`);
|
||||
const prefix_data = await res.json();
|
||||
return {prefix: prefix_data}
|
||||
}
|
||||
141
webapp/src/routes/baskets/[prefix]/+page.svelte
Normal file
141
webapp/src/routes/baskets/[prefix]/+page.svelte
Normal file
@@ -0,0 +1,141 @@
|
||||
<script>
|
||||
import { browser } from '$app/environment';
|
||||
import FormHeader from '$lib/components/FormHeader.svelte';
|
||||
import hotkeys from 'hotkeys-js';
|
||||
|
||||
const { data } = $props();
|
||||
const prefix = {...data.prefix};
|
||||
let pagerForm = $state({id_from: 0, id_to: 0});
|
||||
let current_idx = $state(0);
|
||||
let current_baskets = $state([]);
|
||||
let copy_buffer = $state({prefix: prefix.name, b_id: 0, description: "", donors: "", winning_ticket: 0});
|
||||
|
||||
function changeFocus(idx) {
|
||||
const focusDe = document.getElementById(`${idx}_de`);
|
||||
if (focusDe) {
|
||||
focusDe.focus();
|
||||
}
|
||||
}
|
||||
|
||||
const functions = {
|
||||
refreshPage: async () => {
|
||||
if (current_baskets.length > 0) {
|
||||
functions.saveAll()
|
||||
}
|
||||
const res = await fetch(`/api/baskets/${prefix.name}/${pagerForm.id_from}/${pagerForm.id_to}`);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
current_baskets = [...data];
|
||||
setTimeout(() => changeFocus(0), 100)
|
||||
}
|
||||
},
|
||||
prevPage: () => {
|
||||
const diff = current_baskets.length;
|
||||
pagerForm.id_from = pagerForm.id_from - diff;
|
||||
pagerForm.id_to = pagerForm.id_to - diff;
|
||||
functions.refreshPage();
|
||||
},
|
||||
nextPage: () => {
|
||||
const diff = current_baskets.length;
|
||||
pagerForm.id_from = pagerForm.id_from + diff;
|
||||
pagerForm.id_to = pagerForm.id_to + diff;
|
||||
functions.refreshPage();
|
||||
},
|
||||
duplicateDown: () => {
|
||||
const next_idx = current_idx + 1;
|
||||
if (current_baskets[next_idx]) {
|
||||
current_baskets[next_idx] = {...current_baskets[current_idx], b_id: current_baskets[next_idx].b_id, changed: true};
|
||||
changeFocus(next_idx);
|
||||
} else {
|
||||
changeFocus(next_idx);
|
||||
}
|
||||
},
|
||||
duplicateUp: () => {
|
||||
const prev_idx = current_idx - 1;
|
||||
if (prev_idx >= 0) {
|
||||
current_baskets[prev_idx] = {...current_baskets[current_idx], b_id: current_baskets[prev_idx].b_id, changed: true};
|
||||
changeFocus(prev_idx);
|
||||
} else {
|
||||
changeFocus(prev_idx);
|
||||
}
|
||||
},
|
||||
gotoNext: () => {
|
||||
const next_idx = current_idx + 1;
|
||||
if (current_baskets[next_idx]) {
|
||||
changeFocus(next_idx);
|
||||
} else {
|
||||
changeFocus(current_idx);
|
||||
}
|
||||
},
|
||||
gotoPrev: () => {
|
||||
const prev_idx = current_idx - 1;
|
||||
if (prev_idx >= 0) {
|
||||
changeFocus(prev_idx);
|
||||
} else {
|
||||
changeFocus(current_idx);
|
||||
}
|
||||
},
|
||||
copy: () => {
|
||||
copy_buffer = {...current_baskets[current_idx]};
|
||||
},
|
||||
paste: () => {
|
||||
current_baskets[current_idx] = {...copy_buffer, b_id: current_baskets[current_idx].b_id, changed: true}
|
||||
},
|
||||
saveAll: async () => {
|
||||
const to_save = current_baskets.filter((basket) => basket.changed === true);
|
||||
const res = await fetch(`/api/baskets`, {body: JSON.stringify(to_save), method: 'POST', headers: {'Content-Type': 'application/json'}});
|
||||
if (res.ok) {
|
||||
for (let basket of current_baskets) {basket.changed = false};
|
||||
changeFocus(0);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (browser) {
|
||||
document.title = `${prefix.name} Basket Entry`
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1>{prefix.name} Basket Entry</h1>
|
||||
<FormHeader {prefix} {functions} bind:pagerForm />
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 12ch">Basket ID</th>
|
||||
<th>Description</th>
|
||||
<th>Donors</th>
|
||||
<th>Changed</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each current_baskets as basket, idx}
|
||||
<tr onfocusin={() => current_idx = idx}>
|
||||
<td>{basket.b_id}</td>
|
||||
<td><input type="text" id="{idx}_de" onchange={() => basket.changed = true} bind:value={basket.description}></td>
|
||||
<td><input type="text" id="{idx}_do" onchange={() => basket.changed = true} bind:value={basket.donors}></td>
|
||||
<td><button tabindex="-1" onclick={() => basket.changed = !basket.changed}>{basket.changed ? "Y" : "N"}</button></td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<style>
|
||||
table {
|
||||
width: 100%;
|
||||
th {
|
||||
text-align: left;
|
||||
}
|
||||
tbody tr:nth-child(2n) {
|
||||
background-color: #eeeeee;
|
||||
}
|
||||
input {
|
||||
background: transparent;
|
||||
border: solid 1px #000000;
|
||||
}
|
||||
input, button {
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,7 +1,6 @@
|
||||
<script>
|
||||
import { browser } from '$app/environment';
|
||||
import FormHeader from '$lib/components/FormHeader.svelte';
|
||||
import hotkeys from 'hotkeys-js';
|
||||
|
||||
const { data } = $props();
|
||||
let prefix = {...data.prefix};
|
||||
@@ -30,13 +29,13 @@
|
||||
};
|
||||
},
|
||||
prevPage: () => {
|
||||
const diff = pagerForm.id_to - pagerForm.id_from + 1;
|
||||
const diff = current_tickets.length;
|
||||
pagerForm.id_from = pagerForm.id_from - diff;
|
||||
pagerForm.id_to = pagerForm.id_to - diff;
|
||||
functions.refreshPage()
|
||||
},
|
||||
nextPage: () => {
|
||||
const diff = pagerForm.id_to - pagerForm.id_from + 1;
|
||||
const diff = current_tickets.length;
|
||||
pagerForm.id_from = pagerForm.id_from + diff;
|
||||
pagerForm.id_to = pagerForm.id_to + diff;
|
||||
functions.refreshPage()
|
||||
@@ -87,7 +86,7 @@
|
||||
const to_save = current_tickets.filter((ticket) => ticket.changed === true);
|
||||
const res = await fetch(`/api/tickets`, {body: JSON.stringify(to_save), method: 'POST', headers: {'Content-Type': 'application/json'}});
|
||||
if (res.ok) {
|
||||
current_tickets.map((ticket) => ticket.changed = false);
|
||||
for (let ticket of current_tickets) {ticket.changed = false};
|
||||
changeFocus(0);
|
||||
}
|
||||
}
|
||||
@@ -95,16 +94,6 @@
|
||||
|
||||
if (browser) {
|
||||
document.title = `${prefix.name} Ticket Entry`
|
||||
hotkeys.filter = function(event) {return true}
|
||||
hotkeys('alt+n', function(event) {event.preventDefault(); functions.nextPage(); return false});
|
||||
hotkeys('alt+b', function(event) {event.preventDefault(); functions.prevPage(); return false});
|
||||
hotkeys('alt+j', function(event) {event.preventDefault(); functions.duplicateDown(); return false});
|
||||
hotkeys('alt+u', function(event) {event.preventDefault(); functions.duplicateUp(); return false});
|
||||
hotkeys('alt+l', function(event) {event.preventDefault(); functions.gotoNext(); return false});
|
||||
hotkeys('alt+o', function(event) {event.preventDefault(); functions.gotoPrev(); return false});
|
||||
hotkeys('alt+c', function(event) {event.preventDefault(); functions.copy(); return false});
|
||||
hotkeys('alt+v', function(event) {event.preventDefault(); functions.paste(); return false});
|
||||
hotkeys('alt+s', function(event) {event.preventDefault(); functions.saveAll(); return false});
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user