diff --git a/public/stylesheets/settings.css b/public/stylesheets/settings.css new file mode 100644 index 0000000..8ab0cda --- /dev/null +++ b/public/stylesheets/settings.css @@ -0,0 +1,6 @@ +#settings { + display: grid; + grid-template-columns: repeat(4, calc(90% / 4)); + grid-template-rows: repeat(5, calc(90% / 5)); + grid-gap: 10% 5%; +} \ No newline at end of file diff --git a/public/stylesheets/style.css b/public/stylesheets/style.css index 2423098..71fdf59 100644 --- a/public/stylesheets/style.css +++ b/public/stylesheets/style.css @@ -5,6 +5,7 @@ @import url("/stylesheets/menu.css"); @import url("/stylesheets/main.css"); @import url("/stylesheets/setup.css"); +@import url("/stylesheets/settings.css"); @import url("/stylesheets/containers.css"); @@ -223,10 +224,3 @@ h2 { } -#settings { - display: none; - background-color: red; - width: 100vw; - height: 100vh; -} - diff --git a/src/Utils.ts b/src/Utils.ts index e3abd33..b4a95ce 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -40,7 +40,13 @@ export class Utils { static deleteImage( id ) { - fs.unlinkSync("./public/images/" + id + ".png"); + try { + fs.unlinkSync("./public/images/" + id + ".png"); + } catch( e ) + { + + } + } static checkForImage( id ) diff --git a/src/WebSocketHandler.ts b/src/WebSocketHandler.ts index 1382ea6..ad23228 100644 --- a/src/WebSocketHandler.ts +++ b/src/WebSocketHandler.ts @@ -8,6 +8,9 @@ import Drink from "./database/Drink"; import {IDrink} from "./database/IDrink"; import Ingredient from "./database/Ingredient"; import {RequestType} from "./RequestType"; +import debug from "debug"; + +const log = debug("itender:WShandler"); export class WebSocketHandler { private static _ws: WebSocket; @@ -24,6 +27,7 @@ export class WebSocketHandler { return new Promise(async (resolve, reject) => { try { if (this.ws && this.ws.readyState == 1) { + log("Sending " + payload.event); await this.ws.send(payload.toString()); resolve(); } diff --git a/src/iTender.ts b/src/iTender.ts index 14c11d4..5665282 100644 --- a/src/iTender.ts +++ b/src/iTender.ts @@ -24,9 +24,6 @@ const log = debug("itender:station"); const mixLog = debug("itender:mix"); export class iTender { - static get containers(): { container: IContainer, sensor: HCSR04 | HX711, pump: null }[] { - return this._containers; - } static get drinks(): IDrink[] { return this._drinks; @@ -45,11 +42,6 @@ export class iTender { return this._internetConnection; } - /** - * @Deprecated - * @private - */ - private static _containers: { container: IContainer, sensor: HCSR04 | HX711, pump: null }[] = []; private static _drinks: IDrink[]; static setStatus(status: iTenderStatus) { @@ -82,7 +74,7 @@ export class iTender { if (!ingredient) continue; amounts.push({ingredient: ingredient, amount: x.amount}); - job.completeAmount+= x.amount; + job.completeAmount += x.amount; } } else if (data.amount) { let sum = 0; @@ -94,14 +86,14 @@ export class iTender { for (let x of (drink.ingredients as { type: IIngredient, amount: number }[])) { amounts.push({ingredient: x.type, amount: x.amount * factor}) - job.completeAmount+= x.amount; + job.completeAmount += x.amount; } } else { for (let x of (drink.ingredients as { type: IIngredient, amount: number }[])) { amounts.push({ingredient: x.type, amount: x.amount}); - job.completeAmount+= x.amount; + job.completeAmount += x.amount; } } @@ -245,9 +237,9 @@ export class iTender { let drinkAccept = true; for (let i of d.ingredients) { - let c = await Container.findOne({content: i["type"]}); + let c = await Container.findOne({$and: [{content: i.type}, {content: {$ne: null}}]}); - if (!c) { + if (!c || c.content != i.type) { drinkAccept = false; break; } diff --git a/src/main.ts b/src/main.ts index 4782b6e..4208b75 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import {iTender} from "./iTender"; import {iTenderStatus} from "./iTenderStatus"; import {Utils} from "./Utils"; import {Settings} from "./Settings"; +import Drink from "./database/Drink"; const log = debug("itender:server"); @@ -39,7 +40,7 @@ const wsApp = new WebsocketApp(); } Settings.saveSettings(); - + log("Check OK, starting..."); await init(); setInterval(refresh, 1000 * 60); iTender.setStatus(iTenderStatus.READY); @@ -62,7 +63,8 @@ function init(): Promise { setTimeout( async () => { // Network await iTender.checkNetwork(); - if (iTender.internetConnection && iTender.status == iTenderStatus.READY) { + let drinkCount = await Drink.countDocuments({}); + if (iTender.internetConnection && iTender.status == iTenderStatus.READY && drinkCount < 3 ) { await iTender.refreshFromServer(); } }, 1000 * 20 ) ; diff --git a/views/index.pug b/views/index.pug index 14743eb..4a7d7dc 100644 --- a/views/index.pug +++ b/views/index.pug @@ -53,5 +53,6 @@ block settings // Settings button.btn.btn-primary#settings_refreshDrinks Getränke herunterladen + block main // Main is build dynamically