Finalization of order box behavior

This commit is contained in:
2022-01-06 12:01:09 +10:00
parent 30bc79ef98
commit fc4a5d8624
9 changed files with 163 additions and 44 deletions

View File

@@ -1,18 +1,12 @@
module OrderScreen module OrderScreen
open System.Security.Cryptography.Xml
open System.Web
open DredgeFramework open DredgeFramework
open DredgePos open DredgePos
open DredgePos.Types
open FSharp.Collections open FSharp.Collections
open Thoth.Json.Net open Thoth.Json.Net
open Types open Types
open Theme open Theme
let htmlAttributes (attributes: Map<string, string>) =
" " + (attributes
|> Map.toArray
|> Array.map (fun (attribute, value) -> attribute+"='"+HttpUtility.HtmlEncode value + "'")
|> String.concat " ")
let getAllPageGrids () = Entity.getAllInVenue<order_screen_page_group> let getAllPageGrids () = Entity.getAllInVenue<order_screen_page_group>
|> Array.filter(fun pageGroup -> pageGroup.grid_id <> 0) |> Array.filter(fun pageGroup -> pageGroup.grid_id <> 0)
@@ -81,6 +75,15 @@ let renderPageGroup (pageGroup: order_screen_page_group) (pageHTML: string) =
] ]
loadTemplateWithVars "orderScreen/page_group" vars loadTemplateWithVars "orderScreen/page_group" vars
let categoryPosButton (category: sales_category) = PosButton (language.getAndReplace "print_with" [category.name]) "categoryOverrideButton" ""
let generateSalesCategoryOverrideButtons () =
Entity.getAllInVenue<sales_category>
|> Array.map categoryPosButton
|> Array.append ([|PosButton (language.getAndReplace "print_with" ["default"]) "categoryOverrideButton" ""|])
|> String.concat "\n"
let getPagesHTML (gridInfo: grid * order_screen_page_group) = let getPagesHTML (gridInfo: grid * order_screen_page_group) =
let grid, pageGroup = gridInfo let grid, pageGroup = gridInfo

View File

@@ -71,6 +71,7 @@ let loadOrderScreen (ctx: HttpContext) (tableNumber: int) : HttpHandler =
"orderNumber", orderNumber "orderNumber", orderNumber
"coverSelectorButton", coverSelectorButton "coverSelectorButton", coverSelectorButton
"covers", coverString "covers", coverString
"salesCategoryOverrideButtons", OrderScreen.generateSalesCategoryOverrideButtons ()
] ]
let styles = ["dredgepos.orderScreen.css"] let styles = ["dredgepos.orderScreen.css"]

View File

@@ -1,6 +1,6 @@
module Theme module Theme
open System open System.Web
open System.IO open System.IO
open System.Collections.Generic open System.Collections.Generic
open System.Text.RegularExpressions open System.Text.RegularExpressions
@@ -137,4 +137,19 @@ let loadTemplateWithVarsAndScripts templateName vars scripts =
let loadTemplateWithVarsAndStyles = loadTemplateWithVarsAndScripts let loadTemplateWithVarsAndStyles = loadTemplateWithVarsAndScripts
let loadTemplateWithVarsScriptsAndStyles templateName vars scripts styles = let loadTemplateWithVarsScriptsAndStyles templateName vars scripts styles =
loadTemplateWithVarsArraysScriptsAndStyles templateName vars Map.empty<string, Map<string, string>> scripts styles loadTemplateWithVarsArraysScriptsAndStyles templateName vars Map.empty<string, Map<string, string>> scripts styles
let htmlAttributes (attributes: Map<string, string>) =
" " + (attributes
|> Map.toArray
|> Array.map (fun (attribute, value) -> attribute+"='"+HttpUtility.HtmlEncode value + "'")
|> String.concat " ")
let PosButton (text: string) (classes: string) (attributes: string) =
let vars = map [
"text", text
"classes", classes
"attributes", attributes
]
loadTemplateWithVars "components/posButton" vars

View File

@@ -87,5 +87,7 @@
"partial_table":"Partial Table", "partial_table":"Partial Table",
"paying_table":"Paying Table [1]", "paying_table":"Paying Table [1]",
"msgbox_amount_select":"Enter Amount", "msgbox_amount_select":"Enter Amount",
"msgbox_qty_select":"How many would you like to select?" "msgbox_qty_select":"How many would you like to select?",
"void_mode": "Void Mode is ON."
} }

View File

@@ -221,6 +221,8 @@ const setupTableEvents = (tableGroup: Konva.Group) => {
tableGroup.on('click', tableClicked) tableGroup.on('click', tableClicked)
tableGroup.on('tap', tableClicked) tableGroup.on('tap', tableClicked)
tableGroup.on('dbltap', tableDblClicked)
tableGroup.on('dblclick', tableDblClicked)
tableGroup.on('dragend', tableGroupTransformed) tableGroup.on('dragend', tableGroupTransformed)
tableShape.on('transformend', tableShapeTransformed) tableShape.on('transformend', tableShapeTransformed)
} }
@@ -438,7 +440,14 @@ const selectTable = (tableShape: Konva.Shape) => {
const updateCoverText = (table:table) => $('.selectedTableCovers').text(lang('covers', table.default_covers.toString())) const updateCoverText = (table:table) => $('.selectedTableCovers').text(lang('covers', table.default_covers.toString()))
const tableClicked = (event: Konva.KonvaEventObject<any>) => { const tableDblClicked = (event: Konva.KonvaEventObject<any>) => {
let tableShape = getTableShapeFromGroup(event.currentTarget as Konva.Group)
const table = getTableDataFromShape(tableShape)
redirect(`/order/${table.table_number}`)
}
const tableClicked = (event: Konva.KonvaEventObject<any>) => {
let tableShape = getTableShapeFromGroup(event.currentTarget as Konva.Group) let tableShape = getTableShapeFromGroup(event.currentTarget as Konva.Group)
const table = getTableDataFromShape(tableShape) const table = getTableDataFromShape(tableShape)

View File

@@ -68,12 +68,58 @@ const navigatePage = (direction: number) => {
const goToNextPage = () => navigatePage(1) const goToNextPage = () => navigatePage(1)
const goToPrevPage = () => navigatePage(-1) const goToPrevPage = () => navigatePage(-1)
const addNewItem = (item: item, qty = 1) => { const addItemToOrderBox = (orderItem:orderItem) => {
const orderBox = $('.orderBoxTable tbody') const orderBox = $('.orderBoxTable tbody')
const lastRow = orderBox.find('tr').last() let selectedRows = orderBox.find('tr.selected')
const salesCategory = OrderScreen.sales_categories.where('id', item.item_category) let lastRow : JQuery = selectedRows.length ? selectedRows.first() : orderBox.find('tr').last()
const existingRow = orderBox.find(`.itemCell:contains("${orderItem.item.item_name}")`).closest('tr').last()
const existingRow = orderBox.find(`.itemCell:contains("${item.item_name}")`).closest('tr').last() //If accumulating, just increase the quantity of the existing row.
if(existingRow.length > 0 && isInMode('accumulate')){
incrementRowQty(existingRow, orderItem.qty)
scrollToElement(existingRow)
existingRow.pulse()
} else {
const newRow = createOrderRow(orderItem)
lastRow.length > 0
? lastRow.after(newRow)
: orderBox.append(newRow)
scrollToElement(newRow)
newRow.pulse()
}
deselectRow(orderBox.find('tr'))
}
const addInstructionToOrderBox = (instruction: orderItem) => {
const orderBox = $('.orderBoxTable tbody')
let selectedRows = orderBox.find('tr.selected')
const newRow = createOrderRow(instruction)
//If no items are added, then you can't add an instruction row.
if(!orderBox.find('tr.itemRow').length) return
if(selectedRows.length > 0){
selectedRows.each( (_, row) => {
const selectedRow = $(row)
const parentRow = getParentRow(selectedRow)
if(parentRow.is(selectedRow) || !parentRow.hasClass('selected')) {
const newRow = createOrderRow(instruction)
getLastInstructionRow(selectedRow).after(newRow.pulse())
}
})
return
}
orderBox.append(newRow.pulse())
}
const addNewItem = (item: item, qty = 1) => {
const salesCategory = OrderScreen.sales_categories.where('id', item.item_category)
const orderItem : orderItem = { const orderItem : orderItem = {
id: OrderScreen.order_item_id_generator.next().value, id: OrderScreen.order_item_id_generator.next().value,
@@ -82,17 +128,37 @@ const addNewItem = (item: item, qty = 1) => {
sales_category: salesCategory, sales_category: salesCategory,
} }
if(existingRow.length > 0 && isInMode('accumulate') && orderItem.item.item_type != "instruction"){ switch(item.item_type){
incrementRowQty(existingRow, qty) case 'instruction':
existingRow.pulse() addInstructionToOrderBox(orderItem)
} else { break
const newRow = createOrderRow(orderItem) case 'item':
lastRow.length > 0 default:
? lastRow.after(newRow) addItemToOrderBox(orderItem)
: orderBox.append(newRow) break
newRow.pulse()
} }
}
const getLastInstructionRow = (row: JQuery) => {
let stopCounting = false
let finalRow = row
row.nextAll().each(function (index, activeRow){
if(!stopCounting){
if($(activeRow).hasClass('instructionRow')){
finalRow = $(activeRow)
} else {
stopCounting = true
}
}
})
return $(finalRow)
}
const getParentRow = (row: JQuery) => {
return row.hasClass('instructionRow')
? row.prevAll('.itemRow').first()
: row
} }
const incrementRowQty = (row: JQuery, qty: number) => { const incrementRowQty = (row: JQuery, qty: number) => {
@@ -137,9 +203,6 @@ const createOrderRow = (orderItem: orderItem) => {
return row return row
} }
const saveOrderItem = (orderItem: orderItem) => {}
const itemButtonClicked = (e: JQuery.TriggeredEvent) => { const itemButtonClicked = (e: JQuery.TriggeredEvent) => {
const existingItemRows = $('.itemRow') const existingItemRows = $('.itemRow')
const button = $(e.target).closest('.posButton') const button = $(e.target).closest('.posButton')
@@ -168,10 +231,6 @@ const itemRowClicked = (e: JQuery.TriggeredEvent) => {
const selectRow = (row: JQuery) => { const selectRow = (row: JQuery) => {
row.addClass('selected') row.addClass('selected')
const id = row.data('order-item-id')
if(!OrderScreen.selected_item_ids.includes(id))
OrderScreen.selected_item_ids.push(id)
const instructionRows = row.nextUntil('.itemRow') const instructionRows = row.nextUntil('.itemRow')
if(row.hasClass('itemRow') && instructionRows.length){ if(row.hasClass('itemRow') && instructionRows.length){
@@ -184,7 +243,6 @@ const selectRow = (row: JQuery) => {
const deselectRow = (row: JQuery) => { const deselectRow = (row: JQuery) => {
row.removeClass('selected') row.removeClass('selected')
const instructionRows = row.nextUntil('.itemRow') const instructionRows = row.nextUntil('.itemRow')
OrderScreen.selected_item_ids = OrderScreen.selected_item_ids.filter(id => id != row.data('order-item-id'))
if(row.hasClass('itemRow') && instructionRows.length){ if(row.hasClass('itemRow') && instructionRows.length){
deselectRow(instructionRows) deselectRow(instructionRows)
@@ -194,9 +252,8 @@ const deselectRow = (row: JQuery) => {
const deleteRow = (row: JQuery) => row.find('*:not(.hidden)').slideUp('fast', () => row.remove()) const deleteRow = (row: JQuery) => row.find('*:not(.hidden)').slideUp('fast', () => row.remove())
const voidInstructionRow = (row: JQuery) => { const voidInstructionRow = (row: JQuery) => {
const parentRow = row.prevAll('.itemRow').first() if(!row.prevAll('.itemRow').first().hasClass('selected'))
deleteRow(row)
deleteRow(row)
} }
const voidItemRow = (row : JQuery) => decrementQty(row) const voidItemRow = (row : JQuery) => decrementQty(row)
@@ -237,7 +294,9 @@ const calculateRowTotal = (row: JQuery) => {
const decrementQty = (row: JQuery) => { const decrementQty = (row: JQuery) => {
const qty = getQty(row) const qty = getQty(row)
if(qty <= 1){ if(qty <= 1){
const childRows = row.nextUntil('.itemRow')
deleteRow(row) deleteRow(row)
deleteRow(childRows)
return return
} }
@@ -245,6 +304,7 @@ const decrementQty = (row: JQuery) => {
calculateRowTotal(row) calculateRowTotal(row)
} }
const getOrderItemRow = (orderItem: orderItem) => $('tr').filterByData('order-item-id', orderItem.id) const scrollToElement = (element: JQuery) => element.get()[0].scrollIntoView()
$(() => ajax('/orderScreen/getOrderScreenData/1', null, 'get', setupOrderScreen, null, null) ) $(() => ajax('/orderScreen/getOrderScreenData/1', null, 'get', setupOrderScreen, null, null) )

View File

@@ -29,11 +29,30 @@
overflow-y: auto overflow-y: auto
.orderBoxInfo .orderBoxInfo
@include flex
flex-basis: 5% flex-basis: 5%
background-color: white background-color: white
.voidModeWarning
@include flex
@include flex-item
color: red
font-weight: bold
.orderBoxFooter .orderBoxFooter
flex-basis: 10% flex-basis: 10%
@include flex-column
> *
@include flex
@include flex-column-item
justify-content: flex-end
padding: 0 0.7em
> .orderBoxTotal
align-items: flex-end
> small
align-items: flex-start
#rightColumn #rightColumn
@include flex-column @include flex-column
@@ -239,6 +258,15 @@
text-align: center text-align: center
width: 70% width: 70%
.qtyCell
width: 10%
.printGroupCell
width: 10%
.totalPriceCell
width: 10%
td.itemCell td.itemCell
text-align: left text-align: left

View File

@@ -0,0 +1,3 @@
<a class="posButton <!--[var:classes]-->" <!--[var: attributes]-->>
<!--[var:text]-->
</a>

View File

@@ -29,9 +29,12 @@
<tbody></tbody> <tbody></tbody>
</table> </table>
</div> </div>
<div class="orderBoxInfo"></div> <div class="orderBoxInfo">
<span class="voidModeWarning" data-visible-in-mode='["void"]'><!--[lang:void_mode]--></span>
</div>
<div class="orderBoxFooter"> <div class="orderBoxFooter">
<span class="orderBoxTotal">$0.00</span>
<small><span class="orderBoxSelectedTotal">$0.00</span></small>
</div> </div>
</div> </div>
<div id="rightColumn"> <div id="rightColumn">
@@ -44,12 +47,7 @@
</div> </div>
<div class="functionButtons"> <div class="functionButtons">
<div class="functionColumn"> <div class="functionColumn">
<a class="posButton"></a> <!--[var:salesCategoryOverrideButtons]-->
<a class="posButton"></a>
<a class="posButton"></a>
<a class="posButton"></a>
<a class="posButton"></a>
<a class="posButton"></a>
</div> </div>
<div class="functionColumn"> <div class="functionColumn">
<a class="posButton"></a> <a class="posButton"></a>