diff --git a/ISSUES.txt b/ISSUES.txt index 279018a..9ed05e6 100644 --- a/ISSUES.txt +++ b/ISSUES.txt @@ -5,8 +5,6 @@ Idea, Issue, Work Tracking [Pending] -- [] #3: Save value to recipe -- [] #6: display all recipes with materials from csv [material usages with product code] - [] #7: material & menu creation - [] #9: show & edit price @@ -19,5 +17,7 @@ Idea, Issue, Work Tracking - [x] #2: Send change value from editing in recipe to machine - [x] #5: revert value on close dialog recipe - [x] #8: change recipe version +- [x] #3: Save value to recipe +- [x] #6: display all recipes with materials from csv [material usages with product code] diff --git a/bun.lockb b/bun.lockb index 52bad83..9851d42 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index e8cdbaa..eb20ce4 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "@yume-chan/scrcpy": "^2.3.0", "@yume-chan/stream-extra": "^2.5.3", "animejs": "^4.3.6", - "firebase": "^12.11.0", + "firebase": "^12.14.0", "idb": "^8.0.3", "mode-watcher": "^1.1.0", "usb": "^2.17.0", diff --git a/src/lib/components/recipe-details/recipe-detail.svelte b/src/lib/components/recipe-details/recipe-detail.svelte index 6e68b03..967d1bb 100644 --- a/src/lib/components/recipe-details/recipe-detail.svelte +++ b/src/lib/components/recipe-details/recipe-detail.svelte @@ -16,6 +16,7 @@ import { get, readable, writable } from 'svelte/store'; import { currentEditingRecipeProductCode, + lastRequestSheetPrice, latestRecipeToppingData, materialFromMachineQuery, materialFromServerQuery, @@ -28,6 +29,8 @@ import { addNotification } from '$lib/core/stores/noti'; import { env } from '$env/dynamic/public'; import { sendCommand, sendReset } from '$lib/core/brew/command'; + import { sendCommandRequest } from '$lib/core/handlers/ws_messageSender'; + import { needPermission } from '$lib/core/handlers/permissionHandler'; import { isAdbWriterAvailable } from '$lib/core/stores/adbWriter'; import { sendToAndroid } from '$lib/core/stores/adbWriter'; import { departmentStore } from '$lib/core/stores/departments'; @@ -43,6 +46,10 @@ let menuName: string = $state(''); let menuCurrentPrice: number = $state(0); let isMenuHideByPrice: boolean = $state(false); + let sheetPriceValue: number | null = $state(null); + let showSheetPrice: boolean = $state(false); + let canEditSheetPrice: boolean = $state(false); + let sheetPriceRawCell: any = $state(null); let materialSnapshot: any = $state(); let machineInfoSnapshot: any = $state(); @@ -52,6 +59,8 @@ let toppingSlotState: any = $state([]); + let unsubSheetPrice: (() => void) | null = null; + const recipeDetailDispatch = createEventDispatcher(); function remappingToColumn(data: any[]): RecipelistMaterial[] { @@ -167,6 +176,22 @@ } } + function saveSheetPrice() { + if (!canEditSheetPrice || sheetPriceValue === null) return; + sendCommandRequest('sheet', { + country: get(departmentStore), + content: [ + { + product_code: productCode, + new_price: sheetPriceValue, + cell_coord: sheetPriceRawCell?.coord + } + ], + param: 'price', + action: 'update' + }); + } + async function checkChanges(productCode: string, original: any) { // console.log('old', original, 'updated', recipeListMatState); if (recipeListOriginal.length == 0) { @@ -182,6 +207,26 @@ } } + function updateSheetPrice(sheetData: any) { + if (!productCode) return; + const country = get(departmentStore); + if (!country) return; + + const sheetEntry = sheetData[country]?.[productCode]; + if (sheetEntry && typeof sheetEntry === 'object' && sheetEntry?.value) { + sheetPriceRawCell = sheetEntry; + const parsed = parseInt(sheetEntry.value); + if (!isNaN(parsed) && parsed !== menuCurrentPrice) { + sheetPriceValue = parsed; + showSheetPrice = true; + return; + } + } + + sheetPriceValue = null; + showSheetPrice = false; + } + onMount(() => { machineInfoSnapshot = get(machineInfoStore); @@ -231,8 +276,19 @@ } catch (e) {} } - // save old value\ + // save old value } + + canEditSheetPrice = needPermission('document.write.*'); + + updateSheetPrice(get(lastRequestSheetPrice)); + unsubSheetPrice = lastRequestSheetPrice.subscribe((data) => { + updateSheetPrice(data); + }); + }); + + onDestroy(() => { + if (unsubSheetPrice) unsubSheetPrice(); }); @@ -265,31 +321,152 @@ Info about this menu - -
-
- - + + + + Basic Information + + +
+
+ + +
+
+ + +
+
+
-
- - + + + + Price Information + + +
+ +
+ + +
+ + {#if showSheetPrice} + +
+ +
+ + {#if canEditSheetPrice} + + {/if} +
+
+ {/if} + + +
+
+ + Disabled by Price +
+
-
+ + -
- - -
- - -
- - Disabled - -
- + + + + Additional Recipe Data + + + {#if recipeData} +
+
+ + + {recipeData.LastChange ?? 'N/A'} + +
+
+ + { + const input = e.target as HTMLInputElement | null; + if (input && input.value !== '') { + const value = parseInt(input.value); + if (!isNaN(value)) { + recipeData.total_time = value; + // Notify parent of change + onPendingChange({ + target: 'recipeData', + ref_pd: productCode, + value: { ...recipeData, total_time: value } + }); + } + } + }} + /> +
+
+ +
+
+ + { + const input = e.target as HTMLInputElement | null; + if (input) { + recipeData.uriData = input.value; + onPendingChange({ + target: 'recipeData', + ref_pd: productCode, + value: { ...recipeData, uriData: input.value } + }); + } + }} + /> +
+
+ {:else} +

No recipe data available

+ {/if} +
+