diff --git a/Core/Browser.module.fs b/Core/Browser.module.fs index 07cb33d..b76830f 100644 --- a/Core/Browser.module.fs +++ b/Core/Browser.module.fs @@ -25,5 +25,4 @@ let setCookie name value (expiry: DateTimeOffset) (context: HttpContext) = options.Expires <- expiry context.Response.Cookies.Append(name, value, options); -let redirect url (context: HttpContext) = - context.Response.Redirect url \ No newline at end of file +let redirect url (context: HttpContext) = context.Response.Redirect url \ No newline at end of file diff --git a/DredgePos.fsproj b/DredgePos.fsproj index dfd31b3..21966c6 100644 --- a/DredgePos.fsproj +++ b/DredgePos.fsproj @@ -20,6 +20,7 @@ + @@ -36,6 +37,7 @@ + diff --git a/Entities/Buttons/Model.fs b/Entities/Buttons/Model.fs new file mode 100644 index 0000000..5680079 --- /dev/null +++ b/Entities/Buttons/Model.fs @@ -0,0 +1,19 @@ +module DredgePos.Entities.Buttons.Model + +open DredgePos.Types +open DredgeFramework + +let attr = Giraffe.ViewEngine.HtmlElements.attr + +let getItemActionAttributes (itemCode: string) = + let item = Entity.GetFirstByColumn "code" (StringTrim itemCode) + [(attr "data-item") <| jsonEncode item] + +let getGridActionAttributes (gridId: int) = [(attr "data-grid") <| jsonEncode gridId] + +let getActionAttributes (action: string) (actionValue: string) = + + match action with + | "item" -> getItemActionAttributes actionValue + | "grid" -> actionValue |> int |> getGridActionAttributes + | _ -> [] \ No newline at end of file diff --git a/Floorplan/Model.fs b/Floorplan/Model.fs index f7ac2db..98a6239 100644 --- a/Floorplan/Model.fs +++ b/Floorplan/Model.fs @@ -87,14 +87,20 @@ let saveOrderToTable orderXML tableNumber = File.WriteAllText(tableFile, tableXML) -let getTable (tableNumber : int) = +let getTableSafely (tableNumber: int) = let query = select { table "floorplan_tables" where (eq "table_number" tableNumber + eq "venue_id" (getCurrentVenue())) } - let result = query |> Database.Select - result |> first + query + |> Database.Select + |> Array.tryItem 0 + +let getTable (tableNumber : int) = + match getTableSafely tableNumber with + | None -> failwith $"Table {tableNumber} not found in current venue" + | Some table -> table let getTableById (id : int) = select { diff --git a/Floorplan/View.fs b/Floorplan/View.fs index 7dc3a7d..5e6d51f 100644 --- a/Floorplan/View.fs +++ b/Floorplan/View.fs @@ -8,9 +8,7 @@ open Giraffe.ViewEngine open DredgeFramework -let VisibleInMode (value: string list) = value |> jsonEncode |> (attr "data-visible-in-mode") -let InvisibleInMode (value: string list) = value |> jsonEncode |> (attr "data-invisible-in-mode") -let ActiveInMode (value: string) = value |> (attr "data-active-in-mode") + let pageContainer (clerk: clerk) roomMenu = diff --git a/Global/Router.fs b/Global/Router.fs index 3330747..50842ca 100644 --- a/Global/Router.fs +++ b/Global/Router.fs @@ -8,4 +8,11 @@ let htmlViewWithContext func = func (snd ctx) |> htmlView ) + |> warbler + +let htmlViewWithContextAndId (id: int) func = + (fun ctx -> + func (snd ctx) id + |> htmlView + ) |> warbler \ No newline at end of file diff --git a/Global/View.fs b/Global/View.fs index 543800d..a20d283 100644 --- a/Global/View.fs +++ b/Global/View.fs @@ -1,12 +1,20 @@ module DredgePos.Global.View -open Giraffe.ViewEngine open DredgeFramework +open DredgePos.Types +open Giraffe.ViewEngine let Value = attr "data-value" +let _table (value: floorplan_table) = value |> jsonEncode |> (attr "data-table") + +let VisibleInMode (value: string list) = value |> jsonEncode |> (attr "data-visible-in-mode") +let InvisibleInMode (value: string list) = value |> jsonEncode |> (attr "data-invisible-in-mode") +let ActiveInMode (value: string) = value |> (attr "data-active-in-mode") let innerText = str let lang key = language.get key |> str +let template = tag "template" + let scriptToHTML (scriptFile: string) = let scriptPath = $"/scripts/{scriptFile}" match FileExists ("wwwroot" + scriptPath) with @@ -89,6 +97,23 @@ let keyboards = [| alert |] +let posButton (extraClasses: string) attrs content = + let allAttrs = [_class $"posButton {extraClasses}"] |> List.append attrs + a allAttrs content + +let PosButton classes (attrs: Map) text = + let attrArray = + attrs + |> Map.map (fun key value -> + (attr key) (string value) + ) + |> Map.values + |> Array.ofSeq + + posButton classes [ + yield! attrArray + ] [str text] + let HtmlPage pageTitle scripts styles tags content = html [] [ head [] [ diff --git a/Migrations/PopulateTestData.fs b/Migrations/PopulateTestData.fs index 7d11b33..16d8453 100644 --- a/Migrations/PopulateTestData.fs +++ b/Migrations/PopulateTestData.fs @@ -4,6 +4,8 @@ open DredgeFramework open DredgePos.Types open System.IO +let spaceButton () = (Entity.GetFirstByColumn