From 445cbbabe5d121646dc4a012381b2b7b6e0aa7f2 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 23 Jan 2022 18:16:18 +1000 Subject: [PATCH] OrderScreen complete --- AjaxController.fs | 55 ++-- Decorations.module.fs | 2 +- DredgePos.fsproj | 1 + Floorplan.module.fs | 40 ++- GenericEntities.module.fs | 49 ++-- OrderScreen.module.fs | 95 ++++--- PageController.fs | 33 ++- Program.fs | 4 +- Theme.module.fs | 2 +- Types.fs | 16 +- wwwroot/scripts/ts/dredgepos.core.ts | 10 +- wwwroot/scripts/ts/dredgepos.floorplan.ts | 62 ++--- wwwroot/scripts/ts/dredgepos.orderScreen.ts | 212 +++++++++++++-- wwwroot/scripts/ts/types.ts | 17 +- .../styles/sass/dredgepos.orderScreen.sass | 255 +++++++++++------- wwwroot/themes/restaurant/orderScreen.tpl.htm | 14 +- .../change_cover_number_button.tpl.htm | 1 + .../orderScreen/cover_selector.tpl.htm | 3 + .../orderScreen/cover_selector_button.tpl.htm | 1 - .../orderScreen/grid_container.tpl.htm | 13 + .../restaurant/orderScreen/page.tpl.htm | 5 +- 21 files changed, 609 insertions(+), 281 deletions(-) create mode 100644 wwwroot/themes/restaurant/orderScreen/change_cover_number_button.tpl.htm create mode 100644 wwwroot/themes/restaurant/orderScreen/cover_selector.tpl.htm delete mode 100644 wwwroot/themes/restaurant/orderScreen/cover_selector_button.tpl.htm create mode 100644 wwwroot/themes/restaurant/orderScreen/grid_container.tpl.htm diff --git a/AjaxController.fs b/AjaxController.fs index b33a1bb..205f026 100644 --- a/AjaxController.fs +++ b/AjaxController.fs @@ -42,24 +42,25 @@ let unmergeTable tableNumber = let getFloorplanData (id: int) = - let tableList = Entity.getAllInVenue + let tableList = Entity.GetAllInVenue let reservationList = getReservationList tableList {| tables = tableList - decorations = Entity.getAllInVenue + decorations = Entity.GetAllInVenue activeTableNumbers = Floorplan.getActiveTables (getCurrentVenue()) - rooms = Entity.getAllInVenue + rooms = Entity.GetAllInVenue reservations = reservationList |} |> ajaxSuccess |> json -let getOrderScreenData (id: int) = +let getOrderScreenData (tableNumber: int) = {| - order_screen_pages = Entity.getAllInVenue - sales_categories = Entity.getAllInVenue - print_groups = Entity.getAllInVenue - custom_item = Entity.getAllByColumn "item_code" "OPEN000" |> first + order_screen_pages = Entity.GetAllInVenue + sales_categories = Entity.GetAllInVenue + print_groups = Entity.GetAllInVenue + custom_item = Entity.GetAllByColumn "item_code" "OPEN000" |> first + table = getTable tableNumber |} |> ajaxSuccess |> json @@ -73,21 +74,18 @@ let getKeyboardLayout (language: string) = ] |> json let transformTable (table: floorplan_table) = - Entity.updateInDatabase table + Entity.Update table |> ajaxSuccess |> json let createTable (tableData: floorplan_table) = - - let result = - if tableExists tableData.table_number = "False" then - ajaxSuccess (addNewTable tableData) - else ajaxFail (tableExists tableData.table_number) - - result |> json + if tableExists tableData.table_number = "False" then + ajaxSuccess (addNewTable tableData) + else ajaxFail (tableExists tableData.table_number) + |> json let deleteTable (table: floorplan_table) = - Entity.deleteById table.id + Entity.DeleteById table.id |> ignore table |> ajaxSuccess |> json @@ -113,30 +111,30 @@ let AddDecoration (data: floorplan_decoration) = venue_id = data.venue_id } - Entity.addToDatabase decoration + Entity.Create decoration |> ajaxSuccess |> json let UpdateDecoration (data: floorplan_decoration) = - Entity.updateInDatabase data + Entity.Update data |> ignore ajaxSuccess "true" |> json let DeleteDecoration (decorationToDelete: floorplan_decoration) = - Entity.deleteById decorationToDelete.id + Entity.DeleteById decorationToDelete.id |> ajaxSuccess |> json let newEmptyReservation (reservation: reservation) = let newReservation = {reservation with - reservation_created_at = CurrentTime() - reservation_time = CurrentTime() + created_at = CurrentTime() + time = CurrentTime() } - if reservation.reservation_table_id > 0 then - let table = {(getTableById reservation.reservation_table_id) with + if reservation.floorplan_table_id > 0 then + let table = {(getTableById reservation.floorplan_table_id) with status = 2 - default_covers = reservation.reservation_covers} + default_covers = reservation.covers} updateTablePosition table |> ignore let createdReservation = Floorplan.createEmptyReservation newReservation @@ -149,3 +147,10 @@ let unreserveTable (table: floorplan_table) = updateTablePosition newTable |> ignore DeleteReservation newTable.id newTable |> ajaxSuccess |> json + +let loadGrid (gridId: int) = + let grid = Entity.GetById gridId + let gridHtml = OrderScreen.loadGrid gridId + if gridHtml = "Error" then ajaxFail gridHtml + else ajaxSuccess {|grid=grid;gridHtml=gridHtml|} + |> json \ No newline at end of file diff --git a/Decorations.module.fs b/Decorations.module.fs index 1fe2989..a401e14 100644 --- a/Decorations.module.fs +++ b/Decorations.module.fs @@ -8,7 +8,7 @@ open Dapper.FSharp open DredgePos open Types -let decorationsInRoom (roomId: int) = Entity.getAllByColumn "decoration_room" roomId +let decorationsInRoom (roomId: int) = Entity.GetAllByColumn "decoration_room" roomId let getImageName (image: string, path: string) = let imageName = diff --git a/DredgePos.fsproj b/DredgePos.fsproj index 18cab05..a447edc 100644 --- a/DredgePos.fsproj +++ b/DredgePos.fsproj @@ -61,6 +61,7 @@ + diff --git a/Floorplan.module.fs b/Floorplan.module.fs index 2aca4a4..e04be62 100644 --- a/Floorplan.module.fs +++ b/Floorplan.module.fs @@ -1,6 +1,7 @@ module Floorplan open DredgePos +open DredgePos.Types open Org.BouncyCastle.Asn1.X509 open Reservations @@ -116,16 +117,16 @@ let getRoom (roomId: int) = where (eq "id" roomId) } |> db.Select |> first -let updateTablePosition (floorplanTable: floorplan_table) = Entity.updateInDatabase floorplanTable +let updateTablePosition (floorplanTable: floorplan_table) = Entity.Update floorplanTable let createEmptyReservation (reservation: reservation) = update { table "floorplan_tables" set {| status = 2 |} - where(eq "id" reservation.reservation_table_id) + where(eq "id" reservation.floorplan_table_id) } |> db.Update |> ignore - Entity.addToDatabase reservation + Entity.Create reservation let getChildTables tableNumber = let table = getTable tableNumber @@ -165,7 +166,7 @@ let tableExists (tableNumber: int) = match numberOfResults with | 0 -> let allTables = - Entity.getAllInVenue + Entity.GetAllInVenue |> Array.map(findChildTable tableNumber) |> Array.filter(fun tableNumber -> tableNumber <> 0) @@ -192,7 +193,7 @@ let addNewTableWithoutOutput (newTable: floorplan_table) = } |> db.Insert -let addNewTable (newTable: floorplan_table) = Entity.addToDatabase newTable +let addNewTable (newTable: floorplan_table) = Entity.Create newTable let mergeTables parent child = //Merge two tables together if parent = child then false else @@ -246,7 +247,7 @@ let mergeTables parent child = //Merge two tables together where (eq "table_number" parent + eq "venue_id" (getCurrentVenue())) } |> db.Update |> ignore - Entity.deleteById newChildTable.id + Entity.DeleteById newChildTable.id |> ignore true @@ -289,30 +290,19 @@ let makeRoomButton (room: floorplan_room) = Theme.loadTemplateWithVars "roomButton" vars let getReservationList (tableList: floorplan_table[]) = - let tableIds = - tableList - |> Array.map(fun table -> box table.id) - |> List.ofArray - - if tableIds.Length > 0 then - select { - table "reservations" - where (isIn "reservation_table_id" tableIds) - } - |> db.Select - else [||] + tableList |> Array.collect Entity.GetAllRelated let newReservation name time covers = let reservation = { id = 0 - reservation_name = name - reservation_time = time - reservation_covers = covers - reservation_table_id = 0 - reservation_created_at = CurrentTime() + name = name + time = time + covers = covers + floorplan_table_id = 0 + created_at = CurrentTime() } - Entity.addToDatabase reservation + Entity.Create reservation -let tableList () = Entity.getAllInVenue +let tableList () = Entity.GetAllInVenue diff --git a/GenericEntities.module.fs b/GenericEntities.module.fs index 154ba0c..7fb00f9 100644 --- a/GenericEntities.module.fs +++ b/GenericEntities.module.fs @@ -2,13 +2,14 @@ open Dapper.FSharp open DredgeFramework open Pluralize.NET.Core +open FSharp.Reflection -let getDatabaseTable<'x> = +let GetDatabaseTable<'x> = let typeName = typeof<'x>.Name Pluralizer().Pluralize typeName -let addToDatabase (record: 'x)= - let tableName = getDatabaseTable<'x> +let Create (record: 'x)= + let tableName = GetDatabaseTable<'x> insert { table tableName value record @@ -18,46 +19,58 @@ let addToDatabase (record: 'x)= |> first -let inline updateInDatabase (record: ^x) = - let tableName = getDatabaseTable<'x> - let id = ((^x) : (member id : int) (record)) +let inline Update (record: ^x) = + let tableName = GetDatabaseTable<'x> + let id = ((^x) : (member id : int) record) update { table tableName set record where (eq "id" id) + excludeColumn "id" } |> db.Update -let getAll<'x> = - let typeName = typeof<'x>.Name - let tableName = Pluralizer().Pluralize typeName +let GetAll<'x> = + let tableName = GetDatabaseTable<'x> select { table tableName } |> db.Select<'x> -let getAllByColumn<'x> (column: string) (value: obj) = - let typeName = typeof<'x>.Name - let tableName = Pluralizer().Pluralize typeName +let GetAllByColumn<'x> (column: string) (value: obj) = + let tableName = GetDatabaseTable<'x> select { table tableName where (eq column value) } |> db.Select<'x> -let getAllInVenue<'x> = getAllByColumn<'x> "venue_id" (getCurrentVenue ()) -let getById<'x> (id: int) = getAllByColumn<'x> "id" id |> first +let GetAllInVenue<'x> = GetAllByColumn<'x> "venue_id" (getCurrentVenue ()) +let GetById<'x> (id: int) = GetAllByColumn<'x> "id" id |> first -let deleteById<'x> id = +let inline GetRelated<'x, .. > (entity: ^y) = + let columnName = typeof<'x>.Name + "_id" + let primaryKeyValue = typeof<'y>.GetProperty(columnName).GetValue(entity) :?> int + GetById<'x> primaryKeyValue + +let inline GetAllRelated<'x, .. > (entity: ^y) = + let id = typeof<'y>.GetProperty("id").GetValue(entity) :?> int + let columnName = typeof<'y>.Name + "_id" + GetAllByColumn<'x> columnName id + +let DeleteById<'x> id = let typeName = typeof<'x>.Name let tableName = Pluralizer().Pluralize typeName - - let entity = getById<'x> id + let entity = GetById<'x> id delete { table tableName where (eq "id" id) } |> db.Delete |> ignore - entity \ No newline at end of file + entity + +let inline Delete< ^x when ^x: (member id: int) > (entity: ^x) = + typeof<'x>.GetProperty("id").GetValue(entity) :?> int + |> DeleteById<'x> diff --git a/OrderScreen.module.fs b/OrderScreen.module.fs index 93a31d8..c3d6693 100644 --- a/OrderScreen.module.fs +++ b/OrderScreen.module.fs @@ -4,16 +4,19 @@ open DredgePos open DredgePos.Types open FSharp.Collections open Thoth.Json.Net -open Types open Theme -let getAllPageGrids () = Entity.getAllInVenue +let getAllPageGrids () = Entity.GetAllInVenue |> Array.filter(fun pageGroup -> pageGroup.grid_id <> 0) - |> Array.map(fun pageGroup -> (Entity.getById pageGroup.grid_id), pageGroup) + |> Array.map(fun pageGroup -> (Entity.GetById pageGroup.grid_id), pageGroup) let getImageButtonData (button: button) = - let item = Entity.getAllByColumn "item_code" button.primary_action_value + let itemCode = + if button.primary_action = "item" then button.primary_action_value + else button.secondary_action_value + + let item = Entity.GetAllByColumn "item_code" itemCode |> first let extraData = @@ -26,9 +29,31 @@ let getImageButtonData (button: button) = text = item.item_name |} +let getGridButtonData (button: button) = + let gridId = + if button.primary_action = "grid" then button.primary_action_value + else button.secondary_action_value + |> int + + let grid = Entity.GetById gridId + {| + extra_data = map ["data-grid", jsonEncode gridId] |> htmlAttributes + text = grid.grid_name + |} + +let getActionData (button: button) (action: string) = + let actionValue = + if action = "primary" then button.primary_action + else button.secondary_action + + match actionValue with + | "item" -> getImageButtonData button + | "grid" -> getGridButtonData button + | "spacer" -> {|extra_data=""; text=""|} + | _ -> {|extra_data=""; text=""|} let renderButton (buttonId: int) = - let button = Entity.getById