3 Commits
Author SHA1 Message Date
kennyboy55 b8a20204c7 AI Changes: updated look, recently added, search bar, easy admin checkout
Build dev docker image / build (push) Successful in 36s
Build dev docker image / release (push) Successful in 1s
2026-07-31 21:12:57 +02:00
kennyboy55 4d191c448d Add gitea workflow 2026-07-31 20:30:47 +02:00
kennyboy55 45b655e2b4 Copy images instead of move to fix docker EXDEV error 2025-12-30 11:09:54 +01:00
32 changed files with 541 additions and 14042 deletions
+2 -1
View File
@@ -1,2 +1,3 @@
node_modules
npm-debug.log
npm-debug.log
.gitea/
+89
View File
@@ -0,0 +1,89 @@
name: Build dev docker image
on:
push:
branches:
- main
tags:
- '*'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout repository for build
- name: Checkout beer-inventory repository
uses: actions/checkout@v4
with:
ref: ${{ gitea.ref }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
# Install NPM packages
- name: Install NPM packages
run: npm ci
# Build project
- name: Build project
run: |
npx zenstack generate
npx remix vite:build
# Login to registry
- name: Gitea package registry login
run: |
echo "${{ secrets.ACCESS_TOKEN }}" | docker login gitea.furb.it \
-u "${{ secrets.USERNAME }}" \
--password-stdin
# Build image
- name: Build Docker image - gitea.furb.it/${{ gitea.repository }}:${{ gitea.ref_name }}
run: |
docker build \
-f Dockerfile \
--label beer-inventory.ref=${{ gitea.ref_name }} \
-t gitea.furb.it/${{ gitea.repository }}:${{ gitea.ref_name }} \
.
- name: Tag Docker image - gitea.furb.it/${{ gitea.repository }}:latest
if: startsWith(gitea.ref, 'refs/tags/')
run: |
docker image tag \
gitea.furb.it/${{ gitea.repository }}:${{ gitea.ref_name }} \
gitea.furb.it/${{ gitea.repository }}:latest
# Push images
- name: Push Docker image
run: |
docker push gitea.furb.it/${{ gitea.repository }}:${{ gitea.ref_name }}
- name: Push Docker image :latest
if: startsWith(gitea.ref, 'refs/tags/')
run: |
docker push gitea.furb.it/${{ gitea.repository }}:latest
release:
runs-on: ubuntu-latest
needs: build
if: startsWith(gitea.ref, 'refs/tags/')
steps:
# Create release using gitea-release-action
- name: Create release
uses: akkuman/gitea-release-action@v1
with:
server: "https://gitea.furb.it"
token: ${{ secrets.ACCESS_TOKEN }}
repository: ${{ gitea.repository }}
tag_name: ${{ gitea.ref_name }}
name: ${{ gitea.ref_name }}
body: |
"## Docker images"
"`gitea.furb.it/${{ gitea.repository }}:${{ gitea.ref_name }}`"
"`gitea.furb.it/${{ gitea.repository }}:latest`"
+20
View File
@@ -0,0 +1,20 @@
Beer-inventory project for home use.
Used technology:
- remix.run (now known as react router)
- prisma
- zenstack
Limitations:
- Dependencies cannot be updated
- Project needs to work locally without online dependencies
- Project needs to work with existing database
- The project is turned off when not in use, so needs to be started quickly when needed
Architecture:
- server-client together in the same file, as per remix-run
- react for frontend
- three levels
- user (can view the website on their phone)
- scanner (the physical raspberry pi with barcode scanner at the fridge)
- admin (me, the developer that can access and update everything)
+1 -1
View File
@@ -1,5 +1,5 @@
FROM node:22-alpine
MAINTAINER Kenneth van Ewijk (kennyboy55)
LABEL maintainer="Kenneth van Ewijk (kennyboy55)"
WORKDIR /usr/src/app
+55 -23
View File
@@ -7,6 +7,15 @@ interface Arguments {
drink: DrinkComposite
}
function toDate(value: Date | string | null | undefined): Date | null {
if (!value) {
return null;
}
const parsed = value instanceof Date ? value : new Date(value);
return Number.isNaN(parsed.getTime()) ? null : parsed;
}
function DrinkCard(arg:Arguments) {
var trimmedDescription = arg.drink.description.length > 120 ? arg.drink.description.substring(0, 120) + "..." : arg.drink.description;
var link = "/inventory/";
@@ -39,35 +48,58 @@ function DrinkCard(arg:Arguments) {
ibu = (<Badge bg={arg.drink.ibu > 45 ? "warning" : "secondary"}>IBU: {arg.drink.ibu}</Badge>);
}
var manufacturer = "";
if(isDrinkWithManufacturer(arg.drink)){
manufacturer = arg.drink.manufacturer.name + " (" + arg.drink.manufacturer.country_id + ")";
}
var inventory = "";
let inventoryNum = 0;
let latestActivity: Date | null = null;
if(isDrinkWithContainers(arg.drink)){
let inventoryNum = 0;
arg.drink.containers.map((container) => {
arg.drink.containers.forEach((container: { inventory: number; lastAdded?: Date | string | null }) => {
inventoryNum += container.inventory;
})
inventory = "Inventory: " + inventoryNum;
const candidate = toDate(container.lastAdded);
if (candidate && (!latestActivity || candidate.getTime() > latestActivity.getTime())) {
latestActivity = candidate;
}
});
}
const drinkAddedAt = toDate((arg.drink as { addedAt?: Date | string | null }).addedAt ?? null);
const latestTimestamp = drinkAddedAt && (!latestActivity || drinkAddedAt.getTime() > latestActivity.getTime())
? drinkAddedAt
: latestActivity;
const isNewlyAdded = latestTimestamp ? (Date.now() - latestTimestamp.getTime()) <= 30 * 24 * 60 * 60 * 1000 : false;
const isRecentlyRestocked = latestActivity ? (Date.now() - latestActivity.getTime()) <= 14 * 24 * 60 * 60 * 1000 : false;
return (
<Card key={arg.drink.slug} style={{ borderColor: `${borderColor}`, borderWidth: '2px' }} className='mb-2'>
<Card.Header className="text-muted">{manufacturer}</Card.Header>
<Card.Img variant="top" className='image-fluid' src={arg.drink.image ? arg.drink.image : ""} />
<Card.Body>
<Card.Title><Link to={link + arg.drink.slug.toString()} className='stretched-link text-reset text-decoration-none'>{arg.drink.name}</Link></Card.Title>
<Card.Text>
{trimmedDescription}
</Card.Text>
<Card key={arg.drink.slug} style={{ borderColor: `${borderColor}`, borderWidth: '2px' }} className='mb-2 h-100'>
<div style={{ position: 'relative', width: '100%', aspectRatio: '1 / 1', overflow: 'hidden' }}>
{ (isNewlyAdded || isRecentlyRestocked) ? (
<Badge
bg={isRecentlyRestocked ? "success" : "primary"}
className='position-absolute top-0 start-0 m-2 text-wrap'
style={{ zIndex: 2 }}
>
{isNewlyAdded && isRecentlyRestocked ? "New · Restocked" : isNewlyAdded ? "New" : "Recently added"}
</Badge>
) : null }
<Card.Img
variant="top"
className='image-fluid'
src={arg.drink.image ? arg.drink.image : ""}
style={{ width: '100%', height: '100%', objectFit: 'cover' }}
/>
</div>
<Card.Body className='d-flex flex-column justify-content-between py-3'>
<Card.Title className='h6 mb-2'><Link to={link + arg.drink.slug.toString()} className='stretched-link text-reset text-decoration-none'>{arg.drink.name}</Link></Card.Title>
<div className='d-flex flex-wrap gap-1 align-items-center'>
<Badge bg={arg.drink.abv > 0 ? "warning" : "secondary"} className='py-1'>ABV: {arg.drink.abv}%</Badge>
{style}
{ibu}
{arg.drink.sugar ? "" : <Badge bg="success" className='py-1'>Sugar-free</Badge>}
{arg.drink.gluten ? "" : <Badge bg="success" className='py-1'>Gluten-free</Badge>}
{arg.drink.organic ? <Badge bg="success" className='py-1'>Organic</Badge> : ""}
</div>
</Card.Body>
<ListGroup variant="flush">
<ListGroup.Item><Badge bg={arg.drink.abv > 0 ? "warning" : "secondary"}>ABV: {arg.drink.abv}%</Badge> {style} {ibu} {arg.drink.sugar ? "" : <Badge bg="success">Sugar-free</Badge>} {arg.drink.gluten ? "" : <Badge bg="success">Gluten-free</Badge>} {arg.drink.organic ? <Badge bg="success">Organic</Badge> : ""}</ListGroup.Item>
</ListGroup>
<Card.Footer className="text-muted">{inventory}</Card.Footer>
<Card.Footer className="text-center py-2">
<Badge bg="dark" className='px-3 py-2 fs-6'>Inventory: {inventoryNum}</Badge>
</Card.Footer>
</Card>
);
}
+4 -2
View File
@@ -53,7 +53,6 @@ function DrinkPage(arg:Arguments) {
}
})
}
var link = (<></>);
if(arg.drink.link){
var href = arg.drink.link;
@@ -184,7 +183,10 @@ function DrinkPage(arg:Arguments) {
{arg.isAdmin ? (
<>
<td>{container.price}</td>
<td><LinkContainer to={"/admin/edit/container/" + container.id}><Button variant='primary'>Edit</Button></LinkContainer></td>
<td>
<LinkContainer to={"/admin/edit/container/" + container.id}><Button variant='primary'>Edit</Button></LinkContainer>
<LinkContainer to={"/admin/manage/manual-checkout/" + container.id}><Button variant='secondary'>Checkout</Button></LinkContainer>
</td>
</>
) : ""}
</tr>
+33 -47
View File
@@ -2,9 +2,7 @@
import { useSubmit } from '@remix-run/react';
import { BeerStyle, Manufacturer, WineStyle } from '@zenstackhq/runtime/models';
import { useRef, useState } from 'react';
import { Form, Col, Row, Button } from 'react-bootstrap';
import ReactSlider from 'react-slider';
import { ManufacturerWithDrinks } from '~/models/types';
import { Form, Col, Row } from 'react-bootstrap';
interface Arguments {
beerStyles: BeerStyle[];
@@ -16,8 +14,6 @@ interface Arguments {
function DrinkFilter(arg : Arguments) {
const submit = useSubmit();
const [abv, setAbv] = useState({min: Number(arg.searchParams.get("min-abv") || 0), max: Number(arg.searchParams.get("max-abv") || 50)})
const [ibu, setIbu] = useState({min: Number(arg.searchParams.get("min-ibu") || 0), max: Number(arg.searchParams.get("max-ibu") || 150)})
const showBeerFilter = arg.searchParams.has("drink", "Beer");
const showWineFilter = arg.searchParams.has("drink", "Wine");
@@ -30,54 +26,48 @@ function DrinkFilter(arg : Arguments) {
setTimeout(() => submit(form.current), 10);
}
const sliderAbv = () =>
(<div>
<ReactSlider
className="form-range"
thumbClassName="bg-primary text-light rounded dummy"
trackClassName="bg-secondary h-100 rounded dummy"
min={0}
max={50}
defaultValue={[abv.min, abv.max]}
renderThumb={(props, state) => <div {...props}>{state.valueNow}%</div>}
pearling
minDistance={2}
onAfterChange={(number, index) => {setAbv({min: number[0], max: number[1]}); submitAfterRender()}}
/>
<input type="hidden" name="min-abv" value={abv.min} />
<input type="hidden" name="max-abv" value={abv.max} />
</div>);
const handleFormChange = (event: React.ChangeEvent<HTMLFormElement>) => {
const formData = new FormData(event.currentTarget);
const sliderIbu = () =>
(<div>
<ReactSlider
className="form-range"
thumbClassName="bg-primary text-light rounded dummy"
trackClassName="bg-secondary h-100 rounded dummy"
min={0}
max={150}
defaultValue={[ibu.min, ibu.max]}
renderThumb={(props, state) => <div {...props}>{state.valueNow}</div>}
pearling
minDistance={2}
onAfterChange={(number, index) => {setIbu({min: number[0], max: number[1]}); submitAfterRender()}}
/>
<input type="hidden" name="min-ibu" value={ibu.min} />
<input type="hidden" name="max-ibu" value={ibu.max} />
</div>);
if (formData.get("abv") === "all") {
formData.delete("abv");
}
submit(formData, { method: "get", replace: true });
}
const abvSelection = arg.searchParams.get("abv") || "all";
const abvOptions = [
{ value: "all", label: "All" },
{ value: "alcohol-free", label: "Alcohol free" },
{ value: "1-5", label: "1-5%" },
{ value: "5-10", label: "5-10%" },
{ value: "10-plus", label: "10% +" },
];
const abvOptionsMarkup = abvOptions.map((option) => (
<Form.Check
key={option.value}
id={"abv-" + option.value}
type="radio"
label={option.label}
name="abv"
value={option.value}
defaultChecked={abvSelection === option.value}
/>
));
const sortKey = arg.searchParams.get("sort") || "name";
return (
<Form noValidate method="GET" ref={form} className='pe-2' onChange={(event) => {submit(event.currentTarget); }}>
<Form noValidate method="GET" ref={form} className='pe-2' onChange={handleFormChange}>
<Row>
<Col>
<Form.Group controlId="sort" className='bg-body-secondary rounded p-3'>
<Form.Label className='fw-bold'>Sort</Form.Label>
{ [
["name", "Name"],
["new", "New"],
["popular", "Popularity"],
["abv-asc", "ABV Low -> High"],
["abv-desc", "ABV High -> Low"],
@@ -111,7 +101,7 @@ const sliderIbu = () =>
</Form.Group>
<Form.Group controlId="drink-abv" className='bg-body-secondary rounded p-3 mt-3'>
<Form.Label className='fw-bold'>ABV</Form.Label>
{sliderAbv()}
<div className='d-grid gap-2'>{abvOptionsMarkup}</div>
</Form.Group>
{/* <Form.Group controlId="manufacturer" className='bg-body-secondary rounded p-3 mt-3'>
<Form.Label className='fw-bold'>Manufacturer</Form.Label>
@@ -141,10 +131,6 @@ const sliderIbu = () =>
/>
))}
</Form.Group>
<Form.Group controlId="beer-ibu" className='bg-body-secondary rounded p-3 mt-3'>
<Form.Label className='fw-bold'>IBU</Form.Label>
{sliderIbu()}
</Form.Group>
</>
) : ""}
{ showWineFilter ? (
+39 -9
View File
@@ -8,9 +8,14 @@ export async function findDrinksFromSearch(searchParams: URLSearchParams) : Prom
const dbe = enhance(db);
var result : DrinkComposite[] = [];
var noDrinkSelected = searchParams.getAll("drink").length == 0;
let whereBase = {delegate_aux_drink: {AND: <any>[]}};
var noDrinkSelected = searchParams.getAll("drink").length == 0;
const searchQuery = searchParams.get("q")?.trim();
const searchClauses = searchQuery ? [
{ name: {contains: searchQuery, mode: "insensitive"} },
{ manufacturer: { name: {contains: searchQuery, mode: "insensitive"} } },
{ manufacturer: { country: { name: {contains: searchQuery, mode: "insensitive"} } } },
] : [];
let whereBase: any = {delegate_aux_drink: {AND: []}};
if(searchParams.has("sugar-free")){
whereBase.delegate_aux_drink.AND.push({NOT: {sugar: true}});
@@ -25,13 +30,18 @@ export async function findDrinksFromSearch(searchParams: URLSearchParams) : Prom
whereBase.delegate_aux_drink.AND.push({organic: true});
}
if(searchParams.has("min-abv")){
let minabv = Number(searchParams.get("min-abv"));
whereBase.delegate_aux_drink.AND.push({abv: {gte: minabv}});
const abvFilter = searchParams.get("abv");
if(abvFilter === "alcohol-free"){
whereBase.delegate_aux_drink.AND.push({abv: {lt: 1}});
}
if(searchParams.has("max-abv")){
let maxabv = Number(searchParams.get("max-abv"));
whereBase.delegate_aux_drink.AND.push({abv: {lte: maxabv}});
if(abvFilter === "1-5"){
whereBase.delegate_aux_drink.AND.push({abv: {gte: 1, lt: 5}});
}
if(abvFilter === "5-10"){
whereBase.delegate_aux_drink.AND.push({abv: {gte: 5, lt: 10}});
}
if(abvFilter === "10-plus"){
whereBase.delegate_aux_drink.AND.push({abv: {gte: 10}});
}
if(searchParams.has("manufacturer")){
@@ -49,6 +59,14 @@ export async function findDrinksFromSearch(searchParams: URLSearchParams) : Prom
let where = Object.assign({}, whereBase, {style: {}, OR: <any>[]});
if(searchQuery){
const beerSearchClauses = [...searchClauses];
if(searchParams.has("drink", "Beer")){
beerSearchClauses.push({ style: { name: {contains: searchQuery, mode: "insensitive"} } });
}
where.AND = [{ OR: beerSearchClauses }];
}
// Beer styles
if(searchParams.has("beerstyle")){
where.style = {id: {in: searchParams.getAll("beerstyle").map(Number)}};
@@ -81,6 +99,10 @@ export async function findDrinksFromSearch(searchParams: URLSearchParams) : Prom
let where = Object.assign({}, whereBase, {style: {}});
if(searchQuery){
where.AND = [{ OR: searchClauses }];
}
// Wine styles
if(searchParams.has("winestyle")){
where.style = {id: {in: searchParams.getAll("winestyle").map(Number)}};
@@ -96,6 +118,10 @@ export async function findDrinksFromSearch(searchParams: URLSearchParams) : Prom
let where = whereBase;
if(searchQuery){
where.AND = [{ OR: searchClauses }];
}
// Carbonated
if(searchParams.get("carbonated") == "1"){
where = Object.assign({}, whereBase, {carbonated: true});
@@ -113,6 +139,10 @@ export async function findDrinksFromSearch(searchParams: URLSearchParams) : Prom
if(searchParams.has("drink", "Cocktail") || noDrinkSelected){
let where = whereBase;
if(searchQuery){
where.AND = [{ OR: searchClauses }];
}
// Mix
if(searchParams.has("mix")){
where = Object.assign({}, whereBase, {mix: true});
+54
View File
@@ -0,0 +1,54 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { sortDrinksFromSearch } from './drinks.sort.server';
test('sorts drinks by newest activity when using the new sort option', () => {
const params = new URLSearchParams('sort=new');
const olderDrink = {
id: 1,
name: 'Zeta',
type: 'Beer',
abv: 5,
description: '',
slug: 'zeta',
manufacturer_id: 1,
image: null,
link: null,
gluten: false,
lactose: false,
organic: false,
sugar: true,
addedAt: new Date('2024-01-01T00:00:00.000Z'),
containers: [],
};
const newerDrink = {
id: 2,
name: 'Alpha',
type: 'Beer',
abv: 4.5,
description: '',
slug: 'alpha',
manufacturer_id: 1,
image: null,
link: null,
gluten: false,
lactose: false,
organic: false,
sugar: true,
addedAt: new Date('2024-02-01T00:00:00.000Z'),
containers: [
{
inventory: 3,
lastAdded: new Date('2024-03-01T00:00:00.000Z'),
},
],
};
const sorted = sortDrinksFromSearch(params, [olderDrink, newerDrink] as any);
assert.equal(sorted[0].id, 2);
assert.equal(sorted[1].id, 1);
});
+42
View File
@@ -1,5 +1,25 @@
import { DrinkComposite, isDrinkWithContainers, isDrinkWithContainersAndHistory } from "./types";
function getLatestActivityTimestamp(n: DrinkComposite): Date | null {
const drinkTimestamp = (n as { addedAt?: Date | null }).addedAt ?? null;
if (isDrinkWithContainers(n)) {
const containerTimestamps = n.containers
.map((container) => (container as { lastAdded?: Date | null }).lastAdded)
.filter((value): value is Date => value != null);
if (containerTimestamps.length > 0) {
const latestContainerTimestamp = containerTimestamps.reduce((latest, current) => current > latest ? current : latest, containerTimestamps[0]);
if (drinkTimestamp == null) {
return latestContainerTimestamp;
}
return drinkTimestamp > latestContainerTimestamp ? drinkTimestamp : latestContainerTimestamp;
}
}
return drinkTimestamp;
}
function sortName(n1:DrinkComposite, n2:DrinkComposite) : number{
if (n1.name > n2.name) {
return 1;
@@ -56,6 +76,24 @@ function sortPopularity(n1:DrinkComposite, n2:DrinkComposite) : number{
return totalPopularity(n2) - totalPopularity(n1);
}
function sortNewest(n1:DrinkComposite, n2:DrinkComposite) : number{
const left = getLatestActivityTimestamp(n1);
const right = getLatestActivityTimestamp(n2);
if (!left && !right) {
return 0;
}
if (!left) {
return 1;
}
if (!right) {
return -1;
}
return right.getTime() - left.getTime();
}
export function sortDrinksFromSearch(searchParams: URLSearchParams, searchResult: DrinkComposite[]) : DrinkComposite[] {
@@ -85,6 +123,10 @@ export function sortDrinksFromSearch(searchParams: URLSearchParams, searchResult
callback = sortPopularity;
}
if(searchParams.has("sort", "new")){
callback = sortNewest;
}
var sortedArray: DrinkComposite[] = searchResult.sort(callback);
return sortedArray;
+4
View File
@@ -29,6 +29,9 @@ export const action = async ({
const inventory = Number(form.get("inventory"));
try{
const currentContainer = await dbe.container.findUnique({where: {id: id}, select: {inventory: true, lastAdded: true}});
const shouldSetLastAdded = currentContainer != null && inventory > currentContainer.inventory;
const updatedContainer = await dbe.container.update({ data: {
barcode: barcode,
type: type,
@@ -36,6 +39,7 @@ export const action = async ({
portions: portions,
price: price,
inventory: inventory,
lastAdded: shouldSetLastAdded ? new Date() : currentContainer?.lastAdded ?? null,
//drink: {connect: {id: drink}},
section: {connect: {id: section}}
}, select: {drink: {select: {id: true, type: true}}},
+4 -3
View File
@@ -1,6 +1,6 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useLoaderData } from "@remix-run/react";
import { Container, Row, Button, Form, Image } from "react-bootstrap";
@@ -38,8 +38,9 @@ export const action = async ({
// Remove old image
if(beer.image) rmSync("public"+ beer.image, {force: true});
// Move the file to the beers folder with the slug as name
renameSync(image.getFilePath(), "public" + newFilename);
// Copy the file to the beers folder with the slug as name
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
await dbe.beer.update({data: {image: newFilename}, where: {id: id}});
+4 -3
View File
@@ -1,6 +1,6 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useLoaderData } from "@remix-run/react";
import { Container, Row, Button, Form, Image } from "react-bootstrap";
@@ -38,8 +38,9 @@ export const action = async ({
// Remove old image
if(cocktail.image) rmSync("public"+ cocktail.image, {force: true});
// Move the file to the cocktails folder with the slug as name
renameSync(image.getFilePath(), "public" + newFilename);
// Copy the file to the cocktails folder with the slug as name
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
await dbe.cocktail.update({data: {image: newFilename}, where: {id: id}});
@@ -1,6 +1,6 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useLoaderData } from "@remix-run/react";
import { Container, Row, Button, Form, Image } from "react-bootstrap";
@@ -38,8 +38,9 @@ export const action = async ({
// Remove old image
if(manufacturer.image) rmSync("public"+ manufacturer.image, {force: true});
// Move the file to the manufacturers folder with the slug as name
renameSync(image.getFilePath(), "public" + newFilename);
// Copy the file to the manufacturers folder with the slug as name
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
await dbe.manufacturer.update({data: {image: newFilename}, where: {id: id}});
+4 -3
View File
@@ -1,6 +1,6 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useLoaderData } from "@remix-run/react";
import { Container, Row, Button, Form, Image } from "react-bootstrap";
@@ -38,8 +38,9 @@ export const action = async ({
// Remove old image
if(soda.image) rmSync("public"+ soda.image, {force: true});
// Move the file to the sodas folder with the slug as name
renameSync(image.getFilePath(), "public" + newFilename);
// Copy the file to the sodas folder with the slug as name
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
await dbe.soda.update({data: {image: newFilename}, where: {id: id}});
+4 -3
View File
@@ -1,6 +1,6 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useLoaderData } from "@remix-run/react";
import { Container, Row, Button, Form, Image } from "react-bootstrap";
@@ -38,8 +38,9 @@ export const action = async ({
// Remove old image
if(wine.image) rmSync("public"+ wine.image, {force: true});
// Move the file to the wines folder with the slug as name
renameSync(image.getFilePath(), "public" + newFilename);
// Copy the file to the wines folder with the slug as name
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
await dbe.wine.update({data: {image: newFilename}, where: {id: id}});
+10 -1
View File
@@ -28,7 +28,16 @@ export async function action({
if(inventory <= 0) inventory = 0;
await dbe.container.update({data: { inventory: inventory}, where: {id: containerid}});
const currentContainer = await dbe.container.findUnique({where: {id: containerid}, select: {inventory: true}});
const shouldSetLastAdded = currentContainer != null && inventory > currentContainer.inventory;
await dbe.container.update({
data: {
inventory: inventory,
lastAdded: shouldSetLastAdded ? new Date() : undefined,
},
where: {id: containerid}
});
return null;
};
@@ -0,0 +1,45 @@
import type { LoaderFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { enhance } from "~/utils/db.server";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { dbe, session } = await enhance(request);
const user = session.get("user");
if (!user || user.type !== "Admin") {
return redirect("/");
}
const containerId = Number(params.id);
if (!containerId) {
return redirect("/");
}
const container = await dbe.container.findUnique({
select: { id: true, inventory: true, drink: true },
where: { id: containerId },
});
if (!container){
return redirect("/");
} else if(container.inventory <= 0) {
return redirect("/inventory/drink/" + container.drink.id);
}
const newInventory = Math.max(container.inventory - 1, 0);
await dbe.container.update({
where: { id: container.id },
data: { inventory: newInventory },
});
await dbe.history.create({
data: {
container: { connect: { id: container.id } },
inventoryAfter: newInventory,
},
});
return redirect("/inventory/drink/" + container.drink.id);
}
+7 -2
View File
@@ -1,7 +1,7 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useState } from "react";
import { Button, Container, Form, InputGroup, Row } from "react-bootstrap";
@@ -53,7 +53,12 @@ export const action = async ({
try{
// Move the file to the beers folder with the slug as name
if(newFilename) renameSync(image.getFilePath(), "public" + newFilename);
if(newFilename)
{
// Copy is required for docker container to work
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
}
const createdBeer = await dbe.beer.create({ data: {
slug: slug,
+7 -2
View File
@@ -1,7 +1,7 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useState } from "react";
import { Button, Container, Form, InputGroup, Row } from "react-bootstrap";
@@ -50,7 +50,12 @@ export const action = async ({
try{
// Move the file to the beers folder with the slug as name
if(newFilename) renameSync(image.getFilePath(), "public" + newFilename);
if(newFilename)
{
// Copy is required for docker container to work
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
}
const createdCocktail = await dbe.cocktail.create({ data: {
slug: slug,
+1
View File
@@ -28,6 +28,7 @@ export const action = async ({
portions: portions,
price: price,
inventory: inventory,
lastAdded: inventory > 0 ? new Date() : null,
drink: {connect: {id: drink}},
section: {connect: {id: section}}
}, select: {drink: {select: {slug: true, type: true}}}
+7 -2
View File
@@ -1,6 +1,6 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useActionData, useLoaderData } from "@remix-run/react";
import { Container, Row, Button, Form, Col, ListGroup } from "react-bootstrap";
@@ -34,7 +34,12 @@ export const action = async ({
try{
// Move the file to the manufacturers folder with the slug as name
if(newFilename) renameSync(image.getFilePath(), "public" + newFilename);
if(newFilename)
{
// Copy is required for docker container to work
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
}
const createdManufacturer = await dbe.manufacturer.create({ data: {name: name, description: description, image: newFilename, country: {connect: {code: country}}} });
return redirect("/inventory/manufacturer/" + createdManufacturer.id);
+7 -2
View File
@@ -1,7 +1,7 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useState } from "react";
import { Button, Container, Form, InputGroup, Row } from "react-bootstrap";
@@ -50,7 +50,12 @@ export const action = async ({
try{
// Move the file to the beers folder with the slug as name
if(newFilename) renameSync(image.getFilePath(), "public" + newFilename);
if(newFilename)
{
// Copy is required for docker container to work
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
}
const createdSoda = await dbe.soda.create({ data: {
slug: slug,
+7 -2
View File
@@ -1,7 +1,7 @@
import type { ActionFunctionArgs } from "@remix-run/node";
import { LoaderFunctionArgs, NodeOnDiskFile, json, redirect, unstable_composeUploadHandlers, unstable_createFileUploadHandler, unstable_createMemoryUploadHandler, unstable_parseMultipartFormData } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import { renameSync, rmSync } from "node:fs";
import { copyFileSync, rmSync } from "node:fs";
import { useState } from "react";
import { Button, Container, Form, InputGroup, Row } from "react-bootstrap";
@@ -61,7 +61,12 @@ export const action = async ({
try{
// Move the file to the wines folder with the slug as name
if(newFilename) renameSync(image.getFilePath(), "public" + newFilename);
if(newFilename)
{
// Copy is required for docker container to work
copyFileSync(image.getFilePath(), "public" + newFilename);
rmSync(image.getFilePath(), {force: true});
}
const createdWine = await dbe.wine.create({ data: {
slug: slug,
+1 -1
View File
@@ -9,7 +9,7 @@ export default function AdminRoute() {
<ListGroup.Item><Link to="/admin/new">Add new items</Link></ListGroup.Item>
<ListGroup.Item><Link to="/admin/edit">Edit or remove items</Link></ListGroup.Item>
<ListGroup.Item><Link to="/admin/manage/inventory">Change inventory numbers</Link></ListGroup.Item>
<ListGroup.Item><Link to="/admin/manage/checkout">Undo checkout</Link></ListGroup.Item>
<ListGroup.Item><Link to="/admin/manage/undo-checkout">Undo checkout</Link></ListGroup.Item>
</ListGroup>
<h1>Reports</h1>
+74 -9
View File
@@ -1,8 +1,8 @@
import { LoaderFunctionArgs, json, redirect } from "@remix-run/node";
import { Link, useLoaderData, useNavigate, useSearchParams } from "@remix-run/react";
import { useLoaderData, useNavigate, useSearchParams } from "@remix-run/react";
import { enhance } from "@zenstackhq/runtime";
import { useState } from "react";
import { Accordion, Button, Col, Container, Offcanvas, Row, useAccordionButton } from "react-bootstrap";
import { useEffect, useState } from "react";
import { Button, Col, Container, Form, Offcanvas, Row } from "react-bootstrap";
import DrinkCard from "~/components/cards/drink.card";
import DrinkFilter from "~/components/filters/drink.filter";
import { findDrinksFromSearch } from "~/models/drinks.filter.server";
@@ -34,12 +34,63 @@ export default function BeersRoute() {
const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
const [searchQuery, setSearchQuery] = useState(searchParams.get("q") || "");
const [show, setShow] = useState(false);
useEffect(() => {
setSearchQuery(searchParams.get("q") || "");
}, [searchParams]);
useEffect(() => {
const timer = window.setTimeout(() => {
const nextParams = new URLSearchParams(searchParams);
const trimmedQuery = searchQuery.trim();
if (trimmedQuery) {
nextParams.set("q", trimmedQuery);
} else {
nextParams.delete("q");
}
const nextSearch = nextParams.toString();
const currentSearch = searchParams.toString();
if (nextSearch !== currentSearch) {
setSearchParams(nextParams, { replace: true });
}
}, 250);
return () => window.clearTimeout(timer);
}, [searchQuery, searchParams, setSearchParams]);
const handleClose = () => setShow(false);
const handleShow = () => setShow(true);
const activeFilterKeys = new Set<string>();
if (searchQuery.trim()) {
activeFilterKeys.add("q");
}
searchParams.forEach((value, key) => {
if (!value) {
return;
}
if (key === "sort" && value === "name") {
return;
}
if ((key === "min-abv" && value === "0") || (key === "max-abv" && value === "50") || (key === "min-ibu" && value === "0") || (key === "max-ibu" && value === "150")) {
return;
}
activeFilterKeys.add(key);
});
const activeFilterCount = activeFilterKeys.size;
const hasActiveFilters = activeFilterCount > 0;
const numResults = loadData.drinkResults.length;
let randomDrink = function(){
@@ -52,12 +103,26 @@ export default function BeersRoute() {
<Container>
<Row key="filter-sort-bar" className="pt-1 sticky-top bg-white mb-2" style={{boxShadow: "0px 4px 4px -5px rgba(0,0,0,.5)"}}>
<Col key="filtering" className="mb-3">
<div>
<Button variant="primary" onClick={handleShow}>Filters</Button>
<LinkContainer to="/inventory">
<Button variant="warning" className="mx-3">Clear</Button>
</LinkContainer>
<span className="float-end">{numResults} Results</span>
<div className="d-flex flex-nowrap align-items-center gap-2" style={{ overflowX: 'auto' }}>
<Button
variant={hasActiveFilters ? "warning" : "primary"}
onClick={handleShow}
className="d-flex align-items-center gap-2 flex-shrink-0"
title={hasActiveFilters ? `${activeFilterCount} active filters` : "No active filters"}
>
<span>Filters</span>
{hasActiveFilters ? <span className="badge text-bg-light">{activeFilterCount}</span> : null}
</Button>
<Form.Control
type="search"
placeholder="Search drinks"
value={searchQuery}
onChange={(event) => setSearchQuery(event.target.value)}
className="flex-grow-1"
style={{ minWidth: 0, maxWidth: "420px" }}
/>
<Button variant="warning" onClick={() => navigate("/inventory")} className="flex-shrink-0">Clear</Button>
<span className="ms-auto text-nowrap">{numResults} Results</span>
</div>
<Offcanvas show={show} onHide={handleClose}>
+6 -1
View File
@@ -6,4 +6,9 @@ set -e
npx zenstack generate
npx remix vite:build
docker build -t beer-inventory .
docker build -t gitea.furb.it/kennyboy55/beer-inventory:latest .
## How to tag:
# sudo docker build -t gitea.furb.it/kennyboy55/beer-inventory:latest .
# sudo docker push gitea.furb.it/kennyboy55/beer-inventory:latest
-13921
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -50,6 +50,7 @@ model Drink {
lactose Boolean
organic Boolean
sugar Boolean @default(true)
addedAt DateTime @default(now())
containers Container[]
delegate_aux_beer Beer?
delegate_aux_wine Wine?
@@ -116,6 +117,7 @@ model Container {
portions Int?
price Float @default(0.0)
inventory Int @default(0)
lastAdded DateTime?
checkouts History[]
}
+2
View File
@@ -52,6 +52,7 @@ model Drink {
lactose Boolean
organic Boolean
sugar Boolean @default(true)
addedAt DateTime @default(now())
containers Container[]
@@ -141,6 +142,7 @@ model Container {
price Float @default(0.0)
inventory Int @default(0)
lastAdded DateTime?
checkouts History[]
+2 -1
View File
@@ -120,7 +120,8 @@ export default defineConfig({
route("manage/inventory", "routes/admin/manage/inventory.tsx");
route("manage/checkout", "routes/admin/manage/checkout.tsx");
route("manage/undo-checkout", "routes/admin/manage/undo-checkout.tsx");
route("manage/manual-checkout/:id", "routes/admin/manage/manual-checkout.$id.tsx");
});
});
},